| 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 (*currPlot)->init(this, texture, id, 1, x, y, fPlotWidth, fPlotHeigh
t, fBPP); |
| 247 | 248 |
| 248 // build LRU list | 249 // build LRU list |
| 249 fPlotList.addToHead(currPlot->get()); | 250 fPlotList.addToHead(currPlot->get()); |
| 250 ++currPlot; | 251 ++currPlot; |
| 251 } | 252 } |
| 252 } | 253 } |
| 253 } | 254 } |
| 254 | 255 |
| 255 GrBatchAtlas::~GrBatchAtlas() { | 256 GrBatchAtlas::~GrBatchAtlas() { |
| 256 SkSafeUnref(fTexture); | 257 SkSafeUnref(fTexture); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 // gpu | 312 // gpu |
| 312 plotIter.init(fPlotList, GrBatchPlotList::Iter::kTail_IterStart); | 313 plotIter.init(fPlotList, GrBatchPlotList::Iter::kTail_IterStart); |
| 313 plot = plotIter.get(); | 314 plot = plotIter.get(); |
| 314 SkASSERT(plot); | 315 SkASSERT(plot); |
| 315 if (batchTarget->isIssued(plot->lastRefToken())) { | 316 if (batchTarget->isIssued(plot->lastRefToken())) { |
| 316 this->processEviction(plot->id()); | 317 this->processEviction(plot->id()); |
| 317 plot->resetRects(); | 318 plot->resetRects(); |
| 318 SkDEBUGCODE(bool verify = )plot->addSubImage(width, height, image, loc,
fBPP * width); | 319 SkDEBUGCODE(bool verify = )plot->addSubImage(width, height, image, loc,
fBPP * width); |
| 319 SkASSERT(verify); | 320 SkASSERT(verify); |
| 320 this->updatePlot(batchTarget, id, plot); | 321 this->updatePlot(batchTarget, id, plot); |
| 322 fAtlasGeneration++; |
| 321 return true; | 323 return true; |
| 322 } | 324 } |
| 323 | 325 |
| 324 // The least recently refed plot hasn't been flushed to the gpu yet, however
, if we have flushed | 326 // 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 | 327 // 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 | 328 // 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 | 329 // 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 | 330 // 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 | 331 // target so we can spin off the plot |
| 330 if (plot->lastRefToken() == batchTarget->currentToken()) { | 332 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); | 347 newPlot->init(this, fTexture, index, ++generation, x, y, fPlotWidth, fPlotHe
ight, fBPP); |
| 346 | 348 |
| 347 fPlotList.addToHead(newPlot.get()); | 349 fPlotList.addToHead(newPlot.get()); |
| 348 SkDEBUGCODE(bool verify = )newPlot->addSubImage(width, height, image, loc, f
BPP * width); | 350 SkDEBUGCODE(bool verify = )newPlot->addSubImage(width, height, image, loc, f
BPP * width); |
| 349 SkASSERT(verify); | 351 SkASSERT(verify); |
| 350 newPlot->setLastUploadToken(batchTarget->currentToken()); | 352 newPlot->setLastUploadToken(batchTarget->currentToken()); |
| 351 SkAutoTUnref<GrPlotUploader> uploader(SkNEW_ARGS(GrPlotUploader, (newPlot)))
; | 353 SkAutoTUnref<GrPlotUploader> uploader(SkNEW_ARGS(GrPlotUploader, (newPlot)))
; |
| 352 batchTarget->upload(uploader); | 354 batchTarget->upload(uploader); |
| 353 *id = newPlot->id(); | 355 *id = newPlot->id(); |
| 354 plot->unref(); | 356 plot->unref(); |
| 357 fAtlasGeneration++; |
| 355 return true; | 358 return true; |
| 356 } | 359 } |
| 357 | 360 |
| 358 bool GrBatchAtlas::hasID(AtlasID id) { | 361 bool GrBatchAtlas::hasID(AtlasID id) { |
| 359 int index = this->getIndexFromID(id); | 362 int index = this->getIndexFromID(id); |
| 360 SkASSERT(index < fNumPlotsX * fNumPlotsY); | 363 SkASSERT(index < fNumPlotsX * fNumPlotsY); |
| 361 return fPlotArray[index]->genID() == this->getGenerationFromID(id); | 364 return fPlotArray[index]->genID() == this->getGenerationFromID(id); |
| 362 } | 365 } |
| 363 | 366 |
| 364 void GrBatchAtlas::setLastRefToken(AtlasID id, BatchToken batchToken) { | 367 void GrBatchAtlas::setLastRefToken(AtlasID id, BatchToken batchToken) { |
| 365 SkASSERT(this->hasID(id)); | 368 SkASSERT(this->hasID(id)); |
| 366 int index = this->getIndexFromID(id); | 369 int index = this->getIndexFromID(id); |
| 367 this->makeMRU(fPlotArray[index]); | 370 this->makeMRU(fPlotArray[index]); |
| 368 fPlotArray[index]->setLastRefToken(batchToken); | 371 fPlotArray[index]->setLastRefToken(batchToken); |
| 369 } | 372 } |
| OLD | NEW |