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