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

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

Issue 1076853002: fix for perf regression on ugamsolutions / msaa16 (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: nit Created 5 years, 8 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/GrContext.cpp » ('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 "GrFontAtlasSizes.h" 9 #include "GrFontAtlasSizes.h"
10 #include "GrGpu.h" 10 #include "GrGpu.h"
(...skipping 16 matching lines...) Expand all
27 27
28 // We don't want to flush the context so we claim we're in the middle of flu shing so as to 28 // We don't want to flush the context so we claim we're in the middle of flu shing so as to
29 // guarantee we do not recieve a texture with pending IO 29 // guarantee we do not recieve a texture with pending IO
30 GrTexture* texture = context->refScratchTexture(desc, GrContext::kApprox_Scr atchTexMatch, true); 30 GrTexture* texture = context->refScratchTexture(desc, GrContext::kApprox_Scr atchTexMatch, true);
31 if (!texture) { 31 if (!texture) {
32 return NULL; 32 return NULL;
33 } 33 }
34 return SkNEW_ARGS(GrBatchAtlas, (texture, numPlotsX, numPlotsY)); 34 return SkNEW_ARGS(GrBatchAtlas, (texture, numPlotsX, numPlotsY));
35 } 35 }
36 36
37 int GrBatchFontCache::MaskFormatToAtlasIndex(GrMaskFormat format) { 37 bool GrBatchFontCache::initAtlas(GrMaskFormat format) {
38 static const int sAtlasIndices[] = { 38 int index = MaskFormatToAtlasIndex(format);
39 kA8_GrMaskFormat, 39 if (!fAtlases[index]) {
40 kA565_GrMaskFormat, 40 GrPixelConfig config = this->getPixelConfig(format);
41 kARGB_GrMaskFormat, 41 if (kA8_GrMaskFormat == format) {
42 }; 42 fAtlases[index] = make_atlas(fContext, config,
43 SK_COMPILE_ASSERT(SK_ARRAY_COUNT(sAtlasIndices) == kMaskFormatCount, array_s ize_mismatch); 43 GR_FONT_ATLAS_A8_TEXTURE_WIDTH,
44 GR_FONT_ATLAS_TEXTURE_HEIGHT,
45 GR_FONT_ATLAS_A8_NUM_PLOTS_X,
46 GR_FONT_ATLAS_NUM_PLOTS_Y);
47 } else {
48 fAtlases[index] = make_atlas(fContext, config,
49 GR_FONT_ATLAS_TEXTURE_WIDTH,
50 GR_FONT_ATLAS_TEXTURE_HEIGHT,
51 GR_FONT_ATLAS_NUM_PLOTS_X,
52 GR_FONT_ATLAS_NUM_PLOTS_Y);
53 }
44 54
45 SkASSERT(sAtlasIndices[format] < kMaskFormatCount); 55 // Atlas creation can fail
46 return sAtlasIndices[format]; 56 if (fAtlases[index]) {
57 fAtlases[index]->registerEvictionCallback(&GrBatchFontCache::HandleE viction,
58 (void*)this);
59 } else {
60 return false;
61 }
62 }
63 return true;
47 } 64 }
48 65
49 GrMaskFormat GrBatchFontCache::AtlasIndexToMaskFormat(int atlasIndex) { 66 GrBatchFontCache::GrBatchFontCache(GrContext* context)
50 static GrMaskFormat sMaskFormats[] = { 67 : fContext(context)
51 kA8_GrMaskFormat, 68 , fPreserveStrike(NULL) {
52 kA565_GrMaskFormat, 69 for (int i = 0; i < kMaskFormatCount; ++i) {
53 kARGB_GrMaskFormat, 70 fAtlases[i] = NULL;
54 };
55 SK_COMPILE_ASSERT(SK_ARRAY_COUNT(sMaskFormats) == kMaskFormatCount, array_si ze_mismatch);
56
57 SkASSERT(sMaskFormats[atlasIndex] < kMaskFormatCount);
58 return sMaskFormats[atlasIndex];
59 }
60
61 GrBatchFontCache::GrBatchFontCache()
62 : fPreserveStrike(NULL) {
63 }
64
65 void GrBatchFontCache::init(GrContext* context) {
66 for (int i = 0; i < kMaskFormatCount; i++) {
67 GrMaskFormat format = AtlasIndexToMaskFormat(i);
68 GrPixelConfig config = this->getPixelConfig(format);
69
70 if (kA8_GrMaskFormat == format) {
71 fAtlases[i] = make_atlas(context, config,
72 GR_FONT_ATLAS_A8_TEXTURE_WIDTH,
73 GR_FONT_ATLAS_TEXTURE_HEIGHT,
74 GR_FONT_ATLAS_A8_NUM_PLOTS_X,
75 GR_FONT_ATLAS_NUM_PLOTS_Y);
76 } else {
77 fAtlases[i] = make_atlas(context, config,
78 GR_FONT_ATLAS_TEXTURE_WIDTH,
79 GR_FONT_ATLAS_TEXTURE_HEIGHT,
80 GR_FONT_ATLAS_NUM_PLOTS_X,
81 GR_FONT_ATLAS_NUM_PLOTS_Y);
82 }
83
84 if (fAtlases[i]) {
85 fAtlases[i]->registerEvictionCallback(&GrBatchFontCache::HandleEvict ion, (void*)this);
86 }
87 } 71 }
88 } 72 }
89 73
90 GrBatchFontCache::~GrBatchFontCache() { 74 GrBatchFontCache::~GrBatchFontCache() {
91 SkTDynamicHash<GrBatchTextStrike, GrFontDescKey>::Iter iter(&fCache); 75 SkTDynamicHash<GrBatchTextStrike, GrFontDescKey>::Iter iter(&fCache);
92 while (!iter.done()) { 76 while (!iter.done()) {
93 SkDELETE(&(*iter)); 77 SkDELETE(&(*iter));
94 ++iter; 78 ++iter;
95 } 79 }
96 for (int i = 0; i < kMaskFormatCount; ++i) { 80 for (int i = 0; i < kMaskFormatCount; ++i) {
97 SkDELETE(fAtlases[i]); 81 SkDELETE(fAtlases[i]);
98 } 82 }
99 } 83 }
100 84
101 GrBatchTextStrike* GrBatchFontCache::generateStrike(GrFontScaler* scaler) {
102 GrBatchTextStrike* strike = SkNEW_ARGS(GrBatchTextStrike, (this, scaler->get Key()));
103 fCache.add(strike);
104 return strike;
105 }
106
107 void GrBatchFontCache::freeAll() { 85 void GrBatchFontCache::freeAll() {
108 SkTDynamicHash<GrBatchTextStrike, GrFontDescKey>::Iter iter(&fCache); 86 SkTDynamicHash<GrBatchTextStrike, GrFontDescKey>::Iter iter(&fCache);
109 while (!iter.done()) { 87 while (!iter.done()) {
110 SkDELETE(&(*iter)); 88 SkDELETE(&(*iter));
111 ++iter; 89 ++iter;
112 } 90 }
113 fCache.rewind(); 91 fCache.rewind();
114 for (int i = 0; i < kMaskFormatCount; ++i) { 92 for (int i = 0; i < kMaskFormatCount; ++i) {
115 SkDELETE(fAtlases[i]); 93 SkDELETE(fAtlases[i]);
116 fAtlases[i] = NULL; 94 fAtlases[i] = NULL;
117 } 95 }
118 } 96 }
119 97
120 inline GrBatchAtlas* GrBatchFontCache::getAtlas(GrMaskFormat format) const {
121 int atlasIndex = MaskFormatToAtlasIndex(format);
122 SkASSERT(fAtlases[atlasIndex]);
123 return fAtlases[atlasIndex];
124 }
125
126 bool GrBatchFontCache::hasGlyph(GrGlyph* glyph) {
127 SkASSERT(glyph);
128 return this->getAtlas(glyph->fMaskFormat)->hasID(glyph->fID);
129 }
130
131 void GrBatchFontCache::addGlyphToBulkAndSetUseToken(GrBatchAtlas::BulkUseTokenUp dater* updater,
132 GrGlyph* glyph,
133 GrBatchAtlas::BatchToken tok en) {
134 SkASSERT(glyph);
135 updater->add(glyph->fID);
136 this->getAtlas(glyph->fMaskFormat)->setLastUseToken(glyph->fID, token);
137 }
138
139 void GrBatchFontCache::setUseTokenBulk(const GrBatchAtlas::BulkUseTokenUpdater& updater,
140 GrBatchAtlas::BatchToken token,
141 GrMaskFormat format) {
142 this->getAtlas(format)->setLastUseTokenBulk(updater, token);
143 }
144
145 bool GrBatchFontCache::addToAtlas(GrBatchTextStrike* strike, GrBatchAtlas::Atlas ID* id,
146 GrBatchTarget* batchTarget,
147 GrMaskFormat format, int width, int height, co nst void* image,
148 SkIPoint16* loc) {
149 fPreserveStrike = strike;
150 return this->getAtlas(format)->addToAtlas(id, batchTarget, width, height, im age, loc);
151 }
152
153 uint64_t GrBatchFontCache::atlasGeneration(GrMaskFormat format) const {
154 return this->getAtlas(format)->atlasGeneration();
155 }
156
157 GrTexture* GrBatchFontCache::getTexture(GrMaskFormat format) {
158 int atlasIndex = MaskFormatToAtlasIndex(format);
159 SkASSERT(fAtlases[atlasIndex]);
160 return fAtlases[atlasIndex]->getTexture();
161 }
162
163 GrPixelConfig GrBatchFontCache::getPixelConfig(GrMaskFormat format) const { 98 GrPixelConfig GrBatchFontCache::getPixelConfig(GrMaskFormat format) const {
164 static const GrPixelConfig kPixelConfigs[] = { 99 static const GrPixelConfig kPixelConfigs[] = {
165 kAlpha_8_GrPixelConfig, 100 kAlpha_8_GrPixelConfig,
166 kRGB_565_GrPixelConfig, 101 kRGB_565_GrPixelConfig,
167 kSkia8888_GrPixelConfig 102 kSkia8888_GrPixelConfig
168 }; 103 };
169 SK_COMPILE_ASSERT(SK_ARRAY_COUNT(kPixelConfigs) == kMaskFormatCount, array_s ize_mismatch); 104 SK_COMPILE_ASSERT(SK_ARRAY_COUNT(kPixelConfigs) == kMaskFormatCount, array_s ize_mismatch);
170 105
171 return kPixelConfigs[format]; 106 return kPixelConfigs[format];
172 } 107 }
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 } 248 }
314 249
315 bool success = fBatchFontCache->addToAtlas(this, &glyph->fID, batchTarget, g lyph->fMaskFormat, 250 bool success = fBatchFontCache->addToAtlas(this, &glyph->fID, batchTarget, g lyph->fMaskFormat,
316 glyph->width(), glyph->height(), 251 glyph->width(), glyph->height(),
317 storage.get(), &glyph->fAtlasLoca tion); 252 storage.get(), &glyph->fAtlasLoca tion);
318 if (success) { 253 if (success) {
319 fAtlasedGlyphs++; 254 fAtlasedGlyphs++;
320 } 255 }
321 return success; 256 return success;
322 } 257 }
OLDNEW
« no previous file with comments | « src/gpu/GrBatchFontCache.h ('k') | src/gpu/GrContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698