Mozilla/mozilla/java/webclient/src_moz/cocoa/CocoaBrowserControlCanvas.mm
edburns%acm.org ba350c1664 Checkpoint for mac os x reactivation.
Having trouble with the implementation of getHandleToPeer.

Current problem is that JAWT_DrawingSurface->Lock() is failing.

Why would that be?


git-svn-id: svn://10.0.0.236/trunk@173357 18797224-902f-48f8-a5cc-f745e15eee43
2005-05-13 06:40:12 +00:00

115 lines
3.7 KiB
Plaintext

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s): edburns <edburns@acm.org>
*/
/*
* CocoaBrowserControlCanvas.cpp
*/
#include <jawt_md.h>
#include <assert.h>
#include "CocoaBrowserControlCanvas.h"
#include "jni_util.h" //for throwing Exceptions to Java
jint CocoaBrowserControlCanvas::cocoaGetHandleToPeer(JNIEnv *env, jobject canvas, jobject graphics) {
printf("debug: edburns: in CocoaBrowserControlCanvas::nativeGetHandleToPeer\n");
JAWT awt;
JAWT_DrawingSurface* ds = NULL;
JAWT_DrawingSurfaceInfo* dsi = NULL;
JAWT_MacOSXDrawingSurfaceInfo* dsi_mac = NULL;
jboolean result = JNI_FALSE;
jint lock = 0;
NSView *view = NULL;
printf("debug: edburns: about to get AWT\n");
// get the AWT
awt.version = JAWT_VERSION_1_4;
printf("debug: edburns: set awt version: ok\n");
result = JAWT_GetAWT(env, &awt);
printf("debug: edburns: got awt: result: %d\n",result);
printf("debug: edburns: additional printf\n");
printf("debug: edburns: got AWT\n");
printf("debug: edburns: about to get drawing surface\n");
fflush(stdout);
// Get the drawing surface. This can be safely cached.
// Anything below the DS (DSI, contexts, etc)
// can possibly change/go away and should not be cached.
ds = awt.GetDrawingSurface(env, canvas);
printf("debug: edburns: got drawing surface: %d\n", ds);
fflush(stdout);
if (NULL == ds) {
util_ThrowExceptionToJava(env, "CocoaBrowserControlCanvas: can't get drawing surface");
}
printf("debug: edburns: about to lock drawing surface: %d\n", ds);
fflush(stdout);
// Lock the drawing surface
// You must lock EACH TIME before drawing
lock = ds->Lock(ds);
printf("debug: edburns: acquired lock: %d\n", lock);
fflush(stdout);
if (NULL == lock) {
util_ThrowExceptionToJava(env, "CocoaBrowserControlCanvas: can't lock drawing surface");
}
assert((lock & JAWT_LOCK_ERROR) == 0);
// Get the drawing surface info
dsi = ds->GetDrawingSurfaceInfo(ds);
// Check DrawingSurfaceInfo. This can be NULL on Mac OS X
// if the windowing system is not ready
if (dsi != NULL) {
// Get the platform-specific drawing info
// We will use this to get at Cocoa and CoreGraphics
// See <JavaVM/jawt_md.h>
dsi_mac = (JAWT_MacOSXDrawingSurfaceInfo*)dsi->platformInfo;
if (NULL == dsi_mac) {
util_ThrowExceptionToJava(env, "CocoaBrowserControlCanvas: can't get DrawingSurfaceInfo");
}
// Get the corresponding peer from the caller canvas
view = dsi_mac->cocoaViewRef;
// Free the DrawingSurfaceInfo
ds->FreeDrawingSurfaceInfo(dsi);
}
// Unlock the drawing surface
// You must unlock EACH TIME when done drawing
ds->Unlock(ds);
// Free the drawing surface (if not caching it)
awt.FreeDrawingSurface(ds);
return (jint) view;
}