1 /*
2 * Copyright (c) 2009, 2013, 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
28 import com.sun.javafx.font.CharToGlyphMapper;
29 import com.sun.javafx.font.CompositeGlyphMapper;
30 import com.sun.javafx.font.FontResource;
31 import com.sun.javafx.font.FontStrike;
32 import com.sun.javafx.font.Glyph;
33 import com.sun.javafx.geom.BaseBounds;
34 import com.sun.javafx.geom.Rectangle;
35 import com.sun.javafx.geom.Point2D;
36 import com.sun.javafx.geom.transform.BaseTransform;
37 import com.sun.javafx.scene.text.GlyphList;
38 import com.sun.prism.impl.packrect.RectanglePacker;
39 import com.sun.prism.Texture;
40 import com.sun.prism.impl.shape.MaskData;
41 import com.sun.prism.paint.Color;
42
43 import java.nio.ByteBuffer;
44 import java.util.HashMap;
45 import java.util.WeakHashMap;
46
47 import static com.sun.javafx.logging.PulseLogger.PULSE_LOGGING_ENABLED;
48 import static com.sun.javafx.logging.PulseLogger.PULSE_LOGGER;
49
50 import com.sun.prism.ResourceFactory;
51 import com.sun.prism.Texture.WrapMode;
52
53 public class GlyphCache {
54
55 // REMIND: For a less powerful device, the size of this cache
56 // is likely something we'd want to tune as they may have much less
57 // VRAM and are less likely to be used for apps that have huge
58 // text demands.
59 // 2048 pixels introduced very noticeable pauses when trying
60 // to free 1/4 of the glyphs, which for spiral text also amounts
61 // to 1/4 of the strikes.
62 private static final int WIDTH = PrismSettings.glyphCacheWidth; // in pixels
63 private static final int HEIGHT = PrismSettings.glyphCacheHeight; // in pixels
64 private static ByteBuffer emptyMask;
65
66 private final BaseContext context;
67 private final FontStrike strike;
68
268 // repeated work next time the glyph is used.
269 MaskData maskData = MaskData.create(glyphImage,
270 glyph.getOriginX(),
271 glyph.getOriginY(),
272 glyph.getWidth(),
273 glyph.getHeight());
274
275 // Make room for the rectangle on the backing store
276 int border = 1;
277 int rectW = maskData.getWidth() + (2 * border);
278 int rectH = maskData.getHeight() + (2 * border);
279 int originX = maskData.getOriginX();
280 int originY = maskData.getOriginY();
281 Rectangle rect = new Rectangle(0, 0, rectW, rectH);
282 data = new GlyphData(originX, originY, border,
283 glyph.getPixelXAdvance(),
284 glyph.getPixelYAdvance(),
285 rect);
286
287 if (!packer.add(rect)) {
288 if (PULSE_LOGGING_ENABLED) PULSE_LOGGER.renderIncrementCounter("Font Glyph Cache Cleared");
289 // If add fails,clear up the cache. Try add again.
290 clearAll();
291 packer.add(rect);
292 }
293
294 // We always pass skipFlush=true to backingStore.update()
295 // since we are in control of the contents of the backingStore
296 // texture and explicitly flush the vertex buffer only when
297 // it is truly needed.
298 boolean skipFlush = true;
299
300 // Upload the an empty byte array to ensure the boundary
301 // area is filled with zeros. Note that the rectangle
302 // is already padded on each edge.
303 Texture backingStore = getBackingStore();
304 int emw = rect.width;
305 int emh = rect.height;
306 int bpp = backingStore.getPixelFormat().getBytesPerPixelUnit();
307 int stride = emw * bpp;
308 int size = stride * emh;
|
1 /*
2 * Copyright (c) 2009, 2014, 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
28 import com.sun.javafx.font.CharToGlyphMapper;
29 import com.sun.javafx.font.CompositeGlyphMapper;
30 import com.sun.javafx.font.FontResource;
31 import com.sun.javafx.font.FontStrike;
32 import com.sun.javafx.font.Glyph;
33 import com.sun.javafx.geom.BaseBounds;
34 import com.sun.javafx.geom.Rectangle;
35 import com.sun.javafx.geom.Point2D;
36 import com.sun.javafx.geom.transform.BaseTransform;
37 import com.sun.javafx.scene.text.GlyphList;
38 import com.sun.prism.impl.packrect.RectanglePacker;
39 import com.sun.prism.Texture;
40 import com.sun.prism.impl.shape.MaskData;
41 import com.sun.prism.paint.Color;
42
43 import java.nio.ByteBuffer;
44 import java.util.HashMap;
45 import java.util.WeakHashMap;
46
47 import static com.sun.javafx.logging.PulseLogger.PULSE_LOGGING_ENABLED;
48 import com.sun.javafx.logging.PulseLogger;
49
50 import com.sun.prism.ResourceFactory;
51 import com.sun.prism.Texture.WrapMode;
52
53 public class GlyphCache {
54
55 // REMIND: For a less powerful device, the size of this cache
56 // is likely something we'd want to tune as they may have much less
57 // VRAM and are less likely to be used for apps that have huge
58 // text demands.
59 // 2048 pixels introduced very noticeable pauses when trying
60 // to free 1/4 of the glyphs, which for spiral text also amounts
61 // to 1/4 of the strikes.
62 private static final int WIDTH = PrismSettings.glyphCacheWidth; // in pixels
63 private static final int HEIGHT = PrismSettings.glyphCacheHeight; // in pixels
64 private static ByteBuffer emptyMask;
65
66 private final BaseContext context;
67 private final FontStrike strike;
68
268 // repeated work next time the glyph is used.
269 MaskData maskData = MaskData.create(glyphImage,
270 glyph.getOriginX(),
271 glyph.getOriginY(),
272 glyph.getWidth(),
273 glyph.getHeight());
274
275 // Make room for the rectangle on the backing store
276 int border = 1;
277 int rectW = maskData.getWidth() + (2 * border);
278 int rectH = maskData.getHeight() + (2 * border);
279 int originX = maskData.getOriginX();
280 int originY = maskData.getOriginY();
281 Rectangle rect = new Rectangle(0, 0, rectW, rectH);
282 data = new GlyphData(originX, originY, border,
283 glyph.getPixelXAdvance(),
284 glyph.getPixelYAdvance(),
285 rect);
286
287 if (!packer.add(rect)) {
288 if (PULSE_LOGGING_ENABLED) PulseLogger.incrementCounter("Font Glyph Cache Cleared");
289 // If add fails,clear up the cache. Try add again.
290 clearAll();
291 packer.add(rect);
292 }
293
294 // We always pass skipFlush=true to backingStore.update()
295 // since we are in control of the contents of the backingStore
296 // texture and explicitly flush the vertex buffer only when
297 // it is truly needed.
298 boolean skipFlush = true;
299
300 // Upload the an empty byte array to ensure the boundary
301 // area is filled with zeros. Note that the rectangle
302 // is already padded on each edge.
303 Texture backingStore = getBackingStore();
304 int emw = rect.width;
305 int emh = rect.height;
306 int bpp = backingStore.getPixelFormat().getBytesPerPixelUnit();
307 int stride = emw * bpp;
308 int size = stride * emh;
|