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