< prev index next >

modules/javafx.graphics/src/main/java/com/sun/prism/impl/shape/DMarlinRasterizer.java

Print this page


   1 /*
   2  * Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   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


  66                 // pass null for stroke so that the following is not typically
  67                 // executed, but just here as a safety net.
  68                 shape = stroke.createStrokedShape(shape);
  69                 stroke = null;
  70             }
  71 
  72             xformBounds = new RectBounds();
  73             //TODO: Need to verify that this is a safe cast ... (RT-27427)
  74             xformBounds = (RectBounds) xform.transform(shape.getBounds(), xformBounds);
  75         }
  76         if (xformBounds.isEmpty()) {
  77             return EMPTY_MASK;
  78         }
  79 
  80         final DRendererContext rdrCtx = DMarlinRenderingEngine.getRendererContext();
  81         DMarlinRenderer renderer = null;
  82         try {
  83             final Rectangle rclip = rdrCtx.clip;
  84             rclip.setBounds(xformBounds);
  85 
  86             if (shape instanceof Path2D) {
  87                 renderer = DMarlinPrismUtils.setupRenderer(rdrCtx, (Path2D) shape, stroke, xform, rclip,
  88                         antialiasedShape);
  89             }
  90             if (renderer == null) {
  91                 renderer = DMarlinPrismUtils.setupRenderer(rdrCtx, shape, stroke, xform, rclip,
  92                         antialiasedShape);
  93             }
  94             final int outpix_xmin = renderer.getOutpixMinX();
  95             final int outpix_xmax = renderer.getOutpixMaxX();
  96             final int outpix_ymin = renderer.getOutpixMinY();
  97             final int outpix_ymax = renderer.getOutpixMaxY();
  98             final int w = outpix_xmax - outpix_xmin;
  99             final int h = outpix_ymax - outpix_ymin;
 100             if ((w <= 0) || (h <= 0)) {
 101                 return EMPTY_MASK;
 102             }
 103 
 104             MaskMarlinAlphaConsumer consumer = rdrCtx.consumer;
 105             if (consumer == null || (w * h) > consumer.getAlphaLength()) {
 106                 final int csize = (w * h + 0xfff) & (~0xfff);
 107                 rdrCtx.consumer = consumer = new MaskMarlinAlphaConsumer(csize);
 108                 if (PrismSettings.verbose) {
 109                     System.out.println("new alphas with length = " + csize);
 110                 }
 111             }
 112             consumer.setBoundsNoClone(outpix_xmin, outpix_ymin, w, h);
 113             renderer.produceAlphas(consumer);

 114             return consumer.getMaskData();
 115         } finally {
 116             if (renderer != null) {
 117                 renderer.dispose();
 118             }
 119             // recycle the RendererContext instance























 120             DMarlinRenderingEngine.returnRendererContext(rdrCtx);
 121         }
 122     }
 123 }
   1 /*
   2  * Copyright (c) 2010, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   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


  66                 // pass null for stroke so that the following is not typically
  67                 // executed, but just here as a safety net.
  68                 shape = stroke.createStrokedShape(shape);
  69                 stroke = null;
  70             }
  71 
  72             xformBounds = new RectBounds();
  73             //TODO: Need to verify that this is a safe cast ... (RT-27427)
  74             xformBounds = (RectBounds) xform.transform(shape.getBounds(), xformBounds);
  75         }
  76         if (xformBounds.isEmpty()) {
  77             return EMPTY_MASK;
  78         }
  79 
  80         final DRendererContext rdrCtx = DMarlinRenderingEngine.getRendererContext();
  81         DMarlinRenderer renderer = null;
  82         try {
  83             final Rectangle rclip = rdrCtx.clip;
  84             rclip.setBounds(xformBounds);
  85 
  86             renderer = DMarlinPrismUtils.setupRenderer(rdrCtx, shape, stroke, xform, rclip,
  87                     antialiasedShape);
  88 





  89             final int outpix_xmin = renderer.getOutpixMinX();
  90             final int outpix_xmax = renderer.getOutpixMaxX();
  91             final int outpix_ymin = renderer.getOutpixMinY();
  92             final int outpix_ymax = renderer.getOutpixMaxY();
  93             final int w = outpix_xmax - outpix_xmin;
  94             final int h = outpix_ymax - outpix_ymin;
  95             if ((w <= 0) || (h <= 0)) {
  96                 return EMPTY_MASK;
  97             }
  98 
  99             MaskMarlinAlphaConsumer consumer = rdrCtx.consumer;
 100             if (consumer == null || (w * h) > consumer.getAlphaLength()) {
 101                 final int csize = (w * h + 0xfff) & (~0xfff);
 102                 rdrCtx.consumer = consumer = new MaskMarlinAlphaConsumer(csize);
 103                 if (PrismSettings.verbose) {
 104                     System.out.println("new alphas with length = " + csize);
 105                 }
 106             }
 107             consumer.setBoundsNoClone(outpix_xmin, outpix_ymin, w, h);
 108             renderer.produceAlphas(consumer);
 109 
 110             return consumer.getMaskData();
 111         } finally {
 112             if (renderer != null) {
 113                 renderer.dispose();
 114             }
 115             // recycle the DRendererContext instance
 116             DMarlinRenderingEngine.returnRendererContext(rdrCtx);
 117         }
 118     }
 119 
 120     static Shape createCenteredStrokedShape(Shape s, BasicStroke stroke)
 121     {
 122         final float lw = (stroke.getType() == BasicStroke.TYPE_CENTERED) ?
 123                              stroke.getLineWidth() : stroke.getLineWidth() * 2.0f;
 124 
 125         final DRendererContext rdrCtx = DMarlinRenderingEngine.getRendererContext();
 126         try {
 127             // initialize a large copyable Path2D to avoid a lot of array growing:
 128             final Path2D p2d = rdrCtx.getPath2D();
 129 
 130             DMarlinPrismUtils.strokeTo(rdrCtx, s, stroke, lw,
 131                      rdrCtx.transformerPC2D.wrapPath2d(p2d)
 132             );
 133 
 134             // Use Path2D copy constructor (trim)
 135             return new Path2D(p2d);
 136 
 137         } finally {
 138             // recycle the DRendererContext instance
 139             DMarlinRenderingEngine.returnRendererContext(rdrCtx);
 140         }
 141     }
 142 }
< prev index next >