Path: blob/master/src/java.desktop/windows/classes/sun/java2d/opengl/WGLVolatileSurfaceManager.java
41159 views
/*1* Copyright (c) 2004, 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.image.SunVolatileImage;37import sun.awt.image.VolatileSurfaceManager;38import sun.awt.windows.WComponentPeer;39import sun.java2d.SurfaceData;40import static sun.java2d.opengl.OGLContext.OGLContextCaps.*;41import static sun.java2d.pipe.hw.AccelSurface.*;42import sun.java2d.pipe.hw.ExtendedBufferCapabilities;43import static sun.java2d.pipe.hw.ExtendedBufferCapabilities.VSyncType.*;4445public class WGLVolatileSurfaceManager extends VolatileSurfaceManager {4647private final boolean accelerationEnabled;4849public WGLVolatileSurfaceManager(SunVolatileImage vImg, Object context) {50super(vImg, context);5152/*53* We will attempt to accelerate this image only under the54* following conditions:55* - the image is not bitmask AND the GraphicsConfig supports the FBO56* extension57*/58int transparency = vImg.getTransparency();59WGLGraphicsConfig gc = (WGLGraphicsConfig) vImg.getGraphicsConfig();60accelerationEnabled = gc.isCapPresent(CAPS_EXT_FBOBJECT)61&& transparency != Transparency.BITMASK;62}6364protected boolean isAccelerationEnabled() {65return accelerationEnabled;66}6768/**69* Create a FBO-based SurfaceData object (or init the backbuffer70* of an existing window if this is a double buffered GraphicsConfig).71*/72protected SurfaceData initAcceleratedSurface() {73SurfaceData sData;74Component comp = vImg.getComponent();75final ComponentAccessor acc = AWTAccessor.getComponentAccessor();76WComponentPeer peer = (comp != null) ? acc.getPeer(comp) : null;7778try {79boolean createVSynced = false;80boolean forceback = false;81if (context instanceof Boolean) {82forceback = ((Boolean)context).booleanValue();83if (forceback) {84BufferCapabilities caps = peer.getBackBufferCaps();85if (caps instanceof ExtendedBufferCapabilities) {86ExtendedBufferCapabilities ebc =87(ExtendedBufferCapabilities)caps;88if (ebc.getVSync() == VSYNC_ON &&89ebc.getFlipContents() == COPIED)90{91createVSynced = true;92forceback = false;93}94}95}96}9798if (forceback) {99// peer must be non-null in this case100sData = WGLSurfaceData.createData(peer, vImg, FLIP_BACKBUFFER);101} else {102WGLGraphicsConfig gc =103(WGLGraphicsConfig)vImg.getGraphicsConfig();104ColorModel cm = gc.getColorModel(vImg.getTransparency());105int type = vImg.getForcedAccelSurfaceType();106// if acceleration type is forced (type != UNDEFINED) then107// use the forced type, otherwise choose FBOBJECT108if (type == OGLSurfaceData.UNDEFINED) {109type = OGLSurfaceData.FBOBJECT;110}111if (createVSynced) {112sData = WGLSurfaceData.createData(peer, vImg, type);113} else {114sData = WGLSurfaceData.createData(gc,115vImg.getWidth(),116vImg.getHeight(),117cm, vImg, type);118}119}120} catch (NullPointerException ex) {121sData = null;122} catch (OutOfMemoryError er) {123sData = null;124}125126return sData;127}128129@Override130protected boolean isConfigValid(GraphicsConfiguration gc) {131return ((gc == null) ||132((gc instanceof WGLGraphicsConfig) &&133(gc == vImg.getGraphicsConfig())));134}135136@Override137public void initContents() {138if (vImg.getForcedAccelSurfaceType() != OGLSurfaceData.TEXTURE) {139super.initContents();140}141}142}143144145