Skip to content

Commit

Permalink
OSX/CALayer: Simplify FixCALayerLayout()/layoutSurfaceLayer() call, n…
Browse files Browse the repository at this point in the history
…o more need for explicit call

- OffscreenLayerSurface.layoutSurfaceLayer() removed, no more required

- JAWTWindow adds a ComponentListener, which issues FixCALayerLayout() at resized, moved and shown.

- MyNSOpenGLLayer no more requires fix*Size() methods

- MyNSOpenGLLayer::setDedicatedSize() need no explicit CATransaction, performed by caller.
  • Loading branch information
sgothel committed Mar 14, 2013
1 parent 896e8b0 commit dd705f1
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 94 deletions.
8 changes: 3 additions & 5 deletions src/jogl/classes/javax/media/opengl/awt/GLCanvas.java
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,9 @@ private final void setRealizedImpl(boolean realized) {
_lock.lock();
try {
final GLDrawable _drawable = drawable;
if( null == _drawable || realized && ( 0 >= _drawable.getWidth() || 0 >= _drawable.getHeight() ) ) {
return;
if( null == _drawable || realized == _drawable.isRealized() ||
realized && ( 0 >= _drawable.getWidth() || 0 >= _drawable.getHeight() ) ) {
return;
}
_drawable.setRealized(realized);
if( realized && _drawable.isRealized() ) {
Expand Down Expand Up @@ -705,9 +706,6 @@ public void reshape(int x, int y, int width, int height) {
}
}
sendReshape = true; // async if display() doesn't get called below, but avoiding deadlock
if(null != jawtWindow && jawtWindow.isOffscreenLayerSurfaceEnabled() ) {
jawtWindow.layoutSurfaceLayer();
}
}
}
}
Expand Down
63 changes: 1 addition & 62 deletions src/jogl/native/macosx/MacOSXWindowSystemInterface-calayer.m
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,6 @@ - (void) setNewPBuffer: (NSOpenGLPixelBuffer*)p;
- (void) applyNewPBuffer;

- (void)setDedicatedSize:(CGSize)size; // @NWDedicatedSize
- (CGRect)fixMyFrame;
- (CGRect)fixSuperPosition;
- (id<CAAction>)actionForKey:(NSString *)key ;
- (NSOpenGLPixelFormat *)openGLPixelFormatForDisplayMask:(uint32_t)mask;
- (NSOpenGLContext *)openGLContextForPixelFormat:(NSOpenGLPixelFormat *)pixelFormat;
Expand Down Expand Up @@ -364,14 +362,6 @@ - (Bool) validateTexSize: (int) _texWidth texHeight: (int) _texHeight
if(_texHeight != texHeight || _texWidth != texWidth) {
texWidth = _texWidth;
texHeight = _texHeight;
/**
CGRect lRect = [self bounds];
lRect.origin.x = 0;
lRect.origin.y = 0;
lRect.size.width = texWidth;
lRect.size.height = texHeight;
[self setFrame: lRect]; */
CGRect lRect = [self fixMyFrame];

GLfloat texCoordWidth, texCoordHeight;
if(NULL != pbuffer) {
Expand All @@ -394,13 +384,13 @@ - (Bool) validateTexSize: (int) _texWidth texHeight: (int) _texHeight
gl_texCoords[4] = texCoordWidth;
gl_texCoords[6] = texCoordWidth;
#ifdef VERBOSE_ON
CGRect lRect = [self bounds];
DBG_PRINT("MyNSOpenGLLayer::validateTexSize %p -> tex %dx%d, bounds: %lf/%lf %lfx%lf\n",
self, texWidth, texHeight,
lRect.origin.x, lRect.origin.y, lRect.size.width, lRect.size.height);
#endif
return YES;
} else {
[self fixMyFrame];
return NO;
}
}
Expand Down Expand Up @@ -549,69 +539,18 @@ - (void)setDedicatedSize:(CGSize)size {
DBG_PRINT("MyNSOpenGLLayer::setDedicatedSize: %p, texSize %dx%d <- %lfx%lf\n",
self, texWidth, texHeight, size.width, size.height);

[CATransaction begin];
[CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions];

dedicatedWidth = size.width;
dedicatedHeight = size.height;

CGRect rect = CGRectMake(0, 0, dedicatedWidth, dedicatedHeight);
[self setFrame: rect];

[CATransaction commit];
}

- (void) setFrame:(CGRect) frame {
CGRect rect = CGRectMake(0, 0, dedicatedWidth, dedicatedHeight);
[super setFrame: rect];
}

- (CGRect)fixMyFrame
{
CGRect lRect = [self frame];

// With Java7 our root CALayer's frame gets off-limit -> force 0/0 origin!
if( lRect.origin.x!=0 || lRect.origin.y!=0 || lRect.size.width!=texWidth || lRect.size.height!=texHeight) {
DBG_PRINT("MyNSOpenGLLayer::fixMyFrame: %p, 0/0 texSize %dx%d -> Frame[%lf/%lf %lfx%lf]\n",
self, texWidth, texHeight,
lRect.origin.x, lRect.origin.y, lRect.size.width, lRect.size.height);

[CATransaction begin];
[CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions];

lRect.origin.x = 0;
lRect.origin.y = 0;
lRect.size.width=texWidth;
lRect.size.height=texHeight;
[self setFrame: lRect];

[CATransaction commit];
}
return lRect;
}

- (CGRect)fixSuperPosition
{
CALayer * superL = [self superlayer];
CGRect lRect = [superL frame];

// With Java7 our root CALayer's frame gets off-limit -> force 0/0 origin!
if( lRect.origin.x!=0 || lRect.origin.y!=0 ) {
DBG_PRINT("MyNSOpenGLLayer::fixSuperPosition: %p, 0/0 -> Super Frame[%lf/%lf %lfx%lf]\n",
self, lRect.origin.x, lRect.origin.y, lRect.size.width, lRect.size.height);

[CATransaction begin];
[CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions];

lRect.origin.x = 0;
lRect.origin.y = 0;
[superL setPosition: lRect.origin];

[CATransaction commit];
}
return lRect;
}

- (id<CAAction>)actionForKey:(NSString *)key
{
DBG_PRINT("MyNSOpenGLLayer::actionForKey.0 %p key %s -> NIL\n", self, [key UTF8String]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@

import java.awt.Component;
import java.awt.Container;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.applet.Applet;
import javax.media.nativewindow.AbstractGraphicsConfiguration;
import javax.media.nativewindow.AbstractGraphicsDevice;
Expand Down Expand Up @@ -110,6 +112,25 @@ private void init(Component windowObject) throws NativeWindowException {
this.component = windowObject;
this.isApplet = false;
this.offscreenSurfaceLayer = 0;
this.component.addComponentListener(new ComponentListener() {
@Override
public void componentResized(ComponentEvent e) {
layoutSurfaceLayerIfEnabled();
}

@Override
public void componentMoved(ComponentEvent e) {
layoutSurfaceLayerIfEnabled();
}

@Override
public void componentShown(ComponentEvent e) {
layoutSurfaceLayerIfEnabled();
}

@Override
public void componentHidden(ComponentEvent e) { }
});
}

protected synchronized void invalidate() {
Expand Down Expand Up @@ -215,16 +236,27 @@ public final void attachSurfaceLayer(final long layerHandle) throws NativeWindow
}
protected abstract void attachSurfaceLayerImpl(final long layerHandle);

@Override
public void layoutSurfaceLayer() throws NativeWindowException {
if( !isOffscreenLayerSurfaceEnabled() ) {
throw new NativeWindowException("Not an offscreen layer surface");
}
if( 0 != offscreenSurfaceLayer) {
/**
* Layout the offscreen layer according to the implementing class's constraints.
* <p>
* This method allows triggering a re-layout of the offscreen surface
* in case the implementation requires it.
* </p>
* <p>
* Call this method if any parent or ancestor's layout has been changed,
* which could affects the layout of this surface.
* </p>
* @see #isOffscreenLayerSurfaceEnabled()
* @throws NativeWindowException if {@link #isOffscreenLayerSurfaceEnabled()} == false
*/
protected void layoutSurfaceLayerImpl() {}

private final void layoutSurfaceLayerIfEnabled() throws NativeWindowException {
if( isOffscreenLayerSurfaceEnabled() && 0 != offscreenSurfaceLayer ) {
layoutSurfaceLayerImpl();
}
}
protected void layoutSurfaceLayerImpl() {}


@Override
public final void detachSurfaceLayer() throws NativeWindowException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,6 @@ public interface OffscreenLayerSurface {
*/
public void attachSurfaceLayer(final long layerHandle) throws NativeWindowException;

/**
* Layout the offscreen layer according to the implementing class's constraints.
* <p>
* This method allows triggering a re-layout of the offscreen surface
* in case the implementation requires it.
* </p>
* <p>
* Call this method if any parent or ancestor's layout has been changed,
* which could affects the layout of this surface.
* </p>
* @see #isOffscreenLayerSurfaceEnabled()
* @throws NativeWindowException if {@link #isOffscreenLayerSurfaceEnabled()} == false
*/
public void layoutSurfaceLayer() throws NativeWindowException;

/**
* Detaches a previously attached offscreen layer from this offscreen layer surface.
* @see #attachSurfaceLayer(long)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ protected void invalidateNative() {
}

protected void attachSurfaceLayerImpl(final long layerHandle) {
OSXUtil.AddCASublayer(rootSurfaceLayerHandle, layerHandle);
OSXUtil.AddCASublayer(rootSurfaceLayerHandle, layerHandle, getWidth(), getHeight());
}

protected void layoutSurfaceLayerImpl() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,14 @@ public static long CreateCALayer(final int x, final int y, final int width, fina
* @see #CreateCALayer(int, int, int, int)
* @see #RemoveCASublayer(long, long)
*/
public static void AddCASublayer(final long rootCALayer, final long subCALayer) {
public static void AddCASublayer(final long rootCALayer, final long subCALayer, final int width, final int height) {
if(0==rootCALayer || 0==subCALayer) {
throw new IllegalArgumentException("rootCALayer 0x"+Long.toHexString(rootCALayer)+", subCALayer 0x"+Long.toHexString(subCALayer));
}
RunOnMainThread(false, new Runnable() {
public void run() {
AddCASublayer0(rootCALayer, subCALayer);
FixCALayerLayout0(rootCALayer, subCALayer, width, height);
}
});
}
Expand Down
3 changes: 0 additions & 3 deletions src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java
Original file line number Diff line number Diff line change
Expand Up @@ -445,9 +445,6 @@ public void reshape(int x, int y, int width, int height) {
}
if( validateComponent(true, null) ) {
// newtChild.setSize(width, height);
if(null != jawtWindow && jawtWindow.isOffscreenLayerSurfaceEnabled() ) {
jawtWindow.layoutSurfaceLayer();
}
}
}
}
Expand Down

0 comments on commit dd705f1

Please sign in to comment.