jdk/src/windows/classes/sun/java2d/d3d/D3DBackBufferSurfaceData.java
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2005 Sun Microsystems, Inc.  All Rights Reserved.
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.d3d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.GraphicsConfiguration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.Image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.Transparency;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.image.ColorModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import sun.awt.Win32GraphicsDevice;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import sun.java2d.loops.SurfaceType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import sun.java2d.windows.Win32SurfaceData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
public class D3DBackBufferSurfaceData extends D3DSurfaceData {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
    private Win32SurfaceData parentData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
     * Private constructor.  Use createData() to create an object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    private D3DBackBufferSurfaceData(int width, int height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
                                     SurfaceType sType, ColorModel cm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
                                     GraphicsConfiguration gc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
                                     Image image, int screen,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
                                     Win32SurfaceData parentData)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        super(width, height, D3DSurfaceData.D3D_ATTACHED_SURFACE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
              sType, cm, gc, image, Transparency.OPAQUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        this.parentData = parentData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        initSurface(width, height, screen, parentData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    private native void restoreDepthBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    public void restoreSurface() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        parentData.restoreSurface();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        // The above call restores the primary surface
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        // to which this backbuffer is attached. But
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        // we need to explicitly restore the depth buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        // associated with this backbuffer surface, because it's not
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        // part of a 'complex' primary surface, and thus will not be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        // restored as part of the primary surface restoration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        restoreDepthBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    public static D3DBackBufferSurfaceData
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        createData(int width, int height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
                   ColorModel cm, GraphicsConfiguration gc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
                   Image image,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
                   Win32SurfaceData parentData)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        Win32GraphicsDevice gd = (Win32GraphicsDevice)gc.getDevice();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        if (!gd.isD3DEnabledOnDevice()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        SurfaceType sType = getSurfaceType(cm, Transparency.OPAQUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        return new
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            D3DBackBufferSurfaceData(width, height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                 getSurfaceType(gc, cm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                                D3DSurfaceData.D3D_ATTACHED_SURFACE),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                 cm, gc, image,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                 gd.getScreen(), parentData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
}