Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/macosx/classes/sun/java2d/opengl/CGLVolatileSurfaceManager.java
38918 views
1
/*
2
* Copyright (c) 2011, 2012, 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.BufferCapabilities;
29
import static java.awt.BufferCapabilities.FlipContents.*;
30
import java.awt.Component;
31
import java.awt.GraphicsConfiguration;
32
import java.awt.Transparency;
33
import java.awt.image.ColorModel;
34
import java.awt.peer.ComponentPeer;
35
36
import sun.awt.image.SunVolatileImage;
37
import sun.awt.image.VolatileSurfaceManager;
38
import sun.java2d.BackBufferCapsProvider;
39
import sun.java2d.SurfaceData;
40
import static sun.java2d.opengl.OGLContext.OGLContextCaps.*;
41
import sun.java2d.pipe.hw.ExtendedBufferCapabilities;
42
import static sun.java2d.pipe.hw.AccelSurface.*;
43
import static sun.java2d.pipe.hw.ExtendedBufferCapabilities.VSyncType.*;
44
45
public class CGLVolatileSurfaceManager extends VolatileSurfaceManager {
46
47
private boolean accelerationEnabled;
48
49
public CGLVolatileSurfaceManager(SunVolatileImage vImg, Object context) {
50
super(vImg, context);
51
52
/*
53
* We will attempt to accelerate this image only under the
54
* following conditions:
55
* - the image is opaque OR
56
* - the image is translucent AND
57
* - the GraphicsConfig supports the FBO extension OR
58
* - the GraphicsConfig has a stored alpha channel
59
*/
60
int transparency = vImg.getTransparency();
61
CGLGraphicsConfig gc = (CGLGraphicsConfig)vImg.getGraphicsConfig();
62
accelerationEnabled =
63
(transparency == Transparency.OPAQUE) ||
64
((transparency == Transparency.TRANSLUCENT) &&
65
(gc.isCapPresent(CAPS_EXT_FBOBJECT) ||
66
gc.isCapPresent(CAPS_STORED_ALPHA)));
67
}
68
69
protected boolean isAccelerationEnabled() {
70
return accelerationEnabled;
71
}
72
73
/**
74
* Create a pbuffer-based SurfaceData object (or init the backbuffer
75
* of an existing window if this is a double buffered GraphicsConfig)
76
*/
77
protected SurfaceData initAcceleratedSurface() {
78
SurfaceData sData = null;
79
Component comp = vImg.getComponent();
80
final ComponentPeer peer = (comp != null) ? comp.getPeer() : null;
81
82
try {
83
boolean createVSynced = false;
84
boolean forceback = false;
85
if (context instanceof Boolean) {
86
forceback = ((Boolean)context).booleanValue();
87
if (forceback && peer instanceof BackBufferCapsProvider) {
88
BackBufferCapsProvider provider =
89
(BackBufferCapsProvider)peer;
90
BufferCapabilities caps = provider.getBackBufferCaps();
91
if (caps instanceof ExtendedBufferCapabilities) {
92
ExtendedBufferCapabilities ebc =
93
(ExtendedBufferCapabilities)caps;
94
if (ebc.getVSync() == VSYNC_ON &&
95
ebc.getFlipContents() == COPIED)
96
{
97
createVSynced = true;
98
forceback = false;
99
}
100
}
101
}
102
}
103
104
if (forceback) {
105
// peer must be non-null in this case
106
// TODO: modify parameter to delegate
107
// sData = CGLSurfaceData.createData(peer, vImg, FLIP_BACKBUFFER);
108
} else {
109
CGLGraphicsConfig gc =
110
(CGLGraphicsConfig)vImg.getGraphicsConfig();
111
ColorModel cm = gc.getColorModel(vImg.getTransparency());
112
int type = vImg.getForcedAccelSurfaceType();
113
// if acceleration type is forced (type != UNDEFINED) then
114
// use the forced type, otherwise choose one based on caps
115
if (type == OGLSurfaceData.UNDEFINED) {
116
type = gc.isCapPresent(CAPS_EXT_FBOBJECT) ?
117
OGLSurfaceData.FBOBJECT : OGLSurfaceData.PBUFFER;
118
}
119
if (createVSynced) {
120
// TODO: modify parameter to delegate
121
// sData = CGLSurfaceData.createData(peer, vImg, type);
122
} else {
123
sData = CGLSurfaceData.createData(gc,
124
vImg.getWidth(),
125
vImg.getHeight(),
126
cm, vImg, type);
127
}
128
}
129
} catch (NullPointerException ex) {
130
sData = null;
131
} catch (OutOfMemoryError er) {
132
sData = null;
133
}
134
135
return sData;
136
}
137
138
@Override
139
protected boolean isConfigValid(GraphicsConfiguration gc) {
140
return ((gc == null) || (gc == vImg.getGraphicsConfig()));
141
}
142
143
@Override
144
public void initContents() {
145
if (vImg.getForcedAccelSurfaceType() != OGLSurfaceData.TEXTURE) {
146
super.initContents();
147
}
148
}
149
}
150
151
152