< prev index next >

src/java.desktop/share/classes/sun/java2d/marlin/RendererContext.java

Print this page




   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
  23  * questions.
  24  */
  25 
  26 package sun.java2d.marlin;
  27 

  28 import java.awt.geom.Path2D;
  29 import java.lang.ref.WeakReference;
  30 import java.util.concurrent.atomic.AtomicInteger;
  31 import sun.java2d.ReentrantContext;
  32 import sun.java2d.marlin.ArrayCacheConst.CacheStats;
  33 import sun.java2d.marlin.MarlinRenderingEngine.NormalizingPathIterator;
  34 
  35 /**
  36  * This class is a renderer context dedicated to a single thread
  37  */
  38 final class RendererContext extends ReentrantContext implements IRendererContext {
  39 
  40     // RendererContext creation counter
  41     private static final AtomicInteger CTX_COUNT = new AtomicInteger(1);
  42 
  43     /**
  44      * Create a new renderer context
  45      *
  46      * @return new RendererContext instance
  47      */


  58     final float[] float6 = new float[6];
  59     // shared curve (dirty) (Renderer / Stroker)
  60     final Curve curve = new Curve();
  61     // MarlinRenderingEngine NormalizingPathIterator NearestPixelCenter:
  62     final NormalizingPathIterator nPCPathIterator;
  63     // MarlinRenderingEngine NearestPixelQuarter NormalizingPathIterator:
  64     final NormalizingPathIterator nPQPathIterator;
  65     // MarlinRenderingEngine.TransformingPathConsumer2D
  66     final TransformingPathConsumer2D transformerPC2D;
  67     // recycled Path2D instance (weak)
  68     private WeakReference<Path2D.Float> refPath2D = null;
  69     final Renderer renderer;
  70     final Stroker stroker;
  71     // Simplifies out collinear lines
  72     final CollinearSimplifier simplifier = new CollinearSimplifier();
  73     final Dasher dasher;
  74     final MarlinTileGenerator ptg;
  75     final MarlinCache cache;
  76     // flag indicating the shape is stroked (1) or filled (0)
  77     int stroking = 0;






  78 
  79     // Array caches:
  80     /* clean int[] cache (zero-filled) = 5 refs */
  81     private final IntArrayCache cleanIntCache = new IntArrayCache(true, 5);
  82     /* dirty int[] cache = 4 refs */
  83     private final IntArrayCache dirtyIntCache = new IntArrayCache(false, 4);
  84     /* dirty float[] cache = 3 refs */
  85     private final FloatArrayCache dirtyFloatCache = new FloatArrayCache(false, 3);
  86     /* dirty byte[] cache = 1 ref */
  87     private final ByteArrayCache dirtyByteCache = new ByteArrayCache(false, 1);
  88 
  89     // RendererContext statistics
  90     final RendererStats stats;
  91 
  92     /**
  93      * Constructor
  94      *
  95      * @param name context name (debugging)
  96      */
  97     RendererContext(final String name) {


  99             MarlinUtils.logInfo("new RendererContext = " + name);
 100         }
 101         this.cleanerObj = new Object();
 102 
 103         // create first stats (needed by newOffHeapArray):
 104         if (DO_STATS || DO_MONITORS) {
 105             stats = RendererStats.createInstance(cleanerObj, name);
 106             // push cache stats:
 107             stats.cacheStats = new CacheStats[] { cleanIntCache.stats,
 108                 dirtyIntCache.stats, dirtyFloatCache.stats, dirtyByteCache.stats
 109             };
 110         } else {
 111             stats = null;
 112         }
 113 
 114         // NormalizingPathIterator instances:
 115         nPCPathIterator = new NormalizingPathIterator.NearestPixelCenter(float6);
 116         nPQPathIterator  = new NormalizingPathIterator.NearestPixelQuarter(float6);
 117 
 118         // MarlinRenderingEngine.TransformingPathConsumer2D
 119         transformerPC2D = new TransformingPathConsumer2D();
 120 
 121         // Renderer:
 122         cache = new MarlinCache(this);
 123         renderer = new Renderer(this); // needs MarlinCache from rdrCtx.cache
 124         ptg = new MarlinTileGenerator(stats, renderer, cache);
 125 
 126         stroker = new Stroker(this);
 127         dasher = new Dasher(this);
 128     }
 129 
 130     /**
 131      * Disposes this renderer context:
 132      * clean up before reusing this context
 133      */
 134     void dispose() {
 135         if (DO_STATS) {
 136             if (stats.totalOffHeap > stats.totalOffHeapMax) {
 137                 stats.totalOffHeapMax = stats.totalOffHeap;
 138             }
 139             stats.totalOffHeap = 0L;
 140         }
 141         stroking = 0;



 142         // if context is maked as DIRTY:
 143         if (dirty) {
 144             // may happen if an exception if thrown in the pipeline processing:
 145             // force cleanup of all possible pipelined blocks (except Renderer):
 146 
 147             // NormalizingPathIterator instances:
 148             this.nPCPathIterator.dispose();
 149             this.nPQPathIterator.dispose();
 150             // Dasher:
 151             this.dasher.dispose();
 152             // Stroker:
 153             this.stroker.dispose();
 154 
 155             // mark context as CLEAN:
 156             dirty = false;
 157         }
 158     }
 159 
 160     Path2D.Float getPath2D() {
 161         // resolve reference:




   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
  23  * questions.
  24  */
  25 
  26 package sun.java2d.marlin;
  27 
  28 import java.awt.Rectangle;
  29 import java.awt.geom.Path2D;
  30 import java.lang.ref.WeakReference;
  31 import java.util.concurrent.atomic.AtomicInteger;
  32 import sun.java2d.ReentrantContext;
  33 import sun.java2d.marlin.ArrayCacheConst.CacheStats;
  34 import sun.java2d.marlin.MarlinRenderingEngine.NormalizingPathIterator;
  35 
  36 /**
  37  * This class is a renderer context dedicated to a single thread
  38  */
  39 final class RendererContext extends ReentrantContext implements IRendererContext {
  40 
  41     // RendererContext creation counter
  42     private static final AtomicInteger CTX_COUNT = new AtomicInteger(1);
  43 
  44     /**
  45      * Create a new renderer context
  46      *
  47      * @return new RendererContext instance
  48      */


  59     final float[] float6 = new float[6];
  60     // shared curve (dirty) (Renderer / Stroker)
  61     final Curve curve = new Curve();
  62     // MarlinRenderingEngine NormalizingPathIterator NearestPixelCenter:
  63     final NormalizingPathIterator nPCPathIterator;
  64     // MarlinRenderingEngine NearestPixelQuarter NormalizingPathIterator:
  65     final NormalizingPathIterator nPQPathIterator;
  66     // MarlinRenderingEngine.TransformingPathConsumer2D
  67     final TransformingPathConsumer2D transformerPC2D;
  68     // recycled Path2D instance (weak)
  69     private WeakReference<Path2D.Float> refPath2D = null;
  70     final Renderer renderer;
  71     final Stroker stroker;
  72     // Simplifies out collinear lines
  73     final CollinearSimplifier simplifier = new CollinearSimplifier();
  74     final Dasher dasher;
  75     final MarlinTileGenerator ptg;
  76     final MarlinCache cache;
  77     // flag indicating the shape is stroked (1) or filled (0)
  78     int stroking = 0;
  79     // flag indicating to clip the shape
  80     boolean doClip = false;
  81     // flag indicating if the path is closed or not (in advance) to handle properly caps
  82     boolean closedPath = false;
  83     // clip rectangle (ymin, ymax, xmin, xmax):
  84     final float[] clipRect = new float[4];
  85 
  86     // Array caches:
  87     /* clean int[] cache (zero-filled) = 5 refs */
  88     private final IntArrayCache cleanIntCache = new IntArrayCache(true, 5);
  89     /* dirty int[] cache = 4 refs */
  90     private final IntArrayCache dirtyIntCache = new IntArrayCache(false, 4);
  91     /* dirty float[] cache = 3 refs */
  92     private final FloatArrayCache dirtyFloatCache = new FloatArrayCache(false, 3);
  93     /* dirty byte[] cache = 1 ref */
  94     private final ByteArrayCache dirtyByteCache = new ByteArrayCache(false, 1);
  95 
  96     // RendererContext statistics
  97     final RendererStats stats;
  98 
  99     /**
 100      * Constructor
 101      *
 102      * @param name context name (debugging)
 103      */
 104     RendererContext(final String name) {


 106             MarlinUtils.logInfo("new RendererContext = " + name);
 107         }
 108         this.cleanerObj = new Object();
 109 
 110         // create first stats (needed by newOffHeapArray):
 111         if (DO_STATS || DO_MONITORS) {
 112             stats = RendererStats.createInstance(cleanerObj, name);
 113             // push cache stats:
 114             stats.cacheStats = new CacheStats[] { cleanIntCache.stats,
 115                 dirtyIntCache.stats, dirtyFloatCache.stats, dirtyByteCache.stats
 116             };
 117         } else {
 118             stats = null;
 119         }
 120 
 121         // NormalizingPathIterator instances:
 122         nPCPathIterator = new NormalizingPathIterator.NearestPixelCenter(float6);
 123         nPQPathIterator  = new NormalizingPathIterator.NearestPixelQuarter(float6);
 124 
 125         // MarlinRenderingEngine.TransformingPathConsumer2D
 126         transformerPC2D = new TransformingPathConsumer2D(this);
 127 
 128         // Renderer:
 129         cache = new MarlinCache(this);
 130         renderer = new Renderer(this); // needs MarlinCache from rdrCtx.cache
 131         ptg = new MarlinTileGenerator(stats, renderer, cache);
 132 
 133         stroker = new Stroker(this);
 134         dasher = new Dasher(this);
 135     }
 136 
 137     /**
 138      * Disposes this renderer context:
 139      * clean up before reusing this context
 140      */
 141     void dispose() {
 142         if (DO_STATS) {
 143             if (stats.totalOffHeap > stats.totalOffHeapMax) {
 144                 stats.totalOffHeapMax = stats.totalOffHeap;
 145             }
 146             stats.totalOffHeap = 0L;
 147         }
 148         stroking   = 0;
 149         doClip     = false;
 150         closedPath = false;
 151 
 152         // if context is maked as DIRTY:
 153         if (dirty) {
 154             // may happen if an exception if thrown in the pipeline processing:
 155             // force cleanup of all possible pipelined blocks (except Renderer):
 156 
 157             // NormalizingPathIterator instances:
 158             this.nPCPathIterator.dispose();
 159             this.nPQPathIterator.dispose();
 160             // Dasher:
 161             this.dasher.dispose();
 162             // Stroker:
 163             this.stroker.dispose();
 164 
 165             // mark context as CLEAN:
 166             dirty = false;
 167         }
 168     }
 169 
 170     Path2D.Float getPath2D() {
 171         // resolve reference:


< prev index next >