Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.desktop/windows/classes/sun/awt/Win32GraphicsConfig.java
41153 views
1
/*
2
* Copyright (c) 1997, 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.awt;
27
28
import java.awt.AWTException;
29
import java.awt.BufferCapabilities;
30
import java.awt.Component;
31
import java.awt.Graphics;
32
import java.awt.GraphicsConfiguration;
33
import java.awt.GraphicsDevice;
34
import java.awt.GraphicsEnvironment;
35
import java.awt.Image;
36
import java.awt.Rectangle;
37
import java.awt.Transparency;
38
import java.awt.geom.AffineTransform;
39
import java.awt.image.ColorModel;
40
import java.awt.image.DirectColorModel;
41
import java.awt.image.VolatileImage;
42
import java.awt.image.WritableRaster;
43
44
import sun.awt.image.OffScreenImage;
45
import sun.awt.image.SunVolatileImage;
46
import sun.awt.image.SurfaceManager;
47
import sun.awt.windows.WComponentPeer;
48
import sun.java2d.SurfaceData;
49
import sun.java2d.loops.CompositeType;
50
import sun.java2d.loops.RenderLoops;
51
import sun.java2d.loops.SurfaceType;
52
import sun.java2d.windows.GDIWindowSurfaceData;
53
54
/**
55
* This is an implementation of a GraphicsConfiguration object for a
56
* single Win32 visual.
57
*
58
* @see GraphicsEnvironment
59
* @see GraphicsDevice
60
*/
61
public class Win32GraphicsConfig extends GraphicsConfiguration
62
implements DisplayChangedListener, SurfaceManager.ProxiedGraphicsConfig
63
{
64
private final Win32GraphicsDevice device;
65
protected int visual; //PixelFormatID
66
protected RenderLoops solidloops;
67
68
private static native void initIDs();
69
70
static {
71
initIDs();
72
}
73
74
/**
75
* Returns a Win32GraphicsConfiguration object with the given device
76
* and PixelFormat. Note that this method does NOT check to ensure that
77
* the returned Win32GraphicsConfig will correctly support rendering into a
78
* Java window. This method is provided so that client code can do its
79
* own checking as to the appropriateness of a particular PixelFormat.
80
* Safer access to Win32GraphicsConfigurations is provided by
81
* Win32GraphicsDevice.getConfigurations().
82
*/
83
public static Win32GraphicsConfig getConfig(Win32GraphicsDevice device,
84
int pixFormatID)
85
{
86
return new Win32GraphicsConfig(device, pixFormatID);
87
}
88
89
/**
90
* @deprecated as of JDK version 1.3
91
* replaced by {@code getConfig()}
92
*/
93
@Deprecated
94
public Win32GraphicsConfig(GraphicsDevice device, int visualnum) {
95
this.device = (Win32GraphicsDevice)device;
96
this.visual = visualnum;
97
((Win32GraphicsDevice)device).addDisplayChangedListener(this);
98
}
99
100
/**
101
* Return the graphics device associated with this configuration.
102
*/
103
@Override
104
public Win32GraphicsDevice getDevice() {
105
return device;
106
}
107
108
/**
109
* Return the PixelFormatIndex this GraphicsConfig uses
110
*/
111
public int getVisual() {
112
return visual;
113
}
114
115
@Override
116
public Object getProxyKey() {
117
return device;
118
}
119
120
/**
121
* Return the RenderLoops this type of destination uses for
122
* solid fills and strokes.
123
*/
124
private SurfaceType sTypeOrig = null;
125
public synchronized RenderLoops getSolidLoops(SurfaceType stype) {
126
if (solidloops == null || sTypeOrig != stype) {
127
solidloops = SurfaceData.makeRenderLoops(SurfaceType.OpaqueColor,
128
CompositeType.SrcNoEa,
129
stype);
130
sTypeOrig = stype;
131
}
132
return solidloops;
133
}
134
135
/**
136
* Returns the color model associated with this configuration.
137
*/
138
@Override
139
public synchronized ColorModel getColorModel() {
140
return device.getColorModel();
141
}
142
143
/**
144
* Returns a new color model for this configuration. This call
145
* is only used internally, by images and components that are
146
* associated with the graphics device. When attributes of that
147
* device change (for example, when the device palette is updated),
148
* then this device-based color model will be updated internally
149
* to reflect the new situation.
150
*/
151
public ColorModel getDeviceColorModel() {
152
return device.getDynamicColorModel();
153
}
154
155
/**
156
* Returns the color model associated with this configuration that
157
* supports the specified transparency.
158
*/
159
@Override
160
public ColorModel getColorModel(int transparency) {
161
switch (transparency) {
162
case Transparency.OPAQUE:
163
return getColorModel();
164
case Transparency.BITMASK:
165
return new DirectColorModel(25, 0xff0000, 0xff00, 0xff, 0x1000000);
166
case Transparency.TRANSLUCENT:
167
return ColorModel.getRGBdefault();
168
default:
169
return null;
170
}
171
}
172
173
/**
174
* Returns the default Transform for this configuration. This
175
* Transform is typically the Identity transform for most normal
176
* screens. Device coordinates for screen and printer devices will
177
* have the origin in the upper left-hand corner of the target region of
178
* the device, with X coordinates
179
* increasing to the right and Y coordinates increasing downwards.
180
* For image buffers, this Transform will be the Identity transform.
181
*/
182
@Override
183
public AffineTransform getDefaultTransform() {
184
double scaleX = device.getDefaultScaleX();
185
double scaleY = device.getDefaultScaleY();
186
return AffineTransform.getScaleInstance(scaleX, scaleY);
187
}
188
189
/**
190
*
191
* Returns a Transform that can be composed with the default Transform
192
* of a Graphics2D so that 72 units in user space will equal 1 inch
193
* in device space.
194
* Given a Graphics2D, g, one can reset the transformation to create
195
* such a mapping by using the following pseudocode:
196
* <pre>
197
* GraphicsConfiguration gc = g.getGraphicsConfiguration();
198
*
199
* g.setTransform(gc.getDefaultTransform());
200
* g.transform(gc.getNormalizingTransform());
201
* </pre>
202
* Note that sometimes this Transform will be identity (e.g. for
203
* printers or metafile output) and that this Transform is only
204
* as accurate as the information supplied by the underlying system.
205
* For image buffers, this Transform will be the Identity transform,
206
* since there is no valid distance measurement.
207
*/
208
@Override
209
public AffineTransform getNormalizingTransform() {
210
Win32GraphicsEnvironment ge = (Win32GraphicsEnvironment)
211
GraphicsEnvironment.getLocalGraphicsEnvironment();
212
double xscale = ge.getXResolution() / 72.0;
213
double yscale = ge.getYResolution() / 72.0;
214
return new AffineTransform(xscale, 0.0, 0.0, yscale, 0.0, 0.0);
215
}
216
217
public String toString() {
218
return (super.toString()+"[dev="+device+",pixfmt="+visual+"]");
219
}
220
221
private native Rectangle getBounds(int screen);
222
223
@Override
224
public Rectangle getBounds() {
225
return getBounds(device.getScreen());
226
}
227
228
@Override
229
public synchronized void displayChanged() {
230
solidloops = null;
231
}
232
233
@Override
234
public void paletteChanged() {}
235
236
/**
237
* The following methods are invoked from WComponentPeer.java rather
238
* than having the Win32-dependent implementations hardcoded in that
239
* class. This way the appropriate actions are taken based on the peer's
240
* GraphicsConfig, whether it is a Win32GraphicsConfig or a
241
* WGLGraphicsConfig.
242
*/
243
244
/**
245
* Creates a new SurfaceData that will be associated with the given
246
* WComponentPeer.
247
*/
248
public SurfaceData createSurfaceData(WComponentPeer peer,
249
int numBackBuffers)
250
{
251
return GDIWindowSurfaceData.createData(peer);
252
}
253
254
/**
255
* Creates a new managed image of the given width and height
256
* that is associated with the target Component.
257
*/
258
public Image createAcceleratedImage(Component target,
259
int width, int height)
260
{
261
ColorModel model = getColorModel(Transparency.OPAQUE);
262
WritableRaster wr =
263
model.createCompatibleWritableRaster(width, height);
264
return new OffScreenImage(target, model, wr,
265
model.isAlphaPremultiplied());
266
}
267
268
/**
269
* The following methods correspond to the multibuffering methods in
270
* WComponentPeer.java...
271
*/
272
273
/**
274
* Checks that the requested configuration is natively supported; if not,
275
* an AWTException is thrown.
276
*/
277
public void assertOperationSupported(Component target,
278
int numBuffers,
279
BufferCapabilities caps)
280
throws AWTException
281
{
282
// the default pipeline doesn't support flip buffer strategy
283
throw new AWTException(
284
"The operation requested is not supported");
285
}
286
287
/**
288
* This method is called from WComponentPeer when a surface data is replaced
289
* REMIND: while the default pipeline doesn't support flipping, it may
290
* happen that the accelerated device may have this graphics config
291
* (like if the device restoration failed when one device exits fs mode
292
* while others remain).
293
*/
294
public VolatileImage createBackBuffer(WComponentPeer peer) {
295
Component target = (Component)peer.getTarget();
296
return new SunVolatileImage(target,
297
target.getWidth(), target.getHeight(),
298
Boolean.TRUE);
299
}
300
301
/**
302
* Performs the native flip operation for the given target Component.
303
*
304
* REMIND: we should really not get here because that would mean that
305
* a FLIP BufferStrategy has been created, and one could only be created
306
* if accelerated pipeline is present but in some rare (and transitional)
307
* cases it may happen that the accelerated graphics device may have a
308
* default graphics configuraiton, so this is just a precaution.
309
*/
310
public void flip(WComponentPeer peer,
311
Component target, VolatileImage backBuffer,
312
int x1, int y1, int x2, int y2,
313
BufferCapabilities.FlipContents flipAction)
314
{
315
if (flipAction == BufferCapabilities.FlipContents.COPIED ||
316
flipAction == BufferCapabilities.FlipContents.UNDEFINED) {
317
Graphics g = peer.getGraphics();
318
try {
319
g.drawImage(backBuffer,
320
x1, y1, x2, y2,
321
x1, y1, x2, y2,
322
null);
323
} finally {
324
g.dispose();
325
}
326
} else if (flipAction == BufferCapabilities.FlipContents.BACKGROUND) {
327
Graphics g = backBuffer.getGraphics();
328
try {
329
g.setColor(target.getBackground());
330
g.fillRect(0, 0,
331
backBuffer.getWidth(),
332
backBuffer.getHeight());
333
} finally {
334
g.dispose();
335
}
336
}
337
// the rest of the flip actions are not supported
338
}
339
340
@Override
341
public boolean isTranslucencyCapable() {
342
//XXX: worth checking if 8-bit? Anyway, it doesn't hurt.
343
return true;
344
}
345
}
346
347