blob: 79914431dc731e2d3bd94020ac09547634a26e10 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25
26package sun.java2d.d3d;
27
28import java.awt.GraphicsConfiguration;
29import java.awt.Image;
30import java.awt.Transparency;
31import java.awt.image.ColorModel;
32import sun.awt.Win32GraphicsDevice;
33import sun.java2d.loops.SurfaceType;
34import sun.java2d.windows.Win32SurfaceData;
35
36public class D3DBackBufferSurfaceData extends D3DSurfaceData {
37
38 private Win32SurfaceData parentData;
39
40 /**
41 * Private constructor. Use createData() to create an object.
42 */
43 private D3DBackBufferSurfaceData(int width, int height,
44 SurfaceType sType, ColorModel cm,
45 GraphicsConfiguration gc,
46 Image image, int screen,
47 Win32SurfaceData parentData)
48 {
49 super(width, height, D3DSurfaceData.D3D_ATTACHED_SURFACE,
50 sType, cm, gc, image, Transparency.OPAQUE);
51 this.parentData = parentData;
52 initSurface(width, height, screen, parentData);
53 }
54
55 private native void restoreDepthBuffer();
56
57 @Override
58 public void restoreSurface() {
59 parentData.restoreSurface();
60 // The above call restores the primary surface
61 // to which this backbuffer is attached. But
62 // we need to explicitly restore the depth buffer
63 // associated with this backbuffer surface, because it's not
64 // part of a 'complex' primary surface, and thus will not be
65 // restored as part of the primary surface restoration.
66 restoreDepthBuffer();
67 }
68
69 public static D3DBackBufferSurfaceData
70 createData(int width, int height,
71 ColorModel cm, GraphicsConfiguration gc,
72 Image image,
73 Win32SurfaceData parentData)
74 {
75 Win32GraphicsDevice gd = (Win32GraphicsDevice)gc.getDevice();
76 if (!gd.isD3DEnabledOnDevice()) {
77 return null;
78 }
79 SurfaceType sType = getSurfaceType(cm, Transparency.OPAQUE);
80 return new
81 D3DBackBufferSurfaceData(width, height,
82 getSurfaceType(gc, cm,
83 D3DSurfaceData.D3D_ATTACHED_SURFACE),
84 cm, gc, image,
85 gd.getScreen(), parentData);
86 }
87}