Chromium Code Reviews| 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 "GrBatchTarget.h" | 9 #include "GrBatchTarget.h" |
| 10 #include "GrGpu.h" | 10 #include "GrGpu.h" |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 220 typedef GrBatchTarget::Uploader INHERITED; | 220 typedef GrBatchTarget::Uploader INHERITED; |
| 221 }; | 221 }; |
| 222 | 222 |
| 223 /////////////////////////////////////////////////////////////////////////////// | 223 /////////////////////////////////////////////////////////////////////////////// |
| 224 | 224 |
| 225 GrBatchAtlas::GrBatchAtlas(GrTexture* texture, int numPlotsX, int numPlotsY) | 225 GrBatchAtlas::GrBatchAtlas(GrTexture* texture, int numPlotsX, int numPlotsY) |
| 226 : fTexture(texture) | 226 : fTexture(texture) |
| 227 , fNumPlotsX(numPlotsX) | 227 , fNumPlotsX(numPlotsX) |
| 228 , fNumPlotsY(numPlotsY) | 228 , fNumPlotsY(numPlotsY) |
| 229 , fPlotWidth(texture->width() / numPlotsX) | 229 , fPlotWidth(texture->width() / numPlotsX) |
| 230 , fPlotHeight(texture->height() / numPlotsY) { | 230 , fPlotHeight(texture->height() / numPlotsY) |
| 231 , fAtlasGeneration(kInvalidAtlasGeneration + 1) { | |
| 231 SkASSERT(fPlotWidth * fNumPlotsX == texture->width()); | 232 SkASSERT(fPlotWidth * fNumPlotsX == texture->width()); |
| 232 SkASSERT(fPlotHeight * fNumPlotsY == texture->height()); | 233 SkASSERT(fPlotHeight * fNumPlotsY == texture->height()); |
| 233 | 234 |
| 234 // We currently do not support compressed atlases... | 235 // We currently do not support compressed atlases... |
| 235 SkASSERT(!GrPixelConfigIsCompressed(texture->desc().fConfig)); | 236 SkASSERT(!GrPixelConfigIsCompressed(texture->desc().fConfig)); |
| 236 | 237 |
| 237 // set up allocated plots | 238 // set up allocated plots |
| 238 fBPP = GrBytesPerPixel(texture->desc().fConfig); | 239 fBPP = GrBytesPerPixel(texture->desc().fConfig); |
| 239 fPlotArray = SkNEW_ARRAY(SkAutoTUnref<BatchPlot>, (fNumPlotsX * fNumPlotsY)) ; | 240 fPlotArray = SkNEW_ARRAY(SkAutoTUnref<BatchPlot>, (fNumPlotsX * fNumPlotsY)) ; |
| 240 | 241 |
| 241 SkAutoTUnref<BatchPlot>* currPlot = fPlotArray; | 242 SkAutoTUnref<BatchPlot>* currPlot = fPlotArray; |
| 242 for (int y = fNumPlotsY - 1, r = 0; y >= 0; --y, ++r) { | 243 for (int y = fNumPlotsY - 1, r = 0; y >= 0; --y, ++r) { |
| 243 for (int x = fNumPlotsX - 1, c = 0; x >= 0; --x, ++c) { | 244 for (int x = fNumPlotsX - 1, c = 0; x >= 0; --x, ++c) { |
| 244 int id = r * fNumPlotsX + c; | 245 int id = r * fNumPlotsX + c; |
| 245 currPlot->reset(SkNEW(BatchPlot)); | 246 currPlot->reset(SkNEW(BatchPlot)); |
| 246 (*currPlot)->init(this, texture, id, 0, x, y, fPlotWidth, fPlotHeigh t, fBPP); | 247 // We initialize the new plots with a generation starts of 1 so we c an use |
| 248 // AtlasGeneration 0 for kInvalidAtlasGeneration | |
| 249 (*currPlot)->init(this, texture, id, 1, x, y, fPlotWidth, fPlotHeigh t, fBPP); | |
|
jvanverth1
2015/03/23 20:37:39
Use kInvalidAtlasGeneration + 1 instead of 1?
joshualitt
2015/03/24 14:33:56
Acknowledged.
| |
| 247 | 250 |
| 248 // build LRU list | 251 // build LRU list |
| 249 fPlotList.addToHead(currPlot->get()); | 252 fPlotList.addToHead(currPlot->get()); |
| 250 ++currPlot; | 253 ++currPlot; |
| 251 } | 254 } |
| 252 } | 255 } |
| 253 } | 256 } |
| 254 | 257 |
| 255 GrBatchAtlas::~GrBatchAtlas() { | 258 GrBatchAtlas::~GrBatchAtlas() { |
| 256 SkSafeUnref(fTexture); | 259 SkSafeUnref(fTexture); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 311 // gpu | 314 // gpu |
| 312 plotIter.init(fPlotList, GrBatchPlotList::Iter::kTail_IterStart); | 315 plotIter.init(fPlotList, GrBatchPlotList::Iter::kTail_IterStart); |
| 313 plot = plotIter.get(); | 316 plot = plotIter.get(); |
| 314 SkASSERT(plot); | 317 SkASSERT(plot); |
| 315 if (batchTarget->isIssued(plot->lastRefToken())) { | 318 if (batchTarget->isIssued(plot->lastRefToken())) { |
| 316 this->processEviction(plot->id()); | 319 this->processEviction(plot->id()); |
| 317 plot->resetRects(); | 320 plot->resetRects(); |
| 318 SkDEBUGCODE(bool verify = )plot->addSubImage(width, height, image, loc, fBPP * width); | 321 SkDEBUGCODE(bool verify = )plot->addSubImage(width, height, image, loc, fBPP * width); |
| 319 SkASSERT(verify); | 322 SkASSERT(verify); |
| 320 this->updatePlot(batchTarget, id, plot); | 323 this->updatePlot(batchTarget, id, plot); |
| 324 fAtlasGeneration++; | |
| 321 return true; | 325 return true; |
| 322 } | 326 } |
| 323 | 327 |
| 324 // The least recently refed plot hasn't been flushed to the gpu yet, however , if we have flushed | 328 // The least recently refed plot hasn't been flushed to the gpu yet, however , if we have flushed |
| 325 // it to the batch target than we can reuse it. Our last ref token is guara nteed to be less | 329 // it to the batch target than we can reuse it. Our last ref token is guara nteed to be less |
| 326 // than or equal to the current token. If its 'less than' the current token , than we can spin | 330 // than or equal to the current token. If its 'less than' the current token , than we can spin |
| 327 // off the plot(ie let the batch target manage it) and create a new plot in its place in our | 331 // off the plot(ie let the batch target manage it) and create a new plot in its place in our |
| 328 // array. If it is equal to the currentToken, then the caller has to flush draws to the batch | 332 // array. If it is equal to the currentToken, then the caller has to flush draws to the batch |
| 329 // target so we can spin off the plot | 333 // target so we can spin off the plot |
| 330 if (plot->lastRefToken() == batchTarget->currentToken()) { | 334 if (plot->lastRefToken() == batchTarget->currentToken()) { |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 345 newPlot->init(this, fTexture, index, ++generation, x, y, fPlotWidth, fPlotHe ight, fBPP); | 349 newPlot->init(this, fTexture, index, ++generation, x, y, fPlotWidth, fPlotHe ight, fBPP); |
| 346 | 350 |
| 347 fPlotList.addToHead(newPlot.get()); | 351 fPlotList.addToHead(newPlot.get()); |
| 348 SkDEBUGCODE(bool verify = )newPlot->addSubImage(width, height, image, loc, f BPP * width); | 352 SkDEBUGCODE(bool verify = )newPlot->addSubImage(width, height, image, loc, f BPP * width); |
| 349 SkASSERT(verify); | 353 SkASSERT(verify); |
| 350 newPlot->setLastUploadToken(batchTarget->currentToken()); | 354 newPlot->setLastUploadToken(batchTarget->currentToken()); |
| 351 SkAutoTUnref<GrPlotUploader> uploader(SkNEW_ARGS(GrPlotUploader, (newPlot))) ; | 355 SkAutoTUnref<GrPlotUploader> uploader(SkNEW_ARGS(GrPlotUploader, (newPlot))) ; |
| 352 batchTarget->upload(uploader); | 356 batchTarget->upload(uploader); |
| 353 *id = newPlot->id(); | 357 *id = newPlot->id(); |
| 354 plot->unref(); | 358 plot->unref(); |
| 359 fAtlasGeneration++; | |
| 355 return true; | 360 return true; |
| 356 } | 361 } |
| 357 | 362 |
| 358 bool GrBatchAtlas::hasID(AtlasID id) { | 363 bool GrBatchAtlas::hasID(AtlasID id) { |
| 359 int index = this->getIndexFromID(id); | 364 int index = this->getIndexFromID(id); |
| 360 SkASSERT(index < fNumPlotsX * fNumPlotsY); | 365 SkASSERT(index < fNumPlotsX * fNumPlotsY); |
| 361 return fPlotArray[index]->genID() == this->getGenerationFromID(id); | 366 return fPlotArray[index]->genID() == this->getGenerationFromID(id); |
| 362 } | 367 } |
| 363 | 368 |
| 364 void GrBatchAtlas::setLastRefToken(AtlasID id, BatchToken batchToken) { | 369 void GrBatchAtlas::setLastRefToken(AtlasID id, BatchToken batchToken) { |
| 365 SkASSERT(this->hasID(id)); | 370 SkASSERT(this->hasID(id)); |
| 366 int index = this->getIndexFromID(id); | 371 int index = this->getIndexFromID(id); |
| 367 this->makeMRU(fPlotArray[index]); | 372 this->makeMRU(fPlotArray[index]); |
| 368 fPlotArray[index]->setLastRefToken(batchToken); | 373 fPlotArray[index]->setLastRefToken(batchToken); |
| 369 } | 374 } |
| OLD | NEW |