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