Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/classes/sun/java2d/x11/X11SurfaceDataProxy.java
32288 views
/*1* Copyright (c) 2007, 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.x11;2627import java.awt.Color;28import java.awt.AlphaComposite;29import java.awt.GraphicsConfiguration;30import java.awt.Transparency;31import java.awt.image.ColorModel;32import java.awt.image.IndexColorModel;33import java.awt.image.DirectColorModel;3435import sun.awt.X11GraphicsConfig;36import sun.java2d.SurfaceData;37import sun.java2d.SurfaceDataProxy;38import sun.java2d.SunGraphics2D;39import sun.java2d.loops.SurfaceType;40import sun.java2d.loops.CompositeType;4142/**43* The proxy class contains the logic for when to replace a44* SurfaceData with a cached X11 Pixmap and the code to create45* the accelerated surfaces.46*/47public abstract class X11SurfaceDataProxy extends SurfaceDataProxy48implements Transparency49{50public static SurfaceDataProxy createProxy(SurfaceData srcData,51X11GraphicsConfig dstConfig)52{53if (srcData instanceof X11SurfaceData) {54// srcData must be a VolatileImage which either matches55// our visual or not - either way we do not cache it...56return UNCACHED;57}5859ColorModel cm = srcData.getColorModel();60int transparency = cm.getTransparency();6162if (transparency == Transparency.OPAQUE) {63return new Opaque(dstConfig);64} else if (transparency == Transparency.BITMASK) {65// 4673490: updateBitmask() only handles ICMs with 8-bit indices66if ((cm instanceof IndexColorModel) && cm.getPixelSize() == 8) {67return new Bitmask(dstConfig);68}69// The only other ColorModel handled by updateBitmask() is70// a DCM where the alpha bit, and only the alpha bit, is in71// the top 8 bits72if (cm instanceof DirectColorModel) {73DirectColorModel dcm = (DirectColorModel) cm;74int colormask = (dcm.getRedMask() |75dcm.getGreenMask() |76dcm.getBlueMask());77int alphamask = dcm.getAlphaMask();7879if ((colormask & 0xff000000) == 0 &&80(alphamask & 0xff000000) != 0)81{82return new Bitmask(dstConfig);83}84}85}8687// For whatever reason, this image is not a good candidate for88// caching in a pixmap so we return the non-caching (non-)proxy.89return UNCACHED;90}9192X11GraphicsConfig x11gc;9394public X11SurfaceDataProxy(X11GraphicsConfig x11gc) {95this.x11gc = x11gc;96}9798@Override99public SurfaceData validateSurfaceData(SurfaceData srcData,100SurfaceData cachedData,101int w, int h)102{103if (cachedData == null) {104try {105// Bitmask will be created lazily during the blit phase106cachedData = X11SurfaceData.createData(x11gc, w, h,107x11gc.getColorModel(),108null, 0, getTransparency());109} catch (OutOfMemoryError oome) {110}111}112return cachedData;113}114115/**116* Proxy for opaque source images.117* This proxy can accelerate unscaled Src copies.118*/119public static class Opaque extends X11SurfaceDataProxy {120public Opaque(X11GraphicsConfig x11gc) {121super(x11gc);122}123124public int getTransparency() {125return Transparency.OPAQUE;126}127128@Override129public boolean isSupportedOperation(SurfaceData srcData,130int txtype,131CompositeType comp,132Color bgColor)133{134return (txtype < SunGraphics2D.TRANSFORM_TRANSLATESCALE &&135(CompositeType.SrcOverNoEa.equals(comp) ||136CompositeType.SrcNoEa.equals(comp)));137}138}139140/**141* Proxy for bitmask transparent source images.142* This proxy can accelerate unscaled Src copies or143* unscaled SrcOver copies that use an opaque bgColor.144*/145public static class Bitmask extends X11SurfaceDataProxy {146public Bitmask(X11GraphicsConfig x11gc) {147super(x11gc);148}149150public int getTransparency() {151return Transparency.BITMASK;152}153154@Override155public boolean isSupportedOperation(SurfaceData srcData,156int txtype,157CompositeType comp,158Color bgColor)159{160// These could probably be combined into a single161// nested if, but the logic is easier to follow this way.162163// we don't have X11 scale loops, so always use164// software surface in case of scaling165if (txtype >= SunGraphics2D.TRANSFORM_TRANSLATESCALE) {166return false;167}168169if (bgColor != null &&170bgColor.getTransparency() != Transparency.OPAQUE)171{172return false;173}174175// for transparent images SrcNoEa+bgColor has the176// same effect as SrcOverNoEa+bgColor, so we allow177// copying from pixmap SD using accelerated blitbg loops:178// SrcOver will be changed to SrcNoEa in DrawImage.blitSD179if (CompositeType.SrcOverNoEa.equals(comp) ||180(CompositeType.SrcNoEa.equals(comp) &&181bgColor != null))182{183return true;184}185186return false;187}188}189}190191192