author | bae |
Fri, 29 May 2015 18:32:58 +0300 | |
changeset 31158 | 062c7363dd12 |
parent 25859 | 3317bb8137f4 |
child 31661 | a5cb86f2253b |
permissions | -rw-r--r-- |
2 | 1 |
/* |
22584
eed64ee05369
8032733: Fix cast lint warnings in client libraries
darcy
parents:
12047
diff
changeset
|
2 |
* Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 24 |
*/ |
25 |
||
26 |
package sun.java2d.opengl; |
|
27 |
||
28 |
import java.awt.AlphaComposite; |
|
31158
062c7363dd12
8023794: [macosx] LCD Rendering hints seems not working without FRACTIONALMETRICS=ON
bae
parents:
25859
diff
changeset
|
29 |
import java.awt.Composite; |
2 | 30 |
import java.awt.GraphicsEnvironment; |
887 | 31 |
import java.awt.Rectangle; |
2 | 32 |
import java.awt.Transparency; |
33 |
import java.awt.image.ColorModel; |
|
34 |
import java.awt.image.Raster; |
|
35 |
import sun.awt.SunHints; |
|
36 |
import sun.awt.image.PixelConverter; |
|
887 | 37 |
import sun.java2d.pipe.hw.AccelSurface; |
2 | 38 |
import sun.java2d.SunGraphics2D; |
39 |
import sun.java2d.SurfaceData; |
|
40 |
import sun.java2d.SurfaceDataProxy; |
|
887 | 41 |
import sun.java2d.loops.CompositeType; |
2 | 42 |
import sun.java2d.loops.GraphicsPrimitive; |
43 |
import sun.java2d.loops.MaskFill; |
|
44 |
import sun.java2d.loops.SurfaceType; |
|
887 | 45 |
import sun.java2d.pipe.ParallelogramPipe; |
46 |
import sun.java2d.pipe.PixelToParallelogramConverter; |
|
2 | 47 |
import sun.java2d.pipe.RenderBuffer; |
48 |
import sun.java2d.pipe.TextPipe; |
|
49 |
import static sun.java2d.pipe.BufferedOpCodes.*; |
|
887 | 50 |
import static sun.java2d.opengl.OGLContext.OGLContextCaps.*; |
2 | 51 |
|
52 |
/** |
|
53 |
* This class describes an OpenGL "surface", that is, a region of pixels |
|
54 |
* managed via OpenGL. An OGLSurfaceData can be tagged with one of three |
|
55 |
* different SurfaceType objects for the purpose of registering loops, etc. |
|
56 |
* This diagram shows the hierarchy of OGL SurfaceTypes: |
|
57 |
* |
|
58 |
* Any |
|
59 |
* / \ |
|
60 |
* OpenGLSurface OpenGLTexture |
|
61 |
* | |
|
62 |
* OpenGLSurfaceRTT |
|
63 |
* |
|
64 |
* OpenGLSurface |
|
65 |
* This kind of surface can be rendered to using OpenGL APIs. It is also |
|
66 |
* possible to copy an OpenGLSurface to another OpenGLSurface (or to itself). |
|
67 |
* This is typically accomplished by calling MakeContextCurrent(dstSD, srcSD) |
|
68 |
* and then calling glCopyPixels() (although there are other techniques to |
|
69 |
* achieve the same goal). |
|
70 |
* |
|
71 |
* OpenGLTexture |
|
72 |
* This kind of surface cannot be rendered to using OpenGL (in the same sense |
|
73 |
* as in OpenGLSurface). However, it is possible to upload a region of pixels |
|
74 |
* to an OpenGLTexture object via glTexSubImage2D(). One can also copy a |
|
75 |
* surface of type OpenGLTexture to an OpenGLSurface by binding the texture |
|
76 |
* to a quad and then rendering it to the destination surface (this process |
|
77 |
* is known as "texture mapping"). |
|
78 |
* |
|
79 |
* OpenGLSurfaceRTT |
|
80 |
* This kind of surface can be thought of as a sort of hybrid between |
|
81 |
* OpenGLSurface and OpenGLTexture, in that one can render to this kind of |
|
82 |
* surface as if it were of type OpenGLSurface, but the process of copying |
|
83 |
* this kind of surface to another is more like an OpenGLTexture. (Note that |
|
84 |
* "RTT" stands for "render-to-texture".) |
|
85 |
* |
|
86 |
* In addition to these SurfaceType variants, we have also defined some |
|
87 |
* constants that describe in more detail the type of underlying OpenGL |
|
88 |
* surface. This table helps explain the relationships between those |
|
89 |
* "type" constants and their corresponding SurfaceType: |
|
90 |
* |
|
91 |
* OGL Type Corresponding SurfaceType |
|
92 |
* -------- ------------------------- |
|
93 |
* WINDOW OpenGLSurface |
|
94 |
* PBUFFER OpenGLSurface |
|
95 |
* TEXTURE OpenGLTexture |
|
96 |
* FLIP_BACKBUFFER OpenGLSurface |
|
97 |
* FBOBJECT OpenGLSurfaceRTT |
|
98 |
*/ |
|
887 | 99 |
public abstract class OGLSurfaceData extends SurfaceData |
100 |
implements AccelSurface { |
|
2 | 101 |
|
102 |
/** |
|
103 |
* OGL-specific surface types |
|
887 | 104 |
* |
105 |
* @see sun.java2d.pipe.hw.AccelSurface |
|
2 | 106 |
*/ |
887 | 107 |
public static final int PBUFFER = RT_PLAIN; |
108 |
public static final int FBOBJECT = RT_TEXTURE; |
|
2 | 109 |
|
110 |
/** |
|
111 |
* Pixel formats |
|
112 |
*/ |
|
113 |
public static final int PF_INT_ARGB = 0; |
|
114 |
public static final int PF_INT_ARGB_PRE = 1; |
|
115 |
public static final int PF_INT_RGB = 2; |
|
116 |
public static final int PF_INT_RGBX = 3; |
|
117 |
public static final int PF_INT_BGR = 4; |
|
118 |
public static final int PF_INT_BGRX = 5; |
|
119 |
public static final int PF_USHORT_565_RGB = 6; |
|
120 |
public static final int PF_USHORT_555_RGB = 7; |
|
121 |
public static final int PF_USHORT_555_RGBX = 8; |
|
122 |
public static final int PF_BYTE_GRAY = 9; |
|
123 |
public static final int PF_USHORT_GRAY = 10; |
|
1723
4a616c1eac0b
6739267: D3D/OGL: add missing ThreeByteBgr to texture upload blit loop
tdv
parents:
1717
diff
changeset
|
124 |
public static final int PF_3BYTE_BGR = 11; |
2 | 125 |
|
126 |
/** |
|
127 |
* SurfaceTypes |
|
128 |
*/ |
|
129 |
private static final String DESC_OPENGL_SURFACE = "OpenGL Surface"; |
|
130 |
private static final String DESC_OPENGL_SURFACE_RTT = |
|
131 |
"OpenGL Surface (render-to-texture)"; |
|
132 |
private static final String DESC_OPENGL_TEXTURE = "OpenGL Texture"; |
|
133 |
||
134 |
static final SurfaceType OpenGLSurface = |
|
135 |
SurfaceType.Any.deriveSubType(DESC_OPENGL_SURFACE, |
|
136 |
PixelConverter.ArgbPre.instance); |
|
137 |
static final SurfaceType OpenGLSurfaceRTT = |
|
138 |
OpenGLSurface.deriveSubType(DESC_OPENGL_SURFACE_RTT); |
|
139 |
static final SurfaceType OpenGLTexture = |
|
140 |
SurfaceType.Any.deriveSubType(DESC_OPENGL_TEXTURE); |
|
141 |
||
142 |
/** This will be true if the fbobject system property has been enabled. */ |
|
143 |
private static boolean isFBObjectEnabled; |
|
144 |
||
145 |
/** This will be true if the lcdshader system property has been enabled.*/ |
|
146 |
private static boolean isLCDShaderEnabled; |
|
147 |
||
148 |
/** This will be true if the biopshader system property has been enabled.*/ |
|
149 |
private static boolean isBIOpShaderEnabled; |
|
150 |
||
151 |
/** This will be true if the gradshader system property has been enabled.*/ |
|
152 |
private static boolean isGradShaderEnabled; |
|
153 |
||
154 |
private OGLGraphicsConfig graphicsConfig; |
|
155 |
protected int type; |
|
887 | 156 |
// these fields are set from the native code when the surface is |
157 |
// initialized |
|
158 |
private int nativeWidth, nativeHeight; |
|
2 | 159 |
|
160 |
protected static OGLRenderer oglRenderPipe; |
|
887 | 161 |
protected static PixelToParallelogramConverter oglTxRenderPipe; |
162 |
protected static ParallelogramPipe oglAAPgramPipe; |
|
2 | 163 |
protected static OGLTextRenderer oglTextPipe; |
164 |
protected static OGLDrawImage oglImagePipe; |
|
165 |
||
166 |
protected native boolean initTexture(long pData, |
|
167 |
boolean isOpaque, boolean texNonPow2, |
|
168 |
boolean texRect, |
|
169 |
int width, int height); |
|
170 |
protected native boolean initFBObject(long pData, |
|
171 |
boolean isOpaque, boolean texNonPow2, |
|
172 |
boolean texRect, |
|
173 |
int width, int height); |
|
174 |
protected native boolean initFlipBackbuffer(long pData); |
|
175 |
protected abstract boolean initPbuffer(long pData, long pConfigInfo, |
|
176 |
boolean isOpaque, |
|
177 |
int width, int height); |
|
178 |
||
179 |
private native int getTextureTarget(long pData); |
|
887 | 180 |
private native int getTextureID(long pData); |
2 | 181 |
|
182 |
static { |
|
183 |
if (!GraphicsEnvironment.isHeadless()) { |
|
184 |
// fbobject currently enabled by default; use "false" to disable |
|
22584
eed64ee05369
8032733: Fix cast lint warnings in client libraries
darcy
parents:
12047
diff
changeset
|
185 |
String fbo = java.security.AccessController.doPrivileged( |
2 | 186 |
new sun.security.action.GetPropertyAction( |
187 |
"sun.java2d.opengl.fbobject")); |
|
188 |
isFBObjectEnabled = !"false".equals(fbo); |
|
189 |
||
190 |
// lcdshader currently enabled by default; use "false" to disable |
|
22584
eed64ee05369
8032733: Fix cast lint warnings in client libraries
darcy
parents:
12047
diff
changeset
|
191 |
String lcd = java.security.AccessController.doPrivileged( |
2 | 192 |
new sun.security.action.GetPropertyAction( |
193 |
"sun.java2d.opengl.lcdshader")); |
|
194 |
isLCDShaderEnabled = !"false".equals(lcd); |
|
195 |
||
196 |
// biopshader currently enabled by default; use "false" to disable |
|
22584
eed64ee05369
8032733: Fix cast lint warnings in client libraries
darcy
parents:
12047
diff
changeset
|
197 |
String biop = java.security.AccessController.doPrivileged( |
2 | 198 |
new sun.security.action.GetPropertyAction( |
199 |
"sun.java2d.opengl.biopshader")); |
|
200 |
isBIOpShaderEnabled = !"false".equals(biop); |
|
201 |
||
202 |
// gradshader currently enabled by default; use "false" to disable |
|
22584
eed64ee05369
8032733: Fix cast lint warnings in client libraries
darcy
parents:
12047
diff
changeset
|
203 |
String grad = java.security.AccessController.doPrivileged( |
2 | 204 |
new sun.security.action.GetPropertyAction( |
205 |
"sun.java2d.opengl.gradshader")); |
|
206 |
isGradShaderEnabled = !"false".equals(grad); |
|
207 |
||
208 |
OGLRenderQueue rq = OGLRenderQueue.getInstance(); |
|
209 |
oglImagePipe = new OGLDrawImage(); |
|
210 |
oglTextPipe = new OGLTextRenderer(rq); |
|
211 |
oglRenderPipe = new OGLRenderer(rq); |
|
212 |
if (GraphicsPrimitive.tracingEnabled()) { |
|
213 |
oglTextPipe = oglTextPipe.traceWrap(); |
|
887 | 214 |
//The wrapped oglRenderPipe will wrap the AA pipe as well... |
215 |
//oglAAPgramPipe = oglRenderPipe.traceWrap(); |
|
2 | 216 |
} |
887 | 217 |
oglAAPgramPipe = oglRenderPipe.getAAParallelogramPipe(); |
218 |
oglTxRenderPipe = |
|
219 |
new PixelToParallelogramConverter(oglRenderPipe, |
|
220 |
oglRenderPipe, |
|
221 |
1.0, 0.25, true); |
|
2 | 222 |
|
223 |
OGLBlitLoops.register(); |
|
224 |
OGLMaskFill.register(); |
|
225 |
OGLMaskBlit.register(); |
|
226 |
} |
|
227 |
} |
|
228 |
||
229 |
protected OGLSurfaceData(OGLGraphicsConfig gc, |
|
230 |
ColorModel cm, int type) |
|
231 |
{ |
|
232 |
super(getCustomSurfaceType(type), cm); |
|
233 |
this.graphicsConfig = gc; |
|
234 |
this.type = type; |
|
235 |
setBlitProxyKey(gc.getProxyKey()); |
|
236 |
} |
|
237 |
||
238 |
@Override |
|
239 |
public SurfaceDataProxy makeProxyFor(SurfaceData srcData) { |
|
240 |
return OGLSurfaceDataProxy.createProxy(srcData, graphicsConfig); |
|
241 |
} |
|
242 |
||
243 |
/** |
|
244 |
* Returns the appropriate SurfaceType corresponding to the given OpenGL |
|
245 |
* surface type constant (e.g. TEXTURE -> OpenGLTexture). |
|
246 |
*/ |
|
247 |
private static SurfaceType getCustomSurfaceType(int oglType) { |
|
248 |
switch (oglType) { |
|
249 |
case TEXTURE: |
|
250 |
return OpenGLTexture; |
|
251 |
case FBOBJECT: |
|
252 |
return OpenGLSurfaceRTT; |
|
253 |
case PBUFFER: |
|
254 |
default: |
|
255 |
return OpenGLSurface; |
|
256 |
} |
|
257 |
} |
|
258 |
||
259 |
/** |
|
260 |
* Note: This should only be called from the QFT under the AWT lock. |
|
261 |
* This method is kept separate from the initSurface() method below just |
|
262 |
* to keep the code a bit cleaner. |
|
263 |
*/ |
|
264 |
private void initSurfaceNow(int width, int height) { |
|
265 |
boolean isOpaque = (getTransparency() == Transparency.OPAQUE); |
|
266 |
boolean success = false; |
|
267 |
||
268 |
switch (type) { |
|
269 |
case PBUFFER: |
|
270 |
success = initPbuffer(getNativeOps(), |
|
271 |
graphicsConfig.getNativeConfigInfo(), |
|
272 |
isOpaque, |
|
273 |
width, height); |
|
274 |
break; |
|
275 |
||
276 |
case TEXTURE: |
|
277 |
success = initTexture(getNativeOps(), |
|
278 |
isOpaque, isTexNonPow2Available(), |
|
279 |
isTexRectAvailable(), |
|
280 |
width, height); |
|
281 |
break; |
|
282 |
||
283 |
case FBOBJECT: |
|
284 |
success = initFBObject(getNativeOps(), |
|
285 |
isOpaque, isTexNonPow2Available(), |
|
286 |
isTexRectAvailable(), |
|
287 |
width, height); |
|
288 |
break; |
|
289 |
||
290 |
case FLIP_BACKBUFFER: |
|
291 |
success = initFlipBackbuffer(getNativeOps()); |
|
292 |
break; |
|
293 |
||
294 |
default: |
|
295 |
break; |
|
296 |
} |
|
297 |
||
887 | 298 |
if (!success) { |
2 | 299 |
throw new OutOfMemoryError("can't create offscreen surface"); |
300 |
} |
|
301 |
} |
|
302 |
||
303 |
/** |
|
304 |
* Initializes the appropriate OpenGL offscreen surface based on the value |
|
305 |
* of the type parameter. If the surface creation fails for any reason, |
|
306 |
* an OutOfMemoryError will be thrown. |
|
307 |
*/ |
|
308 |
protected void initSurface(final int width, final int height) { |
|
309 |
OGLRenderQueue rq = OGLRenderQueue.getInstance(); |
|
310 |
rq.lock(); |
|
311 |
try { |
|
312 |
switch (type) { |
|
313 |
case TEXTURE: |
|
314 |
case PBUFFER: |
|
315 |
case FBOBJECT: |
|
316 |
// need to make sure the context is current before |
|
317 |
// creating the texture (or pbuffer, or fbobject) |
|
318 |
OGLContext.setScratchSurface(graphicsConfig); |
|
319 |
break; |
|
320 |
default: |
|
321 |
break; |
|
322 |
} |
|
323 |
rq.flushAndInvokeNow(new Runnable() { |
|
324 |
public void run() { |
|
325 |
initSurfaceNow(width, height); |
|
326 |
} |
|
327 |
}); |
|
328 |
} finally { |
|
329 |
rq.unlock(); |
|
330 |
} |
|
331 |
} |
|
332 |
||
333 |
/** |
|
334 |
* Returns the OGLContext for the GraphicsConfig associated with this |
|
335 |
* surface. |
|
336 |
*/ |
|
887 | 337 |
public final OGLContext getContext() { |
2 | 338 |
return graphicsConfig.getContext(); |
339 |
} |
|
340 |
||
341 |
/** |
|
342 |
* Returns the OGLGraphicsConfig associated with this surface. |
|
343 |
*/ |
|
344 |
final OGLGraphicsConfig getOGLGraphicsConfig() { |
|
345 |
return graphicsConfig; |
|
346 |
} |
|
347 |
||
348 |
/** |
|
349 |
* Returns one of the surface type constants defined above. |
|
350 |
*/ |
|
887 | 351 |
public final int getType() { |
2 | 352 |
return type; |
353 |
} |
|
354 |
||
355 |
/** |
|
356 |
* If this surface is backed by a texture object, returns the target |
|
357 |
* for that texture (either GL_TEXTURE_2D or GL_TEXTURE_RECTANGLE_ARB). |
|
358 |
* Otherwise, this method will return zero. |
|
359 |
*/ |
|
887 | 360 |
public final int getTextureTarget() { |
361 |
return getTextureTarget(getNativeOps()); |
|
362 |
} |
|
363 |
||
364 |
/** |
|
365 |
* If this surface is backed by a texture object, returns the texture ID |
|
366 |
* for that texture. |
|
367 |
* Otherwise, this method will return zero. |
|
368 |
*/ |
|
369 |
public final int getTextureID() { |
|
370 |
return getTextureID(getNativeOps()); |
|
371 |
} |
|
372 |
||
373 |
/** |
|
374 |
* Returns native resource of specified {@code resType} associated with |
|
375 |
* this surface. |
|
376 |
* |
|
377 |
* Specifically, for {@code OGLSurfaceData} this method returns the |
|
378 |
* the following: |
|
379 |
* <pre> |
|
380 |
* TEXTURE - texture id |
|
381 |
* </pre> |
|
382 |
* |
|
383 |
* Note: the resource returned by this method is only valid on the rendering |
|
384 |
* thread. |
|
385 |
* |
|
386 |
* @return native resource of specified type or 0L if |
|
387 |
* such resource doesn't exist or can not be retrieved. |
|
388 |
* @see sun.java2d.pipe.hw.AccelSurface#getNativeResource |
|
389 |
*/ |
|
390 |
public long getNativeResource(int resType) { |
|
391 |
if (resType == TEXTURE) { |
|
392 |
return getTextureID(); |
|
393 |
} |
|
394 |
return 0L; |
|
2 | 395 |
} |
396 |
||
397 |
public Raster getRaster(int x, int y, int w, int h) { |
|
398 |
throw new InternalError("not implemented yet"); |
|
399 |
} |
|
400 |
||
401 |
/** |
|
402 |
* For now, we can only render LCD text if: |
|
403 |
* - the fragment shader extension is available, and |
|
31158
062c7363dd12
8023794: [macosx] LCD Rendering hints seems not working without FRACTIONALMETRICS=ON
bae
parents:
25859
diff
changeset
|
404 |
* - the source color is opaque, and |
062c7363dd12
8023794: [macosx] LCD Rendering hints seems not working without FRACTIONALMETRICS=ON
bae
parents:
25859
diff
changeset
|
405 |
* - blending is SrcOverNoEa or disabled |
1717
5d7c1102107a
6728834: D3D/OGL: LCD AA text becomes bold and blurred when rendering to a non-opaque destination
tdv
parents:
888
diff
changeset
|
406 |
* - and the destination is opaque |
2 | 407 |
* |
408 |
* Eventually, we could enhance the native OGL text rendering code |
|
409 |
* and remove the above restrictions, but that would require significantly |
|
410 |
* more code just to support a few uncommon cases. |
|
411 |
*/ |
|
412 |
public boolean canRenderLCDText(SunGraphics2D sg2d) { |
|
413 |
return |
|
887 | 414 |
graphicsConfig.isCapPresent(CAPS_EXT_LCD_SHADER) && |
31158
062c7363dd12
8023794: [macosx] LCD Rendering hints seems not working without FRACTIONALMETRICS=ON
bae
parents:
25859
diff
changeset
|
415 |
sg2d.surfaceData.getTransparency() == Transparency.OPAQUE && |
1717
5d7c1102107a
6728834: D3D/OGL: LCD AA text becomes bold and blurred when rendering to a non-opaque destination
tdv
parents:
888
diff
changeset
|
416 |
sg2d.paintState <= SunGraphics2D.PAINT_OPAQUECOLOR && |
31158
062c7363dd12
8023794: [macosx] LCD Rendering hints seems not working without FRACTIONALMETRICS=ON
bae
parents:
25859
diff
changeset
|
417 |
(sg2d.compositeState <= SunGraphics2D.COMP_ISCOPY || |
062c7363dd12
8023794: [macosx] LCD Rendering hints seems not working without FRACTIONALMETRICS=ON
bae
parents:
25859
diff
changeset
|
418 |
(sg2d.compositeState <= SunGraphics2D.COMP_ALPHA && canHandleComposite(sg2d.composite))); |
062c7363dd12
8023794: [macosx] LCD Rendering hints seems not working without FRACTIONALMETRICS=ON
bae
parents:
25859
diff
changeset
|
419 |
} |
062c7363dd12
8023794: [macosx] LCD Rendering hints seems not working without FRACTIONALMETRICS=ON
bae
parents:
25859
diff
changeset
|
420 |
|
062c7363dd12
8023794: [macosx] LCD Rendering hints seems not working without FRACTIONALMETRICS=ON
bae
parents:
25859
diff
changeset
|
421 |
private boolean canHandleComposite(Composite c) { |
062c7363dd12
8023794: [macosx] LCD Rendering hints seems not working without FRACTIONALMETRICS=ON
bae
parents:
25859
diff
changeset
|
422 |
if (c instanceof AlphaComposite) { |
062c7363dd12
8023794: [macosx] LCD Rendering hints seems not working without FRACTIONALMETRICS=ON
bae
parents:
25859
diff
changeset
|
423 |
AlphaComposite ac = (AlphaComposite)c; |
062c7363dd12
8023794: [macosx] LCD Rendering hints seems not working without FRACTIONALMETRICS=ON
bae
parents:
25859
diff
changeset
|
424 |
|
062c7363dd12
8023794: [macosx] LCD Rendering hints seems not working without FRACTIONALMETRICS=ON
bae
parents:
25859
diff
changeset
|
425 |
return ac.getRule() == AlphaComposite.SRC_OVER && ac.getAlpha() >= 1f; |
062c7363dd12
8023794: [macosx] LCD Rendering hints seems not working without FRACTIONALMETRICS=ON
bae
parents:
25859
diff
changeset
|
426 |
} |
062c7363dd12
8023794: [macosx] LCD Rendering hints seems not working without FRACTIONALMETRICS=ON
bae
parents:
25859
diff
changeset
|
427 |
return false; |
2 | 428 |
} |
429 |
||
430 |
public void validatePipe(SunGraphics2D sg2d) { |
|
431 |
TextPipe textpipe; |
|
432 |
boolean validated = false; |
|
433 |
||
434 |
// OGLTextRenderer handles both AA and non-AA text, but |
|
435 |
// only works with the following modes: |
|
436 |
// (Note: For LCD text we only enter this code path if |
|
437 |
// canRenderLCDText() has already validated that the mode is |
|
438 |
// CompositeType.SrcNoEa (opaque color), which will be subsumed |
|
439 |
// by the CompositeType.SrcNoEa (any color) test below.) |
|
440 |
||
441 |
if (/* CompositeType.SrcNoEa (any color) */ |
|
11080
7e18e343964e
7117914: Fix javac warnings in src/share/classes/sun/java2d
neugens
parents:
5506
diff
changeset
|
442 |
(sg2d.compositeState <= SunGraphics2D.COMP_ISCOPY && |
7e18e343964e
7117914: Fix javac warnings in src/share/classes/sun/java2d
neugens
parents:
5506
diff
changeset
|
443 |
sg2d.paintState <= SunGraphics2D.PAINT_ALPHACOLOR) || |
2 | 444 |
|
445 |
/* CompositeType.SrcOver (any color) */ |
|
11080
7e18e343964e
7117914: Fix javac warnings in src/share/classes/sun/java2d
neugens
parents:
5506
diff
changeset
|
446 |
(sg2d.compositeState == SunGraphics2D.COMP_ALPHA && |
7e18e343964e
7117914: Fix javac warnings in src/share/classes/sun/java2d
neugens
parents:
5506
diff
changeset
|
447 |
sg2d.paintState <= SunGraphics2D.PAINT_ALPHACOLOR && |
2 | 448 |
(((AlphaComposite)sg2d.composite).getRule() == |
11080
7e18e343964e
7117914: Fix javac warnings in src/share/classes/sun/java2d
neugens
parents:
5506
diff
changeset
|
449 |
AlphaComposite.SRC_OVER)) || |
2 | 450 |
|
451 |
/* CompositeType.Xor (any color) */ |
|
11080
7e18e343964e
7117914: Fix javac warnings in src/share/classes/sun/java2d
neugens
parents:
5506
diff
changeset
|
452 |
(sg2d.compositeState == SunGraphics2D.COMP_XOR && |
7e18e343964e
7117914: Fix javac warnings in src/share/classes/sun/java2d
neugens
parents:
5506
diff
changeset
|
453 |
sg2d.paintState <= SunGraphics2D.PAINT_ALPHACOLOR)) |
2 | 454 |
{ |
455 |
textpipe = oglTextPipe; |
|
456 |
} else { |
|
457 |
// do this to initialize textpipe correctly; we will attempt |
|
458 |
// to override the non-text pipes below |
|
459 |
super.validatePipe(sg2d); |
|
460 |
textpipe = sg2d.textpipe; |
|
461 |
validated = true; |
|
462 |
} |
|
463 |
||
887 | 464 |
PixelToParallelogramConverter txPipe = null; |
2 | 465 |
OGLRenderer nonTxPipe = null; |
466 |
||
467 |
if (sg2d.antialiasHint != SunHints.INTVAL_ANTIALIAS_ON) { |
|
11080
7e18e343964e
7117914: Fix javac warnings in src/share/classes/sun/java2d
neugens
parents:
5506
diff
changeset
|
468 |
if (sg2d.paintState <= SunGraphics2D.PAINT_ALPHACOLOR) { |
7e18e343964e
7117914: Fix javac warnings in src/share/classes/sun/java2d
neugens
parents:
5506
diff
changeset
|
469 |
if (sg2d.compositeState <= SunGraphics2D.COMP_XOR) { |
2 | 470 |
txPipe = oglTxRenderPipe; |
471 |
nonTxPipe = oglRenderPipe; |
|
472 |
} |
|
11080
7e18e343964e
7117914: Fix javac warnings in src/share/classes/sun/java2d
neugens
parents:
5506
diff
changeset
|
473 |
} else if (sg2d.compositeState <= SunGraphics2D.COMP_ALPHA) { |
2 | 474 |
if (OGLPaints.isValid(sg2d)) { |
475 |
txPipe = oglTxRenderPipe; |
|
476 |
nonTxPipe = oglRenderPipe; |
|
477 |
} |
|
478 |
// custom paints handled by super.validatePipe() below |
|
479 |
} |
|
480 |
} else { |
|
11080
7e18e343964e
7117914: Fix javac warnings in src/share/classes/sun/java2d
neugens
parents:
5506
diff
changeset
|
481 |
if (sg2d.paintState <= SunGraphics2D.PAINT_ALPHACOLOR) { |
887 | 482 |
if (graphicsConfig.isCapPresent(CAPS_PS30) && |
483 |
(sg2d.imageComp == CompositeType.SrcOverNoEa || |
|
484 |
sg2d.imageComp == CompositeType.SrcOver)) |
|
485 |
{ |
|
486 |
if (!validated) { |
|
487 |
super.validatePipe(sg2d); |
|
488 |
validated = true; |
|
489 |
} |
|
490 |
PixelToParallelogramConverter aaConverter = |
|
491 |
new PixelToParallelogramConverter(sg2d.shapepipe, |
|
492 |
oglAAPgramPipe, |
|
493 |
1.0/8.0, 0.499, |
|
494 |
false); |
|
495 |
sg2d.drawpipe = aaConverter; |
|
496 |
sg2d.fillpipe = aaConverter; |
|
497 |
sg2d.shapepipe = aaConverter; |
|
11080
7e18e343964e
7117914: Fix javac warnings in src/share/classes/sun/java2d
neugens
parents:
5506
diff
changeset
|
498 |
} else if (sg2d.compositeState == SunGraphics2D.COMP_XOR) { |
887 | 499 |
// install the solid pipes when AA and XOR are both enabled |
500 |
txPipe = oglTxRenderPipe; |
|
501 |
nonTxPipe = oglRenderPipe; |
|
502 |
} |
|
2 | 503 |
} |
504 |
// other cases handled by super.validatePipe() below |
|
505 |
} |
|
506 |
||
507 |
if (txPipe != null) { |
|
11080
7e18e343964e
7117914: Fix javac warnings in src/share/classes/sun/java2d
neugens
parents:
5506
diff
changeset
|
508 |
if (sg2d.transformState >= SunGraphics2D.TRANSFORM_TRANSLATESCALE) { |
2 | 509 |
sg2d.drawpipe = txPipe; |
510 |
sg2d.fillpipe = txPipe; |
|
11080
7e18e343964e
7117914: Fix javac warnings in src/share/classes/sun/java2d
neugens
parents:
5506
diff
changeset
|
511 |
} else if (sg2d.strokeState != SunGraphics2D.STROKE_THIN) { |
2 | 512 |
sg2d.drawpipe = txPipe; |
513 |
sg2d.fillpipe = nonTxPipe; |
|
514 |
} else { |
|
515 |
sg2d.drawpipe = nonTxPipe; |
|
516 |
sg2d.fillpipe = nonTxPipe; |
|
517 |
} |
|
887 | 518 |
// Note that we use the transforming pipe here because it |
519 |
// will examine the shape and possibly perform an optimized |
|
520 |
// operation if it can be simplified. The simplifications |
|
521 |
// will be valid for all STROKE and TRANSFORM types. |
|
522 |
sg2d.shapepipe = txPipe; |
|
2 | 523 |
} else { |
524 |
if (!validated) { |
|
525 |
super.validatePipe(sg2d); |
|
526 |
} |
|
527 |
} |
|
528 |
||
529 |
// install the text pipe based on our earlier decision |
|
530 |
sg2d.textpipe = textpipe; |
|
531 |
||
532 |
// always override the image pipe with the specialized OGL pipe |
|
533 |
sg2d.imagepipe = oglImagePipe; |
|
534 |
} |
|
535 |
||
536 |
@Override |
|
537 |
protected MaskFill getMaskFill(SunGraphics2D sg2d) { |
|
11080
7e18e343964e
7117914: Fix javac warnings in src/share/classes/sun/java2d
neugens
parents:
5506
diff
changeset
|
538 |
if (sg2d.paintState > SunGraphics2D.PAINT_ALPHACOLOR) { |
2 | 539 |
/* |
540 |
* We can only accelerate non-Color MaskFill operations if |
|
541 |
* all of the following conditions hold true: |
|
542 |
* - there is an implementation for the given paintState |
|
543 |
* - the current Paint can be accelerated for this destination |
|
544 |
* - multitexturing is available (since we need to modulate |
|
545 |
* the alpha mask texture with the paint texture) |
|
546 |
* |
|
547 |
* In all other cases, we return null, in which case the |
|
548 |
* validation code will choose a more general software-based loop. |
|
549 |
*/ |
|
550 |
if (!OGLPaints.isValid(sg2d) || |
|
887 | 551 |
!graphicsConfig.isCapPresent(CAPS_MULTITEXTURE)) |
2 | 552 |
{ |
553 |
return null; |
|
554 |
} |
|
555 |
} |
|
556 |
return super.getMaskFill(sg2d); |
|
557 |
} |
|
558 |
||
559 |
public boolean copyArea(SunGraphics2D sg2d, |
|
560 |
int x, int y, int w, int h, int dx, int dy) |
|
561 |
{ |
|
11080
7e18e343964e
7117914: Fix javac warnings in src/share/classes/sun/java2d
neugens
parents:
5506
diff
changeset
|
562 |
if (sg2d.transformState < SunGraphics2D.TRANSFORM_TRANSLATESCALE && |
7e18e343964e
7117914: Fix javac warnings in src/share/classes/sun/java2d
neugens
parents:
5506
diff
changeset
|
563 |
sg2d.compositeState < SunGraphics2D.COMP_XOR) |
2 | 564 |
{ |
565 |
x += sg2d.transX; |
|
566 |
y += sg2d.transY; |
|
567 |
||
568 |
oglRenderPipe.copyArea(sg2d, x, y, w, h, dx, dy); |
|
569 |
||
570 |
return true; |
|
571 |
} |
|
572 |
return false; |
|
573 |
} |
|
574 |
||
575 |
public void flush() { |
|
576 |
invalidate(); |
|
577 |
OGLRenderQueue rq = OGLRenderQueue.getInstance(); |
|
578 |
rq.lock(); |
|
579 |
try { |
|
580 |
// make sure we have a current context before |
|
581 |
// disposing the native resources (e.g. texture object) |
|
582 |
OGLContext.setScratchSurface(graphicsConfig); |
|
583 |
||
584 |
RenderBuffer buf = rq.getBuffer(); |
|
585 |
rq.ensureCapacityAndAlignment(12, 4); |
|
586 |
buf.putInt(FLUSH_SURFACE); |
|
587 |
buf.putLong(getNativeOps()); |
|
588 |
||
589 |
// this call is expected to complete synchronously, so flush now |
|
590 |
rq.flushNow(); |
|
591 |
} finally { |
|
592 |
rq.unlock(); |
|
593 |
} |
|
594 |
} |
|
595 |
||
596 |
/** |
|
597 |
* Disposes the native resources associated with the given OGLSurfaceData |
|
598 |
* (referenced by the pData parameter). This method is invoked from |
|
599 |
* the native Dispose() method from the Disposer thread when the |
|
600 |
* Java-level OGLSurfaceData object is about to go away. Note that we |
|
601 |
* also pass a reference to the native GLX/WGLGraphicsConfigInfo |
|
602 |
* (pConfigInfo) for the purposes of making a context current. |
|
603 |
*/ |
|
604 |
static void dispose(long pData, long pConfigInfo) { |
|
605 |
OGLRenderQueue rq = OGLRenderQueue.getInstance(); |
|
606 |
rq.lock(); |
|
607 |
try { |
|
608 |
// make sure we have a current context before |
|
609 |
// disposing the native resources (e.g. texture object) |
|
610 |
OGLContext.setScratchSurface(pConfigInfo); |
|
611 |
||
612 |
RenderBuffer buf = rq.getBuffer(); |
|
613 |
rq.ensureCapacityAndAlignment(12, 4); |
|
614 |
buf.putInt(DISPOSE_SURFACE); |
|
615 |
buf.putLong(pData); |
|
616 |
||
617 |
// this call is expected to complete synchronously, so flush now |
|
618 |
rq.flushNow(); |
|
619 |
} finally { |
|
620 |
rq.unlock(); |
|
621 |
} |
|
622 |
} |
|
623 |
||
624 |
static void swapBuffers(long window) { |
|
625 |
OGLRenderQueue rq = OGLRenderQueue.getInstance(); |
|
626 |
rq.lock(); |
|
627 |
try { |
|
628 |
RenderBuffer buf = rq.getBuffer(); |
|
629 |
rq.ensureCapacityAndAlignment(12, 4); |
|
630 |
buf.putInt(SWAP_BUFFERS); |
|
631 |
buf.putLong(window); |
|
632 |
rq.flushNow(); |
|
633 |
} finally { |
|
634 |
rq.unlock(); |
|
635 |
} |
|
636 |
} |
|
637 |
||
638 |
/** |
|
639 |
* Returns true if OpenGL textures can have non-power-of-two dimensions |
|
640 |
* when using the basic GL_TEXTURE_2D target. |
|
641 |
*/ |
|
642 |
boolean isTexNonPow2Available() { |
|
887 | 643 |
return graphicsConfig.isCapPresent(CAPS_TEXNONPOW2); |
2 | 644 |
} |
645 |
||
646 |
/** |
|
647 |
* Returns true if OpenGL textures can have non-power-of-two dimensions |
|
648 |
* when using the GL_TEXTURE_RECTANGLE_ARB target (only available when the |
|
649 |
* GL_ARB_texture_rectangle extension is present). |
|
650 |
*/ |
|
651 |
boolean isTexRectAvailable() { |
|
887 | 652 |
return graphicsConfig.isCapPresent(CAPS_EXT_TEXRECT); |
653 |
} |
|
654 |
||
655 |
public Rectangle getNativeBounds() { |
|
656 |
OGLRenderQueue rq = OGLRenderQueue.getInstance(); |
|
657 |
rq.lock(); |
|
658 |
try { |
|
659 |
return new Rectangle(nativeWidth, nativeHeight); |
|
660 |
} finally { |
|
661 |
rq.unlock(); |
|
662 |
} |
|
2 | 663 |
} |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11080
diff
changeset
|
664 |
|
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11080
diff
changeset
|
665 |
/** |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11080
diff
changeset
|
666 |
* Returns true if the surface is an on-screen window surface or |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11080
diff
changeset
|
667 |
* a FBO texture attached to an on-screen CALayer. |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11080
diff
changeset
|
668 |
* |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11080
diff
changeset
|
669 |
* Needed by Mac OS X port. |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11080
diff
changeset
|
670 |
*/ |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11080
diff
changeset
|
671 |
boolean isOnScreen() { |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11080
diff
changeset
|
672 |
return getType() == WINDOW; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11080
diff
changeset
|
673 |
} |
2 | 674 |
} |