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.GraphicsDevice;
29 import java.awt.GraphicsEnvironment;
30 import java.awt.Color;
31 import java.awt.Composite;
32 import java.awt.Rectangle;
33 import java.awt.GraphicsConfiguration;
34 import java.awt.Image;
35 import java.awt.color.ColorSpace;
36 import java.awt.Transparency;
37 import java.awt.image.BufferedImage;
38 import java.awt.image.ColorModel;
39 import java.awt.image.ComponentColorModel;
40 import java.awt.image.DirectColorModel;
41 import java.awt.image.IndexColorModel;
42 import java.awt.image.Raster;
43 import java.awt.peer.ComponentPeer;
44
45 import sun.awt.SunHints;
46 import sun.awt.SunToolkit;
47 import sun.awt.X11ComponentPeer;
48 import sun.awt.X11GraphicsConfig;
49 import sun.awt.X11GraphicsEnvironment;
50 import sun.awt.image.PixelConverter;
51 import sun.font.X11TextRenderer;
52 import sun.java2d.InvalidPipeException;
53 import sun.java2d.SunGraphics2D;
54 import sun.java2d.SunGraphicsEnvironment;
55 import sun.java2d.SurfaceData;
56 import sun.java2d.SurfaceDataProxy;
57 import sun.java2d.loops.SurfaceType;
58 import sun.java2d.loops.CompositeType;
59 import sun.java2d.loops.RenderLoops;
60 import sun.java2d.loops.GraphicsPrimitive;
61 import sun.java2d.loops.XORComposite;
62 import sun.java2d.loops.Blit;
63 import sun.java2d.pipe.ValidatePipe;
64 import sun.java2d.pipe.PixelToShapeConverter;
65 import sun.java2d.pipe.TextPipe;
66 import sun.java2d.pipe.Region;
67
68 public abstract class X11SurfaceData extends XSurfaceData {
69 X11ComponentPeer peer;
70 X11GraphicsConfig graphicsConfig;
71 private RenderLoops solidloops;
72
73 protected int depth;
74
75 private static native void initIDs(Class xorComp, boolean tryDGA);
76 protected native void initSurface(int depth, int width, int height,
77 long drawable);
78
79 public static final String
80 DESC_INT_BGR_X11 = "Integer BGR Pixmap";
81 public static final String
82 DESC_INT_RGB_X11 = "Integer RGB Pixmap";
83
84 public static final String
85 DESC_4BYTE_ABGR_PRE_X11 = "4 byte ABGR Pixmap with pre-multplied alpha";
86 public static final String
278 }
279
280 // EXA based drivers tend to place pixmaps in VRAM, slowing down readbacks.
281 // Don't use pixmaps if dga is available,
282 // or we are local and shared memory Pixmaps are not available.
283 accelerationEnabled =
284 !(isDgaAvailable() || (isDisplayLocal && !isShmPMAvailable()));
285 }
286 }
287 }
288 return accelerationEnabled.booleanValue();
289 }
290
291 @Override
292 public SurfaceDataProxy makeProxyFor(SurfaceData srcData) {
293 return X11SurfaceDataProxy.createProxy(srcData, graphicsConfig);
294 }
295
296 public void validatePipe(SunGraphics2D sg2d) {
297 if (sg2d.antialiasHint != SunHints.INTVAL_ANTIALIAS_ON &&
298 sg2d.paintState <= sg2d.PAINT_ALPHACOLOR &&
299 (sg2d.compositeState <= sg2d.COMP_ISCOPY ||
300 sg2d.compositeState == sg2d.COMP_XOR))
301 {
302 if (x11txpipe == null) {
303 /*
304 * Note: this is thread-safe since x11txpipe is the
305 * second of the two pipes constructed in makePipes().
306 * In the rare case we are racing against another
307 * thread making new pipes, setting lazypipe is a
308 * safe alternative to waiting for the other thread.
309 */
310 sg2d.drawpipe = lazypipe;
311 sg2d.fillpipe = lazypipe;
312 sg2d.shapepipe = lazypipe;
313 sg2d.imagepipe = lazypipe;
314 sg2d.textpipe = lazypipe;
315 return;
316 }
317
318 if (sg2d.clipState == sg2d.CLIP_SHAPE) {
319 // Do this to init textpipe correctly; we will override the
320 // other non-text pipes below
321 // REMIND: we should clean this up eventually instead of
322 // having this work duplicated.
323 super.validatePipe(sg2d);
324 } else {
325 switch (sg2d.textAntialiasHint) {
326
327 case SunHints.INTVAL_TEXT_ANTIALIAS_DEFAULT:
328 /* equating to OFF which it is for us */
329 case SunHints.INTVAL_TEXT_ANTIALIAS_OFF:
330 // Use X11 pipe even if DGA is available since DGA
331 // text slows everything down when mixed with X11 calls
332 if (sg2d.compositeState == sg2d.COMP_ISCOPY) {
333 sg2d.textpipe = x11textpipe;
334 } else {
335 sg2d.textpipe = solidTextRenderer;
336 }
337 break;
338
339 case SunHints.INTVAL_TEXT_ANTIALIAS_ON:
340 // Remind: may use Xrender for these when composite is
341 // copy as above, or if remote X11.
342 sg2d.textpipe = aaTextRenderer;
343 break;
344
345 default:
346 switch (sg2d.getFontInfo().aaHint) {
347
348 case SunHints.INTVAL_TEXT_ANTIALIAS_LCD_HRGB:
349 case SunHints.INTVAL_TEXT_ANTIALIAS_LCD_VRGB:
350 sg2d.textpipe = lcdTextRenderer;
351 break;
352
353 case SunHints.INTVAL_TEXT_ANTIALIAS_OFF:
354 // Use X11 pipe even if DGA is available since DGA
355 // text slows everything down when mixed with X11 calls
356 if (sg2d.compositeState == sg2d.COMP_ISCOPY) {
357 sg2d.textpipe = x11textpipe;
358 } else {
359 sg2d.textpipe = solidTextRenderer;
360 }
361 break;
362
363 case SunHints.INTVAL_TEXT_ANTIALIAS_ON:
364 sg2d.textpipe = aaTextRenderer;
365 break;
366
367 default:
368 sg2d.textpipe = solidTextRenderer;
369 }
370 }
371 }
372
373 if (sg2d.transformState >= sg2d.TRANSFORM_TRANSLATESCALE) {
374 sg2d.drawpipe = x11txpipe;
375 sg2d.fillpipe = x11txpipe;
376 } else if (sg2d.strokeState != sg2d.STROKE_THIN){
377 sg2d.drawpipe = x11txpipe;
378 sg2d.fillpipe = x11pipe;
379 } else {
380 sg2d.drawpipe = x11pipe;
381 sg2d.fillpipe = x11pipe;
382 }
383 sg2d.shapepipe = x11pipe;
384 sg2d.imagepipe = imagepipe;
385
386 // This is needed for AA text.
387 // Note that even an X11TextRenderer can dispatch AA text
388 // if a GlyphVector overrides the AA setting.
389 // We use getRenderLoops() rather than setting solidloops
390 // directly so that we get the appropriate loops in XOR mode.
391 if (sg2d.loops == null) {
392 // assert(some pipe will always be a LoopBasedPipe)
393 sg2d.loops = getRenderLoops(sg2d);
394 }
395 } else {
396 super.validatePipe(sg2d);
397 }
398 }
399
400 public RenderLoops getRenderLoops(SunGraphics2D sg2d) {
401 if (sg2d.paintState <= sg2d.PAINT_ALPHACOLOR &&
402 sg2d.compositeState <= sg2d.COMP_ISCOPY)
403 {
404 return solidloops;
405 }
406 return super.getRenderLoops(sg2d);
407 }
408
409 public GraphicsConfiguration getDeviceConfiguration() {
410 return graphicsConfig;
411 }
412
413 /**
414 * Method for instantiating a Window SurfaceData
415 */
416 public static X11WindowSurfaceData createData(X11ComponentPeer peer) {
417 X11GraphicsConfig gc = getGC(peer);
418 return new X11WindowSurfaceData(peer, gc, gc.getSurfaceType());
419 }
420
421 /**
422 * Method for instantiating a Pixmap SurfaceData (offscreen)
471 * from XCopyArea.
472 * This method allows the SurfaceData copyArea method to determine
473 * if it needs to set the GraphicsExposures attribute of the X11 GC
474 * to True or False to receive or avoid the events.
475 * @return true if there is any chance that an XCopyArea from the
476 * given source coordinates could produce any X11
477 * Exposure events.
478 */
479 public abstract boolean canSourceSendExposures(int x, int y, int w, int h);
480
481 public boolean copyArea(SunGraphics2D sg2d,
482 int x, int y, int w, int h, int dx, int dy)
483 {
484 if (x11pipe == null) {
485 if (!isDrawableValid()) {
486 return true;
487 }
488 makePipes();
489 }
490 CompositeType comptype = sg2d.imageComp;
491 if (sg2d.transformState < sg2d.TRANSFORM_TRANSLATESCALE &&
492 (CompositeType.SrcOverNoEa.equals(comptype) ||
493 CompositeType.SrcNoEa.equals(comptype)))
494 {
495 x += sg2d.transX;
496 y += sg2d.transY;
497 SunToolkit.awtLock();
498 try {
499 boolean needExposures = canSourceSendExposures(x, y, w, h);
500 long xgc = getBlitGC(sg2d.getCompClip(), needExposures);
501 x11pipe.devCopyArea(getNativeOps(), xgc,
502 x, y,
503 x + dx, y + dy,
504 w, h);
505 } finally {
506 SunToolkit.awtUnlock();
507 }
508 return true;
509 }
510 return false;
511 }
|
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, boolean tryDGA);
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
273 }
274
275 // EXA based drivers tend to place pixmaps in VRAM, slowing down readbacks.
276 // Don't use pixmaps if dga is available,
277 // or we are local and shared memory Pixmaps are not available.
278 accelerationEnabled =
279 !(isDgaAvailable() || (isDisplayLocal && !isShmPMAvailable()));
280 }
281 }
282 }
283 return accelerationEnabled.booleanValue();
284 }
285
286 @Override
287 public SurfaceDataProxy makeProxyFor(SurfaceData srcData) {
288 return X11SurfaceDataProxy.createProxy(srcData, graphicsConfig);
289 }
290
291 public void validatePipe(SunGraphics2D sg2d) {
292 if (sg2d.antialiasHint != SunHints.INTVAL_ANTIALIAS_ON &&
293 sg2d.paintState <= SunGraphics2D.PAINT_ALPHACOLOR &&
294 (sg2d.compositeState <= SunGraphics2D.COMP_ISCOPY ||
295 sg2d.compositeState == SunGraphics2D.COMP_XOR))
296 {
297 if (x11txpipe == null) {
298 /*
299 * Note: this is thread-safe since x11txpipe is the
300 * second of the two pipes constructed in makePipes().
301 * In the rare case we are racing against another
302 * thread making new pipes, setting lazypipe is a
303 * safe alternative to waiting for the other thread.
304 */
305 sg2d.drawpipe = lazypipe;
306 sg2d.fillpipe = lazypipe;
307 sg2d.shapepipe = lazypipe;
308 sg2d.imagepipe = lazypipe;
309 sg2d.textpipe = lazypipe;
310 return;
311 }
312
313 if (sg2d.clipState == SunGraphics2D.CLIP_SHAPE) {
314 // Do this to init textpipe correctly; we will override the
315 // other non-text pipes below
316 // REMIND: we should clean this up eventually instead of
317 // having this work duplicated.
318 super.validatePipe(sg2d);
319 } else {
320 switch (sg2d.textAntialiasHint) {
321
322 case SunHints.INTVAL_TEXT_ANTIALIAS_DEFAULT:
323 /* equating to OFF which it is for us */
324 case SunHints.INTVAL_TEXT_ANTIALIAS_OFF:
325 // Use X11 pipe even if DGA is available since DGA
326 // text slows everything down when mixed with X11 calls
327 if (sg2d.compositeState == SunGraphics2D.COMP_ISCOPY) {
328 sg2d.textpipe = x11textpipe;
329 } else {
330 sg2d.textpipe = solidTextRenderer;
331 }
332 break;
333
334 case SunHints.INTVAL_TEXT_ANTIALIAS_ON:
335 // Remind: may use Xrender for these when composite is
336 // copy as above, or if remote X11.
337 sg2d.textpipe = aaTextRenderer;
338 break;
339
340 default:
341 switch (sg2d.getFontInfo().aaHint) {
342
343 case SunHints.INTVAL_TEXT_ANTIALIAS_LCD_HRGB:
344 case SunHints.INTVAL_TEXT_ANTIALIAS_LCD_VRGB:
345 sg2d.textpipe = lcdTextRenderer;
346 break;
347
348 case SunHints.INTVAL_TEXT_ANTIALIAS_OFF:
349 // Use X11 pipe even if DGA is available since DGA
350 // text slows everything down when mixed with X11 calls
351 if (sg2d.compositeState == SunGraphics2D.COMP_ISCOPY) {
352 sg2d.textpipe = x11textpipe;
353 } else {
354 sg2d.textpipe = solidTextRenderer;
355 }
356 break;
357
358 case SunHints.INTVAL_TEXT_ANTIALIAS_ON:
359 sg2d.textpipe = aaTextRenderer;
360 break;
361
362 default:
363 sg2d.textpipe = solidTextRenderer;
364 }
365 }
366 }
367
368 if (sg2d.transformState >= SunGraphics2D.TRANSFORM_TRANSLATESCALE) {
369 sg2d.drawpipe = x11txpipe;
370 sg2d.fillpipe = x11txpipe;
371 } else if (sg2d.strokeState != SunGraphics2D.STROKE_THIN){
372 sg2d.drawpipe = x11txpipe;
373 sg2d.fillpipe = x11pipe;
374 } else {
375 sg2d.drawpipe = x11pipe;
376 sg2d.fillpipe = x11pipe;
377 }
378 sg2d.shapepipe = x11pipe;
379 sg2d.imagepipe = imagepipe;
380
381 // This is needed for AA text.
382 // Note that even an X11TextRenderer can dispatch AA text
383 // if a GlyphVector overrides the AA setting.
384 // We use getRenderLoops() rather than setting solidloops
385 // directly so that we get the appropriate loops in XOR mode.
386 if (sg2d.loops == null) {
387 // assert(some pipe will always be a LoopBasedPipe)
388 sg2d.loops = getRenderLoops(sg2d);
389 }
390 } else {
391 super.validatePipe(sg2d);
392 }
393 }
394
395 public RenderLoops getRenderLoops(SunGraphics2D sg2d) {
396 if (sg2d.paintState <= SunGraphics2D.PAINT_ALPHACOLOR &&
397 sg2d.compositeState <= SunGraphics2D.COMP_ISCOPY)
398 {
399 return solidloops;
400 }
401 return super.getRenderLoops(sg2d);
402 }
403
404 public GraphicsConfiguration getDeviceConfiguration() {
405 return graphicsConfig;
406 }
407
408 /**
409 * Method for instantiating a Window SurfaceData
410 */
411 public static X11WindowSurfaceData createData(X11ComponentPeer peer) {
412 X11GraphicsConfig gc = getGC(peer);
413 return new X11WindowSurfaceData(peer, gc, gc.getSurfaceType());
414 }
415
416 /**
417 * Method for instantiating a Pixmap SurfaceData (offscreen)
466 * from XCopyArea.
467 * This method allows the SurfaceData copyArea method to determine
468 * if it needs to set the GraphicsExposures attribute of the X11 GC
469 * to True or False to receive or avoid the events.
470 * @return true if there is any chance that an XCopyArea from the
471 * given source coordinates could produce any X11
472 * Exposure events.
473 */
474 public abstract boolean canSourceSendExposures(int x, int y, int w, int h);
475
476 public boolean copyArea(SunGraphics2D sg2d,
477 int x, int y, int w, int h, int dx, int dy)
478 {
479 if (x11pipe == null) {
480 if (!isDrawableValid()) {
481 return true;
482 }
483 makePipes();
484 }
485 CompositeType comptype = sg2d.imageComp;
486 if (sg2d.transformState < SunGraphics2D.TRANSFORM_TRANSLATESCALE &&
487 (CompositeType.SrcOverNoEa.equals(comptype) ||
488 CompositeType.SrcNoEa.equals(comptype)))
489 {
490 x += sg2d.transX;
491 y += sg2d.transY;
492 SunToolkit.awtLock();
493 try {
494 boolean needExposures = canSourceSendExposures(x, y, w, h);
495 long xgc = getBlitGC(sg2d.getCompClip(), needExposures);
496 x11pipe.devCopyArea(getNativeOps(), xgc,
497 x, y,
498 x + dx, y + dy,
499 w, h);
500 } finally {
501 SunToolkit.awtUnlock();
502 }
503 return true;
504 }
505 return false;
506 }
|