diff --git a/glass/glass-lib-macosx/src/GlassLayer3D.m b/glass/glass-lib-macosx/src/GlassLayer3D.m --- a/glass/glass-lib-macosx/src/GlassLayer3D.m +++ b/glass/glass-lib-macosx/src/GlassLayer3D.m @@ -112,8 +112,13 @@ LOG(" GlassLayer3D context: %p", self->_ctx); self->isHiDPIAware = HiDPIAware; - - [self setAsynchronous:YES]; // allow the layer to check for dirty flag and repaint if needed + + if ((getenv("GLASS_LAYER_ASYNC") != NULL) && (atoi(getenv("GLASS_LAYER_ASYNC")))) { + [self setAsynchronous:YES]; // force asynchrous painting of layers + } else { + [self setAsynchronous:NO]; // repaint when glass sets the dirty flag or from another thread + //[self setAsynchronous:YES]; // allow the layer to check for dirty flag and repaint if needed + } [self setAutoresizingMask:(kCALayerWidthSizable|kCALayerHeightSizable)]; [self setContentsGravity:kCAGravityTopLeft]; diff --git a/glass/glass-lib-macosx/src/GlassView.h b/glass/glass-lib-macosx/src/GlassView.h --- a/glass/glass-lib-macosx/src/GlassView.h +++ b/glass/glass-lib-macosx/src/GlassView.h @@ -24,6 +24,7 @@ */ #import +#import #import #import "GlassHostView.h" diff --git a/glass/glass-lib-macosx/src/GlassView.m b/glass/glass-lib-macosx/src/GlassView.m --- a/glass/glass-lib-macosx/src/GlassView.m +++ b/glass/glass-lib-macosx/src/GlassView.m @@ -620,6 +620,28 @@ { [view end]; // [view unlockFocus]; + + // Force the layer to draw from a background thread by + // damaging and flushing. This improves FPS because it + // forces drawing to happen when a frame is ready from + // Prism. For some reason, perhaps because of the remote + // layer, drawing from a background thread does not work + // in the browser so the opimization is turned off. + // + // NOTE: Changing the layer to be asynchronous will disable + // this optimization should backround thread drawing cause + // problems in the future. + if ([view window]) { + GlassWindow *window = (GlassWindow*)[[view window] delegate]; + if (window && !window->isEmbedded) { + CAOpenGLLayer *layer = (CAOpenGLLayer *)[view layer]; + if (layer && [layer isAsynchronous] == NO) { + [layer display]; + [CATransaction flush]; + } + } + } + [view release]; } GLASS_POOL_POP; // it was pushed by "_begin" diff --git a/glass/glass-lib-macosx/src/GlassViewDelegate.h b/glass/glass-lib-macosx/src/GlassViewDelegate.h --- a/glass/glass-lib-macosx/src/GlassViewDelegate.h +++ b/glass/glass-lib-macosx/src/GlassViewDelegate.h @@ -56,6 +56,8 @@ NSEvent *lastEvent; NSDragOperation dragOperation; NSInteger lastTrackingNumber; + + BOOL wasAsync; } - (id)initWithView:(NSView*)view withJview:(jobject)jview; diff --git a/glass/glass-lib-macosx/src/GlassViewDelegate.m b/glass/glass-lib-macosx/src/GlassViewDelegate.m --- a/glass/glass-lib-macosx/src/GlassViewDelegate.m +++ b/glass/glass-lib-macosx/src/GlassViewDelegate.m @@ -1034,6 +1034,11 @@ frame.origin = pointInScreenCoords; //NSLog(@"pointInScreenCoords: %.2f,%.2f", pointInScreenCoords.x, pointInScreenCoords.y); + if (self->nsView && [nsView layer]) { + CAOpenGLLayer * layer = (CAOpenGLLayer*)[nsView layer]; + self->wasAsync = [layer isAsynchronous]; + [layer setAsynchronous: YES]; + } @try { // 0. Retain the view while it's in the FS mode @@ -1122,6 +1127,11 @@ { LOG("GlassViewDelegate exitFullscreenWithAnimate"); + if (self->nsView && [nsView layer]) { + CAOpenGLLayer * layer = (CAOpenGLLayer*)[nsView layer]; + [layer setAsynchronous: self->wasAsync]; + } + @try { if (self->nativeFullScreenModeWindow) diff --git a/glass/glass-lib-macosx/src/GlassWindow+Java.m b/glass/glass-lib-macosx/src/GlassWindow+Java.m --- a/glass/glass-lib-macosx/src/GlassWindow+Java.m +++ b/glass/glass-lib-macosx/src/GlassWindow+Java.m @@ -91,6 +91,7 @@ if (self == nil) { return nil; } + isEmbedded = jIsChild; if (jIsChild == JNI_FALSE) { if (windowStyle & (NSUtilityWindowMask | NSNonactivatingPanelMask)) { diff --git a/glass/glass-lib-macosx/src/GlassWindow.h b/glass/glass-lib-macosx/src/GlassWindow.h --- a/glass/glass-lib-macosx/src/GlassWindow.h +++ b/glass/glass-lib-macosx/src/GlassWindow.h @@ -53,6 +53,7 @@ BOOL isTransparent; BOOL isDecorated; BOOL isResizable; + BOOL isEmbedded; BOOL suppressWindowMoveEvent; BOOL suppressWindowResizeEvent;