Path: blob/master/src/java.desktop/unix/classes/sun/java2d/opengl/GLXVolatileSurfaceManager.java
41159 views
/*1* Copyright (c) 2003, 2015, 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;3334import sun.awt.AWTAccessor;35import sun.awt.AWTAccessor.ComponentAccessor;36import sun.awt.X11ComponentPeer;37import sun.awt.image.SunVolatileImage;38import sun.awt.image.VolatileSurfaceManager;39import sun.java2d.BackBufferCapsProvider;40import sun.java2d.SurfaceData;41import static sun.java2d.opengl.OGLContext.OGLContextCaps.*;42import sun.java2d.pipe.hw.ExtendedBufferCapabilities;43import static sun.java2d.pipe.hw.AccelSurface.*;44import static sun.java2d.pipe.hw.ExtendedBufferCapabilities.VSyncType.*;4546public class GLXVolatileSurfaceManager extends VolatileSurfaceManager {4748private final boolean accelerationEnabled;4950public GLXVolatileSurfaceManager(SunVolatileImage vImg, Object context) {51super(vImg, context);5253/*54* We will attempt to accelerate this image only under the55* following conditions:56* - the image is not bitmask AND the GraphicsConfig supports the FBO57* extension58*/59int transparency = vImg.getTransparency();60GLXGraphicsConfig gc = (GLXGraphicsConfig) vImg.getGraphicsConfig();61accelerationEnabled = gc.isCapPresent(CAPS_EXT_FBOBJECT)62&& transparency != Transparency.BITMASK;63}6465protected boolean isAccelerationEnabled() {66return accelerationEnabled;67}6869/**70* Create a FBO-based SurfaceData object (or init the backbuffer71* of an existing window if this is a double buffered GraphicsConfig)72*/73protected SurfaceData initAcceleratedSurface() {74SurfaceData sData;75Component comp = vImg.getComponent();76final ComponentAccessor acc = AWTAccessor.getComponentAccessor();77X11ComponentPeer peer = (comp != null) ? acc.getPeer(comp) : null;7879try {80boolean createVSynced = false;81boolean forceback = false;82if (context instanceof Boolean) {83forceback = ((Boolean)context).booleanValue();84if (forceback && peer instanceof BackBufferCapsProvider) {85BackBufferCapsProvider provider =86(BackBufferCapsProvider)peer;87BufferCapabilities caps = provider.getBackBufferCaps();88if (caps instanceof ExtendedBufferCapabilities) {89ExtendedBufferCapabilities ebc =90(ExtendedBufferCapabilities)caps;91if (ebc.getVSync() == VSYNC_ON &&92ebc.getFlipContents() == COPIED)93{94createVSynced = true;95forceback = false;96}97}98}99}100101if (forceback) {102// peer must be non-null in this case103sData = GLXSurfaceData.createData(peer, vImg, FLIP_BACKBUFFER);104} else {105GLXGraphicsConfig gc =106(GLXGraphicsConfig)vImg.getGraphicsConfig();107ColorModel cm = gc.getColorModel(vImg.getTransparency());108int type = vImg.getForcedAccelSurfaceType();109// if acceleration type is forced (type != UNDEFINED) then110// use the forced type, otherwise choose FBOBJECT111if (type == OGLSurfaceData.UNDEFINED) {112type = OGLSurfaceData.FBOBJECT;113}114if (createVSynced) {115sData = GLXSurfaceData.createData(peer, vImg, type);116} else {117sData = GLXSurfaceData.createData(gc,118vImg.getWidth(),119vImg.getHeight(),120cm, vImg, type);121}122}123} catch (NullPointerException ex) {124sData = null;125} catch (OutOfMemoryError er) {126sData = null;127}128129return sData;130}131132@Override133protected boolean isConfigValid(GraphicsConfiguration gc) {134return ((gc == null) || (gc == vImg.getGraphicsConfig()));135}136137@Override138public void initContents() {139if (vImg.getForcedAccelSurfaceType() != OGLSurfaceData.TEXTURE) {140super.initContents();141}142}143}144145146