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/CGLSurfaceData.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 java.awt.Image;
30
import java.awt.Rectangle;
31
import java.awt.image.ColorModel;
32
33
import sun.java2d.SurfaceData;
34
35
public abstract class CGLSurfaceData extends OGLSurfaceData {
36
37
private final int scale;
38
final int width;
39
final int height;
40
private final CGLGraphicsConfig graphicsConfig;
41
42
private native void initOps(OGLGraphicsConfig gc, long pConfigInfo,
43
long pPeerData, long layerPtr, int xoff,
44
int yoff, boolean isOpaque);
45
46
private CGLSurfaceData(CGLLayer layer, CGLGraphicsConfig gc,
47
ColorModel cm, int type, int width, int height) {
48
super(gc, cm, type);
49
// TEXTURE shouldn't be scaled, it is used for managed BufferedImages.
50
scale = type == TEXTURE ? 1 : gc.getDevice().getScaleFactor();
51
this.width = width * scale;
52
this.height = height * scale;
53
this.graphicsConfig = gc;
54
55
long layerPtr = 0L;
56
boolean isOpaque = true;
57
if (layer != null) {
58
layerPtr = layer.getPointer();
59
isOpaque = layer.isOpaque();
60
}
61
// TODO delete the native code: pPeerData, xoff, yoff are always zero
62
initOps(gc, gc.getNativeConfigInfo(), 0, layerPtr, 0, 0, isOpaque);
63
}
64
65
@Override //SurfaceData
66
public GraphicsConfiguration getDeviceConfiguration() {
67
return graphicsConfig;
68
}
69
70
/**
71
* Creates a SurfaceData object representing the intermediate buffer
72
* between the Java2D flusher thread and the AppKit thread.
73
*/
74
public static CGLLayerSurfaceData createData(CGLLayer layer) {
75
CGLGraphicsConfig gc = (CGLGraphicsConfig) layer.getGraphicsConfiguration();
76
Rectangle r = layer.getBounds();
77
return new CGLLayerSurfaceData(layer, gc, r.width, r.height);
78
}
79
80
/**
81
* Creates a SurfaceData object representing an off-screen buffer (either a
82
* FBO or Texture).
83
*/
84
public static CGLOffScreenSurfaceData createData(CGLGraphicsConfig gc,
85
int width, int height, ColorModel cm, Image image, int type) {
86
return new CGLOffScreenSurfaceData(gc, width, height, image, cm, type);
87
}
88
89
@Override
90
public double getDefaultScaleX() {
91
return scale;
92
}
93
94
@Override
95
public double getDefaultScaleY() {
96
return scale;
97
}
98
99
@Override
100
public Rectangle getBounds() {
101
return new Rectangle(width, height);
102
}
103
104
protected native void clearWindow();
105
106
/**
107
* A surface which implements an intermediate buffer between
108
* the Java2D flusher thread and the AppKit thread.
109
*
110
* This surface serves as a buffer attached to a CGLLayer and
111
* the layer redirects all painting to the buffer's graphics.
112
*/
113
public static class CGLLayerSurfaceData extends CGLSurfaceData {
114
115
private final CGLLayer layer;
116
117
private CGLLayerSurfaceData(CGLLayer layer, CGLGraphicsConfig gc,
118
int width, int height) {
119
super(layer, gc, gc.getColorModel(), FBOBJECT, width, height);
120
this.layer = layer;
121
initSurface(this.width, this.height);
122
}
123
124
@Override
125
public SurfaceData getReplacement() {
126
return layer.getSurfaceData();
127
}
128
129
@Override
130
boolean isOnScreen() {
131
return true;
132
}
133
134
@Override
135
public Object getDestination() {
136
return layer.getDestination();
137
}
138
139
@Override
140
public int getTransparency() {
141
return layer.getTransparency();
142
}
143
144
@Override
145
public void invalidate() {
146
super.invalidate();
147
clearWindow();
148
}
149
}
150
151
/**
152
* SurfaceData object representing an off-screen buffer (either a FBO or
153
* Texture).
154
*/
155
public static class CGLOffScreenSurfaceData extends CGLSurfaceData {
156
157
private final Image offscreenImage;
158
159
private CGLOffScreenSurfaceData(CGLGraphicsConfig gc, int width,
160
int height, Image image,
161
ColorModel cm, int type) {
162
super(null, gc, cm, type, width, height);
163
offscreenImage = image;
164
initSurface(this.width, this.height);
165
}
166
167
@Override
168
public SurfaceData getReplacement() {
169
return restoreContents(offscreenImage);
170
}
171
172
/**
173
* Returns destination Image associated with this SurfaceData.
174
*/
175
@Override
176
public Object getDestination() {
177
return offscreenImage;
178
}
179
}
180
}
181
182