| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "GrBatchAtlas.h" | 8 #include "GrBatchAtlas.h" |
| 9 #include "GrBatchFlushState.h" | 9 #include "GrBatchFlushState.h" |
| 10 #include "GrRectanizer.h" | 10 #include "GrRectanizer.h" |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 , fAtlasGeneration(kInvalidAtlasGeneration + 1) { | 227 , fAtlasGeneration(kInvalidAtlasGeneration + 1) { |
| 228 SkASSERT(fNumPlotsX * fNumPlotsY <= BulkUseTokenUpdater::kMaxPlots); | 228 SkASSERT(fNumPlotsX * fNumPlotsY <= BulkUseTokenUpdater::kMaxPlots); |
| 229 SkASSERT(fPlotWidth * fNumPlotsX == static_cast<uint32_t>(texture->width()))
; | 229 SkASSERT(fPlotWidth * fNumPlotsX == static_cast<uint32_t>(texture->width()))
; |
| 230 SkASSERT(fPlotHeight * fNumPlotsY == static_cast<uint32_t>(texture->height()
)); | 230 SkASSERT(fPlotHeight * fNumPlotsY == static_cast<uint32_t>(texture->height()
)); |
| 231 | 231 |
| 232 // We currently do not support compressed atlases... | 232 // We currently do not support compressed atlases... |
| 233 SkASSERT(!GrPixelConfigIsCompressed(texture->desc().fConfig)); | 233 SkASSERT(!GrPixelConfigIsCompressed(texture->desc().fConfig)); |
| 234 | 234 |
| 235 // set up allocated plots | 235 // set up allocated plots |
| 236 fBPP = GrBytesPerPixel(texture->desc().fConfig); | 236 fBPP = GrBytesPerPixel(texture->desc().fConfig); |
| 237 fPlotArray = SkNEW_ARRAY(SkAutoTUnref<BatchPlot>, (fNumPlotsX * fNumPlotsY))
; | 237 fPlotArray = new SkAutoTUnref<BatchPlot>[(fNumPlotsX * fNumPlotsY)]; |
| 238 | 238 |
| 239 SkAutoTUnref<BatchPlot>* currPlot = fPlotArray; | 239 SkAutoTUnref<BatchPlot>* currPlot = fPlotArray; |
| 240 for (int y = fNumPlotsY - 1, r = 0; y >= 0; --y, ++r) { | 240 for (int y = fNumPlotsY - 1, r = 0; y >= 0; --y, ++r) { |
| 241 for (int x = fNumPlotsX - 1, c = 0; x >= 0; --x, ++c) { | 241 for (int x = fNumPlotsX - 1, c = 0; x >= 0; --x, ++c) { |
| 242 uint32_t id = r * fNumPlotsX + c; | 242 uint32_t id = r * fNumPlotsX + c; |
| 243 currPlot->reset(SkNEW(BatchPlot)); | 243 currPlot->reset(new BatchPlot); |
| 244 (*currPlot)->init(this, texture, id, 1, x, y, fPlotWidth, fPlotHeigh
t, fBPP); | 244 (*currPlot)->init(this, texture, id, 1, x, y, fPlotWidth, fPlotHeigh
t, fBPP); |
| 245 | 245 |
| 246 // build LRU list | 246 // build LRU list |
| 247 fPlotList.addToHead(currPlot->get()); | 247 fPlotList.addToHead(currPlot->get()); |
| 248 ++currPlot; | 248 ++currPlot; |
| 249 } | 249 } |
| 250 } | 250 } |
| 251 } | 251 } |
| 252 | 252 |
| 253 GrBatchAtlas::~GrBatchAtlas() { | 253 GrBatchAtlas::~GrBatchAtlas() { |
| 254 SkSafeUnref(fTexture); | 254 SkSafeUnref(fTexture); |
| 255 SkDELETE_ARRAY(fPlotArray); | 255 delete[] fPlotArray; |
| 256 } | 256 } |
| 257 | 257 |
| 258 void GrBatchAtlas::processEviction(AtlasID id) { | 258 void GrBatchAtlas::processEviction(AtlasID id) { |
| 259 for (int i = 0; i < fEvictionCallbacks.count(); i++) { | 259 for (int i = 0; i < fEvictionCallbacks.count(); i++) { |
| 260 (*fEvictionCallbacks[i].fFunc)(id, fEvictionCallbacks[i].fData); | 260 (*fEvictionCallbacks[i].fFunc)(id, fEvictionCallbacks[i].fData); |
| 261 } | 261 } |
| 262 } | 262 } |
| 263 | 263 |
| 264 void GrBatchAtlas::makeMRU(BatchPlot* plot) { | 264 void GrBatchAtlas::makeMRU(BatchPlot* plot) { |
| 265 if (fPlotList.head() == plot) { | 265 if (fPlotList.head() == plot) { |
| 266 return; | 266 return; |
| 267 } | 267 } |
| 268 | 268 |
| 269 fPlotList.remove(plot); | 269 fPlotList.remove(plot); |
| 270 fPlotList.addToHead(plot); | 270 fPlotList.addToHead(plot); |
| 271 } | 271 } |
| 272 | 272 |
| 273 inline void GrBatchAtlas::updatePlot(GrDrawBatch::Target* target, AtlasID* id, B
atchPlot* plot) { | 273 inline void GrBatchAtlas::updatePlot(GrDrawBatch::Target* target, AtlasID* id, B
atchPlot* plot) { |
| 274 this->makeMRU(plot); | 274 this->makeMRU(plot); |
| 275 | 275 |
| 276 // If our most recent upload has already occurred then we have to insert a n
ew | 276 // If our most recent upload has already occurred then we have to insert a n
ew |
| 277 // upload. Otherwise, we already have a scheduled upload that hasn't yet ocu
rred. | 277 // upload. Otherwise, we already have a scheduled upload that hasn't yet ocu
rred. |
| 278 // This new update will piggy back on that previously scheduled update. | 278 // This new update will piggy back on that previously scheduled update. |
| 279 if (target->hasTokenBeenFlushed(plot->lastUploadToken())) { | 279 if (target->hasTokenBeenFlushed(plot->lastUploadToken())) { |
| 280 plot->setLastUploadToken(target->asapToken()); | 280 plot->setLastUploadToken(target->asapToken()); |
| 281 SkAutoTUnref<GrPlotUploader> uploader(SkNEW_ARGS(GrPlotUploader, (plot))
); | 281 SkAutoTUnref<GrPlotUploader> uploader(new GrPlotUploader(plot)); |
| 282 target->upload(uploader); | 282 target->upload(uploader); |
| 283 } | 283 } |
| 284 *id = plot->id(); | 284 *id = plot->id(); |
| 285 } | 285 } |
| 286 | 286 |
| 287 bool GrBatchAtlas::addToAtlas(AtlasID* id, GrDrawBatch::Target* batchTarget, | 287 bool GrBatchAtlas::addToAtlas(AtlasID* id, GrDrawBatch::Target* batchTarget, |
| 288 int width, int height, const void* image, SkIPoint
16* loc) { | 288 int width, int height, const void* image, SkIPoint
16* loc) { |
| 289 // We should already have a texture, TODO clean this up | 289 // We should already have a texture, TODO clean this up |
| 290 SkASSERT(fTexture && | 290 SkASSERT(fTexture && |
| 291 static_cast<uint32_t>(width) <= fPlotWidth && | 291 static_cast<uint32_t>(width) <= fPlotWidth && |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 // We take an extra ref here so our plot isn't deleted when we reset its ind
ex in the array. | 331 // We take an extra ref here so our plot isn't deleted when we reset its ind
ex in the array. |
| 332 plot->ref(); | 332 plot->ref(); |
| 333 int index = plot->index(); | 333 int index = plot->index(); |
| 334 int x = plot->x(); | 334 int x = plot->x(); |
| 335 int y = plot->y(); | 335 int y = plot->y(); |
| 336 uint64_t generation = plot->genID(); | 336 uint64_t generation = plot->genID(); |
| 337 | 337 |
| 338 this->processEviction(plot->id()); | 338 this->processEviction(plot->id()); |
| 339 fPlotList.remove(plot); | 339 fPlotList.remove(plot); |
| 340 SkAutoTUnref<BatchPlot>& newPlot = fPlotArray[plot->index()]; | 340 SkAutoTUnref<BatchPlot>& newPlot = fPlotArray[plot->index()]; |
| 341 newPlot.reset(SkNEW(BatchPlot)); | 341 newPlot.reset(new BatchPlot); |
| 342 newPlot->init(this, fTexture, index, ++generation, x, y, fPlotWidth, fPlotHe
ight, fBPP); | 342 newPlot->init(this, fTexture, index, ++generation, x, y, fPlotWidth, fPlotHe
ight, fBPP); |
| 343 | 343 |
| 344 fPlotList.addToHead(newPlot.get()); | 344 fPlotList.addToHead(newPlot.get()); |
| 345 SkDEBUGCODE(bool verify = )newPlot->addSubImage(width, height, image, loc, f
BPP * width); | 345 SkDEBUGCODE(bool verify = )newPlot->addSubImage(width, height, image, loc, f
BPP * width); |
| 346 SkASSERT(verify); | 346 SkASSERT(verify); |
| 347 newPlot->setLastUploadToken(batchTarget->currentToken()); | 347 newPlot->setLastUploadToken(batchTarget->currentToken()); |
| 348 SkAutoTUnref<GrPlotUploader> uploader(SkNEW_ARGS(GrPlotUploader, (newPlot)))
; | 348 SkAutoTUnref<GrPlotUploader> uploader(new GrPlotUploader(newPlot)); |
| 349 batchTarget->upload(uploader); | 349 batchTarget->upload(uploader); |
| 350 *id = newPlot->id(); | 350 *id = newPlot->id(); |
| 351 plot->unref(); | 351 plot->unref(); |
| 352 fAtlasGeneration++; | 352 fAtlasGeneration++; |
| 353 return true; | 353 return true; |
| 354 } | 354 } |
| 355 | 355 |
| 356 bool GrBatchAtlas::hasID(AtlasID id) { | 356 bool GrBatchAtlas::hasID(AtlasID id) { |
| 357 uint32_t index = GetIndexFromID(id); | 357 uint32_t index = GetIndexFromID(id); |
| 358 SkASSERT(index < fNumPlotsX * fNumPlotsY); | 358 SkASSERT(index < fNumPlotsX * fNumPlotsY); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 369 | 369 |
| 370 void GrBatchAtlas::setLastUseTokenBulk(const BulkUseTokenUpdater& updater, | 370 void GrBatchAtlas::setLastUseTokenBulk(const BulkUseTokenUpdater& updater, |
| 371 GrBatchToken batchToken) { | 371 GrBatchToken batchToken) { |
| 372 int count = updater.fPlotsToUpdate.count(); | 372 int count = updater.fPlotsToUpdate.count(); |
| 373 for (int i = 0; i < count; i++) { | 373 for (int i = 0; i < count; i++) { |
| 374 BatchPlot* plot = fPlotArray[updater.fPlotsToUpdate[i]]; | 374 BatchPlot* plot = fPlotArray[updater.fPlotsToUpdate[i]]; |
| 375 this->makeMRU(plot); | 375 this->makeMRU(plot); |
| 376 plot->setLastUseToken(batchToken); | 376 plot->setLastUseToken(batchToken); |
| 377 } | 377 } |
| 378 } | 378 } |
| OLD | NEW |