227 return graphicsConfig; 228 } 229 230 /** 231 * Method for instantiating a Window SurfaceData 232 */ 233 public static XRWindowSurfaceData createData(X11ComponentPeer peer) { 234 XRGraphicsConfig gc = getGC(peer); 235 return new XRWindowSurfaceData(peer, gc, gc.getSurfaceType()); 236 } 237 238 /** 239 * Method for instantiating a Pixmap SurfaceData (offscreen). 240 * If the surface * is opaque a 24-bit/RGB surface is chosen, 241 * otherwise a 32-bit ARGB surface. 242 */ 243 public static XRPixmapSurfaceData createData(XRGraphicsConfig gc, 244 int width, int height, 245 ColorModel cm, Image image, 246 long drawable, 247 int transparency) { 248 int depth; 249 // If we have a 32 bit color model for the window it needs 250 // alpha to support translucency of the window so we need 251 // to upgrade what was requested for the surface. 252 if (gc.getColorModel().getPixelSize() == 32) { 253 depth = 32; 254 transparency = Transparency.TRANSLUCENT; 255 } else { 256 depth = transparency > Transparency.OPAQUE ? 32 : 24; 257 } 258 259 if (depth == 24) { 260 cm = new DirectColorModel(depth, 261 0x00FF0000, 0x0000FF00, 0x000000FF); 262 } else { 263 cm = new DirectColorModel(depth, 0x00FF0000, 0x0000FF00, 264 0x000000FF, 0xFF000000); 265 } 266 267 return new XRPixmapSurfaceData 268 (gc, width, height, image, getSurfaceType(gc, transparency), 269 cm, drawable, transparency, 270 XRUtils.getPictureFormatForTransparency(transparency), depth); 271 } 272 273 protected XRSurfaceData(X11ComponentPeer peer, XRGraphicsConfig gc, 274 SurfaceType sType, ColorModel cm, int depth, int transparency) 275 { 276 super(sType, cm); 277 this.peer = peer; 278 this.graphicsConfig = gc; 279 this.solidloops = graphicsConfig.getSolidLoops(sType); 280 this.depth = depth; 281 initOps(peer, graphicsConfig, depth); 282 283 setBlitProxyKey(gc.getProxyKey()); 284 } 285 286 protected XRSurfaceData(XRBackend renderQueue) { 287 super(XRSurfaceData.IntRgbX11, 288 new DirectColorModel(24, 0x00FF0000, 0x0000FF00, 0x000000FF)); 289 this.renderQueue = renderQueue; 290 } 525 SunToolkit.awtLock(); 526 xgc = XCreateGC(getNativeOps()); 527 528 xrpipe = new XRRenderer(maskBuffer.getMaskBuffer()); 529 xrtxpipe = new PixelToShapeConverter(xrpipe); 530 xrtextpipe = maskBuffer.getTextRenderer(); 531 xrDrawImage = new XRDrawImage(); 532 533 if (JulesPathBuf.isCairoAvailable()) { 534 aaShapePipe = 535 new JulesShapePipe(XRCompositeManager.getInstance(this)); 536 aaPixelToShapeConv = new PixelToShapeConverter(aaShapePipe); 537 } 538 } finally { 539 SunToolkit.awtUnlock(); 540 } 541 } 542 } 543 544 public static class XRWindowSurfaceData extends XRSurfaceData { 545 public XRWindowSurfaceData(X11ComponentPeer peer, 546 XRGraphicsConfig gc, SurfaceType sType) { 547 super(peer, gc, sType, peer.getColorModel(), 548 peer.getColorModel().getPixelSize(), Transparency.OPAQUE); 549 550 if (isXRDrawableValid()) { 551 // If we have a 32 bit color model for the window it needs 552 // alpha to support translucency of the window so we need 553 // to get the ARGB32 XRender picture format else for 554 // 24 bit colormodel we need RGB24 or OPAQUE pictureformat. 555 if (peer.getColorModel().getPixelSize() == 32) { 556 initXRender(XRUtils. 557 getPictureFormatForTransparency(Transparency.TRANSLUCENT)); 558 } 559 else { 560 initXRender(XRUtils. 561 getPictureFormatForTransparency(Transparency.OPAQUE)); 562 } 563 makePipes(); 564 } 565 } 566 567 public SurfaceData getReplacement() { 568 return peer.getSurfaceData(); 569 } 570 571 public Rectangle getBounds() { 572 Rectangle r = peer.getBounds(); 573 r.x = r.y = 0; 574 return r; 575 } 576 577 @Override 578 public boolean canSourceSendExposures(int x, int y, int w, int h) { 579 return true; 580 } 581 582 /** 583 * Returns destination Component associated with this SurfaceData. 584 */ 585 public Object getDestination() { 586 return peer.getTarget(); 587 } 588 589 public void invalidate() { 590 try { 591 SunToolkit.awtLock(); 592 freeXSDOPicture(getNativeOps()); 593 }finally { 594 SunToolkit.awtUnlock(); 595 } 596 597 super.invalidate(); 598 } 599 } 600 601 public static class XRInternalSurfaceData extends XRSurfaceData { 602 public XRInternalSurfaceData(XRBackend renderQueue, int pictXid) { 603 super(renderQueue); 604 this.picture = pictXid; 605 this.transformInUse = false; 606 } 607 608 public boolean canSourceSendExposures(int x, int y, int w, int h) { 609 return false; 610 } 611 612 public Rectangle getBounds() { 613 return null; 614 } 615 616 public Object getDestination() { 617 return null; 618 } 619 620 public SurfaceData getReplacement() { 621 return null; 622 } 623 } 624 625 public static class XRPixmapSurfaceData extends XRSurfaceData { 626 Image offscreenImage; 627 int width; 628 int height; 629 int transparency; 630 631 public XRPixmapSurfaceData(XRGraphicsConfig gc, int width, int height, 632 Image image, SurfaceType sType, 633 ColorModel cm, long drawable, 634 int transparency, int pictFormat, 635 int depth) { 636 super(null, gc, sType, cm, depth, transparency); 637 this.width = width; 638 this.height = height; 639 offscreenImage = image; 640 this.transparency = transparency; 641 initSurface(depth, width, height, drawable, pictFormat); 642 643 initXRender(pictFormat); 644 makePipes(); 645 } 646 647 public void initSurface(int depth, int width, int height, 648 long drawable, int pictFormat) { 649 try { 650 SunToolkit.awtLock(); 651 XRInitSurface(depth, width, height, drawable, pictFormat); 652 } finally { 653 SunToolkit.awtUnlock(); 654 } 655 } 656 657 public SurfaceData getReplacement() { 658 return restoreContents(offscreenImage); 659 } 660 661 /** 678 } 679 680 public void flush() { 681 /* 682 * We need to invalidate the surface before disposing the native 683 * Drawable and Picture. This way if an application tries to render 684 * to an already flushed XRSurfaceData, we will notice in the 685 * validate() method above that it has been invalidated, and we will 686 * avoid using those native resources that have already been 687 * disposed. 688 */ 689 invalidate(); 690 flushNativeSurface(); 691 } 692 693 /** 694 * Returns destination Image associated with this SurfaceData. 695 */ 696 public Object getDestination() { 697 return offscreenImage; 698 } 699 } 700 701 public long getGC() { 702 return xgc; 703 } 704 705 public static class LazyPipe extends ValidatePipe { 706 public boolean validate(SunGraphics2D sg2d) { 707 XRSurfaceData xsd = (XRSurfaceData) sg2d.surfaceData; 708 if (!xsd.isXRDrawableValid()) { 709 return false; 710 } 711 xsd.makePipes(); 712 return super.validate(sg2d); 713 } 714 } 715 716 public int getPicture() { 717 return picture; | 227 return graphicsConfig; 228 } 229 230 /** 231 * Method for instantiating a Window SurfaceData 232 */ 233 public static XRWindowSurfaceData createData(X11ComponentPeer peer) { 234 XRGraphicsConfig gc = getGC(peer); 235 return new XRWindowSurfaceData(peer, gc, gc.getSurfaceType()); 236 } 237 238 /** 239 * Method for instantiating a Pixmap SurfaceData (offscreen). 240 * If the surface * is opaque a 24-bit/RGB surface is chosen, 241 * otherwise a 32-bit ARGB surface. 242 */ 243 public static XRPixmapSurfaceData createData(XRGraphicsConfig gc, 244 int width, int height, 245 ColorModel cm, Image image, 246 long drawable, 247 int transparency, 248 boolean isTexture) { 249 int depth; 250 // If we have a 32 bit color model for the window it needs 251 // alpha to support translucency of the window so we need 252 // to upgrade what was requested for the surface. 253 if (gc.getColorModel().getPixelSize() == 32) { 254 depth = 32; 255 transparency = Transparency.TRANSLUCENT; 256 } else { 257 depth = transparency > Transparency.OPAQUE ? 32 : 24; 258 } 259 260 if (depth == 24) { 261 cm = new DirectColorModel(depth, 262 0x00FF0000, 0x0000FF00, 0x000000FF); 263 } else { 264 cm = new DirectColorModel(depth, 0x00FF0000, 0x0000FF00, 265 0x000000FF, 0xFF000000); 266 } 267 268 return new XRPixmapSurfaceData 269 (gc, width, height, image, getSurfaceType(gc, transparency), 270 cm, drawable, transparency, 271 XRUtils.getPictureFormatForTransparency(transparency), depth, isTexture); 272 } 273 274 protected XRSurfaceData(X11ComponentPeer peer, XRGraphicsConfig gc, 275 SurfaceType sType, ColorModel cm, int depth, int transparency) 276 { 277 super(sType, cm); 278 this.peer = peer; 279 this.graphicsConfig = gc; 280 this.solidloops = graphicsConfig.getSolidLoops(sType); 281 this.depth = depth; 282 initOps(peer, graphicsConfig, depth); 283 284 setBlitProxyKey(gc.getProxyKey()); 285 } 286 287 protected XRSurfaceData(XRBackend renderQueue) { 288 super(XRSurfaceData.IntRgbX11, 289 new DirectColorModel(24, 0x00FF0000, 0x0000FF00, 0x000000FF)); 290 this.renderQueue = renderQueue; 291 } 526 SunToolkit.awtLock(); 527 xgc = XCreateGC(getNativeOps()); 528 529 xrpipe = new XRRenderer(maskBuffer.getMaskBuffer()); 530 xrtxpipe = new PixelToShapeConverter(xrpipe); 531 xrtextpipe = maskBuffer.getTextRenderer(); 532 xrDrawImage = new XRDrawImage(); 533 534 if (JulesPathBuf.isCairoAvailable()) { 535 aaShapePipe = 536 new JulesShapePipe(XRCompositeManager.getInstance(this)); 537 aaPixelToShapeConv = new PixelToShapeConverter(aaShapePipe); 538 } 539 } finally { 540 SunToolkit.awtUnlock(); 541 } 542 } 543 } 544 545 public static class XRWindowSurfaceData extends XRSurfaceData { 546 547 protected final int scale; 548 549 public XRWindowSurfaceData(X11ComponentPeer peer, 550 XRGraphicsConfig gc, SurfaceType sType) { 551 super(peer, gc, sType, peer.getColorModel(), 552 peer.getColorModel().getPixelSize(), Transparency.OPAQUE); 553 554 this.scale = gc.getScale(); 555 556 if (isXRDrawableValid()) { 557 // If we have a 32 bit color model for the window it needs 558 // alpha to support translucency of the window so we need 559 // to get the ARGB32 XRender picture format else for 560 // 24 bit colormodel we need RGB24 or OPAQUE pictureformat. 561 if (peer.getColorModel().getPixelSize() == 32) { 562 initXRender(XRUtils. 563 getPictureFormatForTransparency(Transparency.TRANSLUCENT)); 564 } 565 else { 566 initXRender(XRUtils. 567 getPictureFormatForTransparency(Transparency.OPAQUE)); 568 } 569 makePipes(); 570 } 571 } 572 573 public SurfaceData getReplacement() { 574 return peer.getSurfaceData(); 575 } 576 577 public Rectangle getBounds() { 578 Rectangle r = peer.getBounds(); 579 r.x = r.y = 0; 580 r.width *= scale; 581 r.height *= scale; 582 return r; 583 } 584 585 @Override 586 public boolean canSourceSendExposures(int x, int y, int w, int h) { 587 return true; 588 } 589 590 /** 591 * Returns destination Component associated with this SurfaceData. 592 */ 593 public Object getDestination() { 594 return peer.getTarget(); 595 } 596 597 public void invalidate() { 598 try { 599 SunToolkit.awtLock(); 600 freeXSDOPicture(getNativeOps()); 601 }finally { 602 SunToolkit.awtUnlock(); 603 } 604 605 super.invalidate(); 606 } 607 608 @Override 609 public double getDefaultScaleX() { 610 return scale; 611 } 612 613 @Override 614 public double getDefaultScaleY() { 615 return scale; 616 } 617 } 618 619 public static class XRInternalSurfaceData extends XRSurfaceData { 620 public XRInternalSurfaceData(XRBackend renderQueue, int pictXid) { 621 super(renderQueue); 622 this.picture = pictXid; 623 this.transformInUse = false; 624 } 625 626 public boolean canSourceSendExposures(int x, int y, int w, int h) { 627 return false; 628 } 629 630 public Rectangle getBounds() { 631 return null; 632 } 633 634 public Object getDestination() { 635 return null; 636 } 637 638 public SurfaceData getReplacement() { 639 return null; 640 } 641 } 642 643 public static class XRPixmapSurfaceData extends XRSurfaceData { 644 Image offscreenImage; 645 int width; 646 int height; 647 int transparency; 648 private final int scale; 649 650 public XRPixmapSurfaceData(XRGraphicsConfig gc, int width, int height, 651 Image image, SurfaceType sType, 652 ColorModel cm, long drawable, 653 int transparency, int pictFormat, 654 int depth, boolean isTexture) { 655 super(null, gc, sType, cm, depth, transparency); 656 this.scale = isTexture ? 1 : gc.getDevice().getScaleFactor(); 657 this.width = width * scale; 658 this.height = height * scale; 659 offscreenImage = image; 660 this.transparency = transparency; 661 initSurface(depth, this.width, this.height, drawable, pictFormat); 662 663 initXRender(pictFormat); 664 makePipes(); 665 } 666 667 public void initSurface(int depth, int width, int height, 668 long drawable, int pictFormat) { 669 try { 670 SunToolkit.awtLock(); 671 XRInitSurface(depth, width, height, drawable, pictFormat); 672 } finally { 673 SunToolkit.awtUnlock(); 674 } 675 } 676 677 public SurfaceData getReplacement() { 678 return restoreContents(offscreenImage); 679 } 680 681 /** 698 } 699 700 public void flush() { 701 /* 702 * We need to invalidate the surface before disposing the native 703 * Drawable and Picture. This way if an application tries to render 704 * to an already flushed XRSurfaceData, we will notice in the 705 * validate() method above that it has been invalidated, and we will 706 * avoid using those native resources that have already been 707 * disposed. 708 */ 709 invalidate(); 710 flushNativeSurface(); 711 } 712 713 /** 714 * Returns destination Image associated with this SurfaceData. 715 */ 716 public Object getDestination() { 717 return offscreenImage; 718 } 719 720 @Override 721 public double getDefaultScaleX() { 722 return scale; 723 } 724 725 @Override 726 public double getDefaultScaleY() { 727 return scale; 728 } 729 } 730 731 public long getGC() { 732 return xgc; 733 } 734 735 public static class LazyPipe extends ValidatePipe { 736 public boolean validate(SunGraphics2D sg2d) { 737 XRSurfaceData xsd = (XRSurfaceData) sg2d.surfaceData; 738 if (!xsd.isXRDrawableValid()) { 739 return false; 740 } 741 xsd.makePipes(); 742 return super.validate(sg2d); 743 } 744 } 745 746 public int getPicture() { 747 return picture; |