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