Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.desktop/macosx/classes/sun/java2d/opengl/CGLVolatileSurfaceManager.java
41159 views
1
/*
2
* Copyright (c) 2011, 2019, 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.opengl;
27
28
import java.awt.GraphicsConfiguration;
29
import java.awt.Transparency;
30
import java.awt.image.ColorModel;
31
32
import sun.awt.image.SunVolatileImage;
33
import sun.awt.image.VolatileSurfaceManager;
34
import sun.java2d.SurfaceData;
35
36
import static sun.java2d.opengl.OGLContext.OGLContextCaps.CAPS_EXT_FBOBJECT;
37
38
public class CGLVolatileSurfaceManager extends VolatileSurfaceManager {
39
40
private final boolean accelerationEnabled;
41
42
public CGLVolatileSurfaceManager(SunVolatileImage vImg, Object context) {
43
super(vImg, context);
44
45
/*
46
* We will attempt to accelerate this image only under the
47
* following conditions:
48
* - the image is not bitmask AND the GraphicsConfig supports the FBO
49
* extension
50
*/
51
int transparency = vImg.getTransparency();
52
CGLGraphicsConfig gc = (CGLGraphicsConfig) vImg.getGraphicsConfig();
53
accelerationEnabled = gc.isCapPresent(CAPS_EXT_FBOBJECT)
54
&& transparency != Transparency.BITMASK;
55
}
56
57
protected boolean isAccelerationEnabled() {
58
return accelerationEnabled;
59
}
60
61
/**
62
* Create a FBO-based SurfaceData object (or init the backbuffer
63
* of an existing window if this is a double buffered GraphicsConfig)
64
*/
65
protected SurfaceData initAcceleratedSurface() {
66
try {
67
CGLGraphicsConfig gc = (CGLGraphicsConfig)vImg.getGraphicsConfig();
68
ColorModel cm = gc.getColorModel(vImg.getTransparency());
69
int type = vImg.getForcedAccelSurfaceType();
70
// if acceleration type is forced (type != UNDEFINED) then
71
// use the forced type, otherwise choose FBOBJECT
72
if (type == OGLSurfaceData.UNDEFINED) {
73
type = OGLSurfaceData.FBOBJECT;
74
}
75
return CGLSurfaceData.createData(gc, vImg.getWidth(),
76
vImg.getHeight(), cm, vImg, type);
77
} catch (NullPointerException | OutOfMemoryError ignored) {
78
return null;
79
}
80
}
81
82
@Override
83
protected boolean isConfigValid(GraphicsConfiguration gc) {
84
return ((gc == null) || (gc == vImg.getGraphicsConfig()));
85
}
86
87
@Override
88
public void initContents() {
89
if (vImg.getForcedAccelSurfaceType() != OGLSurfaceData.TEXTURE) {
90
super.initContents();
91
}
92
}
93
}
94
95
96