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

Print this page




  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.xr;
  27 
  28 import java.awt.*;
  29 import java.awt.geom.*;
  30 
  31 import sun.awt.SunToolkit;
  32 import sun.java2d.SunGraphics2D;
  33 import sun.java2d.loops.*;
  34 import sun.java2d.pipe.Region;
  35 import sun.java2d.pipe.PixelDrawPipe;
  36 import sun.java2d.pipe.PixelFillPipe;
  37 import sun.java2d.pipe.ShapeDrawPipe;
  38 import sun.java2d.pipe.SpanIterator;
  39 import sun.java2d.pipe.ShapeSpanIterator;
  40 import sun.java2d.pipe.LoopPipe;
  41 



  42 /**
  43  * XRender provides only accalerated rectangles. To emulate higher "order"
  44  *  geometry we have to pass everything else to DoPath/FillSpans.
  45  *
  46  * TODO: DrawRect could be instrified
  47  *
  48  * @author Clemens Eisserer
  49  */
  50 
  51 public class XRRenderer implements PixelDrawPipe, PixelFillPipe, ShapeDrawPipe {
  52     XRDrawHandler drawHandler;
  53     MaskTileManager tileManager;
  54 
  55     public XRRenderer(MaskTileManager tileManager) {
  56         this.tileManager = tileManager;
  57         this.drawHandler = new XRDrawHandler();
  58     }
  59 
  60     /**
  61      * Common validate method, used by all XRRender functions to validate the
  62      * destination context.
  63      */
  64     private final void validateSurface(SunGraphics2D sg2d) {
  65         XRSurfaceData xrsd = (XRSurfaceData) sg2d.surfaceData;
  66         xrsd.validateAsDestination(sg2d, sg2d.getCompClip());
  67         xrsd.maskBuffer.validateCompositeState(sg2d.composite, sg2d.transform,
  68                                                sg2d.paint, sg2d);
  69     }
  70 
  71     public void drawLine(SunGraphics2D sg2d, int x1, int y1, int x2, int y2) {
  72         Region compClip = sg2d.getCompClip();
  73         int transX1 = x1 + sg2d.transX;
  74         int transY1 = y1 + sg2d.transY;
  75         int transX2 = x2 + sg2d.transX;
  76         int transY2 = y2 + sg2d.transY;
  77 
  78         // Non clipped fast path
  79         if (compClip.contains(transX1, transY1)
  80                 && compClip.contains(transX2, transY2)) {
  81             try {
  82                 SunToolkit.awtLock();
  83 
  84                 validateSurface(sg2d);
  85                 tileManager.addLine(transX1, transY1, transX2, transY2);
  86                 tileManager.fillMask((XRSurfaceData) sg2d.surfaceData);
  87             } finally {
  88                 SunToolkit.awtUnlock();
  89             }
  90         } else {
  91             draw(sg2d, new Line2D.Float(x1, y1, x2, y2));
  92         }
  93     }
  94 
  95     public void drawRect(SunGraphics2D sg2d,
  96                          int x, int y, int width, int height) {
  97         draw(sg2d, new Rectangle2D.Float(x, y, width, height));
  98     }
  99 
 100     public void drawPolyline(SunGraphics2D sg2d,
 101                              int xpoints[], int ypoints[], int npoints) {
 102         Path2D.Float p2d = new Path2D.Float();
 103         if (npoints > 1) {
 104             p2d.moveTo(xpoints[0], ypoints[0]);
 105             for (int i = 1; i < npoints; i++) {
 106                 p2d.lineTo(xpoints[i], ypoints[i]);
 107             }
 108         }
 109 
 110         draw(sg2d, p2d);
 111     }
 112 
 113     public void drawPolygon(SunGraphics2D sg2d,
 114                             int xpoints[], int ypoints[], int npoints) {
 115         draw(sg2d, new Polygon(xpoints, ypoints, npoints));
 116     }
 117 
 118     public synchronized void fillRect(SunGraphics2D sg2d,
 119                                       int x, int y, int width, int height) {
 120         SunToolkit.awtLock();
 121         try {
 122             validateSurface(sg2d);







 123 
 124             XRSurfaceData xrsd = (XRSurfaceData) sg2d.surfaceData;

 125 
 126             x += sg2d.transform.getTranslateX();
 127             y += sg2d.transform.getTranslateY();

 128 
 129             tileManager.addRect(x, y, width, height);
 130             tileManager.fillMask(xrsd);






 131 





 132         } finally {
 133             SunToolkit.awtUnlock();
 134         }
 135     }
 136 
 137     public void fillPolygon(SunGraphics2D sg2d,
 138                             int xpoints[], int ypoints[], int npoints) {
 139         fill(sg2d, new Polygon(xpoints, ypoints, npoints));
 140     }
 141 
 142     public void drawRoundRect(SunGraphics2D sg2d,
 143                               int x, int y, int width, int height,
 144                               int arcWidth, int arcHeight) {
 145         draw(sg2d, new RoundRectangle2D.Float(x, y, width, height,
 146                                               arcWidth, arcHeight));
 147     }
 148 
 149     public void fillRoundRect(SunGraphics2D sg2d, int x, int y,
 150                               int width, int height,
 151                               int arcWidth, int arcHeight) {




  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.xr;
  27 
  28 import java.awt.*;
  29 import java.awt.geom.*;

  30 import sun.awt.SunToolkit;
  31 import sun.java2d.SunGraphics2D;
  32 import sun.java2d.loops.*;
  33 import sun.java2d.pipe.Region;
  34 import sun.java2d.pipe.PixelDrawPipe;
  35 import sun.java2d.pipe.PixelFillPipe;
  36 import sun.java2d.pipe.ShapeDrawPipe;
  37 import sun.java2d.pipe.SpanIterator;
  38 import sun.java2d.pipe.ShapeSpanIterator;
  39 import sun.java2d.pipe.LoopPipe;
  40 
  41 import static sun.java2d.xr.XRUtils.clampToShort;
  42 import static sun.java2d.xr.XRUtils.clampToUShort;
  43 
  44 /**
  45  * XRender provides only accalerated rectangles. To emulate higher "order"
  46  *  geometry we have to pass everything else to DoPath/FillSpans.
  47  *
  48  * TODO: DrawRect could be instrified
  49  *
  50  * @author Clemens Eisserer
  51  */
  52 
  53 public class XRRenderer implements PixelDrawPipe, PixelFillPipe, ShapeDrawPipe {
  54     XRDrawHandler drawHandler;
  55     MaskTileManager tileManager;
  56 
  57     public XRRenderer(MaskTileManager tileManager) {
  58         this.tileManager = tileManager;
  59         this.drawHandler = new XRDrawHandler();
  60     }
  61 
  62     /**
  63      * Common validate method, used by all XRRender functions to validate the
  64      * destination context.
  65      */
  66     private final void validateSurface(SunGraphics2D sg2d) {
  67         XRSurfaceData xrsd = (XRSurfaceData) sg2d.surfaceData;
  68         xrsd.validateAsDestination(sg2d, sg2d.getCompClip());
  69         xrsd.maskBuffer.validateCompositeState(sg2d.composite, sg2d.transform,
  70                                                sg2d.paint, sg2d);
  71     }
  72 
  73     public void drawLine(SunGraphics2D sg2d, int x1, int y1, int x2, int y2) {
  74         Region compClip = sg2d.getCompClip();
  75         int transX1 = Region.clipAdd(x1, sg2d.transX);
  76         int transY1 = Region.clipAdd(y1, sg2d.transY);
  77         int transX2 = Region.clipAdd(x2, sg2d.transX);
  78         int transY2 = Region.clipAdd(y2, sg2d.transY);
  79 
  80         // Non clipped fast path
  81         if (compClip.contains(transX1, transY1)
  82                 && compClip.contains(transX2, transY2)) {

  83             SunToolkit.awtLock();
  84             try {
  85                 validateSurface(sg2d);
  86                 tileManager.addLine(transX1, transY1, transX2, transY2);
  87                 tileManager.fillMask((XRSurfaceData) sg2d.surfaceData);
  88             } finally {
  89                 SunToolkit.awtUnlock();
  90             }
  91         } else {
  92             draw(sg2d, new Line2D.Float(x1, y1, x2, y2));
  93         }
  94     }
  95 
  96     public void drawRect(SunGraphics2D sg2d,
  97                          int x, int y, int width, int height) {
  98         draw(sg2d, new Rectangle2D.Float(x, y, width, height));
  99     }
 100 
 101     public void drawPolyline(SunGraphics2D sg2d,
 102                              int xpoints[], int ypoints[], int npoints) {
 103         Path2D.Float p2d = new Path2D.Float();
 104         if (npoints > 1) {
 105             p2d.moveTo(xpoints[0], ypoints[0]);
 106             for (int i = 1; i < npoints; i++) {
 107                 p2d.lineTo(xpoints[i], ypoints[i]);
 108             }
 109         }
 110 
 111         draw(sg2d, p2d);
 112     }
 113 
 114     public void drawPolygon(SunGraphics2D sg2d, 
 115             int xpoints[], int ypoints[], int npoints) {
 116         draw(sg2d, new Polygon(xpoints, ypoints, npoints));
 117     }
 118 
 119     public void fillRect(SunGraphics2D sg2d, int x, int y, int width, int height) {     
 120         x = Region.clipAdd(x, sg2d.transX);
 121         y = Region.clipAdd(y, sg2d.transY);
 122         
 123         /*
 124          * Limit x/y to signed short, width/height to unsigned short,
 125          * to match the X11 coordinate limits for rectangles.
 126          * Correct width/height in case x/y have been modified by clipping.
 127          */     
 128         if(x > Short.MAX_VALUE || y > Short.MAX_VALUE) {
 129             return;
 130         }
 131         
 132         int x2 = Region.dimAdd(x, width);
 133         int y2 = Region.dimAdd(y, height);
 134         
 135         if(x2 < Short.MIN_VALUE || y2 < Short.MIN_VALUE) {
 136             return;
 137         }
 138         
 139         x = clampToShort(x);
 140         y = clampToShort(y);
 141         width = clampToUShort(x2 - x);
 142         height = clampToUShort(y2 - y);
 143 
 144         if (width <= 0 || height <= 0) {
 145             return;
 146         }
 147 
 148         SunToolkit.awtLock();
 149         try {
 150             validateSurface(sg2d);
 151             tileManager.addRect(x, y, width, height);
 152             tileManager.fillMask((XRSurfaceData) sg2d.surfaceData);
 153         } finally {
 154             SunToolkit.awtUnlock();
 155         }
 156     }
 157 
 158     public void fillPolygon(SunGraphics2D sg2d,
 159                             int xpoints[], int ypoints[], int npoints) {
 160         fill(sg2d, new Polygon(xpoints, ypoints, npoints));
 161     }
 162 
 163     public void drawRoundRect(SunGraphics2D sg2d,
 164                               int x, int y, int width, int height,
 165                               int arcWidth, int arcHeight) {
 166         draw(sg2d, new RoundRectangle2D.Float(x, y, width, height,
 167                                               arcWidth, arcHeight));
 168     }
 169 
 170     public void fillRoundRect(SunGraphics2D sg2d, int x, int y,
 171                               int width, int height,
 172                               int arcWidth, int arcHeight) {