src/solaris/classes/sun/java2d/xr/MaskTileManager.java

Print this page




  37  *
  38  * @author Clemens Eisserer
  39  */
  40 
  41 public class MaskTileManager {
  42 
  43     public static final int MASK_SIZE = 256;
  44 
  45     MaskTile mainTile = new MaskTile();
  46 
  47     ArrayList<MaskTile> tileList;
  48     int allocatedTiles = 0;
  49     int xTiles, yTiles;
  50 
  51     XRCompositeManager xrMgr;
  52     XRBackend con;
  53 
  54     int maskPixmap;
  55     int maskPicture;
  56     long maskGC;
  57     int lineMaskPixmap;
  58     int lineMaskPicture;
  59     long drawLineGC;
  60     long clearLineGC;
  61 
  62     public MaskTileManager(XRCompositeManager xrMgr, int parentXid) {
  63         tileList = new ArrayList<MaskTile>();
  64         this.xrMgr = xrMgr;
  65         this.con = xrMgr.getBackend();
  66 
  67         maskPixmap = con.createPixmap(parentXid, 8, MASK_SIZE, MASK_SIZE);
  68         maskPicture = con.createPicture(maskPixmap, XRUtils.PictStandardA8);
  69         con.renderRectangle(maskPicture, XRUtils.PictOpClear,
  70                             new XRColor(Color.black),
  71                             0, 0, MASK_SIZE, MASK_SIZE);
  72         maskGC = con.createGC(maskPixmap);
  73         con.setGCExposures(maskGC, false);
  74 
  75         lineMaskPixmap = con.createPixmap(parentXid, 8, MASK_SIZE, MASK_SIZE);
  76         lineMaskPicture =
  77              con.createPicture(lineMaskPixmap, XRUtils.PictStandardA8);
  78         con.renderRectangle(lineMaskPicture, XRUtils.PictOpClear,
  79                           new XRColor(Color.black), 0, 0, MASK_SIZE, MASK_SIZE);
  80 
  81         drawLineGC = con.createGC(lineMaskPixmap);
  82         con.setGCExposures(drawLineGC, false);
  83         con.setGCForeground(drawLineGC, 255);
  84 
  85         clearLineGC = con.createGC(lineMaskPixmap);
  86         con.setGCExposures(clearLineGC, false);
  87         con.setGCForeground(clearLineGC, 0);
  88     }
  89 
  90     /**
  91      * Adds a rectangle to the mask.
  92      */
  93     public void addRect(int x, int y, int width, int height) {
  94         mainTile.addRect(x, y, width, height);
  95     }
  96 
  97     /**
  98      * Adds a line to the mask.
  99      */
 100     public void addLine(int x1, int y1, int x2, int y2) {
 101         mainTile.addLine(x1, y1, x2, y2);
 102     }
 103 
 104     /**
 105      * Transfers the geometry stored (rectangles, lines) to one or more masks,
 106      * and renders the result to the destination surface.
 107      */
 108     public void fillMask(XRSurfaceData dst) {
 109 
 110         boolean maskRequired = xrMgr.maskRequired();
 111 
 112         if (maskRequired) {
 113             mainTile.calculateDirtyAreas();
 114             DirtyRegion dirtyArea = mainTile.getDirtyArea().cloneRegion();
 115             mainTile.translate(-dirtyArea.x, -dirtyArea.y);
 116 
 117             XRColor maskColor = xrMgr.getMaskColor();
 118 
 119             // We don't need tiling if all geometry fits in a single tile
 120             if (dirtyArea.getWidth() <= MASK_SIZE &&
 121                 dirtyArea.getHeight() <= MASK_SIZE)


 307     /**
 308      * Limits the rect's coordinates to the mask coordinates. The result is used
 309      * by growDirtyRegion.
 310      */
 311     private void limitRectCoords(GrowableRectArray rects, int index) {
 312         if ((rects.getX(index) + rects.getWidth(index)) > MASK_SIZE) {
 313             rects.setWidth(index, MASK_SIZE - rects.getX(index));
 314         }
 315         if ((rects.getY(index) + rects.getHeight(index)) > MASK_SIZE) {
 316             rects.setHeight(index, MASK_SIZE - rects.getY(index));
 317         }
 318         if (rects.getX(index) < 0) {
 319             rects.setWidth(index, rects.getWidth(index) + rects.getX(index));
 320             rects.setX(index, 0);
 321         }
 322         if (rects.getY(index) < 0) {
 323             rects.setHeight(index, rects.getHeight(index) + rects.getY(index));
 324             rects.setY(index, 0);
 325         }
 326     }







 327 }


  37  *
  38  * @author Clemens Eisserer
  39  */
  40 
  41 public class MaskTileManager {
  42 
  43     public static final int MASK_SIZE = 256;
  44 
  45     MaskTile mainTile = new MaskTile();
  46 
  47     ArrayList<MaskTile> tileList;
  48     int allocatedTiles = 0;
  49     int xTiles, yTiles;
  50 
  51     XRCompositeManager xrMgr;
  52     XRBackend con;
  53 
  54     int maskPixmap;
  55     int maskPicture;
  56     long maskGC;




  57 
  58     public MaskTileManager(XRCompositeManager xrMgr, int parentXid) {
  59         tileList = new ArrayList<MaskTile>();
  60         this.xrMgr = xrMgr;
  61         this.con = xrMgr.getBackend();
  62 
  63         maskPixmap = con.createPixmap(parentXid, 8, MASK_SIZE, MASK_SIZE);
  64         maskPicture = con.createPicture(maskPixmap, XRUtils.PictStandardA8);
  65         con.renderRectangle(maskPicture, XRUtils.PictOpClear,
  66                             new XRColor(Color.black),
  67                             0, 0, MASK_SIZE, MASK_SIZE);
  68         maskGC = con.createGC(maskPixmap);
  69         con.setGCExposures(maskGC, false);




























  70     }
  71 
  72     /**
  73      * Transfers the geometry stored (rectangles, lines) to one or more masks,
  74      * and renders the result to the destination surface.
  75      */
  76     public void fillMask(XRSurfaceData dst) {
  77 
  78         boolean maskRequired = xrMgr.maskRequired();
  79 
  80         if (maskRequired) {
  81             mainTile.calculateDirtyAreas();
  82             DirtyRegion dirtyArea = mainTile.getDirtyArea().cloneRegion();
  83             mainTile.translate(-dirtyArea.x, -dirtyArea.y);
  84 
  85             XRColor maskColor = xrMgr.getMaskColor();
  86 
  87             // We don't need tiling if all geometry fits in a single tile
  88             if (dirtyArea.getWidth() <= MASK_SIZE &&
  89                 dirtyArea.getHeight() <= MASK_SIZE)


 275     /**
 276      * Limits the rect's coordinates to the mask coordinates. The result is used
 277      * by growDirtyRegion.
 278      */
 279     private void limitRectCoords(GrowableRectArray rects, int index) {
 280         if ((rects.getX(index) + rects.getWidth(index)) > MASK_SIZE) {
 281             rects.setWidth(index, MASK_SIZE - rects.getX(index));
 282         }
 283         if ((rects.getY(index) + rects.getHeight(index)) > MASK_SIZE) {
 284             rects.setHeight(index, MASK_SIZE - rects.getY(index));
 285         }
 286         if (rects.getX(index) < 0) {
 287             rects.setWidth(index, rects.getWidth(index) + rects.getX(index));
 288             rects.setX(index, 0);
 289         }
 290         if (rects.getY(index) < 0) {
 291             rects.setHeight(index, rects.getHeight(index) + rects.getY(index));
 292             rects.setY(index, 0);
 293         }
 294     }
 295     
 296     /**
 297      * @return MainTile to which rectangles are added before composition.
 298      */
 299     public MaskTile getMainTile() {
 300         return mainTile;
 301      }
 302 }