Path: blob/master/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTSurfaceLayers.m
41152 views
/*1* Copyright (c) 2011, 2021, 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"28#import "JNIUtilities.h"2930#import <QuartzCore/CATransaction.h>31#import <QuartzCore/CAMetalLayer.h>3233@implementation AWTSurfaceLayers3435@synthesize windowLayer;3637- (id) initWithWindowLayer:(CALayer *)aWindowLayer {38self = [super init];39if (self == nil) return self;4041self.windowLayer = aWindowLayer;4243return self;44}4546- (void) dealloc {47self.windowLayer = nil;48[super dealloc];49}5051- (CALayer *) layer {52return layer;53}5455- (void) setLayer:(CALayer *)newLayer {56if (layer != newLayer) {57if (layer != nil || newLayer == nil) {58[layer removeFromSuperlayer];59[layer release];60}6162if (newLayer != nil) {63layer = [newLayer retain];64// REMIND: window layer -> container layer65[windowLayer addSublayer: layer];66}67}68}6970// Updates back buffer size of the layer if it's an OpenGL/Metal layer71// including all OpenGL/Metal sublayers72+ (void) repaintLayersRecursively:(CALayer*)aLayer {73if ([aLayer isKindOfClass:[CAOpenGLLayer class]] ||74[aLayer isKindOfClass:[CAMetalLayer class]]) {75[aLayer setNeedsDisplay];76}77for(CALayer *child in aLayer.sublayers) {78[AWTSurfaceLayers repaintLayersRecursively: child];79}80}8182- (void) setBounds:(CGRect)rect {83// translates values to the coordinate system of the "root" layer84rect.origin.y = windowLayer.bounds.size.height - rect.origin.y - rect.size.height;85[CATransaction begin];86[CATransaction setDisableActions:YES];87layer.frame = rect;88[CATransaction commit];89[AWTSurfaceLayers repaintLayersRecursively:layer];90}9192@end9394/*95* Class: sun_lwawt_macosx_CPlatformComponent96* Method: nativeCreateComponent97* Signature: ()J98*/99JNIEXPORT jlong JNICALL100Java_sun_lwawt_macosx_CPlatformComponent_nativeCreateComponent101(JNIEnv *env, jobject obj, jlong windowLayerPtr)102{103__block AWTSurfaceLayers *surfaceLayers = nil;104105JNI_COCOA_ENTER(env);106107[ThreadUtilities performOnMainThreadWaiting:YES block:^(){108109CALayer *windowLayer = jlong_to_ptr(windowLayerPtr);110surfaceLayers = [[AWTSurfaceLayers alloc] initWithWindowLayer: windowLayer];111}];112113JNI_COCOA_EXIT(env);114115return ptr_to_jlong(surfaceLayers);116}117118/*119* Class: sun_lwawt_macosx_CPlatformComponent120* Method: nativeSetBounds121* Signature: (JIIII)V122*/123JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformComponent_nativeSetBounds124(JNIEnv *env, jclass clazz, jlong surfaceLayersPtr, jint x, jint y, jint width, jint height)125{126JNI_COCOA_ENTER(env);127128AWTSurfaceLayers *surfaceLayers = OBJC(surfaceLayersPtr);129130[ThreadUtilities performOnMainThreadWaiting:NO block:^(){131132CGRect rect = CGRectMake(x, y, width, height);133[surfaceLayers setBounds: rect];134}];135136JNI_COCOA_EXIT(env);137}138139140