Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.desktop/macosx/classes/sun/java2d/metal/MTLLayer.java
41159 views
1
/*
2
* Copyright (c) 2019, 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
package sun.java2d.metal;
27
28
import sun.java2d.NullSurfaceData;
29
import sun.java2d.SurfaceData;
30
import sun.lwawt.LWWindowPeer;
31
import sun.lwawt.macosx.CFLayer;
32
import java.awt.GraphicsConfiguration;
33
import java.awt.Insets;
34
35
public class MTLLayer extends CFLayer {
36
37
private native long nativeCreateLayer();
38
private static native void nativeSetScale(long layerPtr, double scale);
39
40
// Pass the insets to native code to make adjustments in blitTexture
41
private static native void nativeSetInsets(long layerPtr, int top, int left);
42
private static native void validate(long layerPtr, MTLSurfaceData mtlsd);
43
private static native void blitTexture(long layerPtr);
44
45
private int scale = 1;
46
47
public MTLLayer(LWWindowPeer peer) {
48
super(0, true);
49
50
setPtr(nativeCreateLayer());
51
this.peer = peer;
52
}
53
54
public SurfaceData replaceSurfaceData() {
55
if (getBounds().isEmpty()) {
56
surfaceData = NullSurfaceData.theInstance;
57
return surfaceData;
58
}
59
60
// the layer redirects all painting to the buffer's graphics
61
// and blits the buffer to the layer surface (in display callback)
62
MTLGraphicsConfig gc = (MTLGraphicsConfig)getGraphicsConfiguration();
63
surfaceData = gc.createSurfaceData(this);
64
setScale(gc.getDevice().getScaleFactor());
65
if (peer != null) {
66
Insets insets = peer.getInsets();
67
execute(ptr -> nativeSetInsets(ptr, insets.top, insets.left));
68
}
69
// the layer holds a reference to the buffer, which in
70
// turn has a reference back to this layer
71
if (surfaceData instanceof MTLSurfaceData) {
72
validate((MTLSurfaceData)surfaceData);
73
}
74
75
return surfaceData;
76
}
77
78
public void validate(final MTLSurfaceData mtlsd) {
79
MTLRenderQueue rq = MTLRenderQueue.getInstance();
80
rq.lock();
81
try {
82
execute(ptr -> validate(ptr, mtlsd));
83
} finally {
84
rq.unlock();
85
}
86
}
87
88
@Override
89
public void dispose() {
90
// break the connection between the layer and the buffer
91
validate(null);
92
SurfaceData oldData = surfaceData;
93
surfaceData = NullSurfaceData.theInstance;;
94
if (oldData != null) {
95
oldData.flush();
96
}
97
super.dispose();
98
}
99
100
private void setScale(final int _scale) {
101
if (scale != _scale) {
102
scale = _scale;
103
execute(ptr -> nativeSetScale(ptr, scale));
104
}
105
}
106
107
// ----------------------------------------------------------------------
108
// NATIVE CALLBACKS
109
// ----------------------------------------------------------------------
110
111
private void drawInMTLContext() {
112
// tell the flusher thread not to update the intermediate buffer
113
// until we are done blitting from it
114
MTLRenderQueue rq = MTLRenderQueue.getInstance();
115
rq.lock();
116
try {
117
execute(ptr -> blitTexture(ptr));
118
} finally {
119
rq.unlock();
120
}
121
}
122
}
123
124