Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.desktop/macosx/classes/sun/java2d/metal/MTLContext.java
41159 views
1
/*
2
* Copyright (c) 2019, 2021, 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.metal;
27
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
33
import java.lang.annotation.Native;
34
35
import static sun.java2d.pipe.BufferedOpCodes.SET_SCRATCH_SURFACE;
36
37
/**
38
* Note that the RenderQueue lock must be acquired before calling any of
39
* the methods in this class.
40
*/
41
final class MTLContext extends BufferedContext {
42
43
public MTLContext(RenderQueue rq) {
44
super(rq);
45
}
46
47
/**
48
* Convenience method that delegates to setScratchSurface() below.
49
*/
50
static void setScratchSurface(MTLGraphicsConfig gc) {
51
setScratchSurface(gc.getNativeConfigInfo());
52
}
53
54
/**
55
* Makes the given GraphicsConfig's context current to its associated
56
* "scratch surface". Each GraphicsConfig maintains a native context
57
* (MTLDevice) as well as a native MTLTexture
58
* known as the "scratch surface". By making the context current to the
59
* scratch surface, we are assured that we have a current context for
60
* the relevant GraphicsConfig, and can therefore perform operations
61
* depending on the capabilities of that GraphicsConfig.
62
* This method should be used for operations with an MTL texture
63
* as the destination surface (e.g. a sw->texture blit loop), or in those
64
* situations where we may not otherwise have a current context (e.g.
65
* when disposing a texture-based surface).
66
*/
67
public static void setScratchSurface(long pConfigInfo) {
68
// assert MTLRenderQueue.getInstance().lock.isHeldByCurrentThread();
69
70
// invalidate the current context
71
currentContext = null;
72
73
// set the scratch context
74
MTLRenderQueue rq = MTLRenderQueue.getInstance();
75
RenderBuffer buf = rq.getBuffer();
76
rq.ensureCapacityAndAlignment(12, 4);
77
buf.putInt(SET_SCRATCH_SURFACE);
78
buf.putLong(pConfigInfo);
79
}
80
81
public static class MTLContextCaps extends ContextCapabilities {
82
83
/** Indicates that the context is doublebuffered. */
84
@Native
85
public static final int CAPS_DOUBLEBUFFERED = (FIRST_PRIVATE_CAP << 0);
86
/**
87
* This cap will only be set if the lcdshader system property has been
88
* enabled and the hardware supports the minimum number of texture units
89
*/
90
@Native
91
static final int CAPS_EXT_LCD_SHADER = (FIRST_PRIVATE_CAP << 1);
92
/**
93
* This cap will only be set if the biopshader system property has been
94
* enabled and the hardware meets our minimum requirements.
95
*/
96
@Native
97
public static final int CAPS_EXT_BIOP_SHADER = (FIRST_PRIVATE_CAP << 2);
98
/**
99
* This cap will only be set if the gradshader system property has been
100
* enabled and the hardware meets our minimum requirements.
101
*/
102
@Native
103
static final int CAPS_EXT_GRAD_SHADER = (FIRST_PRIVATE_CAP << 3);
104
105
public MTLContextCaps(int caps, String adapterId) {
106
super(caps, adapterId);
107
}
108
109
@Override
110
public String toString() {
111
StringBuilder sb = new StringBuilder(super.toString());
112
if ((caps & CAPS_DOUBLEBUFFERED) != 0) {
113
sb.append("CAPS_DOUBLEBUFFERED|");
114
}
115
if ((caps & CAPS_EXT_LCD_SHADER) != 0) {
116
sb.append("CAPS_EXT_LCD_SHADER|");
117
}
118
if ((caps & CAPS_EXT_BIOP_SHADER) != 0) {
119
sb.append("CAPS_BIOP_SHADER|");
120
}
121
if ((caps & CAPS_EXT_GRAD_SHADER) != 0) {
122
sb.append("CAPS_EXT_GRAD_SHADER|");
123
}
124
return sb.toString();
125
}
126
}
127
}
128
129