author | serb |
Tue, 27 Aug 2019 04:43:01 -0700 | |
changeset 58315 | 07556f8cd819 |
parent 47216 | 71c04702a3d5 |
child 58596 | acbc26afebb6 |
permissions | -rw-r--r-- |
12047 | 1 |
/* |
58315
07556f8cd819
8146238: [macosx] Java2D Queue Flusher crash on OSX after switching between user accounts
serb
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved. |
12047 | 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.Graphics; |
|
29 |
import java.awt.GraphicsConfiguration; |
|
30 |
import java.awt.GraphicsDevice; |
|
31 |
import java.awt.GraphicsEnvironment; |
|
32 |
import java.awt.Image; |
|
33 |
import java.awt.Rectangle; |
|
34 |
import java.awt.image.ColorModel; |
|
35 |
||
36 |
import sun.java2d.SunGraphics2D; |
|
37 |
import sun.java2d.SurfaceData; |
|
38 |
||
39 |
import sun.lwawt.macosx.CPlatformView; |
|
40 |
||
41 |
public abstract class CGLSurfaceData extends OGLSurfaceData { |
|
42 |
||
16840
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
12047
diff
changeset
|
43 |
protected final int scale; |
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
12047
diff
changeset
|
44 |
protected final int width; |
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
12047
diff
changeset
|
45 |
protected final int height; |
12047 | 46 |
protected CPlatformView pView; |
47 |
private CGLGraphicsConfig graphicsConfig; |
|
48 |
||
49 |
native void validate(int xoff, int yoff, int width, int height, boolean isOpaque); |
|
50 |
||
58315
07556f8cd819
8146238: [macosx] Java2D Queue Flusher crash on OSX after switching between user accounts
serb
parents:
47216
diff
changeset
|
51 |
private native void initOps(OGLGraphicsConfig gc, long pConfigInfo, |
07556f8cd819
8146238: [macosx] Java2D Queue Flusher crash on OSX after switching between user accounts
serb
parents:
47216
diff
changeset
|
52 |
long pPeerData, long layerPtr, int xoff, |
07556f8cd819
8146238: [macosx] Java2D Queue Flusher crash on OSX after switching between user accounts
serb
parents:
47216
diff
changeset
|
53 |
int yoff, boolean isOpaque); |
12047 | 54 |
|
16840
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
12047
diff
changeset
|
55 |
protected CGLSurfaceData(CGLGraphicsConfig gc, ColorModel cm, int type, |
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
12047
diff
changeset
|
56 |
int width, int height) { |
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
12047
diff
changeset
|
57 |
super(gc, cm, type); |
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
12047
diff
changeset
|
58 |
// TEXTURE shouldn't be scaled, it is used for managed BufferedImages. |
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
12047
diff
changeset
|
59 |
scale = type == TEXTURE ? 1 : gc.getDevice().getScaleFactor(); |
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
12047
diff
changeset
|
60 |
this.width = width * scale; |
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
12047
diff
changeset
|
61 |
this.height = height * scale; |
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
12047
diff
changeset
|
62 |
} |
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
12047
diff
changeset
|
63 |
|
12047 | 64 |
protected CGLSurfaceData(CPlatformView pView, CGLGraphicsConfig gc, |
16840
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
12047
diff
changeset
|
65 |
ColorModel cm, int type,int width, int height) |
12047 | 66 |
{ |
16840
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
12047
diff
changeset
|
67 |
this(gc, cm, type, width, height); |
12047 | 68 |
this.pView = pView; |
69 |
this.graphicsConfig = gc; |
|
70 |
||
71 |
long pConfigInfo = gc.getNativeConfigInfo(); |
|
72 |
long pPeerData = 0L; |
|
73 |
boolean isOpaque = true; |
|
74 |
if (pView != null) { |
|
75 |
pPeerData = pView.getAWTView(); |
|
76 |
isOpaque = pView.isOpaque(); |
|
77 |
} |
|
58315
07556f8cd819
8146238: [macosx] Java2D Queue Flusher crash on OSX after switching between user accounts
serb
parents:
47216
diff
changeset
|
78 |
initOps(gc, pConfigInfo, pPeerData, 0, 0, 0, isOpaque); |
12047 | 79 |
} |
80 |
||
81 |
protected CGLSurfaceData(CGLLayer layer, CGLGraphicsConfig gc, |
|
16840
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
12047
diff
changeset
|
82 |
ColorModel cm, int type,int width, int height) |
12047 | 83 |
{ |
16840
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
12047
diff
changeset
|
84 |
this(gc, cm, type, width, height); |
12047 | 85 |
this.graphicsConfig = gc; |
86 |
||
87 |
long pConfigInfo = gc.getNativeConfigInfo(); |
|
88 |
long layerPtr = 0L; |
|
89 |
boolean isOpaque = true; |
|
90 |
if (layer != null) { |
|
91 |
layerPtr = layer.getPointer(); |
|
92 |
isOpaque = layer.isOpaque(); |
|
93 |
} |
|
58315
07556f8cd819
8146238: [macosx] Java2D Queue Flusher crash on OSX after switching between user accounts
serb
parents:
47216
diff
changeset
|
94 |
initOps(gc, pConfigInfo, 0, layerPtr, 0, 0, isOpaque); |
12047 | 95 |
} |
96 |
||
97 |
@Override //SurfaceData |
|
98 |
public GraphicsConfiguration getDeviceConfiguration() { |
|
99 |
return graphicsConfig; |
|
100 |
} |
|
101 |
||
102 |
/** |
|
103 |
* Creates a SurfaceData object representing the primary (front) buffer of |
|
104 |
* an on-screen Window. |
|
105 |
*/ |
|
106 |
public static CGLWindowSurfaceData createData(CPlatformView pView) { |
|
107 |
CGLGraphicsConfig gc = getGC(pView); |
|
108 |
return new CGLWindowSurfaceData(pView, gc); |
|
109 |
} |
|
110 |
||
111 |
/** |
|
112 |
* Creates a SurfaceData object representing the intermediate buffer |
|
113 |
* between the Java2D flusher thread and the AppKit thread. |
|
114 |
*/ |
|
115 |
public static CGLLayerSurfaceData createData(CGLLayer layer) { |
|
116 |
CGLGraphicsConfig gc = getGC(layer); |
|
117 |
Rectangle r = layer.getBounds(); |
|
118 |
return new CGLLayerSurfaceData(layer, gc, r.width, r.height); |
|
119 |
} |
|
120 |
||
121 |
/** |
|
122 |
* Creates a SurfaceData object representing the back buffer of a |
|
123 |
* double-buffered on-screen Window. |
|
124 |
*/ |
|
125 |
public static CGLOffScreenSurfaceData createData(CPlatformView pView, |
|
126 |
Image image, int type) { |
|
127 |
CGLGraphicsConfig gc = getGC(pView); |
|
128 |
Rectangle r = pView.getBounds(); |
|
129 |
if (type == FLIP_BACKBUFFER) { |
|
130 |
return new CGLOffScreenSurfaceData(pView, gc, r.width, r.height, |
|
131 |
image, gc.getColorModel(), FLIP_BACKBUFFER); |
|
132 |
} else { |
|
133 |
return new CGLVSyncOffScreenSurfaceData(pView, gc, r.width, |
|
134 |
r.height, image, gc.getColorModel(), type); |
|
135 |
} |
|
136 |
} |
|
137 |
||
138 |
/** |
|
139 |
* Creates a SurfaceData object representing an off-screen buffer (either a |
|
31661
a5cb86f2253b
7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
25859
diff
changeset
|
140 |
* FBO or Texture). |
12047 | 141 |
*/ |
142 |
public static CGLOffScreenSurfaceData createData(CGLGraphicsConfig gc, |
|
143 |
int width, int height, ColorModel cm, Image image, int type) { |
|
144 |
return new CGLOffScreenSurfaceData(null, gc, width, height, image, cm, |
|
145 |
type); |
|
146 |
} |
|
147 |
||
148 |
public static CGLGraphicsConfig getGC(CPlatformView pView) { |
|
149 |
if (pView != null) { |
|
150 |
return (CGLGraphicsConfig)pView.getGraphicsConfiguration(); |
|
151 |
} else { |
|
152 |
// REMIND: this should rarely (never?) happen, but what if |
|
153 |
// default config is not CGL? |
|
154 |
GraphicsEnvironment env = GraphicsEnvironment |
|
155 |
.getLocalGraphicsEnvironment(); |
|
156 |
GraphicsDevice gd = env.getDefaultScreenDevice(); |
|
157 |
return (CGLGraphicsConfig) gd.getDefaultConfiguration(); |
|
158 |
} |
|
159 |
} |
|
160 |
||
161 |
public static CGLGraphicsConfig getGC(CGLLayer layer) { |
|
162 |
return (CGLGraphicsConfig)layer.getGraphicsConfiguration(); |
|
163 |
} |
|
164 |
||
165 |
public void validate() { |
|
166 |
// Overridden in CGLWindowSurfaceData below |
|
167 |
} |
|
168 |
||
16840
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
12047
diff
changeset
|
169 |
@Override |
34394 | 170 |
public double getDefaultScaleX() { |
171 |
return scale; |
|
172 |
} |
|
173 |
||
174 |
@Override |
|
175 |
public double getDefaultScaleY() { |
|
16840
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
12047
diff
changeset
|
176 |
return scale; |
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
12047
diff
changeset
|
177 |
} |
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
12047
diff
changeset
|
178 |
|
12047 | 179 |
protected native void clearWindow(); |
180 |
||
181 |
public static class CGLWindowSurfaceData extends CGLSurfaceData { |
|
182 |
||
183 |
public CGLWindowSurfaceData(CPlatformView pView, |
|
184 |
CGLGraphicsConfig gc) { |
|
16840
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
12047
diff
changeset
|
185 |
super(pView, gc, gc.getColorModel(), WINDOW, 0, 0); |
12047 | 186 |
} |
187 |
||
188 |
@Override |
|
189 |
public SurfaceData getReplacement() { |
|
190 |
return pView.getSurfaceData(); |
|
191 |
} |
|
192 |
||
193 |
@Override |
|
194 |
public Rectangle getBounds() { |
|
195 |
Rectangle r = pView.getBounds(); |
|
196 |
return new Rectangle(0, 0, r.width, r.height); |
|
197 |
} |
|
198 |
||
199 |
/** |
|
200 |
* Returns destination Component associated with this SurfaceData. |
|
201 |
*/ |
|
202 |
@Override |
|
203 |
public Object getDestination() { |
|
204 |
return pView.getDestination(); |
|
205 |
} |
|
206 |
||
207 |
public void validate() { |
|
208 |
OGLRenderQueue rq = OGLRenderQueue.getInstance(); |
|
209 |
rq.lock(); |
|
210 |
try { |
|
211 |
rq.flushAndInvokeNow(new Runnable() { |
|
212 |
public void run() { |
|
213 |
Rectangle peerBounds = pView.getBounds(); |
|
214 |
validate(0, 0, peerBounds.width, peerBounds.height, pView.isOpaque()); |
|
215 |
} |
|
216 |
}); |
|
217 |
} finally { |
|
218 |
rq.unlock(); |
|
219 |
} |
|
220 |
} |
|
221 |
||
222 |
@Override |
|
223 |
public void invalidate() { |
|
224 |
super.invalidate(); |
|
225 |
clearWindow(); |
|
226 |
} |
|
227 |
} |
|
228 |
||
229 |
/** |
|
230 |
* A surface which implements an intermediate buffer between |
|
231 |
* the Java2D flusher thread and the AppKit thread. |
|
232 |
* |
|
233 |
* This surface serves as a buffer attached to a CGLLayer and |
|
234 |
* the layer redirects all painting to the buffer's graphics. |
|
235 |
*/ |
|
236 |
public static class CGLLayerSurfaceData extends CGLSurfaceData { |
|
237 |
||
238 |
private CGLLayer layer; |
|
239 |
||
240 |
public CGLLayerSurfaceData(CGLLayer layer, CGLGraphicsConfig gc, |
|
241 |
int width, int height) { |
|
16840
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
12047
diff
changeset
|
242 |
super(layer, gc, gc.getColorModel(), FBOBJECT, width, height); |
12047 | 243 |
this.layer = layer; |
16840
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
12047
diff
changeset
|
244 |
initSurface(this.width, this.height); |
12047 | 245 |
} |
246 |
||
247 |
@Override |
|
248 |
public SurfaceData getReplacement() { |
|
249 |
return layer.getSurfaceData(); |
|
250 |
} |
|
251 |
||
252 |
@Override |
|
253 |
boolean isOnScreen() { |
|
254 |
return true; |
|
255 |
} |
|
256 |
||
257 |
@Override |
|
258 |
public Rectangle getBounds() { |
|
259 |
return new Rectangle(width, height); |
|
260 |
} |
|
261 |
||
262 |
@Override |
|
263 |
public Object getDestination() { |
|
264 |
return layer.getDestination(); |
|
265 |
} |
|
266 |
||
267 |
@Override |
|
268 |
public int getTransparency() { |
|
269 |
return layer.getTransparency(); |
|
270 |
} |
|
271 |
||
272 |
@Override |
|
273 |
public void invalidate() { |
|
274 |
super.invalidate(); |
|
275 |
clearWindow(); |
|
276 |
} |
|
277 |
} |
|
278 |
||
279 |
/** |
|
280 |
* A surface which implements a v-synced flip back-buffer with COPIED |
|
281 |
* FlipContents. |
|
282 |
* |
|
283 |
* This surface serves as a back-buffer to the outside world, while it is |
|
284 |
* actually an offscreen surface. When the BufferStrategy this surface |
|
285 |
* belongs to is showed, it is first copied to the real private |
|
286 |
* FLIP_BACKBUFFER, which is then flipped. |
|
287 |
*/ |
|
288 |
public static class CGLVSyncOffScreenSurfaceData extends |
|
289 |
CGLOffScreenSurfaceData { |
|
290 |
private CGLOffScreenSurfaceData flipSurface; |
|
291 |
||
292 |
public CGLVSyncOffScreenSurfaceData(CPlatformView pView, |
|
293 |
CGLGraphicsConfig gc, int width, int height, Image image, |
|
294 |
ColorModel cm, int type) { |
|
295 |
super(pView, gc, width, height, image, cm, type); |
|
296 |
flipSurface = CGLSurfaceData.createData(pView, image, |
|
297 |
FLIP_BACKBUFFER); |
|
298 |
} |
|
299 |
||
300 |
public SurfaceData getFlipSurface() { |
|
301 |
return flipSurface; |
|
302 |
} |
|
303 |
||
304 |
@Override |
|
305 |
public void flush() { |
|
306 |
flipSurface.flush(); |
|
307 |
super.flush(); |
|
308 |
} |
|
309 |
} |
|
310 |
||
311 |
public static class CGLOffScreenSurfaceData extends CGLSurfaceData { |
|
312 |
private Image offscreenImage; |
|
313 |
||
314 |
public CGLOffScreenSurfaceData(CPlatformView pView, |
|
315 |
CGLGraphicsConfig gc, int width, int height, Image image, |
|
316 |
ColorModel cm, int type) { |
|
16840
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
12047
diff
changeset
|
317 |
super(pView, gc, cm, type, width, height); |
12047 | 318 |
offscreenImage = image; |
16840
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
12047
diff
changeset
|
319 |
initSurface(this.width, this.height); |
12047 | 320 |
} |
321 |
||
322 |
@Override |
|
323 |
public SurfaceData getReplacement() { |
|
324 |
return restoreContents(offscreenImage); |
|
325 |
} |
|
326 |
||
327 |
@Override |
|
328 |
public Rectangle getBounds() { |
|
329 |
if (type == FLIP_BACKBUFFER) { |
|
330 |
Rectangle r = pView.getBounds(); |
|
331 |
return new Rectangle(0, 0, r.width, r.height); |
|
332 |
} else { |
|
333 |
return new Rectangle(width, height); |
|
334 |
} |
|
335 |
} |
|
336 |
||
337 |
/** |
|
338 |
* Returns destination Image associated with this SurfaceData. |
|
339 |
*/ |
|
340 |
@Override |
|
341 |
public Object getDestination() { |
|
342 |
return offscreenImage; |
|
343 |
} |
|
344 |
} |
|
345 |
||
346 |
// Mac OS X specific APIs for JOGL/Java2D bridge... |
|
347 |
||
348 |
// given a surface create and attach GL context, then return it |
|
32865
f9cb6e427f9e
8136783: Run blessed-modifier-order script on java.desktop
prr
parents:
31661
diff
changeset
|
349 |
private static native long createCGLContextOnSurface(CGLSurfaceData sd, |
12047 | 350 |
long sharedContext); |
351 |
||
352 |
public static long createOGLContextOnSurface(Graphics g, long sharedContext) { |
|
353 |
SurfaceData sd = ((SunGraphics2D) g).surfaceData; |
|
354 |
if ((sd instanceof CGLSurfaceData) == true) { |
|
355 |
CGLSurfaceData cglsd = (CGLSurfaceData) sd; |
|
356 |
return createCGLContextOnSurface(cglsd, sharedContext); |
|
357 |
} else { |
|
358 |
return 0L; |
|
359 |
} |
|
360 |
} |
|
361 |
||
362 |
// returns whether or not the makeCurrent operation succeeded |
|
32865
f9cb6e427f9e
8136783: Run blessed-modifier-order script on java.desktop
prr
parents:
31661
diff
changeset
|
363 |
static native boolean makeCGLContextCurrentOnSurface(CGLSurfaceData sd, |
12047 | 364 |
long ctx); |
365 |
||
366 |
public static boolean makeOGLContextCurrentOnSurface(Graphics g, long ctx) { |
|
367 |
SurfaceData sd = ((SunGraphics2D) g).surfaceData; |
|
368 |
if ((ctx != 0L) && ((sd instanceof CGLSurfaceData) == true)) { |
|
369 |
CGLSurfaceData cglsd = (CGLSurfaceData) sd; |
|
370 |
return makeCGLContextCurrentOnSurface(cglsd, ctx); |
|
371 |
} else { |
|
372 |
return false; |
|
373 |
} |
|
374 |
} |
|
375 |
||
376 |
// additional cleanup |
|
32865
f9cb6e427f9e
8136783: Run blessed-modifier-order script on java.desktop
prr
parents:
31661
diff
changeset
|
377 |
private static native void destroyCGLContext(long ctx); |
12047 | 378 |
|
379 |
public static void destroyOGLContext(long ctx) { |
|
380 |
if (ctx != 0L) { |
|
381 |
destroyCGLContext(ctx); |
|
382 |
} |
|
383 |
} |
|
384 |
} |