author | chegar |
Thu, 17 Oct 2019 20:54:25 +0100 | |
branch | datagramsocketimpl-branch |
changeset 58679 | 9c3209ff7550 |
parent 58678 | 9cf78a70fa4f |
parent 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.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.image.ColorModel; |
|
34 |
||
35 |
import sun.java2d.SurfaceData; |
|
36 |
import sun.lwawt.macosx.CPlatformView; |
|
37 |
||
38 |
public abstract class CGLSurfaceData extends OGLSurfaceData { |
|
39 |
||
16840
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
12047
diff
changeset
|
40 |
protected final int scale; |
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
12047
diff
changeset
|
41 |
protected final int width; |
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
12047
diff
changeset
|
42 |
protected final int height; |
12047 | 43 |
protected CPlatformView pView; |
44 |
private CGLGraphicsConfig graphicsConfig; |
|
45 |
||
46 |
native void validate(int xoff, int yoff, int width, int height, boolean isOpaque); |
|
47 |
||
58315
07556f8cd819
8146238: [macosx] Java2D Queue Flusher crash on OSX after switching between user accounts
serb
parents:
47216
diff
changeset
|
48 |
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
|
49 |
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
|
50 |
int yoff, boolean isOpaque); |
12047 | 51 |
|
16840
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
12047
diff
changeset
|
52 |
protected CGLSurfaceData(CGLGraphicsConfig gc, ColorModel cm, int type, |
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
12047
diff
changeset
|
53 |
int width, int height) { |
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
12047
diff
changeset
|
54 |
super(gc, cm, type); |
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
12047
diff
changeset
|
55 |
// 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
|
56 |
scale = type == TEXTURE ? 1 : gc.getDevice().getScaleFactor(); |
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
12047
diff
changeset
|
57 |
this.width = width * scale; |
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
12047
diff
changeset
|
58 |
this.height = height * scale; |
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
12047
diff
changeset
|
59 |
} |
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
12047
diff
changeset
|
60 |
|
12047 | 61 |
protected CGLSurfaceData(CPlatformView pView, CGLGraphicsConfig gc, |
16840
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
12047
diff
changeset
|
62 |
ColorModel cm, int type,int width, int height) |
12047 | 63 |
{ |
16840
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
12047
diff
changeset
|
64 |
this(gc, cm, type, width, height); |
12047 | 65 |
this.pView = pView; |
66 |
this.graphicsConfig = gc; |
|
67 |
||
68 |
long pConfigInfo = gc.getNativeConfigInfo(); |
|
69 |
long pPeerData = 0L; |
|
70 |
boolean isOpaque = true; |
|
71 |
if (pView != null) { |
|
72 |
pPeerData = pView.getAWTView(); |
|
73 |
isOpaque = pView.isOpaque(); |
|
74 |
} |
|
58315
07556f8cd819
8146238: [macosx] Java2D Queue Flusher crash on OSX after switching between user accounts
serb
parents:
47216
diff
changeset
|
75 |
initOps(gc, pConfigInfo, pPeerData, 0, 0, 0, isOpaque); |
12047 | 76 |
} |
77 |
||
78 |
protected CGLSurfaceData(CGLLayer layer, CGLGraphicsConfig gc, |
|
16840
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
12047
diff
changeset
|
79 |
ColorModel cm, int type,int width, int height) |
12047 | 80 |
{ |
16840
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
12047
diff
changeset
|
81 |
this(gc, cm, type, width, height); |
12047 | 82 |
this.graphicsConfig = gc; |
83 |
||
84 |
long pConfigInfo = gc.getNativeConfigInfo(); |
|
85 |
long layerPtr = 0L; |
|
86 |
boolean isOpaque = true; |
|
87 |
if (layer != null) { |
|
88 |
layerPtr = layer.getPointer(); |
|
89 |
isOpaque = layer.isOpaque(); |
|
90 |
} |
|
58315
07556f8cd819
8146238: [macosx] Java2D Queue Flusher crash on OSX after switching between user accounts
serb
parents:
47216
diff
changeset
|
91 |
initOps(gc, pConfigInfo, 0, layerPtr, 0, 0, isOpaque); |
12047 | 92 |
} |
93 |
||
94 |
@Override //SurfaceData |
|
95 |
public GraphicsConfiguration getDeviceConfiguration() { |
|
96 |
return graphicsConfig; |
|
97 |
} |
|
98 |
||
99 |
/** |
|
100 |
* Creates a SurfaceData object representing the primary (front) buffer of |
|
101 |
* an on-screen Window. |
|
102 |
*/ |
|
103 |
public static CGLWindowSurfaceData createData(CPlatformView pView) { |
|
104 |
CGLGraphicsConfig gc = getGC(pView); |
|
105 |
return new CGLWindowSurfaceData(pView, gc); |
|
106 |
} |
|
107 |
||
108 |
/** |
|
109 |
* Creates a SurfaceData object representing the intermediate buffer |
|
110 |
* between the Java2D flusher thread and the AppKit thread. |
|
111 |
*/ |
|
112 |
public static CGLLayerSurfaceData createData(CGLLayer layer) { |
|
113 |
CGLGraphicsConfig gc = getGC(layer); |
|
114 |
Rectangle r = layer.getBounds(); |
|
115 |
return new CGLLayerSurfaceData(layer, gc, r.width, r.height); |
|
116 |
} |
|
117 |
||
118 |
/** |
|
119 |
* Creates a SurfaceData object representing the back buffer of a |
|
120 |
* double-buffered on-screen Window. |
|
121 |
*/ |
|
122 |
public static CGLOffScreenSurfaceData createData(CPlatformView pView, |
|
123 |
Image image, int type) { |
|
124 |
CGLGraphicsConfig gc = getGC(pView); |
|
125 |
Rectangle r = pView.getBounds(); |
|
126 |
if (type == FLIP_BACKBUFFER) { |
|
127 |
return new CGLOffScreenSurfaceData(pView, gc, r.width, r.height, |
|
128 |
image, gc.getColorModel(), FLIP_BACKBUFFER); |
|
129 |
} else { |
|
130 |
return new CGLVSyncOffScreenSurfaceData(pView, gc, r.width, |
|
131 |
r.height, image, gc.getColorModel(), type); |
|
132 |
} |
|
133 |
} |
|
134 |
||
135 |
/** |
|
136 |
* 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
|
137 |
* FBO or Texture). |
12047 | 138 |
*/ |
139 |
public static CGLOffScreenSurfaceData createData(CGLGraphicsConfig gc, |
|
140 |
int width, int height, ColorModel cm, Image image, int type) { |
|
141 |
return new CGLOffScreenSurfaceData(null, gc, width, height, image, cm, |
|
142 |
type); |
|
143 |
} |
|
144 |
||
145 |
public static CGLGraphicsConfig getGC(CPlatformView pView) { |
|
146 |
if (pView != null) { |
|
147 |
return (CGLGraphicsConfig)pView.getGraphicsConfiguration(); |
|
148 |
} else { |
|
149 |
// REMIND: this should rarely (never?) happen, but what if |
|
150 |
// default config is not CGL? |
|
151 |
GraphicsEnvironment env = GraphicsEnvironment |
|
152 |
.getLocalGraphicsEnvironment(); |
|
153 |
GraphicsDevice gd = env.getDefaultScreenDevice(); |
|
154 |
return (CGLGraphicsConfig) gd.getDefaultConfiguration(); |
|
155 |
} |
|
156 |
} |
|
157 |
||
158 |
public static CGLGraphicsConfig getGC(CGLLayer layer) { |
|
159 |
return (CGLGraphicsConfig)layer.getGraphicsConfiguration(); |
|
160 |
} |
|
161 |
||
162 |
public void validate() { |
|
163 |
// Overridden in CGLWindowSurfaceData below |
|
164 |
} |
|
165 |
||
16840
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
12047
diff
changeset
|
166 |
@Override |
34394 | 167 |
public double getDefaultScaleX() { |
168 |
return scale; |
|
169 |
} |
|
170 |
||
171 |
@Override |
|
172 |
public double getDefaultScaleY() { |
|
16840
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
12047
diff
changeset
|
173 |
return scale; |
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
12047
diff
changeset
|
174 |
} |
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
12047
diff
changeset
|
175 |
|
12047 | 176 |
protected native void clearWindow(); |
177 |
||
178 |
public static class CGLWindowSurfaceData extends CGLSurfaceData { |
|
179 |
||
180 |
public CGLWindowSurfaceData(CPlatformView pView, |
|
181 |
CGLGraphicsConfig gc) { |
|
16840
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
12047
diff
changeset
|
182 |
super(pView, gc, gc.getColorModel(), WINDOW, 0, 0); |
12047 | 183 |
} |
184 |
||
185 |
@Override |
|
186 |
public SurfaceData getReplacement() { |
|
187 |
return pView.getSurfaceData(); |
|
188 |
} |
|
189 |
||
190 |
@Override |
|
191 |
public Rectangle getBounds() { |
|
192 |
Rectangle r = pView.getBounds(); |
|
193 |
return new Rectangle(0, 0, r.width, r.height); |
|
194 |
} |
|
195 |
||
196 |
/** |
|
197 |
* Returns destination Component associated with this SurfaceData. |
|
198 |
*/ |
|
199 |
@Override |
|
200 |
public Object getDestination() { |
|
201 |
return pView.getDestination(); |
|
202 |
} |
|
203 |
||
204 |
public void validate() { |
|
205 |
OGLRenderQueue rq = OGLRenderQueue.getInstance(); |
|
206 |
rq.lock(); |
|
207 |
try { |
|
208 |
rq.flushAndInvokeNow(new Runnable() { |
|
209 |
public void run() { |
|
210 |
Rectangle peerBounds = pView.getBounds(); |
|
211 |
validate(0, 0, peerBounds.width, peerBounds.height, pView.isOpaque()); |
|
212 |
} |
|
213 |
}); |
|
214 |
} finally { |
|
215 |
rq.unlock(); |
|
216 |
} |
|
217 |
} |
|
218 |
||
219 |
@Override |
|
220 |
public void invalidate() { |
|
221 |
super.invalidate(); |
|
222 |
clearWindow(); |
|
223 |
} |
|
224 |
} |
|
225 |
||
226 |
/** |
|
227 |
* A surface which implements an intermediate buffer between |
|
228 |
* the Java2D flusher thread and the AppKit thread. |
|
229 |
* |
|
230 |
* This surface serves as a buffer attached to a CGLLayer and |
|
231 |
* the layer redirects all painting to the buffer's graphics. |
|
232 |
*/ |
|
233 |
public static class CGLLayerSurfaceData extends CGLSurfaceData { |
|
234 |
||
235 |
private CGLLayer layer; |
|
236 |
||
237 |
public CGLLayerSurfaceData(CGLLayer layer, CGLGraphicsConfig gc, |
|
238 |
int width, int height) { |
|
16840
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
12047
diff
changeset
|
239 |
super(layer, gc, gc.getColorModel(), FBOBJECT, width, height); |
12047 | 240 |
this.layer = layer; |
16840
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
12047
diff
changeset
|
241 |
initSurface(this.width, this.height); |
12047 | 242 |
} |
243 |
||
244 |
@Override |
|
245 |
public SurfaceData getReplacement() { |
|
246 |
return layer.getSurfaceData(); |
|
247 |
} |
|
248 |
||
249 |
@Override |
|
250 |
boolean isOnScreen() { |
|
251 |
return true; |
|
252 |
} |
|
253 |
||
254 |
@Override |
|
255 |
public Rectangle getBounds() { |
|
256 |
return new Rectangle(width, height); |
|
257 |
} |
|
258 |
||
259 |
@Override |
|
260 |
public Object getDestination() { |
|
261 |
return layer.getDestination(); |
|
262 |
} |
|
263 |
||
264 |
@Override |
|
265 |
public int getTransparency() { |
|
266 |
return layer.getTransparency(); |
|
267 |
} |
|
268 |
||
269 |
@Override |
|
270 |
public void invalidate() { |
|
271 |
super.invalidate(); |
|
272 |
clearWindow(); |
|
273 |
} |
|
274 |
} |
|
275 |
||
276 |
/** |
|
277 |
* A surface which implements a v-synced flip back-buffer with COPIED |
|
278 |
* FlipContents. |
|
279 |
* |
|
280 |
* This surface serves as a back-buffer to the outside world, while it is |
|
281 |
* actually an offscreen surface. When the BufferStrategy this surface |
|
282 |
* belongs to is showed, it is first copied to the real private |
|
283 |
* FLIP_BACKBUFFER, which is then flipped. |
|
284 |
*/ |
|
285 |
public static class CGLVSyncOffScreenSurfaceData extends |
|
286 |
CGLOffScreenSurfaceData { |
|
287 |
private CGLOffScreenSurfaceData flipSurface; |
|
288 |
||
289 |
public CGLVSyncOffScreenSurfaceData(CPlatformView pView, |
|
290 |
CGLGraphicsConfig gc, int width, int height, Image image, |
|
291 |
ColorModel cm, int type) { |
|
292 |
super(pView, gc, width, height, image, cm, type); |
|
293 |
flipSurface = CGLSurfaceData.createData(pView, image, |
|
294 |
FLIP_BACKBUFFER); |
|
295 |
} |
|
296 |
||
297 |
public SurfaceData getFlipSurface() { |
|
298 |
return flipSurface; |
|
299 |
} |
|
300 |
||
301 |
@Override |
|
302 |
public void flush() { |
|
303 |
flipSurface.flush(); |
|
304 |
super.flush(); |
|
305 |
} |
|
306 |
} |
|
307 |
||
308 |
public static class CGLOffScreenSurfaceData extends CGLSurfaceData { |
|
309 |
private Image offscreenImage; |
|
310 |
||
311 |
public CGLOffScreenSurfaceData(CPlatformView pView, |
|
312 |
CGLGraphicsConfig gc, int width, int height, Image image, |
|
313 |
ColorModel cm, int type) { |
|
16840
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
12047
diff
changeset
|
314 |
super(pView, gc, cm, type, width, height); |
12047 | 315 |
offscreenImage = image; |
16840
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
12047
diff
changeset
|
316 |
initSurface(this.width, this.height); |
12047 | 317 |
} |
318 |
||
319 |
@Override |
|
320 |
public SurfaceData getReplacement() { |
|
321 |
return restoreContents(offscreenImage); |
|
322 |
} |
|
323 |
||
324 |
@Override |
|
325 |
public Rectangle getBounds() { |
|
326 |
if (type == FLIP_BACKBUFFER) { |
|
327 |
Rectangle r = pView.getBounds(); |
|
328 |
return new Rectangle(0, 0, r.width, r.height); |
|
329 |
} else { |
|
330 |
return new Rectangle(width, height); |
|
331 |
} |
|
332 |
} |
|
333 |
||
334 |
/** |
|
335 |
* Returns destination Image associated with this SurfaceData. |
|
336 |
*/ |
|
337 |
@Override |
|
338 |
public Object getDestination() { |
|
339 |
return offscreenImage; |
|
340 |
} |
|
341 |
} |
|
342 |
} |