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