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

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: Rebase to latest 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) {
50 switch (format) { 50 static const GrPixelConfig sPixelConfigs[] = {
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 SK_COMPILE_ASSERT(SK_ARRAY_COUNT(sPixelConfigs) == kMaskFormatCount, array_s ize_mismatch);
57 default: 57
58 SkDEBUGFAIL("unknown maskformat"); 58 return sPixelConfigs[format];
59 } 59 }
60 return kUnknown_GrPixelConfig; 60
61 static int mask_format_to_atlas_index(GrMaskFormat format) {
62 static const int sAtlasIndices[] = {
63 GrFontCache::kA8_AtlasType,
64 GrFontCache::k565_AtlasType,
65 GrFontCache::k8888_AtlasType,
66 GrFontCache::k8888_AtlasType
67 };
68 SK_COMPILE_ASSERT(SK_ARRAY_COUNT(sAtlasIndices) == kMaskFormatCount, array_s ize_mismatch);
69
70 SkASSERT(sAtlasIndices[format] < GrFontCache::kAtlasCount);
71 return sAtlasIndices[format];
61 } 72 }
62 73
63 GrTextStrike* GrFontCache::generateStrike(GrFontScaler* scaler, 74 GrTextStrike* GrFontCache::generateStrike(GrFontScaler* scaler,
64 const Key& key) { 75 const Key& key) {
65 GrMaskFormat format = scaler->getMaskFormat(); 76 GrMaskFormat format = scaler->getMaskFormat();
66 GrPixelConfig config = mask_format_to_pixel_config(format); 77 GrPixelConfig config = mask_format_to_pixel_config(format);
67 if (NULL == fAtlasMgr[format]) { 78 int atlasIndex = mask_format_to_atlas_index(format);
68 fAtlasMgr[format] = SkNEW_ARGS(GrAtlasMgr, (fGpu, config)); 79 if (NULL == fAtlasMgr[atlasIndex]) {
80 fAtlasMgr[atlasIndex] = SkNEW_ARGS(GrAtlasMgr, (fGpu, config));
69 } 81 }
70 GrTextStrike* strike = SkNEW_ARGS(GrTextStrike, 82 GrTextStrike* strike = SkNEW_ARGS(GrTextStrike,
71 (this, scaler->getKey(), format, fAtlasMgr [format])); 83 (this, scaler->getKey(), format, fAtlasMgr [atlasIndex]));
72 fCache.insert(key, strike); 84 fCache.insert(key, strike);
73 85
74 if (fHead) { 86 if (fHead) {
75 fHead->fPrev = strike; 87 fHead->fPrev = strike;
76 } else { 88 } else {
77 SkASSERT(NULL == fTail); 89 SkASSERT(NULL == fTail);
78 fTail = strike; 90 fTail = strike;
79 } 91 }
80 strike->fPrev = NULL; 92 strike->fPrev = NULL;
81 strike->fNext = fHead; 93 strike->fNext = fHead;
82 fHead = strike; 94 fHead = strike;
83 95
84 return strike; 96 return strike;
85 } 97 }
86 98
87 void GrFontCache::freeAll() { 99 void GrFontCache::freeAll() {
88 fCache.deleteAll(); 100 fCache.deleteAll();
89 for (int i = 0; i < kMaskFormatCount; ++i) { 101 for (int i = 0; i < kAtlasCount; ++i) {
90 delete fAtlasMgr[i]; 102 delete fAtlasMgr[i];
91 fAtlasMgr[i] = NULL; 103 fAtlasMgr[i] = NULL;
92 } 104 }
93 fHead = NULL; 105 fHead = NULL;
94 fTail = NULL; 106 fTail = NULL;
95 } 107 }
96 108
97 void GrFontCache::purgeStrike(GrTextStrike* strike) { 109 void GrFontCache::purgeStrike(GrTextStrike* strike) {
98 const GrFontCache::Key key(strike->fFontScalerKey); 110 const GrFontCache::Key key(strike->fFontScalerKey);
99 fCache.remove(key, strike); 111 fCache.remove(key, strike);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 count2 += 1; 182 count2 += 1;
171 strike = strike->fPrev; 183 strike = strike->fPrev;
172 } 184 }
173 SkASSERT(count == count2); 185 SkASSERT(count == count2);
174 } 186 }
175 #endif 187 #endif
176 188
177 #ifdef SK_DEVELOPER 189 #ifdef SK_DEVELOPER
178 void GrFontCache::dump() const { 190 void GrFontCache::dump() const {
179 static int gDumpCount = 0; 191 static int gDumpCount = 0;
180 for (int i = 0; i < kMaskFormatCount; ++i) { 192 for (int i = 0; i < kAtlasCount; ++i) {
181 if (NULL != fAtlasMgr[i]) { 193 if (NULL != fAtlasMgr[i]) {
182 GrTexture* texture = fAtlasMgr[i]->getTexture(); 194 GrTexture* texture = fAtlasMgr[i]->getTexture();
183 if (NULL != texture) { 195 if (NULL != texture) {
184 SkString filename; 196 SkString filename;
185 filename.printf("fontcache_%d%d.png", gDumpCount, i); 197 filename.printf("fontcache_%d%d.png", gDumpCount, i);
186 texture->savePixels(filename.c_str()); 198 texture->savePixels(filename.c_str());
187 } 199 }
188 } 200 }
189 } 201 }
190 ++gDumpCount; 202 ++gDumpCount;
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 } 413 }
402 #endif 414 #endif
403 415
404 if (NULL == plot) { 416 if (NULL == plot) {
405 return false; 417 return false;
406 } 418 }
407 419
408 glyph->fPlot = plot; 420 glyph->fPlot = plot;
409 return true; 421 return true;
410 } 422 }
OLDNEW
« include/gpu/GrTypes.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