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