Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.desktop/unix/classes/sun/java2d/x11/X11VolatileSurfaceManager.java
41159 views
1
/*
2
* Copyright (c) 2000, 2020, 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.x11;
27
28
import java.awt.GraphicsConfiguration;
29
import java.awt.ImageCapabilities;
30
import java.awt.Transparency;
31
import java.awt.image.ColorModel;
32
33
import sun.awt.X11GraphicsConfig;
34
import sun.awt.image.SunVolatileImage;
35
import sun.awt.image.VolatileSurfaceManager;
36
import sun.java2d.SurfaceData;
37
38
/**
39
* X11 platform implementation of the VolatileSurfaceManager class.
40
* The class attempts to create and use a pixmap-based SurfaceData
41
* object (X11PixmapSurfaceData).
42
* If this object cannot be created or re-created as necessary, the
43
* class falls back to a system memory based SurfaceData object
44
* (BufImgSurfaceData) that will be used until the accelerated
45
* SurfaceData can be restored.
46
*/
47
public class X11VolatileSurfaceManager extends VolatileSurfaceManager {
48
49
private boolean accelerationEnabled;
50
51
public X11VolatileSurfaceManager(SunVolatileImage vImg, Object context) {
52
super(vImg, context);
53
54
// We only accelerated opaque vImages currently
55
accelerationEnabled = X11SurfaceData.isAccelerationEnabled() &&
56
(vImg.getTransparency() == Transparency.OPAQUE);
57
58
if ((context != null) && !accelerationEnabled) {
59
// if we're wrapping a backbuffer drawable, we must ensure that
60
// the accelerated surface is initialized up front, regardless
61
// of whether acceleration is enabled. But we need to set
62
// the accelerationEnabled field to true to reflect that this
63
// SM is actually accelerated.
64
accelerationEnabled = true;
65
sdAccel = initAcceleratedSurface();
66
sdCurrent = sdAccel;
67
68
if (sdBackup != null) {
69
// release the system memory backup surface, as we won't be
70
// needing it in this case
71
sdBackup = null;
72
}
73
}
74
}
75
76
protected boolean isAccelerationEnabled() {
77
return accelerationEnabled;
78
}
79
80
/**
81
* Create a pixmap-based SurfaceData object
82
*/
83
protected SurfaceData initAcceleratedSurface() {
84
SurfaceData sData;
85
86
try {
87
X11GraphicsConfig gc = (X11GraphicsConfig)vImg.getGraphicsConfig();
88
ColorModel cm = gc.getColorModel();
89
long drawable = 0;
90
if (context instanceof Long) {
91
drawable = ((Long)context).longValue();
92
}
93
sData = X11SurfaceData.createData(gc,
94
vImg.getWidth(),
95
vImg.getHeight(),
96
cm, vImg, drawable,
97
Transparency.OPAQUE,
98
false);
99
} catch (NullPointerException ex) {
100
sData = null;
101
} catch (OutOfMemoryError er) {
102
sData = null;
103
}
104
105
return sData;
106
}
107
108
protected boolean isConfigValid(GraphicsConfiguration gc) {
109
// REMIND: we might be too paranoid here, requiring that
110
// the GC be exactly the same as the original one. The
111
// real answer is one that guarantees that pixmap copies
112
// will be correct (which requires like bit depths and
113
// formats).
114
return ((gc == null) || (gc == vImg.getGraphicsConfig()));
115
}
116
117
/**
118
* Need to override the default behavior because Pixmaps-based
119
* images are accelerated but not volatile.
120
*/
121
@Override
122
public ImageCapabilities getCapabilities(GraphicsConfiguration gc) {
123
if (isConfigValid(gc) && isAccelerationEnabled()) {
124
// accelerated but not volatile
125
return new ImageCapabilities(true);
126
}
127
// neither accelerated nor volatile
128
return new ImageCapabilities(false);
129
}
130
}
131
132