Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(49)

Side by Side Diff: src/gpu/GrBatchFontCache.cpp

Issue 1255943006: Allow setting of GrBatchFontCache atlas sizes (Closed) Base URL: https://skia.googlesource.com/skia.git@debugatlas2
Patch Set: tweaks Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/GrBatchFontCache.h ('k') | src/gpu/GrFontAtlasSizes.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "GrBatchFontCache.h" 8 #include "GrBatchFontCache.h"
9 #include "GrContext.h" 9 #include "GrContext.h"
10 #include "GrFontAtlasSizes.h"
11 #include "GrGpu.h" 10 #include "GrGpu.h"
12 #include "GrRectanizer.h" 11 #include "GrRectanizer.h"
13 #include "GrResourceProvider.h" 12 #include "GrResourceProvider.h"
14 #include "GrSurfacePriv.h" 13 #include "GrSurfacePriv.h"
15 #include "SkString.h" 14 #include "SkString.h"
16 15
17 #include "SkDistanceFieldGen.h" 16 #include "SkDistanceFieldGen.h"
18 17
19 /////////////////////////////////////////////////////////////////////////////// 18 ///////////////////////////////////////////////////////////////////////////////
20 19
21 bool GrBatchFontCache::initAtlas(GrMaskFormat format) { 20 bool GrBatchFontCache::initAtlas(GrMaskFormat format) {
22 int index = MaskFormatToAtlasIndex(format); 21 int index = MaskFormatToAtlasIndex(format);
23 if (!fAtlases[index]) { 22 if (!fAtlases[index]) {
24 GrPixelConfig config = MaskFormatToPixelConfig(format); 23 GrPixelConfig config = MaskFormatToPixelConfig(format);
25 int width = GR_FONT_ATLAS_TEXTURE_WIDTH; 24 int width = fAtlasConfigs[index].fWidth;
26 int height = GR_FONT_ATLAS_TEXTURE_HEIGHT; 25 int height = fAtlasConfigs[index].fHeight;
27 int numPlotsX = GR_FONT_ATLAS_NUM_PLOTS_X; 26 int numPlotsX = fAtlasConfigs[index].numPlotsX();
28 int numPlotsY = GR_FONT_ATLAS_NUM_PLOTS_Y; 27 int numPlotsY = fAtlasConfigs[index].numPlotsY();
29 28
30 if (kA8_GrMaskFormat == format) {
31 width = GR_FONT_ATLAS_A8_TEXTURE_WIDTH;
32 numPlotsX = GR_FONT_ATLAS_A8_NUM_PLOTS_X;
33 }
34 fAtlases[index] = 29 fAtlases[index] =
35 fContext->resourceProvider()->createAtlas(config, width, height, 30 fContext->resourceProvider()->createAtlas(config, width, height,
36 numPlotsX, numPlotsY, 31 numPlotsX, numPlotsY,
37 &GrBatchFontCache::Han dleEviction, 32 &GrBatchFontCache::Han dleEviction,
38 (void*)this); 33 (void*)this);
39 if (!fAtlases[index]) { 34 if (!fAtlases[index]) {
40 return false; 35 return false;
41 } 36 }
42 } 37 }
43 return true; 38 return true;
44 } 39 }
45 40
46 GrBatchFontCache::GrBatchFontCache(GrContext* context) 41 GrBatchFontCache::GrBatchFontCache(GrContext* context)
47 : fContext(context) 42 : fContext(context)
48 , fPreserveStrike(NULL) { 43 , fPreserveStrike(NULL) {
49 for (int i = 0; i < kMaskFormatCount; ++i) { 44 for (int i = 0; i < kMaskFormatCount; ++i) {
50 fAtlases[i] = NULL; 45 fAtlases[i] = NULL;
51 } 46 }
47
48 // setup default atlas configs
49 fAtlasConfigs[kA8_GrMaskFormat].fWidth = 2048;
50 fAtlasConfigs[kA8_GrMaskFormat].fHeight = 2048;
51 fAtlasConfigs[kA8_GrMaskFormat].fPlotWidth = 512;
52 fAtlasConfigs[kA8_GrMaskFormat].fPlotHeight = 256;
53
54 fAtlasConfigs[kA565_GrMaskFormat].fWidth = 1024;
55 fAtlasConfigs[kA565_GrMaskFormat].fHeight = 2048;
56 fAtlasConfigs[kA565_GrMaskFormat].fPlotWidth = 256;
57 fAtlasConfigs[kA565_GrMaskFormat].fPlotHeight = 256;
58
59 fAtlasConfigs[kARGB_GrMaskFormat].fWidth = 1024;
60 fAtlasConfigs[kARGB_GrMaskFormat].fHeight = 2048;
61 fAtlasConfigs[kARGB_GrMaskFormat].fPlotWidth = 256;
62 fAtlasConfigs[kARGB_GrMaskFormat].fPlotHeight = 256;
52 } 63 }
53 64
54 GrBatchFontCache::~GrBatchFontCache() { 65 GrBatchFontCache::~GrBatchFontCache() {
55 SkTDynamicHash<GrBatchTextStrike, GrFontDescKey>::Iter iter(&fCache); 66 SkTDynamicHash<GrBatchTextStrike, GrFontDescKey>::Iter iter(&fCache);
56 while (!iter.done()) { 67 while (!iter.done()) {
57 (*iter).fIsAbandoned = true; 68 (*iter).fIsAbandoned = true;
58 (*iter).unref(); 69 (*iter).unref();
59 ++iter; 70 ++iter;
60 } 71 }
61 for (int i = 0; i < kMaskFormatCount; ++i) { 72 for (int i = 0; i < kMaskFormatCount; ++i) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 #else 118 #else
108 filename.printf("fontcache_%d%d.png", gDumpCount, i); 119 filename.printf("fontcache_%d%d.png", gDumpCount, i);
109 #endif 120 #endif
110 texture->surfacePriv().savePixels(filename.c_str()); 121 texture->surfacePriv().savePixels(filename.c_str());
111 } 122 }
112 } 123 }
113 } 124 }
114 ++gDumpCount; 125 ++gDumpCount;
115 } 126 }
116 127
128 void GrBatchFontCache::setAtlasSizes_ForTesting(const GrBatchAtlasConfig configs [3]) {
129 // delete any old atlases, this should be safe to do as long as we are not i n the middle of a
130 // flush
131 for (int i = 0; i < kMaskFormatCount; i++) {
132 if (fAtlases[i]) {
133 SkDELETE(fAtlases[i]);
134 fAtlases[i] = NULL;
135 }
136 }
137 memcpy(fAtlasConfigs, configs, sizeof(fAtlasConfigs));
138 }
139
117 /////////////////////////////////////////////////////////////////////////////// 140 ///////////////////////////////////////////////////////////////////////////////
118 141
119 /* 142 /*
120 The text strike is specific to a given font/style/matrix setup, which is 143 The text strike is specific to a given font/style/matrix setup, which is
121 represented by the GrHostFontScaler object we are given in getGlyph(). 144 represented by the GrHostFontScaler object we are given in getGlyph().
122 145
123 We map a 32bit glyphID to a GrGlyph record, which in turn points to a 146 We map a 32bit glyphID to a GrGlyph record, which in turn points to a
124 atlas and a position within that texture. 147 atlas and a position within that texture.
125 */ 148 */
126 149
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 225
203 bool success = fBatchFontCache->addToAtlas(this, &glyph->fID, target, expect edMaskFormat, 226 bool success = fBatchFontCache->addToAtlas(this, &glyph->fID, target, expect edMaskFormat,
204 glyph->width(), glyph->height(), 227 glyph->width(), glyph->height(),
205 storage.get(), &glyph->fAtlasLoca tion); 228 storage.get(), &glyph->fAtlasLoca tion);
206 if (success) { 229 if (success) {
207 SkASSERT(GrBatchAtlas::kInvalidAtlasID != glyph->fID); 230 SkASSERT(GrBatchAtlas::kInvalidAtlasID != glyph->fID);
208 fAtlasedGlyphs++; 231 fAtlasedGlyphs++;
209 } 232 }
210 return success; 233 return success;
211 } 234 }
OLDNEW
« no previous file with comments | « src/gpu/GrBatchFontCache.h ('k') | src/gpu/GrFontAtlasSizes.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698