Chromium Code Reviews| 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 #ifdef SK_DEBUG | 43 #ifdef SK_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, int bpp) : |
| 54 fDrawToken(NULL, 0) { | 54 fDrawToken(NULL, 0) { |
| 55 fAtlasMgr = mgr; // just a pointer, not an owner | 55 fAtlasMgr = mgr; // just a pointer, not an owner |
| 56 fNext = NULL; | 56 fNext = NULL; |
| 57 | 57 |
| 58 fTexture = mgr->getTexture(); // we're not an owner, just a pointer | 58 fTexture = mgr->getTexture(); // 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 fBytesPerPixel = bpp; |
| 65 | 65 |
| 66 #ifdef SK_DEBUG | 66 #ifdef SK_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(fPlot.fX, fPlot.fY); | 73 fAtlasMgr->freePlot(fPlot.fX, fPlot.fY); |
| 74 | 74 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 115 | 115 |
| 116 bool GrAtlas::addSubImage(int width, int height, const void* image, | 116 bool GrAtlas::addSubImage(int width, int height, const void* image, |
| 117 GrIPoint16* loc) { | 117 GrIPoint16* loc) { |
| 118 if (!fRects->addRect(width + BORDER, height + BORDER, loc)) { | 118 if (!fRects->addRect(width + BORDER, height + BORDER, loc)) { |
| 119 return false; | 119 return false; |
| 120 } | 120 } |
| 121 | 121 |
| 122 SkAutoSMalloc<1024> storage; | 122 SkAutoSMalloc<1024> storage; |
| 123 int dstW = width + 2*BORDER; | 123 int dstW = width + 2*BORDER; |
| 124 int dstH = height + 2*BORDER; | 124 int dstH = height + 2*BORDER; |
| 125 if (BORDER) { | 125 if (BORDER) { |
|
robertphillips
2013/09/26 13:47:35
Replace bpp with fBytesPerPixel?
jvanverth1
2013/09/26 15:16:07
Done.
| |
| 126 const int bpp = GrMaskFormatBytesPerPixel(fMaskFormat); | 126 const int bpp = fBytesPerPixel; |
| 127 const size_t dstRB = dstW * bpp; | 127 const size_t dstRB = dstW * bpp; |
| 128 uint8_t* dst = (uint8_t*)storage.reset(dstH * dstRB); | 128 uint8_t* dst = (uint8_t*)storage.reset(dstH * dstRB); |
| 129 Gr_bzero(dst, dstRB); // zero top row | 129 Gr_bzero(dst, dstRB); // zero top row |
| 130 dst += dstRB; | 130 dst += dstRB; |
| 131 for (int y = 0; y < height; y++) { | 131 for (int y = 0; y < height; y++) { |
| 132 dst = zerofill(dst, bpp); // zero left edge | 132 dst = zerofill(dst, bpp); // zero left edge |
| 133 memcpy(dst, image, width * bpp); | 133 memcpy(dst, image, width * bpp); |
| 134 dst += width * bpp; | 134 dst += width * bpp; |
| 135 dst = zerofill(dst, bpp); // zero right edge | 135 dst = zerofill(dst, bpp); // zero right edge |
| 136 image = (const void*)((const char*)image + width * bpp); | 136 image = (const void*)((const char*)image + width * bpp); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 154 | 154 |
| 155 #if FONT_CACHE_STATS | 155 #if FONT_CACHE_STATS |
| 156 ++g_UploadCount; | 156 ++g_UploadCount; |
| 157 #endif | 157 #endif |
| 158 | 158 |
| 159 return true; | 159 return true; |
| 160 } | 160 } |
| 161 | 161 |
| 162 /////////////////////////////////////////////////////////////////////////////// | 162 /////////////////////////////////////////////////////////////////////////////// |
| 163 | 163 |
| 164 GrAtlasMgr::GrAtlasMgr(GrGpu* gpu, GrMaskFormat format) { | 164 GrAtlasMgr::GrAtlasMgr(GrGpu* gpu, GrPixelConfig config) { |
| 165 fGpu = gpu; | 165 fGpu = gpu; |
| 166 fMaskFormat = format; | 166 fPixelConfig = config; |
| 167 gpu->ref(); | 167 gpu->ref(); |
| 168 fTexture = NULL; | 168 fTexture = NULL; |
| 169 fPlotMgr = SkNEW_ARGS(GrPlotMgr, (GR_PLOT_WIDTH, GR_PLOT_HEIGHT)); | 169 fPlotMgr = SkNEW_ARGS(GrPlotMgr, (GR_PLOT_WIDTH, GR_PLOT_HEIGHT)); |
| 170 } | 170 } |
| 171 | 171 |
| 172 GrAtlasMgr::~GrAtlasMgr() { | 172 GrAtlasMgr::~GrAtlasMgr() { |
| 173 SkSafeUnref(fTexture); | 173 SkSafeUnref(fTexture); |
| 174 delete fPlotMgr; | 174 delete fPlotMgr; |
| 175 | 175 |
| 176 fGpu->unref(); | 176 fGpu->unref(); |
| 177 #if FONT_CACHE_STATS | 177 #if FONT_CACHE_STATS |
| 178 GrPrintf("Num uploads: %d\n", g_UploadCount); | 178 GrPrintf("Num uploads: %d\n", g_UploadCount); |
| 179 #endif | 179 #endif |
| 180 } | 180 } |
| 181 | 181 |
| 182 static GrPixelConfig maskformat2pixelconfig(GrMaskFormat format) { | |
| 183 switch (format) { | |
| 184 case kA8_GrMaskFormat: | |
| 185 return kAlpha_8_GrPixelConfig; | |
| 186 case kA565_GrMaskFormat: | |
| 187 return kRGB_565_GrPixelConfig; | |
| 188 case kA888_GrMaskFormat: | |
| 189 return kSkia8888_GrPixelConfig; | |
| 190 default: | |
| 191 SkDEBUGFAIL("unknown maskformat"); | |
| 192 } | |
| 193 return kUnknown_GrPixelConfig; | |
| 194 } | |
| 195 | |
| 196 GrAtlas* GrAtlasMgr::addToAtlas(GrAtlas** atlas, | 182 GrAtlas* GrAtlasMgr::addToAtlas(GrAtlas** atlas, |
| 197 int width, int height, const void* image, | 183 int width, int height, const void* image, |
| 198 GrIPoint16* loc) { | 184 GrIPoint16* loc) { |
| 199 // iterate through entire atlas list, see if we can find a hole | 185 // iterate through entire atlas list, see if we can find a hole |
| 200 GrAtlas* atlasIter = *atlas; | 186 GrAtlas* atlasIter = *atlas; |
| 201 while (atlasIter) { | 187 while (atlasIter) { |
| 202 if (atlasIter->addSubImage(width, height, image, loc)) { | 188 if (atlasIter->addSubImage(width, height, image, loc)) { |
| 203 return atlasIter; | 189 return atlasIter; |
| 204 } | 190 } |
| 205 atlasIter = atlasIter->fNext; | 191 atlasIter = atlasIter->fNext; |
| 206 } | 192 } |
| 207 | 193 |
| 208 // If the above fails, then either we have no starting atlas, or the current | 194 // If the above fails, then either we have no starting atlas, or the current |
| 209 // atlas list is full. Either way we need to allocate a new atlas | 195 // atlas list is full. Either way we need to allocate a new atlas |
| 210 | 196 |
| 211 GrIPoint16 plot; | 197 GrIPoint16 plot; |
| 212 if (!fPlotMgr->newPlot(&plot)) { | 198 if (!fPlotMgr->newPlot(&plot)) { |
| 213 return NULL; | 199 return NULL; |
| 214 } | 200 } |
| 215 | 201 |
| 216 if (NULL == fTexture) { | 202 if (NULL == fTexture) { |
| 217 // TODO: Update this to use the cache rather than directly creating a te xture. | 203 // TODO: Update this to use the cache rather than directly creating a te xture. |
| 218 GrTextureDesc desc; | 204 GrTextureDesc desc; |
| 219 desc.fFlags = kDynamicUpdate_GrTextureFlagBit; | 205 desc.fFlags = kDynamicUpdate_GrTextureFlagBit; |
| 220 desc.fWidth = GR_ATLAS_TEXTURE_WIDTH; | 206 desc.fWidth = GR_ATLAS_TEXTURE_WIDTH; |
| 221 desc.fHeight = GR_ATLAS_TEXTURE_HEIGHT; | 207 desc.fHeight = GR_ATLAS_TEXTURE_HEIGHT; |
| 222 desc.fConfig = maskformat2pixelconfig(fMaskFormat); | 208 desc.fConfig = fPixelConfig; |
| 223 | 209 |
| 224 fTexture = fGpu->createTexture(desc, NULL, 0); | 210 fTexture = fGpu->createTexture(desc, NULL, 0); |
| 225 if (NULL == fTexture) { | 211 if (NULL == fTexture) { |
| 226 return NULL; | 212 return NULL; |
| 227 } | 213 } |
| 228 } | 214 } |
| 229 | 215 |
| 230 GrAtlas* newAtlas = SkNEW_ARGS(GrAtlas, (this, plot.fX, plot.fY, fMaskFormat )); | 216 int bpp = GrBytesPerPixel(fPixelConfig); |
| 217 GrAtlas* newAtlas = SkNEW_ARGS(GrAtlas, (this, plot.fX, plot.fY, bpp)); | |
| 231 if (!newAtlas->addSubImage(width, height, image, loc)) { | 218 if (!newAtlas->addSubImage(width, height, image, loc)) { |
| 232 delete newAtlas; | 219 delete newAtlas; |
| 233 return NULL; | 220 return NULL; |
| 234 } | 221 } |
| 235 | 222 |
| 236 // new atlas, put at head | 223 // new atlas, put at head |
| 237 newAtlas->fNext = *atlas; | 224 newAtlas->fNext = *atlas; |
| 238 *atlas = newAtlas; | 225 *atlas = newAtlas; |
| 239 | 226 |
| 240 return newAtlas; | 227 return newAtlas; |
| 241 } | 228 } |
| 242 | 229 |
| 243 void GrAtlasMgr::freePlot(int x, int y) { | 230 void GrAtlasMgr::freePlot(int x, int y) { |
| 244 SkASSERT(fPlotMgr->isBusy(x, y)); | 231 SkASSERT(fPlotMgr->isBusy(x, y)); |
| 245 fPlotMgr->freePlot(x, y); | 232 fPlotMgr->freePlot(x, y); |
| 246 } | 233 } |
| OLD | NEW |