Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/windows/classes/sun/java2d/d3d/D3DRenderQueue.java
32288 views
1
/*
2
* Copyright (c) 2007, 2008, 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 sun.java2d.ScreenUpdateManager;
29
import sun.java2d.pipe.RenderBuffer;
30
import sun.java2d.pipe.RenderQueue;
31
import static sun.java2d.pipe.BufferedOpCodes.*;
32
33
/**
34
* D3D-specific implementation of RenderQueue.
35
*/
36
public class D3DRenderQueue extends RenderQueue {
37
38
private static D3DRenderQueue theInstance;
39
private static Thread rqThread;
40
41
private D3DRenderQueue() {
42
}
43
44
/**
45
* Returns the single D3DRenderQueue instance. If it has not yet been
46
* initialized, this method will first construct the single instance
47
* before returning it.
48
*/
49
public static synchronized D3DRenderQueue getInstance() {
50
if (theInstance == null) {
51
theInstance = new D3DRenderQueue();
52
// no need to lock, noone has reference to this instance yet
53
theInstance.flushAndInvokeNow(new Runnable() {
54
public void run() {
55
rqThread = Thread.currentThread();
56
}
57
});
58
}
59
return theInstance;
60
}
61
62
/**
63
* Flushes the single D3DRenderQueue instance synchronously. If an
64
* D3DRenderQueue has not yet been instantiated, this method is a no-op.
65
* This method is useful in the case of Toolkit.sync(), in which we want
66
* to flush the D3D pipeline, but only if the D3D pipeline is currently
67
* enabled. Since this class has few external dependencies, callers need
68
* not be concerned that calling this method will trigger initialization
69
* of the D3D pipeline and related classes.
70
*/
71
public static void sync() {
72
if (theInstance != null) {
73
// need to make sure any/all screen surfaces are presented prior
74
// to completing the sync operation
75
D3DScreenUpdateManager mgr =
76
(D3DScreenUpdateManager)ScreenUpdateManager.getInstance();
77
mgr.runUpdateNow();
78
79
theInstance.lock();
80
try {
81
theInstance.ensureCapacity(4);
82
theInstance.getBuffer().putInt(SYNC);
83
theInstance.flushNow();
84
} finally {
85
theInstance.unlock();
86
}
87
}
88
}
89
90
/**
91
* Attempt to restore the devices if they're in the lost state.
92
* (used when a full-screen window is activated/deactivated)
93
*/
94
public static void restoreDevices() {
95
D3DRenderQueue rq = getInstance();
96
rq.lock();
97
try {
98
rq.ensureCapacity(4);
99
rq.getBuffer().putInt(RESTORE_DEVICES);
100
rq.flushNow();
101
} finally {
102
rq.unlock();
103
}
104
}
105
106
/**
107
* @return true if current thread is the render queue thread,
108
* false otherwise
109
*/
110
public static boolean isRenderQueueThread() {
111
return (Thread.currentThread() == rqThread);
112
}
113
114
/**
115
* Disposes the native memory associated with the given native
116
* graphics config info pointer on the single queue flushing thread.
117
*/
118
public static void disposeGraphicsConfig(long pConfigInfo) {
119
D3DRenderQueue rq = getInstance();
120
rq.lock();
121
try {
122
123
RenderBuffer buf = rq.getBuffer();
124
rq.ensureCapacityAndAlignment(12, 4);
125
buf.putInt(DISPOSE_CONFIG);
126
buf.putLong(pConfigInfo);
127
128
// this call is expected to complete synchronously, so flush now
129
rq.flushNow();
130
} finally {
131
rq.unlock();
132
}
133
}
134
135
public void flushNow() {
136
// assert lock.isHeldByCurrentThread();
137
flushBuffer(null);
138
}
139
140
public void flushAndInvokeNow(Runnable r) {
141
// assert lock.isHeldByCurrentThread();
142
flushBuffer(r);
143
}
144
145
private native void flushBuffer(long buf, int limit, Runnable task);
146
147
private void flushBuffer(Runnable task) {
148
// assert lock.isHeldByCurrentThread();
149
int limit = buf.position();
150
if (limit > 0 || task != null) {
151
// process the queue
152
flushBuffer(buf.getAddress(), limit, task);
153
}
154
// reset the buffer position
155
buf.clear();
156
// clear the set of references, since we no longer need them
157
refSet.clear();
158
}
159
}
160
161