jdk/src/java.desktop/windows/classes/sun/java2d/opengl/WGLVolatileSurfaceManager.java
author darcy
Tue, 16 Dec 2014 09:57:33 -0800
changeset 28234 f694f2576719
parent 25859 3317bb8137f4
child 30469 bac0a7ff7e1e
permissions -rw-r--r--
8067092: Suppress windows-specific deprecation warnings in the java.desktop module Reviewed-by: prr, alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
28234
f694f2576719 8067092: Suppress windows-specific deprecation warnings in the java.desktop module
darcy
parents: 25859
diff changeset
     2
 * Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 888
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 888
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 888
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 888
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 888
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.java2d.opengl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    28
import java.awt.BufferCapabilities;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    29
import static java.awt.BufferCapabilities.FlipContents.*;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.Component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.GraphicsConfiguration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.Transparency;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.image.ColorModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import sun.awt.image.SunVolatileImage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import sun.awt.image.VolatileSurfaceManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import sun.awt.windows.WComponentPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import sun.java2d.SurfaceData;
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    38
import static sun.java2d.opengl.OGLContext.OGLContextCaps.*;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    39
import static sun.java2d.pipe.hw.AccelSurface.*;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    40
import sun.java2d.pipe.hw.ExtendedBufferCapabilities;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    41
import static sun.java2d.pipe.hw.ExtendedBufferCapabilities.VSyncType.*;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
public class WGLVolatileSurfaceManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    extends VolatileSurfaceManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    private boolean accelerationEnabled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    public WGLVolatileSurfaceManager(SunVolatileImage vImg, Object context) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        super(vImg, context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
         * We will attempt to accelerate this image only under the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
         * following conditions:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
         *   - the image is opaque OR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
         *   - the image is translucent AND
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
         *       - the GraphicsConfig supports the FBO extension OR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
         *       - the GraphicsConfig has a stored alpha channel
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        int transparency = vImg.getTransparency();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        WGLGraphicsConfig gc = (WGLGraphicsConfig)vImg.getGraphicsConfig();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        accelerationEnabled =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
            (transparency == Transparency.OPAQUE) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
            ((transparency == Transparency.TRANSLUCENT) &&
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    64
             (gc.isCapPresent(CAPS_EXT_FBOBJECT) ||
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    65
              gc.isCapPresent(CAPS_STORED_ALPHA)));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    protected boolean isAccelerationEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        return accelerationEnabled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * Create a pbuffer-based SurfaceData object (or init the backbuffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * of an existing window if this is a double buffered GraphicsConfig).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     */
28234
f694f2576719 8067092: Suppress windows-specific deprecation warnings in the java.desktop module
darcy
parents: 25859
diff changeset
    76
    @SuppressWarnings("deprecation")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    protected SurfaceData initAcceleratedSurface() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        SurfaceData sData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        Component comp = vImg.getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        WComponentPeer peer =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            (comp != null) ? (WComponentPeer)comp.getPeer() : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        try {
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    84
            boolean createVSynced = false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            boolean forceback = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            if (context instanceof Boolean) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                forceback = ((Boolean)context).booleanValue();
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    88
                if (forceback) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    89
                    BufferCapabilities caps = peer.getBackBufferCaps();
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    90
                    if (caps instanceof ExtendedBufferCapabilities) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    91
                        ExtendedBufferCapabilities ebc =
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    92
                            (ExtendedBufferCapabilities)caps;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    93
                        if (ebc.getVSync() == VSYNC_ON &&
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    94
                            ebc.getFlipContents() == COPIED)
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    95
                        {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    96
                            createVSynced = true;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    97
                            forceback = false;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    98
                        }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    99
                    }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   100
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            if (forceback) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                // peer must be non-null in this case
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   105
                sData = WGLSurfaceData.createData(peer, vImg, FLIP_BACKBUFFER);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                WGLGraphicsConfig gc =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                    (WGLGraphicsConfig)vImg.getGraphicsConfig();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                ColorModel cm = gc.getColorModel(vImg.getTransparency());
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   110
                int type = vImg.getForcedAccelSurfaceType();
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   111
                // if acceleration type is forced (type != UNDEFINED) then
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   112
                // use the forced type, otherwise choose one based on caps
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   113
                if (type == OGLSurfaceData.UNDEFINED) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   114
                    type = gc.isCapPresent(CAPS_EXT_FBOBJECT) ?
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   115
                        OGLSurfaceData.FBOBJECT : OGLSurfaceData.PBUFFER;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   116
                }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   117
                if (createVSynced) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   118
                    sData = WGLSurfaceData.createData(peer, vImg, type);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   119
                } else {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   120
                    sData = WGLSurfaceData.createData(gc,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   121
                                                      vImg.getWidth(),
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   122
                                                      vImg.getHeight(),
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   123
                                                      cm, vImg, type);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   124
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        } catch (NullPointerException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            sData = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        } catch (OutOfMemoryError er) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            sData = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        return sData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   135
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    protected boolean isConfigValid(GraphicsConfiguration gc) {
7761
bada7677e624 7003434: test/closed/java/awt/FullScreen/DisplayChangeVITest/DisplayChangeVITest.java fails with ClassCastExc
bae
parents: 5506
diff changeset
   137
        return ((gc == null) ||
bada7677e624 7003434: test/closed/java/awt/FullScreen/DisplayChangeVITest/DisplayChangeVITest.java fails with ClassCastExc
bae
parents: 5506
diff changeset
   138
                ((gc instanceof WGLGraphicsConfig) &&
bada7677e624 7003434: test/closed/java/awt/FullScreen/DisplayChangeVITest/DisplayChangeVITest.java fails with ClassCastExc
bae
parents: 5506
diff changeset
   139
                 (gc == vImg.getGraphicsConfig())));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    }
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   141
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   142
    @Override
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   143
    public void initContents() {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   144
        if (vImg.getForcedAccelSurfaceType() != OGLSurfaceData.TEXTURE) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   145
            super.initContents();
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   146
        }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   147
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
}