Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/macosx/native_NOTIOS/sun/awt/AWTSurfaceLayers.m
38829 views
/*1* Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425#import "AWTSurfaceLayers.h"26#import "ThreadUtilities.h"27#import "LWCToolkit.h"2829#import <JavaNativeFoundation/JavaNativeFoundation.h>30#import <QuartzCore/CATransaction.h>3132@implementation AWTSurfaceLayers3334@synthesize windowLayer;3536- (id) initWithWindowLayer:(CALayer *)aWindowLayer {37self = [super init];38if (self == nil) return self;3940self.windowLayer = aWindowLayer;4142return self;43}4445- (void) dealloc {46self.windowLayer = nil;47[super dealloc];48}4950- (CALayer *) layer {51return layer;52}5354- (void) setLayer:(CALayer *)newLayer {55if (layer != newLayer) {56if (layer != nil || newLayer == nil) {57[layer removeFromSuperlayer];58[layer release];59}6061if (newLayer != nil) {62layer = [newLayer retain];63// REMIND: window layer -> container layer64[windowLayer addSublayer: layer];65}66}67}6869// Updates back buffer size of the layer if it's an OpenGL layer70// including all OpenGL sublayers71+ (void) repaintLayersRecursively:(CALayer*)aLayer {72if ([aLayer isKindOfClass:[CAOpenGLLayer class]]) {73[aLayer setNeedsDisplay];74}75for(CALayer *child in aLayer.sublayers) {76[AWTSurfaceLayers repaintLayersRecursively: child];77}78}7980- (void) setBounds:(CGRect)rect {81// translates values to the coordinate system of the "root" layer82rect.origin.y = windowLayer.bounds.size.height - rect.origin.y - rect.size.height;83[CATransaction begin];84[CATransaction setDisableActions:YES];85layer.frame = rect;86[CATransaction commit];87[AWTSurfaceLayers repaintLayersRecursively:layer];88}8990@end9192/*93* Class: sun_lwawt_macosx_CPlatformComponent94* Method: nativeCreateLayer95* Signature: ()J96*/97JNIEXPORT jlong JNICALL98Java_sun_lwawt_macosx_CPlatformComponent_nativeCreateComponent99(JNIEnv *env, jobject obj, jlong windowLayerPtr)100{101__block AWTSurfaceLayers *surfaceLayers = nil;102103JNF_COCOA_ENTER(env);104105[ThreadUtilities performOnMainThreadWaiting:YES block:^(){106107CALayer *windowLayer = jlong_to_ptr(windowLayerPtr);108surfaceLayers = [[AWTSurfaceLayers alloc] initWithWindowLayer: windowLayer];109}];110111JNF_COCOA_EXIT(env);112113return ptr_to_jlong(surfaceLayers);114}115116/*117* Class: sun_lwawt_macosx_CPlatformComponent118* Method: nativeSetBounds119* Signature: (JIIII)V120*/121JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformComponent_nativeSetBounds122(JNIEnv *env, jclass clazz, jlong surfaceLayersPtr, jint x, jint y, jint width, jint height)123{124JNF_COCOA_ENTER(env);125126AWTSurfaceLayers *surfaceLayers = OBJC(surfaceLayersPtr);127128[ThreadUtilities performOnMainThreadWaiting:NO block:^(){129130CGRect rect = CGRectMake(x, y, width, height);131[surfaceLayers setBounds: rect];132}];133134JNF_COCOA_EXIT(env);135}136137138