Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/classes/sun/java2d/x11/X11VolatileSurfaceManager.java
32288 views
/*1* Copyright (c) 2000, 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.GraphicsConfiguration;28import java.awt.ImageCapabilities;29import java.awt.Transparency;30import java.awt.image.ColorModel;31import sun.awt.X11GraphicsConfig;32import sun.awt.image.SunVolatileImage;33import sun.awt.image.VolatileSurfaceManager;34import sun.java2d.SurfaceData;3536/**37* X11 platform implementation of the VolatileSurfaceManager class.38* The class attempts to create and use a pixmap-based SurfaceData39* object (X11PixmapSurfaceData).40* If this object cannot be created or re-created as necessary, the41* class falls back to a system memory based SurfaceData object42* (BufImgSurfaceData) that will be used until the accelerated43* SurfaceData can be restored.44*/45public class X11VolatileSurfaceManager extends VolatileSurfaceManager {4647private boolean accelerationEnabled;4849public X11VolatileSurfaceManager(SunVolatileImage vImg, Object context) {50super(vImg, context);5152// We only accelerated opaque vImages currently53accelerationEnabled = X11SurfaceData.isAccelerationEnabled() &&54(vImg.getTransparency() == Transparency.OPAQUE);5556if ((context != null) && !accelerationEnabled) {57// if we're wrapping a backbuffer drawable, we must ensure that58// the accelerated surface is initialized up front, regardless59// of whether acceleration is enabled. But we need to set60// the accelerationEnabled field to true to reflect that this61// SM is actually accelerated.62accelerationEnabled = true;63sdAccel = initAcceleratedSurface();64sdCurrent = sdAccel;6566if (sdBackup != null) {67// release the system memory backup surface, as we won't be68// needing it in this case69sdBackup = null;70}71}72}7374protected boolean isAccelerationEnabled() {75return accelerationEnabled;76}7778/**79* Create a pixmap-based SurfaceData object80*/81protected SurfaceData initAcceleratedSurface() {82SurfaceData sData;8384try {85X11GraphicsConfig gc = (X11GraphicsConfig)vImg.getGraphicsConfig();86ColorModel cm = gc.getColorModel();87long drawable = 0;88if (context instanceof Long) {89drawable = ((Long)context).longValue();90}91sData = X11SurfaceData.createData(gc,92vImg.getWidth(),93vImg.getHeight(),94cm, vImg, drawable,95Transparency.OPAQUE);96} catch (NullPointerException ex) {97sData = null;98} catch (OutOfMemoryError er) {99sData = null;100}101102return sData;103}104105protected boolean isConfigValid(GraphicsConfiguration gc) {106// REMIND: we might be too paranoid here, requiring that107// the GC be exactly the same as the original one. The108// real answer is one that guarantees that pixmap copies109// will be correct (which requires like bit depths and110// formats).111return ((gc == null) || (gc == vImg.getGraphicsConfig()));112}113114/**115* Need to override the default behavior because Pixmaps-based116* images are accelerated but not volatile.117*/118@Override119public ImageCapabilities getCapabilities(GraphicsConfiguration gc) {120if (isConfigValid(gc) && isAccelerationEnabled()) {121// accelerated but not volatile122return new ImageCapabilities(true);123}124// neither accelerated nor volatile125return new ImageCapabilities(false);126}127}128129130