OLD | NEW |
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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 | 47 // for testing |
48 #define FONT_CACHE_STATS 0 | 48 #define FONT_CACHE_STATS 0 |
49 #if FONT_CACHE_STATS | 49 #if FONT_CACHE_STATS |
50 static int g_UploadCount = 0; | 50 static int g_UploadCount = 0; |
51 #endif | 51 #endif |
52 | 52 |
53 GrAtlas::GrAtlas(GrAtlasMgr* mgr, int plotX, int plotY, GrMaskFormat format) { | 53 GrAtlas::GrAtlas(GrAtlasMgr* mgr, int plotX, int plotY, GrMaskFormat format) : |
| 54 fDrawToken(NULL, 0) { |
54 fAtlasMgr = mgr; // just a pointer, not an owner | 55 fAtlasMgr = mgr; // just a pointer, not an owner |
55 fNext = NULL; | 56 fNext = NULL; |
56 fUsed = false; | |
57 | 57 |
58 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 |
59 fPlot.set(plotX, plotY); | 59 fPlot.set(plotX, plotY); |
60 | 60 |
61 fRects = GrRectanizer::Factory(GR_ATLAS_WIDTH - BORDER, | 61 fRects = GrRectanizer::Factory(GR_ATLAS_WIDTH - BORDER, |
62 GR_ATLAS_HEIGHT - BORDER); | 62 GR_ATLAS_HEIGHT - BORDER); |
63 | 63 |
64 fMaskFormat = format; | 64 fMaskFormat = format; |
65 | 65 |
66 #if GR_DEBUG | 66 #if GR_DEBUG |
(...skipping 13 matching lines...) Expand all Loading... |
80 #endif | 80 #endif |
81 } | 81 } |
82 | 82 |
83 bool GrAtlas::RemoveUnusedAtlases(GrAtlasMgr* atlasMgr, GrAtlas** startAtlas) { | 83 bool GrAtlas::RemoveUnusedAtlases(GrAtlasMgr* atlasMgr, GrAtlas** startAtlas) { |
84 // GrAtlas** is used so that a pointer to the head element can be passed in
and | 84 // GrAtlas** is used so that a pointer to the head element can be passed in
and |
85 // modified when the first element is deleted | 85 // modified when the first element is deleted |
86 GrAtlas** atlasRef = startAtlas; | 86 GrAtlas** atlasRef = startAtlas; |
87 GrAtlas* atlas = *startAtlas; | 87 GrAtlas* atlas = *startAtlas; |
88 bool removed = false; | 88 bool removed = false; |
89 while (NULL != atlas) { | 89 while (NULL != atlas) { |
90 if (!atlas->used()) { | 90 if (atlas->drawToken().isIssued()) { |
91 *atlasRef = atlas->fNext; | 91 *atlasRef = atlas->fNext; |
92 atlasMgr->deleteAtlas(atlas); | 92 atlasMgr->deleteAtlas(atlas); |
93 atlas = *atlasRef; | 93 atlas = *atlasRef; |
94 removed = true; | 94 removed = true; |
95 } else { | 95 } else { |
96 atlasRef = &atlas->fNext; | 96 atlasRef = &atlas->fNext; |
97 atlas = atlas->fNext; | 97 atlas = atlas->fNext; |
98 } | 98 } |
99 } | 99 } |
100 | 100 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 | 182 |
183 static GrPixelConfig maskformat2pixelconfig(GrMaskFormat format) { | 183 static GrPixelConfig maskformat2pixelconfig(GrMaskFormat format) { |
184 switch (format) { | 184 switch (format) { |
185 case kA8_GrMaskFormat: | 185 case kA8_GrMaskFormat: |
186 return kAlpha_8_GrPixelConfig; | 186 return kAlpha_8_GrPixelConfig; |
187 case kA565_GrMaskFormat: | 187 case kA565_GrMaskFormat: |
188 return kRGB_565_GrPixelConfig; | 188 return kRGB_565_GrPixelConfig; |
189 case kA888_GrMaskFormat: | 189 case kA888_GrMaskFormat: |
190 return kSkia8888_GrPixelConfig; | 190 return kSkia8888_GrPixelConfig; |
191 default: | 191 default: |
192 GrAssert(!"unknown maskformat"); | 192 SkASSERT(!"unknown maskformat"); |
193 } | 193 } |
194 return kUnknown_GrPixelConfig; | 194 return kUnknown_GrPixelConfig; |
195 } | 195 } |
196 | 196 |
197 GrAtlas* GrAtlasMgr::addToAtlas(GrAtlas** atlas, | 197 GrAtlas* GrAtlasMgr::addToAtlas(GrAtlas** atlas, |
198 int width, int height, const void* image, | 198 int width, int height, const void* image, |
199 GrMaskFormat format, | 199 GrMaskFormat format, |
200 GrIPoint16* loc) { | 200 GrIPoint16* loc) { |
201 GrAssert(NULL == *atlas || (*atlas)->getMaskFormat() == format); | 201 GrAssert(NULL == *atlas || (*atlas)->getMaskFormat() == format); |
202 | 202 |
203 // iterate through entire atlas list, see if we can find a hole | 203 // iterate through entire atlas list, see if we can find a hole |
204 GrAtlas* atlasIter = *atlas; | 204 GrAtlas* atlasIter = *atlas; |
205 while (atlasIter) { | 205 while (atlasIter) { |
206 if (atlasIter->addSubImage(width, height, image, loc)) { | 206 if (atlasIter->addSubImage(width, height, image, loc)) { |
207 return atlasIter; | 207 return atlasIter; |
208 } | 208 } |
209 atlasIter = atlasIter->fNext; | 209 atlasIter = atlasIter->fNext; |
210 } | 210 } |
211 | 211 |
212 // If the above fails, then either we have no starting atlas, or the current | 212 // If the above fails, then either we have no starting atlas, or the current |
213 // atlas list is full. Either way we need to allocate a new atlas | 213 // atlas list is full. Either way we need to allocate a new atlas |
214 | 214 |
215 GrIPoint16 plot; | 215 GrIPoint16 plot; |
216 if (!fPlotMgr->newPlot(&plot)) { | 216 if (!fPlotMgr->newPlot(&plot)) { |
217 return NULL; | 217 return NULL; |
218 } | 218 } |
219 | 219 |
220 GrAssert(0 == kA8_GrMaskFormat); | 220 SkASSERT(0 == kA8_GrMaskFormat); |
221 GrAssert(1 == kA565_GrMaskFormat); | 221 SkASSERT(1 == kA565_GrMaskFormat); |
222 if (NULL == fTexture[format]) { | 222 if (NULL == fTexture[format]) { |
223 // TODO: Update this to use the cache rather than directly creating a te
xture. | 223 // TODO: Update this to use the cache rather than directly creating a te
xture. |
224 GrTextureDesc desc; | 224 GrTextureDesc desc; |
225 desc.fFlags = kDynamicUpdate_GrTextureFlagBit; | 225 desc.fFlags = kDynamicUpdate_GrTextureFlagBit; |
226 desc.fWidth = GR_ATLAS_TEXTURE_WIDTH; | 226 desc.fWidth = GR_ATLAS_TEXTURE_WIDTH; |
227 desc.fHeight = GR_ATLAS_TEXTURE_HEIGHT; | 227 desc.fHeight = GR_ATLAS_TEXTURE_HEIGHT; |
228 desc.fConfig = maskformat2pixelconfig(format); | 228 desc.fConfig = maskformat2pixelconfig(format); |
229 | 229 |
230 fTexture[format] = fGpu->createTexture(desc, NULL, 0); | 230 fTexture[format] = fGpu->createTexture(desc, NULL, 0); |
231 if (NULL == fTexture[format]) { | 231 if (NULL == fTexture[format]) { |
232 return NULL; | 232 return NULL; |
233 } | 233 } |
234 } | 234 } |
235 | 235 |
236 GrAtlas* newAtlas = SkNEW_ARGS(GrAtlas, (this, plot.fX, plot.fY, format)); | 236 GrAtlas* newAtlas = SkNEW_ARGS(GrAtlas, (this, plot.fX, plot.fY, format)); |
237 if (!newAtlas->addSubImage(width, height, image, loc)) { | 237 if (!newAtlas->addSubImage(width, height, image, loc)) { |
238 delete newAtlas; | 238 delete newAtlas; |
239 return NULL; | 239 return NULL; |
240 } | 240 } |
241 | 241 |
242 // new atlas, put at head | 242 // new atlas, put at head |
243 newAtlas->fNext = *atlas; | 243 newAtlas->fNext = *atlas; |
244 *atlas = newAtlas; | 244 *atlas = newAtlas; |
245 | 245 |
246 return newAtlas; | 246 return newAtlas; |
247 } | 247 } |
248 | 248 |
249 void GrAtlasMgr::freePlot(GrMaskFormat format, int x, int y) { | 249 void GrAtlasMgr::freePlot(GrMaskFormat format, int x, int y) { |
250 GrAssert(fPlotMgr->isBusy(x, y)); | 250 SkASSERT(fPlotMgr->isBusy(x, y)); |
251 fPlotMgr->freePlot(x, y); | 251 fPlotMgr->freePlot(x, y); |
252 } | 252 } |
OLD | NEW |