0N/A/*
3909N/A * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage sun.java2d.opengl;
0N/A
430N/Aimport java.awt.BufferCapabilities;
430N/Aimport static java.awt.BufferCapabilities.FlipContents.*;
0N/Aimport java.awt.Component;
0N/Aimport java.awt.GraphicsConfiguration;
0N/Aimport java.awt.Transparency;
0N/Aimport java.awt.image.ColorModel;
0N/Aimport sun.awt.image.SunVolatileImage;
0N/Aimport sun.awt.image.VolatileSurfaceManager;
0N/Aimport sun.awt.windows.WComponentPeer;
0N/Aimport sun.java2d.SurfaceData;
430N/Aimport static sun.java2d.opengl.OGLContext.OGLContextCaps.*;
430N/Aimport static sun.java2d.pipe.hw.AccelSurface.*;
430N/Aimport sun.java2d.pipe.hw.ExtendedBufferCapabilities;
430N/Aimport static sun.java2d.pipe.hw.ExtendedBufferCapabilities.VSyncType.*;
0N/A
0N/Apublic class WGLVolatileSurfaceManager
0N/A extends VolatileSurfaceManager
0N/A{
0N/A private boolean accelerationEnabled;
0N/A
0N/A public WGLVolatileSurfaceManager(SunVolatileImage vImg, Object context) {
0N/A super(vImg, context);
0N/A
0N/A /*
0N/A * We will attempt to accelerate this image only under the
0N/A * following conditions:
0N/A * - the image is opaque OR
0N/A * - the image is translucent AND
0N/A * - the GraphicsConfig supports the FBO extension OR
0N/A * - the GraphicsConfig has a stored alpha channel
0N/A */
0N/A int transparency = vImg.getTransparency();
0N/A WGLGraphicsConfig gc = (WGLGraphicsConfig)vImg.getGraphicsConfig();
0N/A accelerationEnabled =
0N/A (transparency == Transparency.OPAQUE) ||
0N/A ((transparency == Transparency.TRANSLUCENT) &&
430N/A (gc.isCapPresent(CAPS_EXT_FBOBJECT) ||
430N/A gc.isCapPresent(CAPS_STORED_ALPHA)));
0N/A }
0N/A
0N/A protected boolean isAccelerationEnabled() {
0N/A return accelerationEnabled;
0N/A }
0N/A
0N/A /**
0N/A * Create a pbuffer-based SurfaceData object (or init the backbuffer
0N/A * of an existing window if this is a double buffered GraphicsConfig).
0N/A */
0N/A protected SurfaceData initAcceleratedSurface() {
0N/A SurfaceData sData;
0N/A Component comp = vImg.getComponent();
0N/A WComponentPeer peer =
0N/A (comp != null) ? (WComponentPeer)comp.getPeer() : null;
0N/A
0N/A try {
430N/A boolean createVSynced = false;
0N/A boolean forceback = false;
0N/A if (context instanceof Boolean) {
0N/A forceback = ((Boolean)context).booleanValue();
430N/A if (forceback) {
430N/A BufferCapabilities caps = peer.getBackBufferCaps();
430N/A if (caps instanceof ExtendedBufferCapabilities) {
430N/A ExtendedBufferCapabilities ebc =
430N/A (ExtendedBufferCapabilities)caps;
430N/A if (ebc.getVSync() == VSYNC_ON &&
430N/A ebc.getFlipContents() == COPIED)
430N/A {
430N/A createVSynced = true;
430N/A forceback = false;
430N/A }
430N/A }
430N/A }
0N/A }
0N/A
0N/A if (forceback) {
0N/A // peer must be non-null in this case
430N/A sData = WGLSurfaceData.createData(peer, vImg, FLIP_BACKBUFFER);
0N/A } else {
0N/A WGLGraphicsConfig gc =
0N/A (WGLGraphicsConfig)vImg.getGraphicsConfig();
0N/A ColorModel cm = gc.getColorModel(vImg.getTransparency());
430N/A int type = vImg.getForcedAccelSurfaceType();
430N/A // if acceleration type is forced (type != UNDEFINED) then
430N/A // use the forced type, otherwise choose one based on caps
430N/A if (type == OGLSurfaceData.UNDEFINED) {
430N/A type = gc.isCapPresent(CAPS_EXT_FBOBJECT) ?
430N/A OGLSurfaceData.FBOBJECT : OGLSurfaceData.PBUFFER;
430N/A }
430N/A if (createVSynced) {
430N/A sData = WGLSurfaceData.createData(peer, vImg, type);
430N/A } else {
430N/A sData = WGLSurfaceData.createData(gc,
430N/A vImg.getWidth(),
430N/A vImg.getHeight(),
430N/A cm, vImg, type);
430N/A }
0N/A }
0N/A } catch (NullPointerException ex) {
0N/A sData = null;
0N/A } catch (OutOfMemoryError er) {
0N/A sData = null;
0N/A }
0N/A
0N/A return sData;
0N/A }
0N/A
430N/A @Override
0N/A protected boolean isConfigValid(GraphicsConfiguration gc) {
3281N/A return ((gc == null) ||
3281N/A ((gc instanceof WGLGraphicsConfig) &&
3281N/A (gc == vImg.getGraphicsConfig())));
0N/A }
430N/A
430N/A @Override
430N/A public void initContents() {
430N/A if (vImg.getForcedAccelSurfaceType() != OGLSurfaceData.TEXTURE) {
430N/A super.initContents();
430N/A }
430N/A }
0N/A}