jdk/src/solaris/classes/sun/java2d/opengl/GLXVolatileSurfaceManager.java
author tdv
Tue, 22 Jul 2008 11:24:32 -0700
changeset 888 c7009cf0001f
parent 887 0aab8d3fa11a
child 5506 202f599c92aa
permissions -rw-r--r--
6728492: typo in copyrights in some files touched by the d3d pipeline port Reviewed-by: prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
888
c7009cf0001f 6728492: typo in copyrights in some files touched by the d3d pipeline port
tdv
parents: 887
diff changeset
     2
 * Copyright 2003-2008 Sun Microsystems, Inc.  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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
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.X11ComponentPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import sun.awt.image.SunVolatileImage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import sun.awt.image.VolatileSurfaceManager;
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    37
import sun.java2d.BackBufferCapsProvider;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import sun.java2d.SurfaceData;
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    39
import static sun.java2d.opengl.OGLContext.OGLContextCaps.*;
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.AccelSurface.*;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    42
import static sun.java2d.pipe.hw.ExtendedBufferCapabilities.VSyncType.*;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
public class GLXVolatileSurfaceManager 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 GLXVolatileSurfaceManager(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
        GLXGraphicsConfig gc = (GLXGraphicsConfig)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
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    protected SurfaceData initAcceleratedSurface() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        SurfaceData sData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        Component comp = vImg.getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        X11ComponentPeer peer =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            (comp != null) ? (X11ComponentPeer)comp.getPeer() : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        try {
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    83
            boolean createVSynced = false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            boolean forceback = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            if (context instanceof Boolean) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                forceback = ((Boolean)context).booleanValue();
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    87
                if (forceback && peer instanceof BackBufferCapsProvider) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    88
                    BackBufferCapsProvider provider =
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    89
                        (BackBufferCapsProvider)peer;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    90
                    BufferCapabilities caps = provider.getBackBufferCaps();
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    91
                    if (caps instanceof ExtendedBufferCapabilities) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    92
                        ExtendedBufferCapabilities ebc =
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    93
                            (ExtendedBufferCapabilities)caps;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    94
                        if (ebc.getVSync() == VSYNC_ON &&
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    95
                            ebc.getFlipContents() == COPIED)
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    96
                        {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    97
                            createVSynced = true;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    98
                            forceback = false;
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
                    }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   101
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            if (forceback) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                // peer must be non-null in this case
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   106
                sData = GLXSurfaceData.createData(peer, vImg, FLIP_BACKBUFFER);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                GLXGraphicsConfig gc =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                    (GLXGraphicsConfig)vImg.getGraphicsConfig();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                ColorModel cm = gc.getColorModel(vImg.getTransparency());
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   111
                int type = vImg.getForcedAccelSurfaceType();
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   112
                // if acceleration type is forced (type != UNDEFINED) then
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   113
                // 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
   114
                if (type == OGLSurfaceData.UNDEFINED) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   115
                    type = gc.isCapPresent(CAPS_EXT_FBOBJECT) ?
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   116
                        OGLSurfaceData.FBOBJECT : OGLSurfaceData.PBUFFER;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   117
                }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   118
                if (createVSynced) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   119
                    sData = GLXSurfaceData.createData(peer, vImg, type);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   120
                } else {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   121
                    sData = GLXSurfaceData.createData(gc,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   122
                                                      vImg.getWidth(),
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   123
                                                      vImg.getHeight(),
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   124
                                                      cm, vImg, type);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   125
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        } catch (NullPointerException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            sData = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        } catch (OutOfMemoryError er) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            sData = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        return sData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   136
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    protected boolean isConfigValid(GraphicsConfiguration gc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        return ((gc == null) || (gc == vImg.getGraphicsConfig()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    }
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   140
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   141
    @Override
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   142
    public void initContents() {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   143
        if (vImg.getForcedAccelSurfaceType() != OGLSurfaceData.TEXTURE) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   144
            super.initContents();
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   145
        }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   146
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
}