2
|
1 |
/*
|
5506
|
2 |
* Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
|
2
|
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
|
5506
|
7 |
* published by the Free Software Foundation. Oracle designates this
|
2
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
5506
|
9 |
* by Oracle in the LICENSE file that accompanied this code.
|
2
|
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 |
*
|
5506
|
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.
|
2
|
24 |
*/
|
|
25 |
|
|
26 |
package sun.java2d.d3d;
|
|
27 |
|
887
|
28 |
import sun.java2d.pipe.BufferedContext;
|
|
29 |
import sun.java2d.pipe.RenderBuffer;
|
|
30 |
import sun.java2d.pipe.RenderQueue;
|
|
31 |
import sun.java2d.pipe.hw.ContextCapabilities;
|
|
32 |
import static sun.java2d.pipe.BufferedOpCodes.*;
|
|
33 |
import static sun.java2d.pipe.hw.ContextCapabilities.*;
|
|
34 |
import static sun.java2d.d3d.D3DContext.D3DContextCaps.*;
|
2
|
35 |
|
887
|
36 |
/**
|
|
37 |
* Note that the RenderQueue lock must be acquired before calling any of
|
|
38 |
* the methods in this class.
|
|
39 |
*/
|
|
40 |
class D3DContext extends BufferedContext {
|
2
|
41 |
|
887
|
42 |
private final D3DGraphicsDevice device;
|
2
|
43 |
|
887
|
44 |
D3DContext(RenderQueue rq, D3DGraphicsDevice device) {
|
|
45 |
super(rq);
|
|
46 |
this.device = device;
|
2
|
47 |
}
|
|
48 |
|
|
49 |
/**
|
887
|
50 |
* Invalidates the currentContext field to ensure that we properly
|
|
51 |
* revalidate the D3DContext (make it current, etc.) next time through
|
|
52 |
* the validate() method. This is typically invoked from methods
|
|
53 |
* that affect the current context state (e.g. disposing a context or
|
|
54 |
* surface).
|
2
|
55 |
*/
|
887
|
56 |
static void invalidateCurrentContext() {
|
|
57 |
// assert D3DRenderQueue.getInstance().lock.isHeldByCurrentThread();
|
|
58 |
|
|
59 |
// invalidate the current Java-level context so that we
|
|
60 |
// revalidate everything the next time around
|
|
61 |
if (currentContext != null) {
|
|
62 |
currentContext.invalidateContext();
|
|
63 |
currentContext = null;
|
2
|
64 |
}
|
887
|
65 |
|
|
66 |
// invalidate the context reference at the native level, and
|
|
67 |
// then flush the queue so that we have no pending operations
|
|
68 |
// dependent on the current context
|
|
69 |
D3DRenderQueue rq = D3DRenderQueue.getInstance();
|
|
70 |
rq.ensureCapacity(4);
|
|
71 |
rq.getBuffer().putInt(INVALIDATE_CONTEXT);
|
|
72 |
rq.flushNow();
|
2
|
73 |
}
|
|
74 |
|
|
75 |
/**
|
887
|
76 |
* Sets the current context on the native level to be the one passed as
|
|
77 |
* the argument.
|
|
78 |
* If the context is not the same as the defaultContext the latter
|
|
79 |
* will be reset to null.
|
2
|
80 |
*
|
887
|
81 |
* This call is needed when copying from a SW surface to a Texture
|
|
82 |
* (the upload test) or copying from d3d to SW surface to make sure we
|
|
83 |
* have the correct current context.
|
2
|
84 |
*
|
887
|
85 |
* @param d3dc the context to be made current on the native level
|
2
|
86 |
*/
|
887
|
87 |
static void setScratchSurface(D3DContext d3dc) {
|
|
88 |
// assert D3DRenderQueue.getInstance().lock.isHeldByCurrentThread();
|
2
|
89 |
|
887
|
90 |
// invalidate the current context
|
|
91 |
if (d3dc != currentContext) {
|
|
92 |
currentContext = null;
|
2
|
93 |
}
|
|
94 |
|
887
|
95 |
// set the scratch context
|
|
96 |
D3DRenderQueue rq = D3DRenderQueue.getInstance();
|
|
97 |
RenderBuffer buf = rq.getBuffer();
|
|
98 |
rq.ensureCapacity(8);
|
|
99 |
buf.putInt(SET_SCRATCH_SURFACE);
|
|
100 |
buf.putInt(d3dc.getDevice().getScreen());
|
|
101 |
}
|
2
|
102 |
|
887
|
103 |
public RenderQueue getRenderQueue() {
|
|
104 |
return D3DRenderQueue.getInstance();
|
|
105 |
}
|
|
106 |
|
|
107 |
@Override
|
|
108 |
public void saveState() {
|
|
109 |
// assert rq.lock.isHeldByCurrentThread();
|
2
|
110 |
|
887
|
111 |
// reset all attributes of this and current contexts
|
|
112 |
invalidateContext();
|
|
113 |
invalidateCurrentContext();
|
|
114 |
|
|
115 |
setScratchSurface(this);
|
2
|
116 |
|
887
|
117 |
// save the state on the native level
|
|
118 |
rq.ensureCapacity(4);
|
|
119 |
buf.putInt(SAVE_STATE);
|
|
120 |
rq.flushNow();
|
|
121 |
}
|
|
122 |
|
|
123 |
@Override
|
|
124 |
public void restoreState() {
|
|
125 |
// assert rq.lock.isHeldByCurrentThread();
|
|
126 |
|
|
127 |
// reset all attributes of this and current contexts
|
|
128 |
invalidateContext();
|
|
129 |
invalidateCurrentContext();
|
2
|
130 |
|
887
|
131 |
setScratchSurface(this);
|
|
132 |
|
|
133 |
// restore the state on the native level
|
|
134 |
rq.ensureCapacity(4);
|
|
135 |
buf.putInt(RESTORE_STATE);
|
|
136 |
rq.flushNow();
|
|
137 |
}
|
|
138 |
|
|
139 |
D3DGraphicsDevice getDevice() {
|
|
140 |
return device;
|
|
141 |
}
|
|
142 |
|
|
143 |
static class D3DContextCaps extends ContextCapabilities {
|
|
144 |
/**
|
|
145 |
* Indicates the presence of pixel shaders (v2.0 or greater).
|
|
146 |
* This cap will only be set if the hardware supports the minimum number
|
|
147 |
* of texture units.
|
|
148 |
*/
|
|
149 |
static final int CAPS_LCD_SHADER = (FIRST_PRIVATE_CAP << 0);
|
|
150 |
/**
|
|
151 |
* Indicates the presence of pixel shaders (v2.0 or greater).
|
|
152 |
* This cap will only be set if the hardware meets our
|
|
153 |
* minimum requirements.
|
|
154 |
*/
|
|
155 |
static final int CAPS_BIOP_SHADER = (FIRST_PRIVATE_CAP << 1);
|
|
156 |
/**
|
|
157 |
* Indicates that the device was successfully initialized and can
|
|
158 |
* be safely used.
|
|
159 |
*/
|
|
160 |
static final int CAPS_DEVICE_OK = (FIRST_PRIVATE_CAP << 2);
|
|
161 |
/**
|
|
162 |
* Indicates that the device has all of the necessary capabilities
|
|
163 |
* to support the Antialiasing Pixel Shader program.
|
|
164 |
*/
|
|
165 |
static final int CAPS_AA_SHADER = (FIRST_PRIVATE_CAP << 3);
|
|
166 |
|
|
167 |
D3DContextCaps(int caps, String adapterId) {
|
|
168 |
super(caps, adapterId);
|
2
|
169 |
}
|
|
170 |
|
887
|
171 |
@Override
|
|
172 |
public String toString() {
|
|
173 |
StringBuffer buf = new StringBuffer(super.toString());
|
|
174 |
if ((caps & CAPS_LCD_SHADER) != 0) {
|
|
175 |
buf.append("CAPS_LCD_SHADER|");
|
2
|
176 |
}
|
887
|
177 |
if ((caps & CAPS_BIOP_SHADER) != 0) {
|
|
178 |
buf.append("CAPS_BIOP_SHADER|");
|
2
|
179 |
}
|
887
|
180 |
if ((caps & CAPS_AA_SHADER) != 0) {
|
|
181 |
buf.append("CAPS_AA_SHADER|");
|
2
|
182 |
}
|
887
|
183 |
if ((caps & CAPS_DEVICE_OK) != 0) {
|
|
184 |
buf.append("CAPS_DEVICE_OK|");
|
|
185 |
}
|
|
186 |
return buf.toString();
|
2
|
187 |
}
|
|
188 |
}
|
|
189 |
}
|