Path: blob/master/src/java.desktop/macosx/classes/sun/java2d/metal/MTLDrawImage.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.SurfaceType;30import sun.java2d.loops.TransformBlit;31import sun.java2d.pipe.DrawImage;3233import java.awt.Color;34import java.awt.Image;35import java.awt.geom.AffineTransform;36import java.awt.image.AffineTransformOp;37import java.awt.image.BufferedImage;38import java.awt.image.BufferedImageOp;3940public class MTLDrawImage extends DrawImage {4142@Override43protected void renderImageXform(SunGraphics2D sg, Image img,44AffineTransform tx, int interpType,45int sx1, int sy1, int sx2, int sy2,46Color bgColor)47{48// punt to the MediaLib-based transformImage() in the superclass if:49// - bicubic interpolation is specified50// - a background color is specified and will be used51// - the source surface is neither a texture nor render-to-texture52// surface, and a non-default interpolation hint is specified53// (we can only control the filtering for texture->surface54// copies)55// REMIND: we should tweak the sw->texture->surface56// transform case to handle filtering appropriately57// (see 4841762)...58// - an appropriate TransformBlit primitive could not be found59if (interpType != AffineTransformOp.TYPE_BICUBIC) {60SurfaceData dstData = sg.surfaceData;61SurfaceData srcData =62dstData.getSourceSurfaceData(img,63SunGraphics2D.TRANSFORM_GENERIC,64sg.imageComp,65bgColor);6667if (srcData != null &&68!isBgOperation(srcData, bgColor) &&69(srcData.getSurfaceType() == MTLSurfaceData.MTLTexture ||70srcData.getSurfaceType() == MTLSurfaceData.MTLSurfaceRTT ||71interpType == AffineTransformOp.TYPE_NEAREST_NEIGHBOR))72{73SurfaceType srcType = srcData.getSurfaceType();74SurfaceType dstType = dstData.getSurfaceType();75TransformBlit blit = TransformBlit.getFromCache(srcType,76sg.imageComp,77dstType);7879if (blit != null) {80blit.Transform(srcData, dstData,81sg.composite, sg.getCompClip(),82tx, interpType,83sx1, sy1, 0, 0, sx2-sx1, sy2-sy1);84return;85}86}87}8889super.renderImageXform(sg, img, tx, interpType,90sx1, sy1, sx2, sy2, bgColor);91}9293@Override94public void transformImage(SunGraphics2D sg, BufferedImage img,95BufferedImageOp op, int x, int y)96{97if (op != null) {98if (op instanceof AffineTransformOp) {99AffineTransformOp atop = (AffineTransformOp) op;100transformImage(sg, img, x, y,101atop.getTransform(),102atop.getInterpolationType());103return;104} else {105if (MTLBufImgOps.renderImageWithOp(sg, img, op, x, y)) {106return;107}108}109img = op.filter(img, null);110}111copyImage(sg, img, x, y, null);112}113}114115116