Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTSurfaceLayers.m
41152 views
1
/*
2
* Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
26
#import "AWTSurfaceLayers.h"
27
#import "ThreadUtilities.h"
28
#import "LWCToolkit.h"
29
#import "JNIUtilities.h"
30
31
#import <QuartzCore/CATransaction.h>
32
#import <QuartzCore/CAMetalLayer.h>
33
34
@implementation AWTSurfaceLayers
35
36
@synthesize windowLayer;
37
38
- (id) initWithWindowLayer:(CALayer *)aWindowLayer {
39
self = [super init];
40
if (self == nil) return self;
41
42
self.windowLayer = aWindowLayer;
43
44
return self;
45
}
46
47
- (void) dealloc {
48
self.windowLayer = nil;
49
[super dealloc];
50
}
51
52
- (CALayer *) layer {
53
return layer;
54
}
55
56
- (void) setLayer:(CALayer *)newLayer {
57
if (layer != newLayer) {
58
if (layer != nil || newLayer == nil) {
59
[layer removeFromSuperlayer];
60
[layer release];
61
}
62
63
if (newLayer != nil) {
64
layer = [newLayer retain];
65
// REMIND: window layer -> container layer
66
[windowLayer addSublayer: layer];
67
}
68
}
69
}
70
71
// Updates back buffer size of the layer if it's an OpenGL/Metal layer
72
// including all OpenGL/Metal sublayers
73
+ (void) repaintLayersRecursively:(CALayer*)aLayer {
74
if ([aLayer isKindOfClass:[CAOpenGLLayer class]] ||
75
[aLayer isKindOfClass:[CAMetalLayer class]]) {
76
[aLayer setNeedsDisplay];
77
}
78
for(CALayer *child in aLayer.sublayers) {
79
[AWTSurfaceLayers repaintLayersRecursively: child];
80
}
81
}
82
83
- (void) setBounds:(CGRect)rect {
84
// translates values to the coordinate system of the "root" layer
85
rect.origin.y = windowLayer.bounds.size.height - rect.origin.y - rect.size.height;
86
[CATransaction begin];
87
[CATransaction setDisableActions:YES];
88
layer.frame = rect;
89
[CATransaction commit];
90
[AWTSurfaceLayers repaintLayersRecursively:layer];
91
}
92
93
@end
94
95
/*
96
* Class: sun_lwawt_macosx_CPlatformComponent
97
* Method: nativeCreateComponent
98
* Signature: ()J
99
*/
100
JNIEXPORT jlong JNICALL
101
Java_sun_lwawt_macosx_CPlatformComponent_nativeCreateComponent
102
(JNIEnv *env, jobject obj, jlong windowLayerPtr)
103
{
104
__block AWTSurfaceLayers *surfaceLayers = nil;
105
106
JNI_COCOA_ENTER(env);
107
108
[ThreadUtilities performOnMainThreadWaiting:YES block:^(){
109
110
CALayer *windowLayer = jlong_to_ptr(windowLayerPtr);
111
surfaceLayers = [[AWTSurfaceLayers alloc] initWithWindowLayer: windowLayer];
112
}];
113
114
JNI_COCOA_EXIT(env);
115
116
return ptr_to_jlong(surfaceLayers);
117
}
118
119
/*
120
* Class: sun_lwawt_macosx_CPlatformComponent
121
* Method: nativeSetBounds
122
* Signature: (JIIII)V
123
*/
124
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformComponent_nativeSetBounds
125
(JNIEnv *env, jclass clazz, jlong surfaceLayersPtr, jint x, jint y, jint width, jint height)
126
{
127
JNI_COCOA_ENTER(env);
128
129
AWTSurfaceLayers *surfaceLayers = OBJC(surfaceLayersPtr);
130
131
[ThreadUtilities performOnMainThreadWaiting:NO block:^(){
132
133
CGRect rect = CGRectMake(x, y, width, height);
134
[surfaceLayers setBounds: rect];
135
}];
136
137
JNI_COCOA_EXIT(env);
138
}
139
140