< prev index next >

modules/javafx.graphics/src/main/java/com/sun/marlin/DRendererContext.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 com.sun.marlin;
  27 

  28 import java.util.concurrent.atomic.AtomicInteger;
  29 import com.sun.util.reentrant.ReentrantContext;
  30 import com.sun.javafx.geom.Rectangle;
  31 import com.sun.marlin.ArrayCacheConst.CacheStats;

  32 
  33 /**
  34  * This class is a renderer context dedicated to a single thread
  35  */
  36 public final class DRendererContext extends ReentrantContext implements MarlinConst {
  37 
  38     // RendererContext creation counter
  39     private static final AtomicInteger CTX_COUNT = new AtomicInteger(1);
  40 
  41     /**
  42      * Create a new renderer context
  43      *
  44      * @return new RendererContext instance
  45      */
  46     public static DRendererContext createContext() {
  47         return new DRendererContext("ctx"
  48                        + Integer.toString(CTX_COUNT.getAndIncrement()));
  49     }
  50 
  51     // Smallest object used as Cleaner's parent reference
  52     private final Object cleanerObj;
  53     // dirty flag indicating an exception occured during pipeline in pathTo()
  54     public boolean dirty = false;
  55     // shared data
  56     public final float[] float6 = new float[6];
  57     // shared curve (dirty) (Renderer / Stroker)
  58     final DCurve curve = new DCurve();
  59     // MarlinRenderingEngine.TransformingPathConsumer2D
  60     public final DTransformingPathConsumer2D transformerPC2D;


  61     // shared memory between renderer instances:
  62     final DRendererSharedMemory rdrMem;
  63     public final DRenderer renderer;
  64     private DRendererNoAA rendererNoAA = null;
  65     public final DStroker stroker;
  66     // Simplifies out collinear lines
  67     public final DCollinearSimplifier simplifier = new DCollinearSimplifier();
  68     public final DDasher dasher;
  69     // flag indicating the shape is stroked (1) or filled (0)
  70     int stroking = 0;
  71 
  72 // MarlinFX specific:
  73     // dirty bbox rectangle
  74     public final Rectangle clip = new Rectangle();
  75     // dirty MaskMarlinAlphaConsumer
  76     public MaskMarlinAlphaConsumer consumer = null;
  77 
  78     // Array caches:
  79     /* clean int[] cache (zero-filled) = 4 refs */
  80     private final IntArrayCache cleanIntCache = new IntArrayCache(true, 4);


 131         if (DO_STATS) {
 132             if (stats.totalOffHeap > stats.totalOffHeapMax) {
 133                 stats.totalOffHeapMax = stats.totalOffHeap;
 134             }
 135             stats.totalOffHeap = 0L;
 136         }
 137         stroking = 0;
 138         // if context is maked as DIRTY:
 139         if (dirty) {
 140             // may happen if an exception if thrown in the pipeline processing:
 141             // force cleanup of all possible pipelined blocks (except Renderer):
 142 
 143             // Dasher:
 144             this.dasher.dispose();
 145             // Stroker:
 146             this.stroker.dispose();
 147 
 148             // mark context as CLEAN:
 149             dirty = false;
 150         }
















 151     }
 152 
 153     public DRendererNoAA getRendererNoAA() {
 154         if (rendererNoAA == null) {
 155             rendererNoAA = new DRendererNoAA(this);
 156         }
 157         return rendererNoAA;
 158     }
 159 
 160     OffHeapArray newOffHeapArray(final long initialSize) {
 161         if (DO_STATS) {
 162             stats.totalOffHeapInitial += initialSize;
 163         }
 164         return new OffHeapArray(cleanerObj, initialSize);
 165     }
 166 
 167     IntArrayCache.Reference newCleanIntArrayRef(final int initialSize) {
 168         return cleanIntCache.createRef(initialSize);
 169     }
 170 




   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 com.sun.marlin;
  27 
  28 import com.sun.javafx.geom.Path2D;
  29 import java.util.concurrent.atomic.AtomicInteger;
  30 import com.sun.util.reentrant.ReentrantContext;
  31 import com.sun.javafx.geom.Rectangle;
  32 import com.sun.marlin.ArrayCacheConst.CacheStats;
  33 import java.lang.ref.WeakReference;
  34 
  35 /**
  36  * This class is a renderer context dedicated to a single thread
  37  */
  38 public final class DRendererContext extends ReentrantContext implements MarlinConst {
  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      */
  48     public static DRendererContext createContext() {
  49         return new DRendererContext("ctx"
  50                        + Integer.toString(CTX_COUNT.getAndIncrement()));
  51     }
  52 
  53     // Smallest object used as Cleaner's parent reference
  54     private final Object cleanerObj;
  55     // dirty flag indicating an exception occured during pipeline in pathTo()
  56     public boolean dirty = false;
  57     // shared data
  58     public final float[] float6 = new float[6];
  59     // shared curve (dirty) (Renderer / Stroker)
  60     final DCurve curve = new DCurve();
  61     // MarlinRenderingEngine.TransformingPathConsumer2D
  62     public final DTransformingPathConsumer2D transformerPC2D;
  63     // recycled Path2D instance (weak)
  64     private WeakReference<Path2D> refPath2D = null;
  65     // shared memory between renderer instances:
  66     final DRendererSharedMemory rdrMem;
  67     public final DRenderer renderer;
  68     private DRendererNoAA rendererNoAA = null;
  69     public final DStroker stroker;
  70     // Simplifies out collinear lines
  71     public final DCollinearSimplifier simplifier = new DCollinearSimplifier();
  72     public final DDasher dasher;
  73     // flag indicating the shape is stroked (1) or filled (0)
  74     int stroking = 0;
  75 
  76 // MarlinFX specific:
  77     // dirty bbox rectangle
  78     public final Rectangle clip = new Rectangle();
  79     // dirty MaskMarlinAlphaConsumer
  80     public MaskMarlinAlphaConsumer consumer = null;
  81 
  82     // Array caches:
  83     /* clean int[] cache (zero-filled) = 4 refs */
  84     private final IntArrayCache cleanIntCache = new IntArrayCache(true, 4);


 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             // Dasher:
 148             this.dasher.dispose();
 149             // Stroker:
 150             this.stroker.dispose();
 151 
 152             // mark context as CLEAN:
 153             dirty = false;
 154         }
 155     }
 156 
 157     public Path2D getPath2D() {
 158         // resolve reference:
 159         Path2D p2d = (refPath2D != null) ? refPath2D.get() : null;
 160 
 161         // create a new Path2D ?
 162         if (p2d == null) {
 163             p2d = new Path2D(Path2D.WIND_NON_ZERO, INITIAL_EDGES_COUNT); // 32K
 164 
 165             // update weak reference:
 166             refPath2D = new WeakReference<Path2D>(p2d);
 167         }
 168         // reset the path anyway:
 169         p2d.reset();
 170         return p2d;
 171     }
 172 
 173     public DRendererNoAA getRendererNoAA() {
 174         if (rendererNoAA == null) {
 175             rendererNoAA = new DRendererNoAA(this);
 176         }
 177         return rendererNoAA;
 178     }
 179 
 180     OffHeapArray newOffHeapArray(final long initialSize) {
 181         if (DO_STATS) {
 182             stats.totalOffHeapInitial += initialSize;
 183         }
 184         return new OffHeapArray(cleanerObj, initialSize);
 185     }
 186 
 187     IntArrayCache.Reference newCleanIntArrayRef(final int initialSize) {
 188         return cleanIntCache.createRef(initialSize);
 189     }
 190 


< prev index next >