generic_native_drawing_works_but_not_for_mozilla
git-svn-id: svn://10.0.0.236/trunk@173697 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -31,7 +31,7 @@ import org.mozilla.webclient.BrowserControlCanvas;
|
||||
import org.mozilla.webclient.impl.wrapper_native.WCRunnable;
|
||||
import org.mozilla.webclient.impl.wrapper_native.NativeEventThread;
|
||||
|
||||
import java.awt.Graphics;
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -45,6 +45,7 @@ public class CocoaBrowserControlCanvas extends BrowserControlCanvas {
|
||||
|
||||
//New method for obtaining access to the Native Peer handle
|
||||
private native int getHandleToPeer();
|
||||
private native void paintMe(Graphics g);
|
||||
|
||||
/**
|
||||
* Obtain the native window handle for this
|
||||
@@ -63,6 +64,26 @@ public class CocoaBrowserControlCanvas extends BrowserControlCanvas {
|
||||
});
|
||||
return result.intValue();
|
||||
}
|
||||
|
||||
public void paint(Graphics g) {
|
||||
g.setColor(Color.green);
|
||||
g.fillRect(0, 0, 100, 100);
|
||||
|
||||
g.setColor(Color.blue);
|
||||
g.fillRect(5, 5, 90, 90);
|
||||
|
||||
// flush any outstanding graphics operations
|
||||
Toolkit.getDefaultToolkit().sync();
|
||||
// Call native code to render third (red) rect
|
||||
paintMe(g);
|
||||
|
||||
g.setColor(Color.yellow);
|
||||
g.fillRect(25, 25, 50, 50);
|
||||
|
||||
g.setColor(Color.black);
|
||||
g.fillRect(40, 40, 20, 20);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -137,7 +137,7 @@ CMMSRCS = cocoa/CocoaBrowserControlCanvas.mm
|
||||
CPPSRCS += cocoa/CocoaBrowserControlCanvasImpl.cpp
|
||||
DLL_SUFFIX = .jnilib
|
||||
#DSO_LDOPTS += -L/System/Library/Frameworks/JavaVM.Framework/Libraries -ljawt
|
||||
DSO_LDOPTS += -framework JavaVM -lobjc
|
||||
DSO_LDOPTS += -framework JavaVM -framework AppKit -lobjc -L../src_share
|
||||
else
|
||||
ifeq ($(OS_ARCH),WINNT)
|
||||
CPPSRCS += \
|
||||
|
||||
@@ -31,6 +31,7 @@ class CocoaBrowserControlCanvas {
|
||||
public:
|
||||
|
||||
static jint cocoaGetHandleToPeer(JNIEnv *env, jobject canvas);
|
||||
static void paintMe(JNIEnv *env, jobject canvas, jobject graphics);
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -98,5 +98,98 @@ jint CocoaBrowserControlCanvas::cocoaGetHandleToPeer(JNIEnv *env, jobject canvas
|
||||
// Free the drawing surface (if not caching it)
|
||||
awt.FreeDrawingSurface(ds);
|
||||
|
||||
printf("debug: edburns: CocoaBC: winPtr: %p\n", windowPtr);
|
||||
fflush(stdout);
|
||||
|
||||
return (jint) windowPtr;
|
||||
}
|
||||
|
||||
|
||||
void CocoaBrowserControlCanvas::paintMe(JNIEnv *env, jobject canvas, jobject graphics) {
|
||||
|
||||
JAWT awt;
|
||||
JAWT_DrawingSurface* ds = NULL;
|
||||
JAWT_DrawingSurfaceInfo* dsi = NULL;
|
||||
JAWT_MacOSXDrawingSurfaceInfo* dsi_mac = NULL;
|
||||
jboolean result = JNI_FALSE;
|
||||
jint lock = 0;
|
||||
jclass bcClass;
|
||||
jmethodID mid;
|
||||
|
||||
// get the AWT
|
||||
awt.version = JAWT_VERSION_1_4;
|
||||
result = JAWT_GetAWT(env, &awt);
|
||||
if (env->ExceptionOccurred()) {
|
||||
env->ExceptionDescribe();
|
||||
}
|
||||
assert(result != JNI_FALSE);
|
||||
|
||||
// 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);
|
||||
if (env->ExceptionOccurred()) {
|
||||
env->ExceptionDescribe();
|
||||
}
|
||||
assert(ds != NULL);
|
||||
|
||||
// Lock the drawing surface
|
||||
// You must lock EACH TIME before drawing
|
||||
lock = ds->Lock(ds);
|
||||
if (env->ExceptionOccurred()) {
|
||||
env->ExceptionDescribe();
|
||||
}
|
||||
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 (env->ExceptionOccurred()) {
|
||||
env->ExceptionDescribe();
|
||||
}
|
||||
|
||||
// Get the corresponding peer from the caller canvas
|
||||
NSView *view = dsi_mac->cocoaViewRef;
|
||||
|
||||
// Get the CoreGraphics context from the parent window.
|
||||
// DO NOT CACHE NSGraphicsContexts -- they may go away.
|
||||
NSWindow *window = [view window];
|
||||
NSGraphicsContext *ctxt = [NSGraphicsContext graphicsContextWithWindow:window];
|
||||
CGContextRef cg = [ctxt graphicsPort];
|
||||
|
||||
// Match Java's ctm
|
||||
NSRect windowRect = [window frame];
|
||||
CGContextConcatCTM(cg, CGAffineTransformMake(1, 0, 0, -1, dsi->bounds.x, windowRect.size.height-dsi->bounds.y));
|
||||
|
||||
// Draw a pattern using CoreGraphics
|
||||
CGContextSetRGBFillColor(cg, 1.0f, 0.0f, 0.0f, 1.0f);
|
||||
CGContextFillRect(cg, CGRectMake(15, 15, dsi->bounds.width-30, dsi->bounds.height-30));
|
||||
|
||||
// Free the DrawingSurfaceInfo
|
||||
ds->FreeDrawingSurfaceInfo(dsi);
|
||||
if (env->ExceptionOccurred()){
|
||||
env->ExceptionDescribe();
|
||||
}
|
||||
}
|
||||
|
||||
// Unlock the drawing surface
|
||||
// You must unlock EACH TIME when done drawing
|
||||
ds->Unlock(ds);
|
||||
if (env->ExceptionOccurred()) {
|
||||
env->ExceptionDescribe();
|
||||
}
|
||||
|
||||
// Free the drawing surface (if not caching it)
|
||||
awt.FreeDrawingSurface(ds);
|
||||
if (env->ExceptionOccurred()) {
|
||||
env->ExceptionDescribe();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,3 +44,7 @@ JNIEXPORT jint JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_CocoaBrow
|
||||
result = CocoaBrowserControlCanvas::cocoaGetHandleToPeer(env, canvas);
|
||||
return result;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_CocoaBrowserControlCanvas_paintMe(JNIEnv *env, jobject canvas, jobject graphics) {
|
||||
CocoaBrowserControlCanvas::paintMe(env, canvas, graphics);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user