< prev index next >

src/java.desktop/unix/classes/sun/java2d/xr/XRRenderer.java

Print this page




  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


  52 
  53 public class XRRenderer implements PixelDrawPipe, PixelFillPipe, ShapeDrawPipe {
  54     XRDrawHandler drawHandler;
  55     MaskTileManager tileManager;
  56     XRDrawLine lineGen;
  57     GrowableRectArray rectBuffer;
  58 
  59     public XRRenderer(MaskTileManager tileManager) {
  60         this.tileManager = tileManager;
  61         this.rectBuffer = tileManager.getMainTile().getRects();
  62 
  63         this.drawHandler = new XRDrawHandler();
  64         this.lineGen = new XRDrawLine();
  65     }
  66 
  67     /**
  68      * Common validate method, used by all XRRender functions to validate the
  69      * destination context.
  70      */
  71     private final void validateSurface(SunGraphics2D sg2d) {
  72         XRSurfaceData xrsd = (XRSurfaceData) sg2d.surfaceData;





  73         xrsd.validateAsDestination(sg2d, sg2d.getCompClip());
  74         xrsd.maskBuffer.validateCompositeState(sg2d.composite, sg2d.transform,
  75                                                sg2d.paint, sg2d);
  76     }
  77 
  78     public void drawLine(SunGraphics2D sg2d, int x1, int y1, int x2, int y2) {
  79         Region compClip = sg2d.getCompClip();
  80         int transX1 = Region.clipAdd(x1, sg2d.transX);
  81         int transY1 = Region.clipAdd(y1, sg2d.transY);
  82         int transX2 = Region.clipAdd(x2, sg2d.transX);
  83         int transY2 = Region.clipAdd(y2, sg2d.transY);
  84 
  85         SunToolkit.awtLock();
  86         try {
  87             validateSurface(sg2d);
  88             lineGen.rasterizeLine(rectBuffer, transX1, transY1,
  89                     transX2, transY2, compClip.getLoX(), compClip.getLoY(),
  90                     compClip.getHiX(), compClip.getHiY(), true, true);
  91             tileManager.fillMask((XRSurfaceData) sg2d.surfaceData);
  92         } finally {




  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.InvalidPipeException;
  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 import static sun.java2d.xr.XRUtils.clampToShort;
  43 import static sun.java2d.xr.XRUtils.clampToUShort;
  44 
  45 /**
  46  * XRender provides only accalerated rectangles. To emulate higher "order"
  47  *  geometry we have to pass everything else to DoPath/FillSpans.
  48  *
  49  * TODO: DrawRect could be instrified
  50  *
  51  * @author Clemens Eisserer


  53 
  54 public class XRRenderer implements PixelDrawPipe, PixelFillPipe, ShapeDrawPipe {
  55     XRDrawHandler drawHandler;
  56     MaskTileManager tileManager;
  57     XRDrawLine lineGen;
  58     GrowableRectArray rectBuffer;
  59 
  60     public XRRenderer(MaskTileManager tileManager) {
  61         this.tileManager = tileManager;
  62         this.rectBuffer = tileManager.getMainTile().getRects();
  63 
  64         this.drawHandler = new XRDrawHandler();
  65         this.lineGen = new XRDrawLine();
  66     }
  67 
  68     /**
  69      * Common validate method, used by all XRRender functions to validate the
  70      * destination context.
  71      */
  72     private final void validateSurface(SunGraphics2D sg2d) {
  73         XRSurfaceData xrsd;
  74         try {
  75             xrsd = (XRSurfaceData) sg2d.surfaceData;
  76         } catch (ClassCastException e) {
  77             throw new InvalidPipeException("wrong surface data type: " + sg2d.surfaceData);
  78         }
  79         xrsd.validateAsDestination(sg2d, sg2d.getCompClip());
  80         xrsd.maskBuffer.validateCompositeState(sg2d.composite, sg2d.transform,
  81                                                sg2d.paint, sg2d);
  82     }
  83 
  84     public void drawLine(SunGraphics2D sg2d, int x1, int y1, int x2, int y2) {
  85         Region compClip = sg2d.getCompClip();
  86         int transX1 = Region.clipAdd(x1, sg2d.transX);
  87         int transY1 = Region.clipAdd(y1, sg2d.transY);
  88         int transX2 = Region.clipAdd(x2, sg2d.transX);
  89         int transY2 = Region.clipAdd(y2, sg2d.transY);
  90 
  91         SunToolkit.awtLock();
  92         try {
  93             validateSurface(sg2d);
  94             lineGen.rasterizeLine(rectBuffer, transX1, transY1,
  95                     transX2, transY2, compClip.getLoX(), compClip.getLoY(),
  96                     compClip.getHiX(), compClip.getHiY(), true, true);
  97             tileManager.fillMask((XRSurfaceData) sg2d.surfaceData);
  98         } finally {


< prev index next >