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.AlphaComposite;
29 import java.awt.GraphicsEnvironment;
30 import java.awt.Rectangle;
31 import java.awt.Transparency;
32 import java.awt.image.ColorModel;
33 import java.awt.image.Raster;
34 import sun.awt.SunHints;
35 import sun.awt.image.PixelConverter;
36 import sun.java2d.pipe.hw.AccelSurface;
37 import sun.java2d.SunGraphics2D;
38 import sun.java2d.SurfaceData;
39 import sun.java2d.SurfaceDataProxy;
40 import sun.java2d.loops.CompositeType;
41 import sun.java2d.loops.GraphicsPrimitive;
42 import sun.java2d.loops.MaskFill;
43 import sun.java2d.loops.SurfaceType;
44 import sun.java2d.pipe.ParallelogramPipe;
45 import sun.java2d.pipe.PixelToParallelogramConverter;
46 import sun.java2d.pipe.RenderBuffer;
47 import sun.java2d.pipe.TextPipe;
48 import static sun.java2d.pipe.BufferedOpCodes.*;
49 import static sun.java2d.opengl.OGLContext.OGLContextCaps.*;
50
51 /**
383 * thread.
384 *
385 * @return native resource of specified type or 0L if
386 * such resource doesn't exist or can not be retrieved.
387 * @see sun.java2d.pipe.hw.AccelSurface#getNativeResource
388 */
389 public long getNativeResource(int resType) {
390 if (resType == TEXTURE) {
391 return getTextureID();
392 }
393 return 0L;
394 }
395
396 public Raster getRaster(int x, int y, int w, int h) {
397 throw new InternalError("not implemented yet");
398 }
399
400 /**
401 * For now, we can only render LCD text if:
402 * - the fragment shader extension is available, and
403 * - blending is disabled, and
404 * - the source color is opaque
405 * - and the destination is opaque
406 *
407 * Eventually, we could enhance the native OGL text rendering code
408 * and remove the above restrictions, but that would require significantly
409 * more code just to support a few uncommon cases.
410 */
411 public boolean canRenderLCDText(SunGraphics2D sg2d) {
412 return
413 graphicsConfig.isCapPresent(CAPS_EXT_LCD_SHADER) &&
414 sg2d.compositeState <= SunGraphics2D.COMP_ISCOPY &&
415 sg2d.paintState <= SunGraphics2D.PAINT_OPAQUECOLOR &&
416 sg2d.surfaceData.getTransparency() == Transparency.OPAQUE;
417 }
418
419 public void validatePipe(SunGraphics2D sg2d) {
420 TextPipe textpipe;
421 boolean validated = false;
422
423 // OGLTextRenderer handles both AA and non-AA text, but
424 // only works with the following modes:
425 // (Note: For LCD text we only enter this code path if
426 // canRenderLCDText() has already validated that the mode is
427 // CompositeType.SrcNoEa (opaque color), which will be subsumed
428 // by the CompositeType.SrcNoEa (any color) test below.)
429
430 if (/* CompositeType.SrcNoEa (any color) */
431 (sg2d.compositeState <= SunGraphics2D.COMP_ISCOPY &&
432 sg2d.paintState <= SunGraphics2D.PAINT_ALPHACOLOR) ||
433
434 /* CompositeType.SrcOver (any color) */
435 (sg2d.compositeState == SunGraphics2D.COMP_ALPHA &&
436 sg2d.paintState <= SunGraphics2D.PAINT_ALPHACOLOR &&
|
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.*;
29 import java.awt.image.ColorModel;
30 import java.awt.image.Raster;
31 import sun.awt.SunHints;
32 import sun.awt.image.PixelConverter;
33 import sun.java2d.pipe.hw.AccelSurface;
34 import sun.java2d.SunGraphics2D;
35 import sun.java2d.SurfaceData;
36 import sun.java2d.SurfaceDataProxy;
37 import sun.java2d.loops.CompositeType;
38 import sun.java2d.loops.GraphicsPrimitive;
39 import sun.java2d.loops.MaskFill;
40 import sun.java2d.loops.SurfaceType;
41 import sun.java2d.pipe.ParallelogramPipe;
42 import sun.java2d.pipe.PixelToParallelogramConverter;
43 import sun.java2d.pipe.RenderBuffer;
44 import sun.java2d.pipe.TextPipe;
45 import static sun.java2d.pipe.BufferedOpCodes.*;
46 import static sun.java2d.opengl.OGLContext.OGLContextCaps.*;
47
48 /**
380 * thread.
381 *
382 * @return native resource of specified type or 0L if
383 * such resource doesn't exist or can not be retrieved.
384 * @see sun.java2d.pipe.hw.AccelSurface#getNativeResource
385 */
386 public long getNativeResource(int resType) {
387 if (resType == TEXTURE) {
388 return getTextureID();
389 }
390 return 0L;
391 }
392
393 public Raster getRaster(int x, int y, int w, int h) {
394 throw new InternalError("not implemented yet");
395 }
396
397 /**
398 * For now, we can only render LCD text if:
399 * - the fragment shader extension is available, and
400 * - the source color is opaque, and
401 * - blending is SrcOverNoEa or disabled
402 *
403 * Eventually, we could enhance the native OGL text rendering code
404 * and remove the above restrictions, but that would require significantly
405 * more code just to support a few uncommon cases.
406 */
407 public boolean canRenderLCDText(SunGraphics2D sg2d) {
408 return
409 graphicsConfig.isCapPresent(CAPS_EXT_LCD_SHADER) &&
410 sg2d.surfaceData.getTransparency() == Transparency.OPAQUE &&
411 sg2d.paintState <= SunGraphics2D.PAINT_OPAQUECOLOR &&
412 (sg2d.compositeState <= SunGraphics2D.COMP_ISCOPY ||
413 (sg2d.compositeState <= SunGraphics2D.COMP_ALPHA && canHandleComposite(sg2d.composite)));
414 }
415
416 private boolean canHandleComposite(Composite c) {
417 if (c instanceof AlphaComposite) {
418 AlphaComposite ac = (AlphaComposite)c;
419
420 return ac.getRule() == AlphaComposite.SRC_OVER && ac.getAlpha() >= 1f;
421 }
422 return false;
423 }
424
425 public void validatePipe(SunGraphics2D sg2d) {
426 TextPipe textpipe;
427 boolean validated = false;
428
429 // OGLTextRenderer handles both AA and non-AA text, but
430 // only works with the following modes:
431 // (Note: For LCD text we only enter this code path if
432 // canRenderLCDText() has already validated that the mode is
433 // CompositeType.SrcNoEa (opaque color), which will be subsumed
434 // by the CompositeType.SrcNoEa (any color) test below.)
435
436 if (/* CompositeType.SrcNoEa (any color) */
437 (sg2d.compositeState <= SunGraphics2D.COMP_ISCOPY &&
438 sg2d.paintState <= SunGraphics2D.PAINT_ALPHACOLOR) ||
439
440 /* CompositeType.SrcOver (any color) */
441 (sg2d.compositeState == SunGraphics2D.COMP_ALPHA &&
442 sg2d.paintState <= SunGraphics2D.PAINT_ALPHACOLOR &&
|