Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/macosx/classes/sun/java2d/opengl/CGLVolatileSurfaceManager.java
38918 views
/*1* Copyright (c) 2011, 2012, 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 java.awt.peer.ComponentPeer;3435import sun.awt.image.SunVolatileImage;36import sun.awt.image.VolatileSurfaceManager;37import sun.java2d.BackBufferCapsProvider;38import sun.java2d.SurfaceData;39import static sun.java2d.opengl.OGLContext.OGLContextCaps.*;40import sun.java2d.pipe.hw.ExtendedBufferCapabilities;41import static sun.java2d.pipe.hw.AccelSurface.*;42import static sun.java2d.pipe.hw.ExtendedBufferCapabilities.VSyncType.*;4344public class CGLVolatileSurfaceManager extends VolatileSurfaceManager {4546private boolean accelerationEnabled;4748public CGLVolatileSurfaceManager(SunVolatileImage vImg, Object context) {49super(vImg, context);5051/*52* We will attempt to accelerate this image only under the53* following conditions:54* - the image is opaque OR55* - the image is translucent AND56* - the GraphicsConfig supports the FBO extension OR57* - the GraphicsConfig has a stored alpha channel58*/59int transparency = vImg.getTransparency();60CGLGraphicsConfig gc = (CGLGraphicsConfig)vImg.getGraphicsConfig();61accelerationEnabled =62(transparency == Transparency.OPAQUE) ||63((transparency == Transparency.TRANSLUCENT) &&64(gc.isCapPresent(CAPS_EXT_FBOBJECT) ||65gc.isCapPresent(CAPS_STORED_ALPHA)));66}6768protected boolean isAccelerationEnabled() {69return accelerationEnabled;70}7172/**73* Create a pbuffer-based SurfaceData object (or init the backbuffer74* of an existing window if this is a double buffered GraphicsConfig)75*/76protected SurfaceData initAcceleratedSurface() {77SurfaceData sData = null;78Component comp = vImg.getComponent();79final ComponentPeer peer = (comp != null) ? 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 case105// TODO: modify parameter to delegate106// sData = CGLSurfaceData.createData(peer, vImg, FLIP_BACKBUFFER);107} else {108CGLGraphicsConfig gc =109(CGLGraphicsConfig)vImg.getGraphicsConfig();110ColorModel cm = gc.getColorModel(vImg.getTransparency());111int type = vImg.getForcedAccelSurfaceType();112// if acceleration type is forced (type != UNDEFINED) then113// use the forced type, otherwise choose one based on caps114if (type == OGLSurfaceData.UNDEFINED) {115type = gc.isCapPresent(CAPS_EXT_FBOBJECT) ?116OGLSurfaceData.FBOBJECT : OGLSurfaceData.PBUFFER;117}118if (createVSynced) {119// TODO: modify parameter to delegate120// sData = CGLSurfaceData.createData(peer, vImg, type);121} else {122sData = CGLSurfaceData.createData(gc,123vImg.getWidth(),124vImg.getHeight(),125cm, vImg, type);126}127}128} catch (NullPointerException ex) {129sData = null;130} catch (OutOfMemoryError er) {131sData = null;132}133134return sData;135}136137@Override138protected boolean isConfigValid(GraphicsConfiguration gc) {139return ((gc == null) || (gc == vImg.getGraphicsConfig()));140}141142@Override143public void initContents() {144if (vImg.getForcedAccelSurfaceType() != OGLSurfaceData.TEXTURE) {145super.initContents();146}147}148}149150151152