Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/classes/sun/java2d/xr/XRMaskImage.java
32288 views
/*1* Copyright (c) 2010, 2013, 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.xr;2627import java.awt.*;28import java.awt.geom.*;2930/**31* Management of mask used for some blit-types.32*33* @author Clemens Eisserer34*/3536public class XRMaskImage {3738private static final int MASK_SCALE_FACTOR = 8;3940private static final int BLIT_MASK_SIZE = 8;4142Dimension blitMaskDimensions = new Dimension(BLIT_MASK_SIZE, BLIT_MASK_SIZE);43int blitMaskPixmap;44int blitMaskPicture;45int lastMaskWidth = 0;46int lastMaskHeight = 0;47int lastEA = -1;48AffineTransform lastMaskTransform;4950XRCompositeManager xrMgr;51XRBackend con;5253public XRMaskImage(XRCompositeManager xrMgr, int parentDrawable) {54this.xrMgr = xrMgr;55this.con = xrMgr.getBackend();5657initBlitMask(parentDrawable, BLIT_MASK_SIZE, BLIT_MASK_SIZE);58}596061/**62* Prepares a mask used by a TransformedBlit, fills mask-contents and applies63* transformation.64*/65public int prepareBlitMask(XRSurfaceData dst, AffineTransform maskTX, int width,66int height) {6768int maskWidth = Math.max(width / MASK_SCALE_FACTOR, 1);69int maskHeight = Math.max(height / MASK_SCALE_FACTOR, 1);70maskTX.scale(((double) width) / maskWidth, ((double) height) / maskHeight);7172try {73maskTX.invert();74} catch (NoninvertibleTransformException ex) {75maskTX.setToIdentity();76}7778ensureBlitMaskSize(maskWidth, maskHeight);7980if (lastMaskTransform == null || !lastMaskTransform.equals(maskTX)) {81con.setPictureTransform(blitMaskPicture, maskTX);82lastMaskTransform = maskTX;83}8485int currentEA = xrMgr.getAlphaColor().getAlpha();86if (lastMaskWidth != maskWidth || lastMaskHeight != maskHeight || lastEA != currentEA) {87//Only clear mask, if previous mask area is larger than new one, otherwise simple overpaint it88if (lastMaskWidth > maskWidth || lastMaskHeight > maskHeight) {89con.renderRectangle(blitMaskPicture, XRUtils.PictOpClear, XRColor.NO_ALPHA, 0, 0, lastMaskWidth, lastMaskHeight);90}9192con.renderRectangle(blitMaskPicture, XRUtils.PictOpSrc, xrMgr.getAlphaColor(), 0, 0, maskWidth, maskHeight);93lastEA = currentEA;94}9596lastMaskWidth = maskWidth;97lastMaskHeight = maskHeight;9899return blitMaskPicture;100}101102private void initBlitMask(int parentDrawable, int width, int height) {103int newPM = con.createPixmap(parentDrawable, 8, width, height);104int newPict = con.createPicture(newPM, XRUtils.PictStandardA8);105106/*Free old mask*/107if (blitMaskPixmap != 0) {108con.freePixmap(blitMaskPixmap);109con.freePicture(blitMaskPicture);110}111112blitMaskPixmap = newPM;113blitMaskPicture = newPict;114115con.renderRectangle(blitMaskPicture, XRUtils.PictOpClear, XRColor.NO_ALPHA, 0, 0, width, height);116117blitMaskDimensions.width = width;118blitMaskDimensions.height = height;119lastMaskWidth = 0;120lastMaskHeight = 0;121lastMaskTransform = null;122}123124private void ensureBlitMaskSize(int minSizeX, int minSizeY) {125if (minSizeX > blitMaskDimensions.width || minSizeY > blitMaskDimensions.height) {126int newWidth = Math.max(minSizeX, blitMaskDimensions.width);127int newHeight = Math.max(minSizeY, blitMaskDimensions.height);128initBlitMask(blitMaskPixmap, newWidth, newHeight);129}130}131}132133134