Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/windows/classes/sun/java2d/opengl/WGLVolatileSurfaceManager.java
32288 views
/*1* Copyright (c) 2004, 2010, 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.image.SunVolatileImage;34import sun.awt.image.VolatileSurfaceManager;35import sun.awt.windows.WComponentPeer;36import sun.java2d.SurfaceData;37import static sun.java2d.opengl.OGLContext.OGLContextCaps.*;38import static sun.java2d.pipe.hw.AccelSurface.*;39import sun.java2d.pipe.hw.ExtendedBufferCapabilities;40import static sun.java2d.pipe.hw.ExtendedBufferCapabilities.VSyncType.*;4142public class WGLVolatileSurfaceManager43extends VolatileSurfaceManager44{45private boolean accelerationEnabled;4647public WGLVolatileSurfaceManager(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();59WGLGraphicsConfig gc = (WGLGraphicsConfig)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();78WComponentPeer peer =79(comp != null) ? (WComponentPeer)comp.getPeer() : null;8081try {82boolean createVSynced = false;83boolean forceback = false;84if (context instanceof Boolean) {85forceback = ((Boolean)context).booleanValue();86if (forceback) {87BufferCapabilities caps = peer.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 = WGLSurfaceData.createData(peer, vImg, FLIP_BACKBUFFER);104} else {105WGLGraphicsConfig gc =106(WGLGraphicsConfig)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 one based on caps111if (type == OGLSurfaceData.UNDEFINED) {112type = gc.isCapPresent(CAPS_EXT_FBOBJECT) ?113OGLSurfaceData.FBOBJECT : OGLSurfaceData.PBUFFER;114}115if (createVSynced) {116sData = WGLSurfaceData.createData(peer, vImg, type);117} else {118sData = WGLSurfaceData.createData(gc,119vImg.getWidth(),120vImg.getHeight(),121cm, vImg, type);122}123}124} catch (NullPointerException ex) {125sData = null;126} catch (OutOfMemoryError er) {127sData = null;128}129130return sData;131}132133@Override134protected boolean isConfigValid(GraphicsConfiguration gc) {135return ((gc == null) ||136((gc instanceof WGLGraphicsConfig) &&137(gc == vImg.getGraphicsConfig())));138}139140@Override141public void initContents() {142if (vImg.getForcedAccelSurfaceType() != OGLSurfaceData.TEXTURE) {143super.initContents();144}145}146}147148149