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