Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/classes/sun/java2d/opengl/GLXVolatileSurfaceManager.java
32288 views
/*1* Copyright (c) 2003, 2008, 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.opengl;2627import java.awt.BufferCapabilities;28import static java.awt.BufferCapabilities.FlipContents.*;29import java.awt.Component;30import java.awt.GraphicsConfiguration;31import java.awt.Transparency;32import java.awt.image.ColorModel;33import sun.awt.X11ComponentPeer;34import sun.awt.image.SunVolatileImage;35import sun.awt.image.VolatileSurfaceManager;36import sun.java2d.BackBufferCapsProvider;37import sun.java2d.SurfaceData;38import static sun.java2d.opengl.OGLContext.OGLContextCaps.*;39import sun.java2d.pipe.hw.ExtendedBufferCapabilities;40import static sun.java2d.pipe.hw.AccelSurface.*;41import static sun.java2d.pipe.hw.ExtendedBufferCapabilities.VSyncType.*;4243public class GLXVolatileSurfaceManager extends VolatileSurfaceManager {4445private boolean accelerationEnabled;4647public GLXVolatileSurfaceManager(SunVolatileImage vImg, Object context) {48super(vImg, context);4950/*51* We will attempt to accelerate this image only under the52* following conditions:53* - the image is opaque OR54* - the image is translucent AND55* - the GraphicsConfig supports the FBO extension OR56* - the GraphicsConfig has a stored alpha channel57*/58int transparency = vImg.getTransparency();59GLXGraphicsConfig gc = (GLXGraphicsConfig)vImg.getGraphicsConfig();60accelerationEnabled =61(transparency == Transparency.OPAQUE) ||62((transparency == Transparency.TRANSLUCENT) &&63(gc.isCapPresent(CAPS_EXT_FBOBJECT) ||64gc.isCapPresent(CAPS_STORED_ALPHA)));65}6667protected boolean isAccelerationEnabled() {68return accelerationEnabled;69}7071/**72* Create a pbuffer-based SurfaceData object (or init the backbuffer73* of an existing window if this is a double buffered GraphicsConfig)74*/75protected SurfaceData initAcceleratedSurface() {76SurfaceData sData;77Component comp = vImg.getComponent();78X11ComponentPeer peer =79(comp != null) ? (X11ComponentPeer)comp.getPeer() : null;8081try {82boolean createVSynced = false;83boolean forceback = false;84if (context instanceof Boolean) {85forceback = ((Boolean)context).booleanValue();86if (forceback && peer instanceof BackBufferCapsProvider) {87BackBufferCapsProvider provider =88(BackBufferCapsProvider)peer;89BufferCapabilities caps = provider.getBackBufferCaps();90if (caps instanceof ExtendedBufferCapabilities) {91ExtendedBufferCapabilities ebc =92(ExtendedBufferCapabilities)caps;93if (ebc.getVSync() == VSYNC_ON &&94ebc.getFlipContents() == COPIED)95{96createVSynced = true;97forceback = false;98}99}100}101}102103if (forceback) {104// peer must be non-null in this case105sData = GLXSurfaceData.createData(peer, vImg, FLIP_BACKBUFFER);106} else {107GLXGraphicsConfig gc =108(GLXGraphicsConfig)vImg.getGraphicsConfig();109ColorModel cm = gc.getColorModel(vImg.getTransparency());110int type = vImg.getForcedAccelSurfaceType();111// if acceleration type is forced (type != UNDEFINED) then112// use the forced type, otherwise choose one based on caps113if (type == OGLSurfaceData.UNDEFINED) {114type = gc.isCapPresent(CAPS_EXT_FBOBJECT) ?115OGLSurfaceData.FBOBJECT : OGLSurfaceData.PBUFFER;116}117if (createVSynced) {118sData = GLXSurfaceData.createData(peer, vImg, type);119} else {120sData = GLXSurfaceData.createData(gc,121vImg.getWidth(),122vImg.getHeight(),123cm, vImg, type);124}125}126} catch (NullPointerException ex) {127sData = null;128} catch (OutOfMemoryError er) {129sData = null;130}131132return sData;133}134135@Override136protected boolean isConfigValid(GraphicsConfiguration gc) {137return ((gc == null) || (gc == vImg.getGraphicsConfig()));138}139140@Override141public void initContents() {142if (vImg.getForcedAccelSurfaceType() != OGLSurfaceData.TEXTURE) {143super.initContents();144}145}146}147148149