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

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

Issue 21594005: GPU Font Cache improvements: (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Remove useless class identifier. Created 7 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 | Annotate | Revision Log
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2010 Google Inc. 3 * Copyright 2010 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 10
(...skipping 26 matching lines...) Expand all
37 #endif 37 #endif
38 38
39 /////////////////////////////////////////////////////////////////////////////// 39 ///////////////////////////////////////////////////////////////////////////////
40 40
41 #define BORDER 1 41 #define BORDER 1
42 42
43 #if GR_DEBUG 43 #if GR_DEBUG
44 static int gCounter; 44 static int gCounter;
45 #endif 45 #endif
46 46
47 // for testing
48 #define FONT_CACHE_STATS 0
49 #if FONT_CACHE_STATS
50 static int g_UploadCount = 0;
51 #endif
52
47 GrAtlas::GrAtlas(GrAtlasMgr* mgr, int plotX, int plotY, GrMaskFormat format) { 53 GrAtlas::GrAtlas(GrAtlasMgr* mgr, int plotX, int plotY, GrMaskFormat format) {
48 fAtlasMgr = mgr; // just a pointer, not an owner 54 fAtlasMgr = mgr; // just a pointer, not an owner
49 fNext = NULL; 55 fNext = NULL;
56 fUsed = false;
57
50 fTexture = mgr->getTexture(format); // we're not an owner, just a pointer 58 fTexture = mgr->getTexture(format); // we're not an owner, just a pointer
51 fPlot.set(plotX, plotY); 59 fPlot.set(plotX, plotY);
52 60
53 fRects = GrRectanizer::Factory(GR_ATLAS_WIDTH - BORDER, 61 fRects = GrRectanizer::Factory(GR_ATLAS_WIDTH - BORDER,
54 GR_ATLAS_HEIGHT - BORDER); 62 GR_ATLAS_HEIGHT - BORDER);
55 63
56 fMaskFormat = format; 64 fMaskFormat = format;
57 65
58 #if GR_DEBUG 66 #if GR_DEBUG
59 // GrPrintf(" GrAtlas %p [%d %d] %d\n", this, plotX, plotY, gCounter); 67 // GrPrintf(" GrAtlas %p [%d %d] %d\n", this, plotX, plotY, gCounter);
60 gCounter += 1; 68 gCounter += 1;
61 #endif 69 #endif
62 } 70 }
63 71
64 GrAtlas::~GrAtlas() { 72 GrAtlas::~GrAtlas() {
65 fAtlasMgr->freePlot(fPlot.fX, fPlot.fY); 73 fAtlasMgr->freePlot(fMaskFormat, fPlot.fX, fPlot.fY);
66 74
67 delete fRects; 75 delete fRects;
68 76
69 #if GR_DEBUG 77 #if GR_DEBUG
70 --gCounter; 78 --gCounter;
71 // GrPrintf("~GrAtlas %p [%d %d] %d\n", this, fPlot.fX, fPlot.fY, gCounter); 79 // GrPrintf("~GrAtlas %p [%d %d] %d\n", this, fPlot.fX, fPlot.fY, gCounter);
72 #endif 80 #endif
73 } 81 }
74 82
83 bool GrAtlas::RemoveUnusedAtlases(GrAtlasMgr* atlasMgr, GrAtlas** startAtlas) {
robertphillips 2013/08/05 15:11:40 // add comment here why a **?
84 GrAtlas** atlasRef = startAtlas;
85 GrAtlas* atlas = *startAtlas;
86 bool removed = false;
87 while (NULL != atlas) {
88 if (!atlas->used()) {
89 *atlasRef = atlas->fNext;
90 atlasMgr->deleteAtlas(atlas);
91 atlas = *atlasRef;
92 removed = true;
93 } else {
94 atlasRef = &atlas->fNext;
95 atlas = atlas->fNext;
96 }
97 }
98
99 return removed;
100 }
101
75 static void adjustForPlot(GrIPoint16* loc, const GrIPoint16& plot) { 102 static void adjustForPlot(GrIPoint16* loc, const GrIPoint16& plot) {
76 loc->fX += plot.fX * GR_ATLAS_WIDTH; 103 loc->fX += plot.fX * GR_ATLAS_WIDTH;
77 loc->fY += plot.fY * GR_ATLAS_HEIGHT; 104 loc->fY += plot.fY * GR_ATLAS_HEIGHT;
78 } 105 }
79 106
80 static uint8_t* zerofill(uint8_t* ptr, int count) { 107 static uint8_t* zerofill(uint8_t* ptr, int count) {
81 while (--count >= 0) { 108 while (--count >= 0) {
82 *ptr++ = 0; 109 *ptr++ = 0;
83 } 110 }
84 return ptr; 111 return ptr;
(...skipping 30 matching lines...) Expand all
115 // smart and hasn't referenced the part of the texture we're about to update 142 // smart and hasn't referenced the part of the texture we're about to update
116 // since the last flush. 143 // since the last flush.
117 context->writeTexturePixels(fTexture, 144 context->writeTexturePixels(fTexture,
118 loc->fX, loc->fY, dstW, dstH, 145 loc->fX, loc->fY, dstW, dstH,
119 fTexture->config(), image, 0, 146 fTexture->config(), image, 0,
120 GrContext::kDontFlush_PixelOpsFlag); 147 GrContext::kDontFlush_PixelOpsFlag);
121 148
122 // now tell the caller to skip the top/left BORDER 149 // now tell the caller to skip the top/left BORDER
123 loc->fX += BORDER; 150 loc->fX += BORDER;
124 loc->fY += BORDER; 151 loc->fY += BORDER;
152
153 #if FONT_CACHE_STATS
154 ++g_UploadCount;
155 #endif
156
125 return true; 157 return true;
126 } 158 }
127 159
128 /////////////////////////////////////////////////////////////////////////////// 160 ///////////////////////////////////////////////////////////////////////////////
129 161
130 GrAtlasMgr::GrAtlasMgr(GrGpu* gpu) { 162 GrAtlasMgr::GrAtlasMgr(GrGpu* gpu) {
131 fGpu = gpu; 163 fGpu = gpu;
132 gpu->ref(); 164 gpu->ref();
133 Gr_bzero(fTexture, sizeof(fTexture)); 165 Gr_bzero(fTexture, sizeof(fTexture));
134 fPlotMgr = SkNEW_ARGS(GrPlotMgr, (GR_PLOT_WIDTH, GR_PLOT_HEIGHT)); 166 fPlotMgr = SkNEW_ARGS(GrPlotMgr, (GR_PLOT_WIDTH, GR_PLOT_HEIGHT));
135 } 167 }
136 168
137 GrAtlasMgr::~GrAtlasMgr() { 169 GrAtlasMgr::~GrAtlasMgr() {
138 for (size_t i = 0; i < GR_ARRAY_COUNT(fTexture); i++) { 170 for (size_t i = 0; i < GR_ARRAY_COUNT(fTexture); i++) {
139 GrSafeUnref(fTexture[i]); 171 GrSafeUnref(fTexture[i]);
140 } 172 }
141 delete fPlotMgr; 173 delete fPlotMgr;
174
142 fGpu->unref(); 175 fGpu->unref();
176 #if FONT_CACHE_STATS
177 GrPrintf("Num uploads: %d\n", g_UploadCount);
178 #endif
143 } 179 }
144 180
145 static GrPixelConfig maskformat2pixelconfig(GrMaskFormat format) { 181 static GrPixelConfig maskformat2pixelconfig(GrMaskFormat format) {
146 switch (format) { 182 switch (format) {
147 case kA8_GrMaskFormat: 183 case kA8_GrMaskFormat:
148 return kAlpha_8_GrPixelConfig; 184 return kAlpha_8_GrPixelConfig;
149 case kA565_GrMaskFormat: 185 case kA565_GrMaskFormat:
150 return kRGB_565_GrPixelConfig; 186 return kRGB_565_GrPixelConfig;
151 case kA888_GrMaskFormat: 187 case kA888_GrMaskFormat:
152 return kSkia8888_GrPixelConfig; 188 return kSkia8888_GrPixelConfig;
153 default: 189 default:
154 GrAssert(!"unknown maskformat"); 190 GrAssert(!"unknown maskformat");
155 } 191 }
156 return kUnknown_GrPixelConfig; 192 return kUnknown_GrPixelConfig;
157 } 193 }
158 194
159 GrAtlas* GrAtlasMgr::addToAtlas(GrAtlas* atlas, 195 GrAtlas* GrAtlasMgr::addToAtlas(GrAtlas** atlas,
160 int width, int height, const void* image, 196 int width, int height, const void* image,
161 GrMaskFormat format, 197 GrMaskFormat format,
162 GrIPoint16* loc) { 198 GrIPoint16* loc) {
163 GrAssert(NULL == atlas || atlas->getMaskFormat() == format); 199 GrAssert(NULL == *atlas || (*atlas)->getMaskFormat() == format);
164 200
165 if (atlas && atlas->addSubImage(width, height, image, loc)) { 201 // iterate through entire atlas list, see if we can find a hole
166 return atlas; 202 GrAtlas* atlasIter = *atlas;
203 while (atlasIter) {
204 if (atlasIter->addSubImage(width, height, image, loc)) {
205 return atlasIter;
206 }
207 atlasIter = atlasIter->fNext;
167 } 208 }
168 209
169 // If the above fails, then either we have no starting atlas, or the current 210 // If the above fails, then either we have no starting atlas, or the current
170 // one is full. Either way we need to allocate a new atlas 211 // atlas list is full. Either way we need to allocate a new atlas
171 212
172 GrIPoint16 plot; 213 GrIPoint16 plot;
173 if (!fPlotMgr->newPlot(&plot)) { 214 if (!fPlotMgr->newPlot(&plot)) {
174 return NULL; 215 return NULL;
175 } 216 }
176 217
177 GrAssert(0 == kA8_GrMaskFormat); 218 GrAssert(0 == kA8_GrMaskFormat);
178 GrAssert(1 == kA565_GrMaskFormat); 219 GrAssert(1 == kA565_GrMaskFormat);
179 if (NULL == fTexture[format]) { 220 if (NULL == fTexture[format]) {
180 // TODO: Update this to use the cache rather than directly creating a te xture. 221 // TODO: Update this to use the cache rather than directly creating a te xture.
181 GrTextureDesc desc; 222 GrTextureDesc desc;
182 desc.fFlags = kDynamicUpdate_GrTextureFlagBit; 223 desc.fFlags = kDynamicUpdate_GrTextureFlagBit;
183 desc.fWidth = GR_ATLAS_TEXTURE_WIDTH; 224 desc.fWidth = GR_ATLAS_TEXTURE_WIDTH;
184 desc.fHeight = GR_ATLAS_TEXTURE_HEIGHT; 225 desc.fHeight = GR_ATLAS_TEXTURE_HEIGHT;
185 desc.fConfig = maskformat2pixelconfig(format); 226 desc.fConfig = maskformat2pixelconfig(format);
186 227
187 fTexture[format] = fGpu->createTexture(desc, NULL, 0); 228 fTexture[format] = fGpu->createTexture(desc, NULL, 0);
188 if (NULL == fTexture[format]) { 229 if (NULL == fTexture[format]) {
189 return NULL; 230 return NULL;
190 } 231 }
191 } 232 }
192 233
193 GrAtlas* newAtlas = SkNEW_ARGS(GrAtlas, (this, plot.fX, plot.fY, format)); 234 GrAtlas* newAtlas = SkNEW_ARGS(GrAtlas, (this, plot.fX, plot.fY, format));
194 if (!newAtlas->addSubImage(width, height, image, loc)) { 235 if (!newAtlas->addSubImage(width, height, image, loc)) {
195 delete newAtlas; 236 delete newAtlas;
196 return NULL; 237 return NULL;
197 } 238 }
198 239
199 newAtlas->fNext = atlas; 240 // new atlas, put at head
241 newAtlas->fNext = *atlas;
242 *atlas = newAtlas;
243
200 return newAtlas; 244 return newAtlas;
201 } 245 }
202 246
203 void GrAtlasMgr::freePlot(int x, int y) { 247 void GrAtlasMgr::freePlot(GrMaskFormat format, int x, int y) {
204 GrAssert(fPlotMgr->isBusy(x, y)); 248 GrAssert(fPlotMgr->isBusy(x, y));
205 fPlotMgr->freePlot(x, y); 249 fPlotMgr->freePlot(x, y);
206 } 250 }
OLDNEW
« src/gpu/GrAtlas.h ('K') | « src/gpu/GrAtlas.h ('k') | src/gpu/GrTextContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698