| 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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 fDirtyRect.setEmpty(); | 109 fDirtyRect.setEmpty(); |
| 110 SkDEBUGCODE(fDirty = false;) | 110 SkDEBUGCODE(fDirty = false;) |
| 111 } | 111 } |
| 112 | 112 |
| 113 /////////////////////////////////////////////////////////////////////////////// | 113 /////////////////////////////////////////////////////////////////////////////// |
| 114 | 114 |
| 115 GrBatchAtlas::GrBatchAtlas(GrTexture* texture, int numPlotsX, int numPlotsY) | 115 GrBatchAtlas::GrBatchAtlas(GrTexture* texture, int numPlotsX, int numPlotsY) |
| 116 : fTexture(texture) | 116 : fTexture(texture) |
| 117 , fAtlasGeneration(kInvalidAtlasGeneration + 1) { | 117 , fAtlasGeneration(kInvalidAtlasGeneration + 1) { |
| 118 | 118 |
| 119 int plotWidth = texture->width() / numPlotsX; | 119 fPlotWidth = texture->width() / numPlotsX; |
| 120 int plotHeight = texture->height() / numPlotsY; | 120 fPlotHeight = texture->height() / numPlotsY; |
| 121 SkASSERT(numPlotsX * numPlotsY <= BulkUseTokenUpdater::kMaxPlots); | 121 SkASSERT(numPlotsX * numPlotsY <= BulkUseTokenUpdater::kMaxPlots); |
| 122 SkASSERT(plotWidth * numPlotsX == texture->width()); | 122 SkASSERT(fPlotWidth * numPlotsX == texture->width()); |
| 123 SkASSERT(plotHeight * numPlotsY == texture->height()); | 123 SkASSERT(fPlotHeight * numPlotsY == texture->height()); |
| 124 | 124 |
| 125 SkDEBUGCODE(fNumPlots = numPlotsX * numPlotsY;) | 125 SkDEBUGCODE(fNumPlots = numPlotsX * numPlotsY;) |
| 126 | 126 |
| 127 // We currently do not support compressed atlases... | 127 // We currently do not support compressed atlases... |
| 128 SkASSERT(!GrPixelConfigIsCompressed(texture->desc().fConfig)); | 128 SkASSERT(!GrPixelConfigIsCompressed(texture->desc().fConfig)); |
| 129 | 129 |
| 130 // set up allocated plots | 130 // set up allocated plots |
| 131 fPlotArray = new SkAutoTUnref<BatchPlot>[numPlotsX * numPlotsY]; | 131 fPlotArray = new SkAutoTUnref<BatchPlot>[numPlotsX * numPlotsY]; |
| 132 | 132 |
| 133 SkAutoTUnref<BatchPlot>* currPlot = fPlotArray; | 133 SkAutoTUnref<BatchPlot>* currPlot = fPlotArray; |
| 134 for (int y = numPlotsY - 1, r = 0; y >= 0; --y, ++r) { | 134 for (int y = numPlotsY - 1, r = 0; y >= 0; --y, ++r) { |
| 135 for (int x = numPlotsX - 1, c = 0; x >= 0; --x, ++c) { | 135 for (int x = numPlotsX - 1, c = 0; x >= 0; --x, ++c) { |
| 136 uint32_t index = r * numPlotsX + c; | 136 uint32_t index = r * numPlotsX + c; |
| 137 currPlot->reset(new BatchPlot(index, 1, x, y, plotWidth, plotHeight, | 137 currPlot->reset(new BatchPlot(index, 1, x, y, fPlotWidth, fPlotHeigh
t, |
| 138 texture->desc().fConfig)); | 138 texture->desc().fConfig)); |
| 139 | 139 |
| 140 // build LRU list | 140 // build LRU list |
| 141 fPlotList.addToHead(currPlot->get()); | 141 fPlotList.addToHead(currPlot->get()); |
| 142 ++currPlot; | 142 ++currPlot; |
| 143 } | 143 } |
| 144 } | 144 } |
| 145 } | 145 } |
| 146 | 146 |
| 147 GrBatchAtlas::~GrBatchAtlas() { | 147 GrBatchAtlas::~GrBatchAtlas() { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 172 ); | 172 ); |
| 173 plot->setLastUploadToken(lastUploadToken); | 173 plot->setLastUploadToken(lastUploadToken); |
| 174 } | 174 } |
| 175 *id = plot->id(); | 175 *id = plot->id(); |
| 176 } | 176 } |
| 177 | 177 |
| 178 bool GrBatchAtlas::addToAtlas(AtlasID* id, GrDrawBatch::Target* target, | 178 bool GrBatchAtlas::addToAtlas(AtlasID* id, GrDrawBatch::Target* target, |
| 179 int width, int height, const void* image, SkIPoint
16* loc) { | 179 int width, int height, const void* image, SkIPoint
16* loc) { |
| 180 // We should already have a texture, TODO clean this up | 180 // We should already have a texture, TODO clean this up |
| 181 SkASSERT(fTexture); | 181 SkASSERT(fTexture); |
| 182 if (width > fPlotWidth || height > fPlotHeight) { |
| 183 return false; |
| 184 } |
| 182 | 185 |
| 183 // now look through all allocated plots for one we can share, in Most Recent
ly Refed order | 186 // now look through all allocated plots for one we can share, in Most Recent
ly Refed order |
| 184 GrBatchPlotList::Iter plotIter; | 187 GrBatchPlotList::Iter plotIter; |
| 185 plotIter.init(fPlotList, GrBatchPlotList::Iter::kHead_IterStart); | 188 plotIter.init(fPlotList, GrBatchPlotList::Iter::kHead_IterStart); |
| 186 BatchPlot* plot; | 189 BatchPlot* plot; |
| 187 while ((plot = plotIter.get())) { | 190 while ((plot = plotIter.get())) { |
| 188 SkASSERT(GrBytesPerPixel(fTexture->desc().fConfig) == plot->bpp()); | 191 SkASSERT(GrBytesPerPixel(fTexture->desc().fConfig) == plot->bpp()); |
| 189 if (plot->addSubImage(width, height, image, loc)) { | 192 if (plot->addSubImage(width, height, image, loc)) { |
| 190 this->updatePlot(target, id, plot); | 193 this->updatePlot(target, id, plot); |
| 191 return true; | 194 return true; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 plotsp->uploadToTexture(writePixels, texture); | 242 plotsp->uploadToTexture(writePixels, texture); |
| 240 } | 243 } |
| 241 ); | 244 ); |
| 242 newPlot->setLastUploadToken(lastUploadToken); | 245 newPlot->setLastUploadToken(lastUploadToken); |
| 243 | 246 |
| 244 *id = newPlot->id(); | 247 *id = newPlot->id(); |
| 245 | 248 |
| 246 fAtlasGeneration++; | 249 fAtlasGeneration++; |
| 247 return true; | 250 return true; |
| 248 } | 251 } |
| OLD | NEW |