0N/A/*
2362N/A * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage sun.java2d.opengl;
0N/A
0N/Aimport java.awt.image.AffineTransformOp;
0N/Aimport java.awt.image.BufferedImage;
0N/Aimport java.awt.image.BufferedImageOp;
0N/Aimport java.awt.image.ConvolveOp;
0N/Aimport java.awt.image.LookupOp;
0N/Aimport java.awt.image.RescaleOp;
0N/Aimport sun.java2d.SunGraphics2D;
0N/Aimport sun.java2d.SurfaceData;
0N/Aimport sun.java2d.loops.CompositeType;
0N/Aimport sun.java2d.pipe.BufferedBufImgOps;
430N/Aimport static sun.java2d.opengl.OGLContext.OGLContextCaps.*;
0N/A
0N/Aclass OGLBufImgOps extends BufferedBufImgOps {
0N/A
0N/A /**
0N/A * This method is called from OGLDrawImage.transformImage() only. It
0N/A * validates the provided BufferedImageOp to determine whether the op
0N/A * is one that can be accelerated by the OGL pipeline. If the operation
0N/A * cannot be completed for any reason, this method returns false;
0N/A * otherwise, the given BufferedImage is rendered to the destination
0N/A * using the provided BufferedImageOp and this method returns true.
0N/A */
0N/A static boolean renderImageWithOp(SunGraphics2D sg, BufferedImage img,
0N/A BufferedImageOp biop, int x, int y)
0N/A {
0N/A // Validate the provided BufferedImage (make sure it is one that
0N/A // is supported, and that its properties are acceleratable)
0N/A if (biop instanceof ConvolveOp) {
0N/A if (!isConvolveOpValid((ConvolveOp)biop)) {
0N/A return false;
0N/A }
0N/A } else if (biop instanceof RescaleOp) {
0N/A if (!isRescaleOpValid((RescaleOp)biop, img)) {
0N/A return false;
0N/A }
0N/A } else if (biop instanceof LookupOp) {
0N/A if (!isLookupOpValid((LookupOp)biop, img)) {
0N/A return false;
0N/A }
0N/A } else {
0N/A // No acceleration for other BufferedImageOps (yet)
0N/A return false;
0N/A }
0N/A
0N/A SurfaceData dstData = sg.surfaceData;
0N/A if (!(dstData instanceof OGLSurfaceData) ||
0N/A (sg.interpolationType == AffineTransformOp.TYPE_BICUBIC) ||
0N/A (sg.compositeState > SunGraphics2D.COMP_ALPHA))
0N/A {
0N/A return false;
0N/A }
0N/A
0N/A SurfaceData srcData =
0N/A dstData.getSourceSurfaceData(img, sg.TRANSFORM_ISIDENT,
0N/A CompositeType.SrcOver, null);
0N/A if (!(srcData instanceof OGLSurfaceData)) {
0N/A // REMIND: this hack tries to ensure that we have a cached texture
0N/A srcData =
0N/A dstData.getSourceSurfaceData(img, sg.TRANSFORM_ISIDENT,
0N/A CompositeType.SrcOver, null);
0N/A if (!(srcData instanceof OGLSurfaceData)) {
0N/A return false;
0N/A }
0N/A }
0N/A
0N/A // Verify that the source surface is actually a texture and
0N/A // that the operation is supported
0N/A OGLSurfaceData oglSrc = (OGLSurfaceData)srcData;
0N/A OGLGraphicsConfig gc = oglSrc.getOGLGraphicsConfig();
0N/A if (oglSrc.getType() != OGLSurfaceData.TEXTURE ||
430N/A !gc.isCapPresent(CAPS_EXT_BIOP_SHADER))
0N/A {
0N/A return false;
0N/A }
0N/A
0N/A int sw = img.getWidth();
0N/A int sh = img.getHeight();
0N/A OGLBlitLoops.IsoBlit(srcData, dstData,
0N/A img, biop,
0N/A sg.composite, sg.getCompClip(),
0N/A sg.transform, sg.interpolationType,
0N/A 0, 0, sw, sh,
0N/A x, y, x+sw, y+sh,
0N/A true);
0N/A
0N/A return true;
0N/A }
0N/A}