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