AWTSurfaceLayers.m revision 5555
84N/A/*
84N/A * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
84N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
84N/A *
84N/A * This code is free software; you can redistribute it and/or modify it
84N/A * under the terms of the GNU General Public License version 2 only, as
84N/A * published by the Free Software Foundation. Oracle designates this
84N/A * particular file as subject to the "Classpath" exception as provided
84N/A * by Oracle in the LICENSE file that accompanied this code.
84N/A *
84N/A * This code is distributed in the hope that it will be useful, but WITHOUT
84N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
84N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
84N/A * version 2 for more details (a copy is included in the LICENSE file that
84N/A * accompanied this code).
84N/A *
84N/A * You should have received a copy of the GNU General Public License version
84N/A * 2 along with this work; if not, write to the Free Software Foundation,
84N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
873N/A *
84N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
84N/A * or visit www.oracle.com if you need additional information or have any
84N/A * questions.
84N/A */
84N/A
828N/A#import "AWTSurfaceLayers.h"
84N/A#import "ThreadUtilities.h"
84N/A#import "LWCToolkit.h"
84N/A
828N/A#import <JavaNativeFoundation/JavaNativeFoundation.h>
84N/A
84N/A@implementation AWTSurfaceLayers
623N/A
84N/A@synthesize windowLayer;
84N/A
84N/A- (id) initWithWindowLayer:(CALayer *)aWindowLayer {
84N/A self = [super init];
84N/A if (self == nil) return self;
84N/A
619N/A windowLayer = aWindowLayer;
84N/A
623N/A return self;
84N/A}
1194N/A
1194N/A
623N/A- (CALayer *) layer {
623N/A return layer;
623N/A}
623N/A
84N/A- (void) setLayer:(CALayer *)newLayer {
1186N/A if (layer != newLayer) {
1304N/A if (layer != nil || newLayer == nil) {
84N/A [layer removeFromSuperlayer];
84N/A [layer release];
1186N/A }
1186N/A
1186N/A if (newLayer != nil) {
1304N/A layer = [newLayer retain];
1186N/A // REMIND: window layer -> container layer
84N/A [windowLayer addSublayer: layer];
84N/A }
1194N/A }
1591N/A}
84N/A
481N/A// Updates back buffer size of the layer if it's an OpenGL layer
84N/A// including all OpenGL sublayers
1186N/A+ (void) repaintLayersRecursively:(CALayer*)aLayer {
1186N/A if ([aLayer isKindOfClass:[CAOpenGLLayer class]]) {
1186N/A [aLayer setNeedsDisplay];
1186N/A }
1510N/A for(CALayer *child in aLayer.sublayers) {
828N/A [AWTSurfaceLayers repaintLayersRecursively: child];
828N/A }
828N/A}
828N/A
828N/A- (void) setBounds:(CGRect)rect {
828N/A layer.anchorPoint = CGPointMake(0, 0);
828N/A
623N/A // translates values to the coordinate system of the "root" layer
828N/A CGFloat newY = windowLayer.bounds.size.height - rect.origin.y - rect.size.height;
84N/A CGRect newRect = CGRectMake(rect.origin.x, newY, rect.size.width, rect.size.height);
84N/A
84N/A layer.frame = newRect;
[AWTSurfaceLayers repaintLayersRecursively:layer];
}
@end
/*
* Class: sun_lwawt_macosx_CPlatformComponent
* Method: nativeCreateLayer
* Signature: ()J
*/
JNIEXPORT jlong JNICALL
Java_sun_lwawt_macosx_CPlatformComponent_nativeCreateComponent
(JNIEnv *env, jobject obj, jlong windowLayerPtr)
{
__block AWTSurfaceLayers *surfaceLayers = nil;
JNF_COCOA_ENTER(env);
[ThreadUtilities performOnMainThreadWaiting:YES block:^(){
AWT_ASSERT_APPKIT_THREAD;
CALayer *windowLayer = jlong_to_ptr(windowLayerPtr);
surfaceLayers = [[AWTSurfaceLayers alloc] initWithWindowLayer: windowLayer];
CFRetain(surfaceLayers);
[surfaceLayers release];
}];
JNF_COCOA_EXIT(env);
return ptr_to_jlong(surfaceLayers);
}
/*
* Class: sun_lwawt_macosx_CPlatformComponent
* Method: nativeSetBounds
* Signature: (JIIII)V
*/
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformComponent_nativeSetBounds
(JNIEnv *env, jclass clazz, jlong surfaceLayersPtr, jint x, jint y, jint width, jint height)
{
JNF_COCOA_ENTER(env);
AWTSurfaceLayers *surfaceLayers = OBJC(surfaceLayersPtr);
[ThreadUtilities performOnMainThreadWaiting:NO block:^(){
AWT_ASSERT_APPKIT_THREAD;
CGRect rect = CGRectMake(x, y, width, height);
[surfaceLayers setBounds: rect];
}];
JNF_COCOA_EXIT(env);
}