001: /*
002: * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package sun.java2d.opengl;
027:
028: import java.awt.image.AffineTransformOp;
029: import java.awt.image.BufferedImage;
030: import java.awt.image.BufferedImageOp;
031: import java.awt.image.ConvolveOp;
032: import java.awt.image.LookupOp;
033: import java.awt.image.RescaleOp;
034: import sun.java2d.SunGraphics2D;
035: import sun.java2d.SurfaceData;
036: import sun.java2d.loops.CompositeType;
037: import sun.java2d.pipe.BufferedBufImgOps;
038:
039: class OGLBufImgOps extends BufferedBufImgOps {
040:
041: /**
042: * This method is called from OGLDrawImage.transformImage() only. It
043: * validates the provided BufferedImageOp to determine whether the op
044: * is one that can be accelerated by the OGL pipeline. If the operation
045: * cannot be completed for any reason, this method returns false;
046: * otherwise, the given BufferedImage is rendered to the destination
047: * using the provided BufferedImageOp and this method returns true.
048: */
049: static boolean renderImageWithOp(SunGraphics2D sg,
050: BufferedImage img, BufferedImageOp biop, int x, int y) {
051: // Validate the provided BufferedImage (make sure it is one that
052: // is supported, and that its properties are acceleratable)
053: if (biop instanceof ConvolveOp) {
054: if (!isConvolveOpValid((ConvolveOp) biop)) {
055: return false;
056: }
057: } else if (biop instanceof RescaleOp) {
058: if (!isRescaleOpValid((RescaleOp) biop, img)) {
059: return false;
060: }
061: } else if (biop instanceof LookupOp) {
062: if (!isLookupOpValid((LookupOp) biop, img)) {
063: return false;
064: }
065: } else {
066: // No acceleration for other BufferedImageOps (yet)
067: return false;
068: }
069:
070: SurfaceData dstData = sg.surfaceData;
071: if (!(dstData instanceof OGLSurfaceData)
072: || (sg.interpolationType == AffineTransformOp.TYPE_BICUBIC)
073: || (sg.compositeState > SunGraphics2D.COMP_ALPHA)) {
074: return false;
075: }
076:
077: SurfaceData srcData = dstData.getSourceSurfaceData(img,
078: sg.TRANSFORM_ISIDENT, CompositeType.SrcOver, null);
079: if (!(srcData instanceof OGLSurfaceData)) {
080: // REMIND: this hack tries to ensure that we have a cached texture
081: srcData = dstData.getSourceSurfaceData(img,
082: sg.TRANSFORM_ISIDENT, CompositeType.SrcOver, null);
083: if (!(srcData instanceof OGLSurfaceData)) {
084: return false;
085: }
086: }
087:
088: // Verify that the source surface is actually a texture and
089: // that the operation is supported
090: OGLSurfaceData oglSrc = (OGLSurfaceData) srcData;
091: OGLGraphicsConfig gc = oglSrc.getOGLGraphicsConfig();
092: if (oglSrc.getType() != OGLSurfaceData.TEXTURE
093: || !gc.isCapPresent(OGLContext.CAPS_EXT_BIOP_SHADER)) {
094: return false;
095: }
096:
097: int sw = img.getWidth();
098: int sh = img.getHeight();
099: OGLBlitLoops.IsoBlit(srcData, dstData, img, biop, sg.composite,
100: sg.getCompClip(), sg.transform, sg.interpolationType,
101: 0, 0, sw, sh, x, y, x + sw, y + sh, true);
102:
103: return true;
104: }
105: }
|