Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/classes/sun/java2d/opengl/GLXSurfaceData.java
32288 views
1
/*
2
* Copyright (c) 2003, 2008, 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.GraphicsDevice;
30
import java.awt.GraphicsEnvironment;
31
import java.awt.Image;
32
import java.awt.Rectangle;
33
import java.awt.Transparency;
34
import java.awt.image.ColorModel;
35
import sun.awt.X11ComponentPeer;
36
import sun.java2d.SurfaceData;
37
import sun.java2d.loops.SurfaceType;
38
39
public abstract class GLXSurfaceData extends OGLSurfaceData {
40
41
protected X11ComponentPeer peer;
42
private GLXGraphicsConfig graphicsConfig;
43
44
private native void initOps(OGLGraphicsConfig gc, X11ComponentPeer peer,
45
long aData);
46
protected native boolean initPbuffer(long pData, long pConfigInfo,
47
boolean isOpaque,
48
int width, int height);
49
50
protected GLXSurfaceData(X11ComponentPeer peer, GLXGraphicsConfig gc,
51
ColorModel cm, int type)
52
{
53
super(gc, cm, type);
54
this.peer = peer;
55
this.graphicsConfig = gc;
56
initOps(gc, peer, graphicsConfig.getAData());
57
}
58
59
public GraphicsConfiguration getDeviceConfiguration() {
60
return graphicsConfig;
61
}
62
63
/**
64
* Creates a SurfaceData object representing the primary (front) buffer
65
* of an on-screen Window.
66
*/
67
public static GLXWindowSurfaceData createData(X11ComponentPeer peer) {
68
GLXGraphicsConfig gc = getGC(peer);
69
return new GLXWindowSurfaceData(peer, gc);
70
}
71
72
/**
73
* Creates a SurfaceData object representing the back buffer of a
74
* double-buffered on-screen Window.
75
*/
76
public static GLXOffScreenSurfaceData createData(X11ComponentPeer peer,
77
Image image,
78
int type)
79
{
80
GLXGraphicsConfig gc = getGC(peer);
81
Rectangle r = peer.getBounds();
82
if (type == FLIP_BACKBUFFER) {
83
return new GLXOffScreenSurfaceData(peer, gc, r.width, r.height,
84
image, peer.getColorModel(),
85
FLIP_BACKBUFFER);
86
} else {
87
return new GLXVSyncOffScreenSurfaceData(peer, gc, r.width, r.height,
88
image, peer.getColorModel(),
89
type);
90
}
91
}
92
93
/**
94
* Creates a SurfaceData object representing an off-screen buffer (either
95
* a Pbuffer or Texture).
96
*/
97
public static GLXOffScreenSurfaceData createData(GLXGraphicsConfig gc,
98
int width, int height,
99
ColorModel cm,
100
Image image, int type)
101
{
102
return new GLXOffScreenSurfaceData(null, gc, width, height,
103
image, cm, type);
104
}
105
106
public static GLXGraphicsConfig getGC(X11ComponentPeer peer) {
107
if (peer != null) {
108
return (GLXGraphicsConfig)peer.getGraphicsConfiguration();
109
} else {
110
// REMIND: this should rarely (never?) happen, but what if
111
// default config is not GLX?
112
GraphicsEnvironment env =
113
GraphicsEnvironment.getLocalGraphicsEnvironment();
114
GraphicsDevice gd = env.getDefaultScreenDevice();
115
return (GLXGraphicsConfig)gd.getDefaultConfiguration();
116
}
117
}
118
119
public static class GLXWindowSurfaceData extends GLXSurfaceData {
120
121
public GLXWindowSurfaceData(X11ComponentPeer peer,
122
GLXGraphicsConfig gc)
123
{
124
super(peer, gc, peer.getColorModel(), WINDOW);
125
}
126
127
public SurfaceData getReplacement() {
128
return peer.getSurfaceData();
129
}
130
131
public Rectangle getBounds() {
132
Rectangle r = peer.getBounds();
133
r.x = r.y = 0;
134
return r;
135
}
136
137
/**
138
* Returns destination Component associated with this SurfaceData.
139
*/
140
public Object getDestination() {
141
return peer.getTarget();
142
}
143
}
144
145
/**
146
* A surface which implements a v-synced flip back-buffer with COPIED
147
* FlipContents.
148
*
149
* This surface serves as a back-buffer to the outside world, while
150
* it is actually an offscreen surface. When the BufferStrategy this surface
151
* belongs to is showed, it is first copied to the real private
152
* FLIP_BACKBUFFER, which is then flipped.
153
*/
154
public static class GLXVSyncOffScreenSurfaceData extends
155
GLXOffScreenSurfaceData
156
{
157
private GLXOffScreenSurfaceData flipSurface;
158
159
public GLXVSyncOffScreenSurfaceData(X11ComponentPeer peer,
160
GLXGraphicsConfig gc,
161
int width, int height,
162
Image image, ColorModel cm,
163
int type)
164
{
165
super(peer, gc, width, height, image, cm, type);
166
flipSurface = GLXSurfaceData.createData(peer, image, FLIP_BACKBUFFER);
167
}
168
169
public SurfaceData getFlipSurface() {
170
return flipSurface;
171
}
172
173
@Override
174
public void flush() {
175
flipSurface.flush();
176
super.flush();
177
}
178
179
}
180
181
public static class GLXOffScreenSurfaceData extends GLXSurfaceData {
182
183
private Image offscreenImage;
184
private int width, height;
185
186
public GLXOffScreenSurfaceData(X11ComponentPeer peer,
187
GLXGraphicsConfig gc,
188
int width, int height,
189
Image image, ColorModel cm,
190
int type)
191
{
192
super(peer, gc, cm, type);
193
194
this.width = width;
195
this.height = height;
196
offscreenImage = image;
197
198
initSurface(width, height);
199
}
200
201
public SurfaceData getReplacement() {
202
return restoreContents(offscreenImage);
203
}
204
205
public Rectangle getBounds() {
206
if (type == FLIP_BACKBUFFER) {
207
Rectangle r = peer.getBounds();
208
r.x = r.y = 0;
209
return r;
210
} else {
211
return new Rectangle(width, height);
212
}
213
}
214
215
/**
216
* Returns destination Image associated with this SurfaceData.
217
*/
218
public Object getDestination() {
219
return offscreenImage;
220
}
221
}
222
}
223
224