Path: blob/master/src/java.desktop/unix/classes/sun/java2d/x11/X11SurfaceDataProxy.java
41159 views
/*1* Copyright (c) 2007, 2020, 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.Transparency;29import java.awt.image.ColorModel;30import java.awt.image.DirectColorModel;31import java.awt.image.IndexColorModel;3233import sun.awt.X11GraphicsConfig;34import sun.java2d.SunGraphics2D;35import sun.java2d.SurfaceData;36import sun.java2d.SurfaceDataProxy;37import sun.java2d.loops.CompositeType;3839/**40* The proxy class contains the logic for when to replace a41* SurfaceData with a cached X11 Pixmap and the code to create42* the accelerated surfaces.43*/44public abstract class X11SurfaceDataProxy extends SurfaceDataProxy45implements Transparency46{47public static SurfaceDataProxy createProxy(SurfaceData srcData,48X11GraphicsConfig dstConfig)49{50if (srcData instanceof X11SurfaceData) {51// srcData must be a VolatileImage which either matches52// our visual or not - either way we do not cache it...53return UNCACHED;54}5556ColorModel cm = srcData.getColorModel();57int transparency = cm.getTransparency();5859if (transparency == Transparency.OPAQUE) {60return new Opaque(dstConfig);61} else if (transparency == Transparency.BITMASK) {62// 4673490: updateBitmask() only handles ICMs with 8-bit indices63if ((cm instanceof IndexColorModel) && cm.getPixelSize() == 8) {64return new Bitmask(dstConfig);65}66// The only other ColorModel handled by updateBitmask() is67// a DCM where the alpha bit, and only the alpha bit, is in68// the top 8 bits69if (cm instanceof DirectColorModel) {70DirectColorModel dcm = (DirectColorModel) cm;71int colormask = (dcm.getRedMask() |72dcm.getGreenMask() |73dcm.getBlueMask());74int alphamask = dcm.getAlphaMask();7576if ((colormask & 0xff000000) == 0 &&77(alphamask & 0xff000000) != 0)78{79return new Bitmask(dstConfig);80}81}82}8384// For whatever reason, this image is not a good candidate for85// caching in a pixmap so we return the non-caching (non-)proxy.86return UNCACHED;87}8889X11GraphicsConfig x11gc;9091public X11SurfaceDataProxy(X11GraphicsConfig x11gc) {92this.x11gc = x11gc;93}9495@Override96public SurfaceData validateSurfaceData(SurfaceData srcData,97SurfaceData cachedData,98int w, int h)99{100if (cachedData == null) {101try {102// Bitmask will be created lazily during the blit phase103cachedData = X11SurfaceData.createData(x11gc, w, h,104x11gc.getColorModel(),105null, 0,106getTransparency(), true);107} catch (OutOfMemoryError oome) {108}109}110return cachedData;111}112113/**114* Proxy for opaque source images.115* This proxy can accelerate unscaled Src copies.116*/117public static class Opaque extends X11SurfaceDataProxy {118public Opaque(X11GraphicsConfig x11gc) {119super(x11gc);120}121122public int getTransparency() {123return Transparency.OPAQUE;124}125126@Override127public boolean isSupportedOperation(SurfaceData srcData,128int txtype,129CompositeType comp,130Color bgColor)131{132return (txtype < SunGraphics2D.TRANSFORM_TRANSLATESCALE &&133(CompositeType.SrcOverNoEa.equals(comp) ||134CompositeType.SrcNoEa.equals(comp)));135}136}137138/**139* Proxy for bitmask transparent source images.140* This proxy can accelerate unscaled Src copies or141* unscaled SrcOver copies that use an opaque bgColor.142*/143public static class Bitmask extends X11SurfaceDataProxy {144public Bitmask(X11GraphicsConfig x11gc) {145super(x11gc);146}147148public int getTransparency() {149return Transparency.BITMASK;150}151152@Override153public boolean isSupportedOperation(SurfaceData srcData,154int txtype,155CompositeType comp,156Color bgColor)157{158// These could probably be combined into a single159// nested if, but the logic is easier to follow this way.160161// we don't have X11 scale loops, so always use162// software surface in case of scaling163if (txtype >= SunGraphics2D.TRANSFORM_TRANSLATESCALE) {164return false;165}166167if (bgColor != null &&168bgColor.getTransparency() != Transparency.OPAQUE)169{170return false;171}172173// for transparent images SrcNoEa+bgColor has the174// same effect as SrcOverNoEa+bgColor, so we allow175// copying from pixmap SD using accelerated blitbg loops:176// SrcOver will be changed to SrcNoEa in DrawImage.blitSD177if (CompositeType.SrcOverNoEa.equals(comp) ||178(CompositeType.SrcNoEa.equals(comp) &&179bgColor != null))180{181return true;182}183184return false;185}186}187}188189190