1 /*
2 * Copyright (c) 2007, 2014, Oracle and/or its affiliates. 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. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package sun.java2d.d3d;
27
28 import java.awt.Component;
29 import java.awt.GraphicsConfiguration;
30 import java.awt.Image;
31 import java.awt.Transparency;
32 import java.awt.image.ColorModel;
33 import sun.awt.Win32GraphicsConfig;
34 import sun.awt.image.SunVolatileImage;
35 import sun.awt.image.SurfaceManager;
36 import sun.awt.image.VolatileSurfaceManager;
37 import sun.awt.windows.WComponentPeer;
38 import sun.java2d.InvalidPipeException;
39 import sun.java2d.SurfaceData;
40 import static sun.java2d.pipe.hw.AccelSurface.*;
41 import static sun.java2d.d3d.D3DContext.D3DContextCaps.*;
42 import sun.java2d.windows.GDIWindowSurfaceData;
43
44 public class D3DVolatileSurfaceManager
45 extends VolatileSurfaceManager
46 {
47 private boolean accelerationEnabled;
48 private int restoreCountdown;
49
50 public D3DVolatileSurfaceManager(SunVolatileImage vImg, Object context) {
51 super(vImg, context);
52
62 D3DGraphicsDevice gd = (D3DGraphicsDevice)
63 vImg.getGraphicsConfig().getDevice();
64 accelerationEnabled =
65 (transparency == Transparency.OPAQUE) ||
66 (transparency == Transparency.TRANSLUCENT &&
67 (gd.isCapPresent(CAPS_RT_PLAIN_ALPHA) ||
68 gd.isCapPresent(CAPS_RT_TEXTURE_ALPHA)));
69 }
70
71 protected boolean isAccelerationEnabled() {
72 return accelerationEnabled;
73 }
74 public void setAccelerationEnabled(boolean accelerationEnabled) {
75 this.accelerationEnabled = accelerationEnabled;
76 }
77
78 /**
79 * Create a pbuffer-based SurfaceData object (or init the backbuffer
80 * of an existing window if this is a double buffered GraphicsConfig).
81 */
82 @SuppressWarnings("deprecation")
83 protected SurfaceData initAcceleratedSurface() {
84 SurfaceData sData;
85 Component comp = vImg.getComponent();
86 WComponentPeer peer =
87 (comp != null) ? (WComponentPeer)comp.getPeer() : null;
88
89 try {
90 boolean forceback = false;
91 if (context instanceof Boolean) {
92 forceback = ((Boolean)context).booleanValue();
93 }
94
95 if (forceback) {
96 // peer must be non-null in this case
97 sData = D3DSurfaceData.createData(peer, vImg);
98 } else {
99 D3DGraphicsConfig gc =
100 (D3DGraphicsConfig)vImg.getGraphicsConfig();
101 ColorModel cm = gc.getColorModel(vImg.getTransparency());
102 int type = vImg.getForcedAccelSurfaceType();
103 // if acceleration type is forced (type != UNDEFINED) then
104 // use the forced type, otherwise use RT_TEXTURE
105 if (type == UNDEFINED) {
106 type = RT_TEXTURE;
107 }
|
1 /*
2 * Copyright (c) 2007, 2015, Oracle and/or its affiliates. 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. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package sun.java2d.d3d;
27
28 import java.awt.Component;
29 import java.awt.GraphicsConfiguration;
30 import java.awt.Image;
31 import java.awt.Transparency;
32 import java.awt.image.ColorModel;
33
34 import sun.awt.AWTAccessor;
35 import sun.awt.AWTAccessor.ComponentAccessor;
36 import sun.awt.Win32GraphicsConfig;
37 import sun.awt.image.SunVolatileImage;
38 import sun.awt.image.SurfaceManager;
39 import sun.awt.image.VolatileSurfaceManager;
40 import sun.awt.windows.WComponentPeer;
41 import sun.java2d.InvalidPipeException;
42 import sun.java2d.SurfaceData;
43 import static sun.java2d.pipe.hw.AccelSurface.*;
44 import static sun.java2d.d3d.D3DContext.D3DContextCaps.*;
45 import sun.java2d.windows.GDIWindowSurfaceData;
46
47 public class D3DVolatileSurfaceManager
48 extends VolatileSurfaceManager
49 {
50 private boolean accelerationEnabled;
51 private int restoreCountdown;
52
53 public D3DVolatileSurfaceManager(SunVolatileImage vImg, Object context) {
54 super(vImg, context);
55
65 D3DGraphicsDevice gd = (D3DGraphicsDevice)
66 vImg.getGraphicsConfig().getDevice();
67 accelerationEnabled =
68 (transparency == Transparency.OPAQUE) ||
69 (transparency == Transparency.TRANSLUCENT &&
70 (gd.isCapPresent(CAPS_RT_PLAIN_ALPHA) ||
71 gd.isCapPresent(CAPS_RT_TEXTURE_ALPHA)));
72 }
73
74 protected boolean isAccelerationEnabled() {
75 return accelerationEnabled;
76 }
77 public void setAccelerationEnabled(boolean accelerationEnabled) {
78 this.accelerationEnabled = accelerationEnabled;
79 }
80
81 /**
82 * Create a pbuffer-based SurfaceData object (or init the backbuffer
83 * of an existing window if this is a double buffered GraphicsConfig).
84 */
85 protected SurfaceData initAcceleratedSurface() {
86 SurfaceData sData;
87 Component comp = vImg.getComponent();
88 final ComponentAccessor acc = AWTAccessor.getComponentAccessor();
89 WComponentPeer peer = (comp != null) ? acc.getPeer(comp) : null;
90
91 try {
92 boolean forceback = false;
93 if (context instanceof Boolean) {
94 forceback = ((Boolean)context).booleanValue();
95 }
96
97 if (forceback) {
98 // peer must be non-null in this case
99 sData = D3DSurfaceData.createData(peer, vImg);
100 } else {
101 D3DGraphicsConfig gc =
102 (D3DGraphicsConfig)vImg.getGraphicsConfig();
103 ColorModel cm = gc.getColorModel(vImg.getTransparency());
104 int type = vImg.getForcedAccelSurfaceType();
105 // if acceleration type is forced (type != UNDEFINED) then
106 // use the forced type, otherwise use RT_TEXTURE
107 if (type == UNDEFINED) {
108 type = RT_TEXTURE;
109 }
|