Path: blob/master/src/java.desktop/unix/classes/sun/java2d/x11/X11VolatileSurfaceManager.java
41159 views
/*1* Copyright (c) 2000, 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.GraphicsConfiguration;28import java.awt.ImageCapabilities;29import java.awt.Transparency;30import java.awt.image.ColorModel;3132import sun.awt.X11GraphicsConfig;33import sun.awt.image.SunVolatileImage;34import sun.awt.image.VolatileSurfaceManager;35import sun.java2d.SurfaceData;3637/**38* X11 platform implementation of the VolatileSurfaceManager class.39* The class attempts to create and use a pixmap-based SurfaceData40* object (X11PixmapSurfaceData).41* If this object cannot be created or re-created as necessary, the42* class falls back to a system memory based SurfaceData object43* (BufImgSurfaceData) that will be used until the accelerated44* SurfaceData can be restored.45*/46public class X11VolatileSurfaceManager extends VolatileSurfaceManager {4748private boolean accelerationEnabled;4950public X11VolatileSurfaceManager(SunVolatileImage vImg, Object context) {51super(vImg, context);5253// We only accelerated opaque vImages currently54accelerationEnabled = X11SurfaceData.isAccelerationEnabled() &&55(vImg.getTransparency() == Transparency.OPAQUE);5657if ((context != null) && !accelerationEnabled) {58// if we're wrapping a backbuffer drawable, we must ensure that59// the accelerated surface is initialized up front, regardless60// of whether acceleration is enabled. But we need to set61// the accelerationEnabled field to true to reflect that this62// SM is actually accelerated.63accelerationEnabled = true;64sdAccel = initAcceleratedSurface();65sdCurrent = sdAccel;6667if (sdBackup != null) {68// release the system memory backup surface, as we won't be69// needing it in this case70sdBackup = null;71}72}73}7475protected boolean isAccelerationEnabled() {76return accelerationEnabled;77}7879/**80* Create a pixmap-based SurfaceData object81*/82protected SurfaceData initAcceleratedSurface() {83SurfaceData sData;8485try {86X11GraphicsConfig gc = (X11GraphicsConfig)vImg.getGraphicsConfig();87ColorModel cm = gc.getColorModel();88long drawable = 0;89if (context instanceof Long) {90drawable = ((Long)context).longValue();91}92sData = X11SurfaceData.createData(gc,93vImg.getWidth(),94vImg.getHeight(),95cm, vImg, drawable,96Transparency.OPAQUE,97false);98} catch (NullPointerException ex) {99sData = null;100} catch (OutOfMemoryError er) {101sData = null;102}103104return sData;105}106107protected boolean isConfigValid(GraphicsConfiguration gc) {108// REMIND: we might be too paranoid here, requiring that109// the GC be exactly the same as the original one. The110// real answer is one that guarantees that pixmap copies111// will be correct (which requires like bit depths and112// formats).113return ((gc == null) || (gc == vImg.getGraphicsConfig()));114}115116/**117* Need to override the default behavior because Pixmaps-based118* images are accelerated but not volatile.119*/120@Override121public ImageCapabilities getCapabilities(GraphicsConfiguration gc) {122if (isConfigValid(gc) && isAccelerationEnabled()) {123// accelerated but not volatile124return new ImageCapabilities(true);125}126// neither accelerated nor volatile127return new ImageCapabilities(false);128}129}130131132