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

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

Issue 99993002: Add GPU support for color bitmap fonts (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Add ignored test Created 7 years 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright 2010 Google Inc. 2 * Copyright 2010 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 "GrAtlas.h" 8 #include "GrAtlas.h"
9 #include "GrGpu.h" 9 #include "GrGpu.h"
10 #include "GrRectanizer.h" 10 #include "GrRectanizer.h"
(...skipping 10 matching lines...) Expand all
21 21
22 /////////////////////////////////////////////////////////////////////////////// 22 ///////////////////////////////////////////////////////////////////////////////
23 23
24 #define FONT_CACHE_STATS 0 24 #define FONT_CACHE_STATS 0
25 #if FONT_CACHE_STATS 25 #if FONT_CACHE_STATS
26 static int g_PurgeCount = 0; 26 static int g_PurgeCount = 0;
27 #endif 27 #endif
28 28
29 GrFontCache::GrFontCache(GrGpu* gpu) : fGpu(gpu) { 29 GrFontCache::GrFontCache(GrGpu* gpu) : fGpu(gpu) {
30 gpu->ref(); 30 gpu->ref();
31 for (int i = 0; i < kMaskFormatCount; ++i) { 31 for (int i = 0; i < kAtlasCount; ++i) {
32 fAtlasMgr[i] = NULL; 32 fAtlasMgr[i] = NULL;
33 } 33 }
34 34
35 fHead = fTail = NULL; 35 fHead = fTail = NULL;
36 } 36 }
37 37
38 GrFontCache::~GrFontCache() { 38 GrFontCache::~GrFontCache() {
39 fCache.deleteAll(); 39 fCache.deleteAll();
40 for (int i = 0; i < kMaskFormatCount; ++i) { 40 for (int i = 0; i < kAtlasCount; ++i) {
41 delete fAtlasMgr[i]; 41 delete fAtlasMgr[i];
42 } 42 }
43 fGpu->unref(); 43 fGpu->unref();
44 #if FONT_CACHE_STATS 44 #if FONT_CACHE_STATS
45 GrPrintf("Num purges: %d\n", g_PurgeCount); 45 GrPrintf("Num purges: %d\n", g_PurgeCount);
46 #endif 46 #endif
47 } 47 }
48 48
49 static GrPixelConfig mask_format_to_pixel_config(GrMaskFormat format) { 49 static GrPixelConfig mask_format_to_pixel_config(GrMaskFormat format) {
robertphillips 2013/12/02 21:05:40 const?
50 switch (format) { 50 static GrPixelConfig sPixelConfigs[kMaskFormatCount] = {
51 case kA8_GrMaskFormat: 51 kAlpha_8_GrPixelConfig,
52 return kAlpha_8_GrPixelConfig; 52 kRGB_565_GrPixelConfig,
53 case kA565_GrMaskFormat: 53 kSkia8888_GrPixelConfig,
54 return kRGB_565_GrPixelConfig; 54 kSkia8888_GrPixelConfig
55 case kA888_GrMaskFormat: 55 };
56 return kSkia8888_GrPixelConfig; 56
57 default: 57 return sPixelConfigs[format];
58 SkDEBUGFAIL("unknown maskformat"); 58 }
59 } 59
60 return kUnknown_GrPixelConfig; 60 static int mask_format_to_atlas_index(GrMaskFormat format) {
robertphillips 2013/12/02 21:05:40 const?
61 static int sAtlasIndices[kMaskFormatCount] = { 0, 1, 2, 2 };
robertphillips 2013/12/02 21:05:40 assert "sAtlasIndices[format] < kAtlasCount" or a
62
63 return sAtlasIndices[format];
61 } 64 }
62 65
63 GrTextStrike* GrFontCache::generateStrike(GrFontScaler* scaler, 66 GrTextStrike* GrFontCache::generateStrike(GrFontScaler* scaler,
64 const Key& key) { 67 const Key& key) {
65 GrMaskFormat format = scaler->getMaskFormat(); 68 GrMaskFormat format = scaler->getMaskFormat();
66 GrPixelConfig config = mask_format_to_pixel_config(format); 69 GrPixelConfig config = mask_format_to_pixel_config(format);
67 if (NULL == fAtlasMgr[format]) { 70 int atlasIndex = mask_format_to_atlas_index(format);
robertphillips 2013/12/02 21:05:40 Move assert up into mask_format_to_atlas?
68 fAtlasMgr[format] = SkNEW_ARGS(GrAtlasMgr, (fGpu, config)); 71 SkASSERT(atlasIndex < kAtlasCount);
72 if (NULL == fAtlasMgr[atlasIndex]) {
73 fAtlasMgr[atlasIndex] = SkNEW_ARGS(GrAtlasMgr, (fGpu, config));
69 } 74 }
70 GrTextStrike* strike = SkNEW_ARGS(GrTextStrike, 75 GrTextStrike* strike = SkNEW_ARGS(GrTextStrike,
71 (this, scaler->getKey(), format, fAtlasMgr [format])); 76 (this, scaler->getKey(), format, fAtlasMgr [atlasIndex]));
72 fCache.insert(key, strike); 77 fCache.insert(key, strike);
73 78
74 if (fHead) { 79 if (fHead) {
75 fHead->fPrev = strike; 80 fHead->fPrev = strike;
76 } else { 81 } else {
77 SkASSERT(NULL == fTail); 82 SkASSERT(NULL == fTail);
78 fTail = strike; 83 fTail = strike;
79 } 84 }
80 strike->fPrev = NULL; 85 strike->fPrev = NULL;
81 strike->fNext = fHead; 86 strike->fNext = fHead;
82 fHead = strike; 87 fHead = strike;
83 88
84 return strike; 89 return strike;
85 } 90 }
86 91
87 void GrFontCache::freeAll() { 92 void GrFontCache::freeAll() {
88 fCache.deleteAll(); 93 fCache.deleteAll();
89 for (int i = 0; i < kMaskFormatCount; ++i) { 94 for (int i = 0; i < kAtlasCount; ++i) {
90 delete fAtlasMgr[i]; 95 delete fAtlasMgr[i];
91 fAtlasMgr[i] = NULL; 96 fAtlasMgr[i] = NULL;
92 } 97 }
93 fHead = NULL; 98 fHead = NULL;
94 fTail = NULL; 99 fTail = NULL;
95 } 100 }
96 101
97 void GrFontCache::purgeStrike(GrTextStrike* strike) { 102 void GrFontCache::purgeStrike(GrTextStrike* strike) {
98 const GrFontCache::Key key(strike->fFontScalerKey); 103 const GrFontCache::Key key(strike->fFontScalerKey);
99 fCache.remove(key, strike); 104 fCache.remove(key, strike);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 count2 += 1; 175 count2 += 1;
171 strike = strike->fPrev; 176 strike = strike->fPrev;
172 } 177 }
173 SkASSERT(count == count2); 178 SkASSERT(count == count2);
174 } 179 }
175 #endif 180 #endif
176 181
177 #ifdef SK_DEVELOPER 182 #ifdef SK_DEVELOPER
178 void GrFontCache::dump() const { 183 void GrFontCache::dump() const {
179 static int gDumpCount = 0; 184 static int gDumpCount = 0;
180 for (int i = 0; i < kMaskFormatCount; ++i) { 185 for (int i = 0; i < kAtlasCount; ++i) {
181 if (NULL != fAtlasMgr[i]) { 186 if (NULL != fAtlasMgr[i]) {
182 GrTexture* texture = fAtlasMgr[i]->getTexture(); 187 GrTexture* texture = fAtlasMgr[i]->getTexture();
183 if (NULL != texture) { 188 if (NULL != texture) {
184 SkString filename; 189 SkString filename;
185 filename.printf("fontcache_%d%d.png", gDumpCount, i); 190 filename.printf("fontcache_%d%d.png", gDumpCount, i);
186 texture->savePixels(filename.c_str()); 191 texture->savePixels(filename.c_str());
187 } 192 }
188 } 193 }
189 } 194 }
190 ++gDumpCount; 195 ++gDumpCount;
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 } 406 }
402 #endif 407 #endif
403 408
404 if (NULL == plot) { 409 if (NULL == plot) {
405 return false; 410 return false;
406 } 411 }
407 412
408 glyph->fPlot = plot; 413 glyph->fPlot = plot;
409 return true; 414 return true;
410 } 415 }
OLDNEW
« src/gpu/GrTextStrike.h ('K') | « src/gpu/GrTextStrike.h ('k') | src/gpu/SkGrFontScaler.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698