Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/windows/classes/sun/java2d/d3d/D3DBufImgOps.java
32288 views
/*1* Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.java2d.d3d;2627import java.awt.image.AffineTransformOp;28import java.awt.image.BufferedImage;29import java.awt.image.BufferedImageOp;30import java.awt.image.ConvolveOp;31import java.awt.image.LookupOp;32import java.awt.image.RescaleOp;33import sun.java2d.SunGraphics2D;34import sun.java2d.SurfaceData;35import sun.java2d.loops.CompositeType;36import sun.java2d.pipe.BufferedBufImgOps;37import static sun.java2d.d3d.D3DContext.D3DContextCaps.*;3839class D3DBufImgOps extends BufferedBufImgOps {4041/**42* This method is called from D3DDrawImage.transformImage() only. It43* validates the provided BufferedImageOp to determine whether the op44* is one that can be accelerated by the D3D pipeline. If the operation45* cannot be completed for any reason, this method returns false;46* otherwise, the given BufferedImage is rendered to the destination47* using the provided BufferedImageOp and this method returns true.48*/49static boolean renderImageWithOp(SunGraphics2D sg, BufferedImage img,50BufferedImageOp biop, int x, int y)51{52// Validate the provided BufferedImage (make sure it is one that53// is supported, and that its properties are acceleratable)54if (biop instanceof ConvolveOp) {55if (!isConvolveOpValid((ConvolveOp)biop)) {56return false;57}58} else if (biop instanceof RescaleOp) {59if (!isRescaleOpValid((RescaleOp)biop, img)) {60return false;61}62} else if (biop instanceof LookupOp) {63if (!isLookupOpValid((LookupOp)biop, img)) {64return false;65}66} else {67// No acceleration for other BufferedImageOps (yet)68return false;69}7071SurfaceData dstData = sg.surfaceData;72if (!(dstData instanceof D3DSurfaceData) ||73(sg.interpolationType == AffineTransformOp.TYPE_BICUBIC) ||74(sg.compositeState > SunGraphics2D.COMP_ALPHA))75{76return false;77}7879SurfaceData srcData =80dstData.getSourceSurfaceData(img, sg.TRANSFORM_ISIDENT,81CompositeType.SrcOver, null);82if (!(srcData instanceof D3DSurfaceData)) {83// REMIND: this hack tries to ensure that we have a cached texture84srcData =85dstData.getSourceSurfaceData(img, sg.TRANSFORM_ISIDENT,86CompositeType.SrcOver, null);87if (!(srcData instanceof D3DSurfaceData)) {88return false;89}90}9192// Verify that the source surface is actually a texture and that93// shaders are supported94D3DSurfaceData d3dSrc = (D3DSurfaceData)srcData;95D3DGraphicsDevice gd =96(D3DGraphicsDevice)d3dSrc.getDeviceConfiguration().getDevice();97if (d3dSrc.getType() != D3DSurfaceData.TEXTURE ||98!gd.isCapPresent(CAPS_LCD_SHADER))99{100return false;101}102103int sw = img.getWidth();104int sh = img.getHeight();105D3DBlitLoops.IsoBlit(srcData, dstData,106img, biop,107sg.composite, sg.getCompClip(),108sg.transform, sg.interpolationType,1090, 0, sw, sh,110x, y, x+sw, y+sh,111true);112113return true;114}115}116117118