1 /*
2 * Copyright (c) 2015, 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
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 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 static RendererContext createContext() {
49 return new RendererContext("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 boolean dirty = false;
57 // shared data
58 final float[] float6 = new float[6];
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(renderer);
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:
157 }
158 }
159
160 Path2D.Float getPath2D() {
161 // resolve reference:
162 Path2D.Float p2d
163 = (refPath2D != null) ? refPath2D.get() : null;
164
165 // create a new Path2D ?
166 if (p2d == null) {
167 p2d = new Path2D.Float(Path2D.WIND_NON_ZERO, INITIAL_EDGES_COUNT); // 32K
168
169 // update weak reference:
170 refPath2D = new WeakReference<Path2D.Float>(p2d);
171 }
172 // reset the path anyway:
173 p2d.reset();
174 return p2d;
175 }
176
177 OffHeapArray newOffHeapArray(final long initialSize) {
178 if (DO_STATS) {
179 stats.totalOffHeapInitial += initialSize;
180 }
181 return new OffHeapArray(cleanerObj, initialSize);
182 }
183
184 IntArrayCache.Reference newCleanIntArrayRef(final int initialSize) {
185 return cleanIntCache.createRef(initialSize);
186 }
187
188 IntArrayCache.Reference newDirtyIntArrayRef(final int initialSize) {
189 return dirtyIntCache.createRef(initialSize);
190 }
191
192 FloatArrayCache.Reference newDirtyFloatArrayRef(final int initialSize) {
193 return dirtyFloatCache.createRef(initialSize);
194 }
195
196 ByteArrayCache.Reference newDirtyByteArrayRef(final int initialSize) {
197 return dirtyByteCache.createRef(initialSize);
198 }
199 }
|
1 /*
2 * Copyright (c) 2015, 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
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 */
48 static RendererContext createContext() {
49 return new RendererContext("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 boolean dirty = false;
57 // shared data
58 final float[] float6 = new float[6];
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:
157 }
158 }
159
160 Path2D.Float getPath2D() {
161 // resolve reference:
162 Path2D.Float p2d
163 = (refPath2D != null) ? refPath2D.get() : null;
164
165 // create a new Path2D ?
166 if (p2d == null) {
167 p2d = new Path2D.Float(Path2D.WIND_NON_ZERO, INITIAL_EDGES_COUNT); // 32K
168
169 // update weak reference:
170 refPath2D = new WeakReference<Path2D.Float>(p2d);
171 }
172 // reset the path anyway:
173 p2d.reset();
174 return p2d;
175 }
176
177 @Override
178 public RendererStats stats() {
179 return stats;
180 }
181
182 @Override
183 public OffHeapArray newOffHeapArray(final long initialSize) {
184 if (DO_STATS) {
185 stats.totalOffHeapInitial += initialSize;
186 }
187 return new OffHeapArray(cleanerObj, initialSize);
188 }
189
190 @Override
191 public IntArrayCache.Reference newCleanIntArrayRef(final int initialSize) {
192 return cleanIntCache.createRef(initialSize);
193 }
194
195 IntArrayCache.Reference newDirtyIntArrayRef(final int initialSize) {
196 return dirtyIntCache.createRef(initialSize);
197 }
198
199 FloatArrayCache.Reference newDirtyFloatArrayRef(final int initialSize) {
200 return dirtyFloatCache.createRef(initialSize);
201 }
202
203 ByteArrayCache.Reference newDirtyByteArrayRef(final int initialSize) {
204 return dirtyByteCache.createRef(initialSize);
205 }
206 }
|