Path: blob/master/src/java.desktop/macosx/classes/sun/java2d/metal/MTLBufImgOps.java
41159 views
/*1* Copyright (c) 2019, 2021, 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.metal;2627import sun.java2d.SunGraphics2D;28import sun.java2d.SurfaceData;29import sun.java2d.loops.CompositeType;30import sun.java2d.pipe.BufferedBufImgOps;3132import java.awt.image.AffineTransformOp;33import java.awt.image.BufferedImage;34import java.awt.image.BufferedImageOp;35import java.awt.image.ConvolveOp;36import java.awt.image.LookupOp;37import java.awt.image.RescaleOp;3839import static sun.java2d.metal.MTLContext.MTLContextCaps.CAPS_EXT_BIOP_SHADER;4041class MTLBufImgOps extends BufferedBufImgOps {4243/**44* This method is called from MTLDrawImage.transformImage() only. It45* validates the provided BufferedImageOp to determine whether the op46* is one that can be accelerated by the MTL pipeline. If the operation47* cannot be completed for any reason, this method returns false;48* otherwise, the given BufferedImage is rendered to the destination49* using the provided BufferedImageOp and this method returns true.50*/51static boolean renderImageWithOp(SunGraphics2D sg, BufferedImage img,52BufferedImageOp biop, int x, int y)53{54// Validate the provided BufferedImage (make sure it is one that55// is supported, and that its properties are acceleratable)56if (biop instanceof ConvolveOp) {57if (!isConvolveOpValid((ConvolveOp)biop)) {58return false;59}60} else if (biop instanceof RescaleOp) {61if (!isRescaleOpValid((RescaleOp)biop, img)) {62return false;63}64} else if (biop instanceof LookupOp) {65if (!isLookupOpValid((LookupOp)biop, img)) {66return false;67}68} else {69// No acceleration for other BufferedImageOps (yet)70return false;71}7273SurfaceData dstData = sg.surfaceData;74if (!(dstData instanceof MTLSurfaceData) ||75(sg.interpolationType == AffineTransformOp.TYPE_BICUBIC) ||76(sg.compositeState > SunGraphics2D.COMP_ALPHA))77{78return false;79}8081SurfaceData srcData =82dstData.getSourceSurfaceData(img, SunGraphics2D.TRANSFORM_ISIDENT,83CompositeType.SrcOver, null);84if (!(srcData instanceof MTLSurfaceData)) {85// REMIND: this hack tries to ensure that we have a cached texture86srcData =87dstData.getSourceSurfaceData(img, SunGraphics2D.TRANSFORM_ISIDENT,88CompositeType.SrcOver, null);89if (!(srcData instanceof MTLSurfaceData)) {90return false;91}92}9394// Verify that the source surface is actually a texture and95// that the operation is supported96MTLSurfaceData mtlSrc = (MTLSurfaceData)srcData;97MTLGraphicsConfig gc = mtlSrc.getMTLGraphicsConfig();98if (mtlSrc.getType() != MTLSurfaceData.TEXTURE ||99!gc.isCapPresent(CAPS_EXT_BIOP_SHADER))100{101return false;102}103104int sw = img.getWidth();105int sh = img.getHeight();106MTLBlitLoops.IsoBlit(srcData, dstData,107img, biop,108sg.composite, sg.getCompClip(),109sg.transform, sg.interpolationType,1100, 0, sw, sh,111x, y, x+sw, y+sh,112true);113114return true;115}116}117118119