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/MTLVolatileSurfaceManager.java
41159 views
1
/*
2
* Copyright (c) 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.awt.image.SunVolatileImage;
29
import sun.awt.image.VolatileSurfaceManager;
30
import sun.java2d.SurfaceData;
31
32
import java.awt.GraphicsConfiguration;
33
import java.awt.Transparency;
34
import java.awt.image.ColorModel;
35
import sun.java2d.pipe.hw.AccelSurface;
36
37
public class MTLVolatileSurfaceManager extends VolatileSurfaceManager {
38
39
private final boolean accelerationEnabled;
40
41
public MTLVolatileSurfaceManager(SunVolatileImage vImg, Object context) {
42
super(vImg, context);
43
44
/*
45
* We will attempt to accelerate this image only
46
* if the image is not bitmask
47
*/
48
int transparency = vImg.getTransparency();
49
accelerationEnabled = transparency != Transparency.BITMASK;
50
}
51
52
protected boolean isAccelerationEnabled() {
53
return accelerationEnabled;
54
}
55
56
/**
57
* Create a SurfaceData object (or init the backbuffer
58
* of an existing window if this is a double buffered GraphicsConfig)
59
*/
60
protected SurfaceData initAcceleratedSurface() {
61
try {
62
MTLGraphicsConfig gc =
63
(MTLGraphicsConfig)vImg.getGraphicsConfig();
64
ColorModel cm = gc.getColorModel(vImg.getTransparency());
65
int type = vImg.getForcedAccelSurfaceType();
66
// if acceleration type is forced (type != UNDEFINED) then
67
// use the forced type, otherwise choose RT_TEXTURE
68
if (type == AccelSurface.UNDEFINED) {
69
type = AccelSurface.RT_TEXTURE;
70
}
71
return MTLSurfaceData.createData(gc,
72
vImg.getWidth(),
73
vImg.getHeight(),
74
cm, vImg, type);
75
} catch (NullPointerException | OutOfMemoryError ignored) {
76
return null;
77
}
78
}
79
80
@Override
81
protected boolean isConfigValid(GraphicsConfiguration gc) {
82
return ((gc == null) || (gc == vImg.getGraphicsConfig()));
83
}
84
85
@Override
86
public void initContents() {
87
if (vImg.getForcedAccelSurfaceType() != AccelSurface.TEXTURE) {
88
super.initContents();
89
}
90
}
91
}
92
93