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/X11SurfaceData.java
41159 views
1
/*
2
* Copyright (c) 1999, 2021, 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.Composite;
29
import java.awt.GraphicsConfiguration;
30
import java.awt.GraphicsDevice;
31
import java.awt.GraphicsEnvironment;
32
import java.awt.Image;
33
import java.awt.Rectangle;
34
import java.awt.Transparency;
35
import java.awt.color.ColorSpace;
36
import java.awt.image.ColorModel;
37
import java.awt.image.ComponentColorModel;
38
import java.awt.image.DirectColorModel;
39
import java.awt.image.IndexColorModel;
40
import java.awt.image.Raster;
41
42
import sun.awt.SunHints;
43
import sun.awt.SunToolkit;
44
import sun.awt.X11ComponentPeer;
45
import sun.awt.X11GraphicsConfig;
46
import sun.awt.image.PixelConverter;
47
import sun.font.X11TextRenderer;
48
import sun.java2d.InvalidPipeException;
49
import sun.java2d.SunGraphics2D;
50
import sun.java2d.SunGraphicsEnvironment;
51
import sun.java2d.SurfaceData;
52
import sun.java2d.SurfaceDataProxy;
53
import sun.java2d.loops.CompositeType;
54
import sun.java2d.loops.GraphicsPrimitive;
55
import sun.java2d.loops.RenderLoops;
56
import sun.java2d.loops.SurfaceType;
57
import sun.java2d.loops.XORComposite;
58
import sun.java2d.pipe.PixelToShapeConverter;
59
import sun.java2d.pipe.Region;
60
import sun.java2d.pipe.TextPipe;
61
import sun.java2d.pipe.ValidatePipe;
62
63
public abstract class X11SurfaceData extends XSurfaceData {
64
X11ComponentPeer peer;
65
X11GraphicsConfig graphicsConfig;
66
private RenderLoops solidloops;
67
68
protected int depth;
69
70
private static native void initIDs(Class<?> xorComp);
71
protected native void initSurface(int depth, int width, int height,
72
long drawable);
73
74
public static final String
75
DESC_INT_BGR_X11 = "Integer BGR Pixmap";
76
public static final String
77
DESC_INT_RGB_X11 = "Integer RGB Pixmap";
78
79
public static final String
80
DESC_4BYTE_ABGR_PRE_X11 = "4 byte ABGR Pixmap with pre-multplied alpha";
81
public static final String
82
DESC_INT_ARGB_PRE_X11 = "Integer ARGB Pixmap with pre-multiplied " +
83
"alpha";
84
85
public static final String
86
DESC_BYTE_IND_OPQ_X11 = "Byte Indexed Opaque Pixmap";
87
88
public static final String
89
DESC_INT_BGR_X11_BM = "Integer BGR Pixmap with 1-bit transp";
90
public static final String
91
DESC_INT_RGB_X11_BM = "Integer RGB Pixmap with 1-bit transp";
92
public static final String
93
DESC_BYTE_IND_X11_BM = "Byte Indexed Pixmap with 1-bit transp";
94
95
public static final String
96
DESC_BYTE_GRAY_X11 = "Byte Gray Opaque Pixmap";
97
public static final String
98
DESC_INDEX8_GRAY_X11 = "Index8 Gray Opaque Pixmap";
99
100
public static final String
101
DESC_BYTE_GRAY_X11_BM = "Byte Gray Opaque Pixmap with 1-bit transp";
102
public static final String
103
DESC_INDEX8_GRAY_X11_BM = "Index8 Gray Opaque Pixmap with 1-bit transp";
104
105
public static final String
106
DESC_3BYTE_RGB_X11 = "3 Byte RGB Pixmap";
107
public static final String
108
DESC_3BYTE_BGR_X11 = "3 Byte BGR Pixmap";
109
110
public static final String
111
DESC_3BYTE_RGB_X11_BM = "3 Byte RGB Pixmap with 1-bit transp";
112
public static final String
113
DESC_3BYTE_BGR_X11_BM = "3 Byte BGR Pixmap with 1-bit transp";
114
115
public static final String
116
DESC_USHORT_555_RGB_X11 = "Ushort 555 RGB Pixmap";
117
public static final String
118
DESC_USHORT_565_RGB_X11 = "Ushort 565 RGB Pixmap";
119
120
public static final String
121
DESC_USHORT_555_RGB_X11_BM
122
= "Ushort 555 RGB Pixmap with 1-bit transp";
123
public static final String
124
DESC_USHORT_565_RGB_X11_BM
125
= "Ushort 565 RGB Pixmap with 1-bit transp";
126
public static final String
127
DESC_USHORT_INDEXED_X11 = "Ushort Indexed Pixmap";
128
129
public static final String
130
DESC_USHORT_INDEXED_X11_BM = "Ushort Indexed Pixmap with 1-bit transp";
131
132
public static final SurfaceType IntBgrX11 =
133
SurfaceType.IntBgr.deriveSubType(DESC_INT_BGR_X11);
134
public static final SurfaceType IntRgbX11 =
135
SurfaceType.IntRgb.deriveSubType(DESC_INT_RGB_X11);
136
137
public static final SurfaceType FourByteAbgrPreX11 =
138
SurfaceType.FourByteAbgrPre.deriveSubType(DESC_4BYTE_ABGR_PRE_X11);
139
public static final SurfaceType IntArgbPreX11 =
140
SurfaceType.IntArgbPre.deriveSubType(DESC_INT_ARGB_PRE_X11);
141
142
public static final SurfaceType ThreeByteRgbX11 =
143
SurfaceType.ThreeByteRgb.deriveSubType(DESC_3BYTE_RGB_X11);
144
public static final SurfaceType ThreeByteBgrX11 =
145
SurfaceType.ThreeByteBgr.deriveSubType(DESC_3BYTE_BGR_X11);
146
147
public static final SurfaceType UShort555RgbX11 =
148
SurfaceType.Ushort555Rgb.deriveSubType(DESC_USHORT_555_RGB_X11);
149
public static final SurfaceType UShort565RgbX11 =
150
SurfaceType.Ushort565Rgb.deriveSubType(DESC_USHORT_565_RGB_X11);
151
152
public static final SurfaceType UShortIndexedX11 =
153
SurfaceType.UshortIndexed.deriveSubType(DESC_USHORT_INDEXED_X11);
154
155
public static final SurfaceType ByteIndexedOpaqueX11 =
156
SurfaceType.ByteIndexedOpaque.deriveSubType(DESC_BYTE_IND_OPQ_X11);
157
158
public static final SurfaceType ByteGrayX11 =
159
SurfaceType.ByteGray.deriveSubType(DESC_BYTE_GRAY_X11);
160
public static final SurfaceType Index8GrayX11 =
161
SurfaceType.Index8Gray.deriveSubType(DESC_INDEX8_GRAY_X11);
162
163
// Bitmap surface types
164
public static final SurfaceType IntBgrX11_BM =
165
SurfaceType.Custom.deriveSubType(DESC_INT_BGR_X11_BM,
166
PixelConverter.Xbgr.instance);
167
public static final SurfaceType IntRgbX11_BM =
168
SurfaceType.Custom.deriveSubType(DESC_INT_RGB_X11_BM,
169
PixelConverter.Xrgb.instance);
170
171
public static final SurfaceType ThreeByteRgbX11_BM =
172
SurfaceType.Custom.deriveSubType(DESC_3BYTE_RGB_X11_BM,
173
PixelConverter.Xbgr.instance);
174
public static final SurfaceType ThreeByteBgrX11_BM =
175
SurfaceType.Custom.deriveSubType(DESC_3BYTE_BGR_X11_BM,
176
PixelConverter.Xrgb.instance);
177
178
public static final SurfaceType UShort555RgbX11_BM =
179
SurfaceType.Custom.deriveSubType(DESC_USHORT_555_RGB_X11_BM,
180
PixelConverter.Ushort555Rgb.instance);
181
public static final SurfaceType UShort565RgbX11_BM =
182
SurfaceType.Custom.deriveSubType(DESC_USHORT_565_RGB_X11_BM,
183
PixelConverter.Ushort565Rgb.instance);
184
185
public static final SurfaceType UShortIndexedX11_BM =
186
SurfaceType.Custom.deriveSubType(DESC_USHORT_INDEXED_X11_BM);
187
188
public static final SurfaceType ByteIndexedX11_BM =
189
SurfaceType.Custom.deriveSubType(DESC_BYTE_IND_X11_BM);
190
191
public static final SurfaceType ByteGrayX11_BM =
192
SurfaceType.Custom.deriveSubType(DESC_BYTE_GRAY_X11_BM);
193
public static final SurfaceType Index8GrayX11_BM =
194
SurfaceType.Custom.deriveSubType(DESC_INDEX8_GRAY_X11_BM);
195
196
197
private static Boolean accelerationEnabled = null;
198
199
public Raster getRaster(int x, int y, int w, int h) {
200
throw new InternalError("not implemented yet");
201
}
202
203
protected X11Renderer x11pipe;
204
protected PixelToShapeConverter x11txpipe;
205
protected static TextPipe x11textpipe;
206
207
static {
208
if (!isX11SurfaceDataInitialized() &&
209
!GraphicsEnvironment.isHeadless()) {
210
211
initIDs(XORComposite.class);
212
213
@SuppressWarnings("removal")
214
String xtextpipe = java.security.AccessController.doPrivileged
215
(new sun.security.action.GetPropertyAction("sun.java2d.xtextpipe"));
216
if (xtextpipe == null || "true".startsWith(xtextpipe)) {
217
if ("true".equals(xtextpipe)) {
218
// Only verbose if they use the full string "true"
219
System.out.println("using X11 text renderer");
220
}
221
x11textpipe = new X11TextRenderer();
222
if (GraphicsPrimitive.tracingEnabled()) {
223
x11textpipe = ((X11TextRenderer) x11textpipe).traceWrap();
224
}
225
} else {
226
if ("false".equals(xtextpipe)) {
227
// Only verbose if they use the full string "false"
228
System.out.println("using DGA text renderer");
229
}
230
x11textpipe = solidTextRenderer;
231
}
232
233
if (isAccelerationEnabled()) {
234
X11PMBlitLoops.register();
235
X11PMBlitBgLoops.register();
236
}
237
}
238
}
239
240
/**
241
* Returns true if shared memory pixmaps are available
242
*/
243
private static native boolean isShmPMAvailable();
244
245
public static boolean isAccelerationEnabled() {
246
if (accelerationEnabled == null) {
247
248
if (GraphicsEnvironment.isHeadless()) {
249
accelerationEnabled = Boolean.FALSE;
250
} else {
251
@SuppressWarnings("removal")
252
String prop = java.security.AccessController.doPrivileged(
253
new sun.security.action.GetPropertyAction("sun.java2d.pmoffscreen"));
254
if (prop != null) {
255
// true iff prop==true, false otherwise
256
accelerationEnabled = Boolean.valueOf(prop);
257
} else {
258
boolean isDisplayLocal = false;
259
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
260
if (ge instanceof SunGraphicsEnvironment) {
261
isDisplayLocal = ((SunGraphicsEnvironment) ge).isDisplayLocal();
262
}
263
264
// EXA based drivers tend to place pixmaps in VRAM, slowing down readbacks.
265
// Don't use pixmaps if we are local and shared memory Pixmaps
266
// are not available.
267
accelerationEnabled = !(isDisplayLocal && !isShmPMAvailable());
268
}
269
}
270
}
271
return accelerationEnabled.booleanValue();
272
}
273
274
@Override
275
public SurfaceDataProxy makeProxyFor(SurfaceData srcData) {
276
return X11SurfaceDataProxy.createProxy(srcData, graphicsConfig);
277
}
278
279
public void validatePipe(SunGraphics2D sg2d) {
280
if (sg2d.antialiasHint != SunHints.INTVAL_ANTIALIAS_ON &&
281
sg2d.paintState <= SunGraphics2D.PAINT_ALPHACOLOR &&
282
(sg2d.compositeState <= SunGraphics2D.COMP_ISCOPY ||
283
sg2d.compositeState == SunGraphics2D.COMP_XOR))
284
{
285
if (x11txpipe == null) {
286
/*
287
* Note: this is thread-safe since x11txpipe is the
288
* second of the two pipes constructed in makePipes().
289
* In the rare case we are racing against another
290
* thread making new pipes, setting lazypipe is a
291
* safe alternative to waiting for the other thread.
292
*/
293
sg2d.drawpipe = lazypipe;
294
sg2d.fillpipe = lazypipe;
295
sg2d.shapepipe = lazypipe;
296
sg2d.imagepipe = lazypipe;
297
sg2d.textpipe = lazypipe;
298
return;
299
}
300
301
if (sg2d.clipState == SunGraphics2D.CLIP_SHAPE) {
302
// Do this to init textpipe correctly; we will override the
303
// other non-text pipes below
304
// REMIND: we should clean this up eventually instead of
305
// having this work duplicated.
306
super.validatePipe(sg2d);
307
} else {
308
switch (sg2d.textAntialiasHint) {
309
310
case SunHints.INTVAL_TEXT_ANTIALIAS_DEFAULT:
311
/* equating to OFF which it is for us */
312
case SunHints.INTVAL_TEXT_ANTIALIAS_OFF:
313
// Use X11 pipe even if DGA is available since DGA
314
// text slows everything down when mixed with X11 calls
315
if (sg2d.compositeState == SunGraphics2D.COMP_ISCOPY) {
316
sg2d.textpipe = x11textpipe;
317
} else {
318
sg2d.textpipe = solidTextRenderer;
319
}
320
break;
321
322
case SunHints.INTVAL_TEXT_ANTIALIAS_ON:
323
// Remind: may use Xrender for these when composite is
324
// copy as above, or if remote X11.
325
sg2d.textpipe = aaTextRenderer;
326
break;
327
328
default:
329
switch (sg2d.getFontInfo().aaHint) {
330
331
case SunHints.INTVAL_TEXT_ANTIALIAS_LCD_HRGB:
332
case SunHints.INTVAL_TEXT_ANTIALIAS_LCD_VRGB:
333
sg2d.textpipe = lcdTextRenderer;
334
break;
335
336
case SunHints.INTVAL_TEXT_ANTIALIAS_OFF:
337
// Use X11 pipe even if DGA is available since DGA
338
// text slows everything down when mixed with X11 calls
339
if (sg2d.compositeState == SunGraphics2D.COMP_ISCOPY) {
340
sg2d.textpipe = x11textpipe;
341
} else {
342
sg2d.textpipe = solidTextRenderer;
343
}
344
break;
345
346
case SunHints.INTVAL_TEXT_ANTIALIAS_ON:
347
sg2d.textpipe = aaTextRenderer;
348
break;
349
350
default:
351
sg2d.textpipe = solidTextRenderer;
352
}
353
}
354
}
355
356
if (sg2d.transformState >= SunGraphics2D.TRANSFORM_TRANSLATESCALE) {
357
sg2d.drawpipe = x11txpipe;
358
sg2d.fillpipe = x11txpipe;
359
} else if (sg2d.strokeState != SunGraphics2D.STROKE_THIN){
360
sg2d.drawpipe = x11txpipe;
361
sg2d.fillpipe = x11pipe;
362
} else {
363
sg2d.drawpipe = x11pipe;
364
sg2d.fillpipe = x11pipe;
365
}
366
sg2d.shapepipe = x11pipe;
367
sg2d.imagepipe = imagepipe;
368
369
// This is needed for AA text.
370
// Note that even an X11TextRenderer can dispatch AA text
371
// if a GlyphVector overrides the AA setting.
372
// We use getRenderLoops() rather than setting solidloops
373
// directly so that we get the appropriate loops in XOR mode.
374
if (sg2d.loops == null) {
375
// assert(some pipe will always be a LoopBasedPipe)
376
sg2d.loops = getRenderLoops(sg2d);
377
}
378
} else {
379
super.validatePipe(sg2d);
380
}
381
}
382
383
public RenderLoops getRenderLoops(SunGraphics2D sg2d) {
384
if (sg2d.paintState <= SunGraphics2D.PAINT_ALPHACOLOR &&
385
sg2d.compositeState <= SunGraphics2D.COMP_ISCOPY)
386
{
387
return solidloops;
388
}
389
return super.getRenderLoops(sg2d);
390
}
391
392
public GraphicsConfiguration getDeviceConfiguration() {
393
return graphicsConfig;
394
}
395
396
/**
397
* Method for instantiating a Window SurfaceData
398
*/
399
public static X11WindowSurfaceData createData(X11ComponentPeer peer) {
400
X11GraphicsConfig gc = getGC(peer);
401
return new X11WindowSurfaceData(peer, gc, gc.getSurfaceType());
402
}
403
404
/**
405
* Method for instantiating a Pixmap SurfaceData (offscreen)
406
*/
407
public static X11PixmapSurfaceData createData(X11GraphicsConfig gc,
408
int width, int height,
409
ColorModel cm, Image image,
410
long drawable,
411
int transparency,
412
boolean isTexture)
413
{
414
return new X11PixmapSurfaceData(gc, width, height, image,
415
getSurfaceType(gc, transparency, true),
416
cm, drawable, transparency, isTexture);
417
}
418
419
// /**
420
// * Initializes the native Ops pointer.
421
// */
422
// private native void initOps(X11ComponentPeer peer,
423
// X11GraphicsConfig gc, int depth);
424
425
protected X11SurfaceData(X11ComponentPeer peer,
426
X11GraphicsConfig gc,
427
SurfaceType sType,
428
ColorModel cm) {
429
super(sType, cm);
430
this.peer = peer;
431
this.graphicsConfig = gc;
432
this.solidloops = graphicsConfig.getSolidLoops(sType);
433
this.depth = cm.getPixelSize();
434
initOps(peer, graphicsConfig, depth);
435
if (isAccelerationEnabled()) {
436
setBlitProxyKey(gc.getProxyKey());
437
}
438
}
439
440
public static X11GraphicsConfig getGC(X11ComponentPeer peer) {
441
if (peer != null) {
442
return (X11GraphicsConfig) peer.getGraphicsConfiguration();
443
} else {
444
GraphicsEnvironment env =
445
GraphicsEnvironment.getLocalGraphicsEnvironment();
446
GraphicsDevice gd = env.getDefaultScreenDevice();
447
return (X11GraphicsConfig)gd.getDefaultConfiguration();
448
}
449
}
450
451
/**
452
* Returns a boolean indicating whether or not a copyArea from
453
* the given rectangle source coordinates might be incomplete
454
* and result in X11 GraphicsExposure events being generated
455
* from XCopyArea.
456
* This method allows the SurfaceData copyArea method to determine
457
* if it needs to set the GraphicsExposures attribute of the X11 GC
458
* to True or False to receive or avoid the events.
459
* @return true if there is any chance that an XCopyArea from the
460
* given source coordinates could produce any X11
461
* Exposure events.
462
*/
463
public abstract boolean canSourceSendExposures(int x, int y, int w, int h);
464
465
public boolean copyArea(SunGraphics2D sg2d,
466
int x, int y, int w, int h, int dx, int dy)
467
{
468
if (x11pipe == null) {
469
if (!isDrawableValid()) {
470
return true;
471
}
472
makePipes();
473
}
474
CompositeType comptype = sg2d.imageComp;
475
if ((CompositeType.SrcOverNoEa.equals(comptype) ||
476
CompositeType.SrcNoEa.equals(comptype)))
477
{
478
SunToolkit.awtLock();
479
try {
480
boolean needExposures = canSourceSendExposures(x, y, w, h);
481
long xgc = getBlitGC(sg2d.getCompClip(), needExposures);
482
x11pipe.devCopyArea(getNativeOps(), xgc,
483
x, y,
484
x + dx, y + dy,
485
w, h);
486
} finally {
487
SunToolkit.awtUnlock();
488
}
489
return true;
490
}
491
return false;
492
}
493
494
public static SurfaceType getSurfaceType(X11GraphicsConfig gc,
495
int transparency)
496
{
497
return getSurfaceType(gc, transparency, false);
498
}
499
500
@SuppressWarnings("fallthrough")
501
public static SurfaceType getSurfaceType(X11GraphicsConfig gc,
502
int transparency,
503
boolean pixmapSurface)
504
{
505
boolean transparent = (transparency == Transparency.BITMASK);
506
SurfaceType sType;
507
ColorModel cm = gc.getColorModel();
508
switch (cm.getPixelSize()) {
509
case 24:
510
if (gc.getBitsPerPixel() == 24) {
511
if (cm instanceof DirectColorModel) {
512
// 4517321: We will always use ThreeByteBgr for 24 bpp
513
// surfaces, regardless of the pixel masks reported by
514
// X11. Despite ambiguity in the X11 spec in how 24 bpp
515
// surfaces are treated, it appears that the best
516
// SurfaceType for these configurations (including
517
// some Matrox Millenium and ATI Radeon boards) is
518
// ThreeByteBgr.
519
sType = transparent ? X11SurfaceData.ThreeByteBgrX11_BM : X11SurfaceData.ThreeByteBgrX11;
520
} else {
521
throw new sun.java2d.InvalidPipeException("Unsupported bit " +
522
"depth/cm combo: " +
523
cm.getPixelSize() +
524
", " + cm);
525
}
526
break;
527
}
528
// Fall through for 32 bit case
529
case 32:
530
if (cm instanceof DirectColorModel) {
531
if (((SunToolkit)java.awt.Toolkit.getDefaultToolkit()
532
).isTranslucencyCapable(gc) && !pixmapSurface)
533
{
534
sType = X11SurfaceData.IntArgbPreX11;
535
} else {
536
if (((DirectColorModel)cm).getRedMask() == 0xff0000) {
537
sType = transparent ? X11SurfaceData.IntRgbX11_BM :
538
X11SurfaceData.IntRgbX11;
539
} else {
540
sType = transparent ? X11SurfaceData.IntBgrX11_BM :
541
X11SurfaceData.IntBgrX11;
542
}
543
}
544
} else if (cm instanceof ComponentColorModel) {
545
sType = X11SurfaceData.FourByteAbgrPreX11;
546
} else {
547
548
throw new sun.java2d.InvalidPipeException("Unsupported bit " +
549
"depth/cm combo: " +
550
cm.getPixelSize() +
551
", " + cm);
552
}
553
break;
554
case 15:
555
sType = transparent ? X11SurfaceData.UShort555RgbX11_BM : X11SurfaceData.UShort555RgbX11;
556
break;
557
case 16:
558
if ((cm instanceof DirectColorModel) &&
559
(((DirectColorModel)cm).getGreenMask() == 0x3e0))
560
{
561
// fix for 4352984: Riva128 on Linux
562
sType = transparent ? X11SurfaceData.UShort555RgbX11_BM : X11SurfaceData.UShort555RgbX11;
563
} else {
564
sType = transparent ? X11SurfaceData.UShort565RgbX11_BM : X11SurfaceData.UShort565RgbX11;
565
}
566
break;
567
case 12:
568
if (cm instanceof IndexColorModel) {
569
sType = transparent ?
570
X11SurfaceData.UShortIndexedX11_BM :
571
X11SurfaceData.UShortIndexedX11;
572
} else {
573
throw new sun.java2d.InvalidPipeException("Unsupported bit " +
574
"depth: " +
575
cm.getPixelSize() +
576
" cm="+cm);
577
}
578
break;
579
case 8:
580
if (cm.getColorSpace().getType() == ColorSpace.TYPE_GRAY &&
581
cm instanceof ComponentColorModel) {
582
sType = transparent ? X11SurfaceData.ByteGrayX11_BM : X11SurfaceData.ByteGrayX11;
583
} else if (cm instanceof IndexColorModel &&
584
isOpaqueGray((IndexColorModel)cm)) {
585
sType = transparent ? X11SurfaceData.Index8GrayX11_BM : X11SurfaceData.Index8GrayX11;
586
} else {
587
sType = transparent ? X11SurfaceData.ByteIndexedX11_BM : X11SurfaceData.ByteIndexedOpaqueX11;
588
}
589
break;
590
default:
591
throw new sun.java2d.InvalidPipeException("Unsupported bit " +
592
"depth: " +
593
cm.getPixelSize());
594
}
595
return sType;
596
}
597
598
public void invalidate() {
599
if (isValid()) {
600
setInvalid();
601
super.invalidate();
602
}
603
}
604
605
/**
606
* The following methods and variables are used to keep the Java-level
607
* context state in sync with the native X11 GC associated with this
608
* X11SurfaceData object.
609
*/
610
611
private static native void XSetCopyMode(long xgc);
612
private static native void XSetXorMode(long xgc);
613
private static native void XSetForeground(long xgc, int pixel);
614
615
private long xgc;
616
private Region validatedClip;
617
private XORComposite validatedXorComp;
618
private int xorpixelmod;
619
private int validatedPixel;
620
private boolean validatedExposures = true;
621
622
public final long getRenderGC(Region clip,
623
int compState, Composite comp,
624
int pixel)
625
{
626
return getGC(clip, compState, comp, pixel, validatedExposures);
627
}
628
629
public final long getBlitGC(Region clip, boolean needExposures) {
630
return getGC(clip, SunGraphics2D.COMP_ISCOPY, null,
631
validatedPixel, needExposures);
632
}
633
634
final long getGC(Region clip,
635
int compState, Composite comp,
636
int pixel, boolean needExposures)
637
{
638
// assert SunToolkit.isAWTLockHeldByCurrentThread();
639
640
if (!isValid()) {
641
throw new InvalidPipeException("bounds changed");
642
}
643
644
// validate clip
645
if (clip != validatedClip) {
646
validatedClip = clip;
647
if (clip != null) {
648
XSetClip(xgc,
649
clip.getLoX(), clip.getLoY(),
650
clip.getHiX(), clip.getHiY(),
651
(clip.isRectangular() ? null : clip));
652
} else {
653
XResetClip(xgc);
654
}
655
}
656
657
// validate composite
658
if (compState == SunGraphics2D.COMP_ISCOPY) {
659
if (validatedXorComp != null) {
660
validatedXorComp = null;
661
xorpixelmod = 0;
662
XSetCopyMode(xgc);
663
}
664
} else {
665
if (validatedXorComp != comp) {
666
validatedXorComp = (XORComposite)comp;
667
xorpixelmod = validatedXorComp.getXorPixel();
668
XSetXorMode(xgc);
669
}
670
}
671
672
// validate pixel
673
pixel ^= xorpixelmod;
674
if (pixel != validatedPixel) {
675
validatedPixel = pixel;
676
XSetForeground(xgc, pixel);
677
}
678
679
if (validatedExposures != needExposures) {
680
validatedExposures = needExposures;
681
XSetGraphicsExposures(xgc, needExposures);
682
}
683
684
return xgc;
685
}
686
687
public synchronized void makePipes() {
688
if (x11pipe == null) {
689
SunToolkit.awtLock();
690
try {
691
xgc = XCreateGC(getNativeOps());
692
} finally {
693
SunToolkit.awtUnlock();
694
}
695
x11pipe = X11Renderer.getInstance();
696
x11txpipe = new PixelToShapeConverter(x11pipe);
697
}
698
}
699
700
private static final class X11WindowSurfaceData extends X11SurfaceData {
701
702
private final int scale;
703
704
public X11WindowSurfaceData(X11ComponentPeer peer,
705
X11GraphicsConfig gc,
706
SurfaceType sType) {
707
super(peer, gc, sType, peer.getColorModel());
708
this.scale = gc.getDevice().getScaleFactor();
709
if (isDrawableValid()) {
710
makePipes();
711
}
712
}
713
714
public SurfaceData getReplacement() {
715
return peer.getSurfaceData();
716
}
717
718
public Rectangle getBounds() {
719
Rectangle r = peer.getBounds();
720
r.x = r.y = 0;
721
r.width *= scale;
722
r.height *= scale;
723
return r;
724
}
725
726
@Override
727
public boolean canSourceSendExposures(int x, int y, int w, int h) {
728
return true;
729
}
730
731
/**
732
* Returns destination Component associated with this SurfaceData.
733
*/
734
public Object getDestination() {
735
return peer.getTarget();
736
}
737
738
@Override
739
public double getDefaultScaleX() {
740
return scale;
741
}
742
743
@Override
744
public double getDefaultScaleY() {
745
return scale;
746
}
747
}
748
749
private static final class X11PixmapSurfaceData extends X11SurfaceData {
750
751
private final Image offscreenImage;
752
private final int width;
753
private final int height;
754
private final int transparency;
755
private final int scale;
756
757
public X11PixmapSurfaceData(X11GraphicsConfig gc,
758
int width, int height,
759
Image image,
760
SurfaceType sType, ColorModel cm,
761
long drawable, int transparency,
762
boolean isTexture)
763
{
764
super(null, gc, sType, cm);
765
this.scale = isTexture ? 1 : gc.getDevice().getScaleFactor();
766
this.width = width * scale;
767
this.height = height * scale;
768
offscreenImage = image;
769
this.transparency = transparency;
770
initSurface(depth, this.width, this.height, drawable);
771
makePipes();
772
}
773
774
public SurfaceData getReplacement() {
775
return restoreContents(offscreenImage);
776
}
777
778
/**
779
* Need this since the surface data is created with
780
* the color model of the target GC, which is always
781
* opaque. But in SunGraphics2D.blitSD we choose loops
782
* based on the transparency on the source SD, so
783
* it could choose wrong loop (blit instead of blitbg,
784
* for example).
785
*/
786
public int getTransparency() {
787
return transparency;
788
}
789
790
public Rectangle getBounds() {
791
return new Rectangle(width, height);
792
}
793
794
@Override
795
public boolean canSourceSendExposures(int x, int y, int w, int h) {
796
return (x < 0 || y < 0 || (x+w) > width || (y+h) > height);
797
}
798
799
public void flush() {
800
/*
801
* We need to invalidate the surface before disposing the
802
* native Drawable and GC. This way if an application tries
803
* to render to an already flushed X11SurfaceData, we will notice
804
* in the validate() method above that it has been invalidated,
805
* and we will avoid using those native resources that have
806
* already been disposed.
807
*/
808
invalidate();
809
flushNativeSurface();
810
}
811
812
/**
813
* Returns destination Image associated with this SurfaceData.
814
*/
815
public Object getDestination() {
816
return offscreenImage;
817
}
818
819
@Override
820
public double getDefaultScaleX() {
821
return scale;
822
}
823
824
@Override
825
public double getDefaultScaleY() {
826
return scale;
827
}
828
}
829
830
private static LazyPipe lazypipe = new LazyPipe();
831
832
public static class LazyPipe extends ValidatePipe {
833
public boolean validate(SunGraphics2D sg2d) {
834
X11SurfaceData xsd = (X11SurfaceData) sg2d.surfaceData;
835
if (!xsd.isDrawableValid()) {
836
return false;
837
}
838
xsd.makePipes();
839
return super.validate(sg2d);
840
}
841
}
842
}
843
844