J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. |
| 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. Sun designates this |
| 8 | * particular file as subject to the "Classpath" exception as provided |
| 9 | * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 22 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 23 | * have any questions. |
| 24 | */ |
| 25 | |
| 26 | package sun.java2d.opengl; |
| 27 | |
| 28 | import java.awt.image.AffineTransformOp; |
| 29 | import java.awt.image.BufferedImage; |
| 30 | import java.awt.image.BufferedImageOp; |
| 31 | import java.awt.image.ConvolveOp; |
| 32 | import java.awt.image.LookupOp; |
| 33 | import java.awt.image.RescaleOp; |
| 34 | import sun.java2d.SunGraphics2D; |
| 35 | import sun.java2d.SurfaceData; |
| 36 | import sun.java2d.loops.CompositeType; |
| 37 | import sun.java2d.pipe.BufferedBufImgOps; |
| 38 | |
| 39 | class OGLBufImgOps extends BufferedBufImgOps { |
| 40 | |
| 41 | /** |
| 42 | * This method is called from OGLDrawImage.transformImage() only. It |
| 43 | * validates the provided BufferedImageOp to determine whether the op |
| 44 | * is one that can be accelerated by the OGL pipeline. If the operation |
| 45 | * cannot be completed for any reason, this method returns false; |
| 46 | * otherwise, the given BufferedImage is rendered to the destination |
| 47 | * using the provided BufferedImageOp and this method returns true. |
| 48 | */ |
| 49 | static boolean renderImageWithOp(SunGraphics2D sg, BufferedImage img, |
| 50 | BufferedImageOp biop, int x, int y) |
| 51 | { |
| 52 | // Validate the provided BufferedImage (make sure it is one that |
| 53 | // is supported, and that its properties are acceleratable) |
| 54 | if (biop instanceof ConvolveOp) { |
| 55 | if (!isConvolveOpValid((ConvolveOp)biop)) { |
| 56 | return false; |
| 57 | } |
| 58 | } else if (biop instanceof RescaleOp) { |
| 59 | if (!isRescaleOpValid((RescaleOp)biop, img)) { |
| 60 | return false; |
| 61 | } |
| 62 | } else if (biop instanceof LookupOp) { |
| 63 | if (!isLookupOpValid((LookupOp)biop, img)) { |
| 64 | return false; |
| 65 | } |
| 66 | } else { |
| 67 | // No acceleration for other BufferedImageOps (yet) |
| 68 | return false; |
| 69 | } |
| 70 | |
| 71 | SurfaceData dstData = sg.surfaceData; |
| 72 | if (!(dstData instanceof OGLSurfaceData) || |
| 73 | (sg.interpolationType == AffineTransformOp.TYPE_BICUBIC) || |
| 74 | (sg.compositeState > SunGraphics2D.COMP_ALPHA)) |
| 75 | { |
| 76 | return false; |
| 77 | } |
| 78 | |
| 79 | SurfaceData srcData = |
| 80 | dstData.getSourceSurfaceData(img, sg.TRANSFORM_ISIDENT, |
| 81 | CompositeType.SrcOver, null); |
| 82 | if (!(srcData instanceof OGLSurfaceData)) { |
| 83 | // REMIND: this hack tries to ensure that we have a cached texture |
| 84 | srcData = |
| 85 | dstData.getSourceSurfaceData(img, sg.TRANSFORM_ISIDENT, |
| 86 | CompositeType.SrcOver, null); |
| 87 | if (!(srcData instanceof OGLSurfaceData)) { |
| 88 | return false; |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | // Verify that the source surface is actually a texture and |
| 93 | // that the operation is supported |
| 94 | OGLSurfaceData oglSrc = (OGLSurfaceData)srcData; |
| 95 | OGLGraphicsConfig gc = oglSrc.getOGLGraphicsConfig(); |
| 96 | if (oglSrc.getType() != OGLSurfaceData.TEXTURE || |
| 97 | !gc.isCapPresent(OGLContext.CAPS_EXT_BIOP_SHADER)) |
| 98 | { |
| 99 | return false; |
| 100 | } |
| 101 | |
| 102 | int sw = img.getWidth(); |
| 103 | int sh = img.getHeight(); |
| 104 | OGLBlitLoops.IsoBlit(srcData, dstData, |
| 105 | img, biop, |
| 106 | sg.composite, sg.getCompClip(), |
| 107 | sg.transform, sg.interpolationType, |
| 108 | 0, 0, sw, sh, |
| 109 | x, y, x+sw, y+sh, |
| 110 | true); |
| 111 | |
| 112 | return true; |
| 113 | } |
| 114 | } |