Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(544)

Side by Side Diff: src/gpu/GrBatchAtlas.cpp

Issue 1253003005: bump the size of the atlas id to 64 bits (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: tweaks Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« src/gpu/GrBatchAtlas.h ('K') | « src/gpu/GrBatchAtlas.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "GrRectanizer.h" 11 #include "GrRectanizer.h"
12 #include "GrTracing.h" 12 #include "GrTracing.h"
13 #include "GrVertexBuffer.h" 13 #include "GrVertexBuffer.h"
14 14
15 static inline void adjust_for_offset(SkIPoint16* loc, const SkIPoint16& offset) { 15 static inline void adjust_for_offset(SkIPoint16* loc, const SkIPoint16& offset) {
16 loc->fX += offset.fX; 16 loc->fX += offset.fX;
17 loc->fY += offset.fY; 17 loc->fY += offset.fY;
18 } 18 }
19 19
20 static GrBatchAtlas::AtlasID create_id(int index, int generation) { 20 static GrBatchAtlas::AtlasID create_id(uint32_t index, uint64_t generation) {
21 // Generation ID can roll over because we only check for equality
22 SkASSERT(index < (1 << 16)); 21 SkASSERT(index < (1 << 16));
robertphillips 2015/07/31 15:00:54 SkASSERT(generation < (1 << 48)); ?
23 return generation << 16 | index; 22 return generation << 16 | index;
24 } 23 }
25 24
26 // The backing GrTexture for a GrBatchAtlas is broken into a spatial grid of GrB atchPlots. 25 // The backing GrTexture for a GrBatchAtlas is broken into a spatial grid of GrB atchPlots.
27 // The GrBatchPlots keep track of subimage placement via their GrRectanizer. In turn, a GrBatchPlot 26 // The GrBatchPlots keep track of subimage placement via their GrRectanizer. In turn, a GrBatchPlot
28 // manages the lifetime of its data using two tokens, a last ref toke and a last upload token. 27 // manages the lifetime of its data using two tokens, a last ref toke and a last upload token.
29 // Once a GrBatchPlot is "full" (i.e. there is no room for the new subimage acco rding to the 28 // Once a GrBatchPlot is "full" (i.e. there is no room for the new subimage acco rding to the
30 // GrRectanizer), it can no longer be used unless the last ref on the GrPlot has already been 29 // GrRectanizer), it can no longer be used unless the last ref on the GrPlot has already been
31 // flushed through to the gpu. 30 // flushed through to the gpu.
32 31
33 class BatchPlot : public SkRefCnt { 32 class BatchPlot : public SkRefCnt {
34 public: 33 public:
35 typedef GrBatchAtlas::BatchToken BatchToken; 34 typedef GrBatchAtlas::BatchToken BatchToken;
36 35
37 SK_DECLARE_INTERNAL_LLIST_INTERFACE(BatchPlot); 36 SK_DECLARE_INTERNAL_LLIST_INTERFACE(BatchPlot);
38 37
39 // index() refers to the index of the plot in the owning GrAtlas's plot arra y. genID() is a 38 // index() refers to the index of the plot in the owning GrAtlas's plot arra y. genID() is a
40 // monotonically incrementing number which is bumped every time the cpu back ing store is 39 // monotonically incrementing number which is bumped every time the cpu back ing store is
41 // wiped, or when the plot itself is evicted from the atlas(ie, there is con tinuity in genID() 40 // wiped, or when the plot itself is evicted from the atlas(ie, there is con tinuity in genID()
42 // across atlas spills) 41 // across atlas spills)
43 int index() const { return fIndex; } 42 uint32_t index() const { return fIndex; }
44 int genID() const { return fGenID; } 43 uint64_t genID() const { return fGenID; }
45 GrBatchAtlas::AtlasID id() { return fID; } 44 GrBatchAtlas::AtlasID id() { return fID; }
46 45
47 GrTexture* texture() const { return fTexture; } 46 GrTexture* texture() const { return fTexture; }
48 47
49 bool addSubImage(int width, int height, const void* image, SkIPoint16* loc, size_t rowBytes) { 48 bool addSubImage(int width, int height, const void* image, SkIPoint16* loc, size_t rowBytes) {
50 if (!fRects->addRect(width, height, loc)) { 49 if (!fRects->addRect(width, height, loc)) {
51 return false; 50 return false;
52 } 51 }
53 52
54 if (!fData) { 53 if (!fData) {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 fID = create_id(fIndex, fGenID); 112 fID = create_id(fIndex, fGenID);
114 113
115 // zero out the plot 114 // zero out the plot
116 if (fData) { 115 if (fData) {
117 sk_bzero(fData, fBytesPerPixel * fWidth * fHeight); 116 sk_bzero(fData, fBytesPerPixel * fWidth * fHeight);
118 } 117 }
119 118
120 fDirtyRect.setEmpty(); 119 fDirtyRect.setEmpty();
121 SkDEBUGCODE(fDirty = false;) 120 SkDEBUGCODE(fDirty = false;)
122 } 121 }
123 122
robertphillips 2015/07/31 15:00:54 Do we need to be explicit here ?
124 int x() const { return fX; } 123 uint32_t x() const { return fX; }
125 int y() const { return fY; } 124 uint32_t y() const { return fY; }
126 125
127 private: 126 private:
128 BatchPlot() 127 BatchPlot()
129 : fLastUpload(0) 128 : fLastUpload(0)
130 , fLastUse(0) 129 , fLastUse(0)
131 , fIndex(-1) 130 , fIndex(-1)
132 , fGenID(-1) 131 , fGenID(-1)
133 , fID(0) 132 , fID(0)
134 , fData(NULL) 133 , fData(NULL)
135 , fWidth(0) 134 , fWidth(0)
(...skipping 10 matching lines...) Expand all
146 { 145 {
147 fOffset.set(0, 0); 146 fOffset.set(0, 0);
148 } 147 }
149 148
150 ~BatchPlot() { 149 ~BatchPlot() {
151 sk_free(fData); 150 sk_free(fData);
152 fData = NULL; 151 fData = NULL;
153 delete fRects; 152 delete fRects;
154 } 153 }
155 154
156 void init(GrBatchAtlas* atlas, GrTexture* texture, int index, uint32_t gener ation, 155 void init(GrBatchAtlas* atlas, GrTexture* texture, int index, uint64_t gener ation,
157 int offX, int offY, int width, int height, size_t bpp) { 156 int offX, int offY, int width, int height, size_t bpp) {
158 fIndex = index; 157 fIndex = index;
159 fGenID = generation; 158 fGenID = generation;
160 fID = create_id(index, generation); 159 fID = create_id(index, generation);
161 fWidth = width; 160 fWidth = width;
162 fHeight = height; 161 fHeight = height;
163 fX = offX; 162 fX = offX;
164 fY = offY; 163 fY = offY;
165 fRects = GrRectanizer::Factory(width, height); 164 fRects = GrRectanizer::Factory(width, height);
166 fAtlas = atlas; 165 fAtlas = atlas;
167 fOffset.set(offX * width, offY * height); 166 fOffset.set(offX * width, offY * height);
168 fBytesPerPixel = bpp; 167 fBytesPerPixel = bpp;
169 fData = NULL; 168 fData = NULL;
170 fDirtyRect.setEmpty(); 169 fDirtyRect.setEmpty();
171 SkDEBUGCODE(fDirty = false;) 170 SkDEBUGCODE(fDirty = false;)
172 fTexture = texture; 171 fTexture = texture;
173 } 172 }
174 173
175 BatchToken fLastUpload; 174 BatchToken fLastUpload;
176 BatchToken fLastUse; 175 BatchToken fLastUse;
177 176
178 uint32_t fIndex; 177 uint32_t fIndex;
179 uint32_t fGenID; 178 uint64_t fGenID;
180 GrBatchAtlas::AtlasID fID; 179 GrBatchAtlas::AtlasID fID;
181 unsigned char* fData; 180 unsigned char* fData;
robertphillips 2015/07/31 15:00:54 Do we need to be explicit here ?
182 int fWidth; 181 uint32_t fWidth;
183 int fHeight; 182 uint32_t fHeight;
184 int fX; 183 uint32_t fX;
185 int fY; 184 uint32_t fY;
186 GrTexture* fTexture; 185 GrTexture* fTexture;
187 GrRectanizer* fRects; 186 GrRectanizer* fRects;
188 GrBatchAtlas* fAtlas; 187 GrBatchAtlas* fAtlas;
189 SkIPoint16 fOffset; // the offset of the plot in the backing texture 188 SkIPoint16 fOffset; // the offset of the plot in the backing texture
190 size_t fBytesPerPixel; 189 size_t fBytesPerPixel;
191 SkIRect fDirtyRect; 190 SkIRect fDirtyRect;
192 SkDEBUGCODE(bool fDirty;) 191 SkDEBUGCODE(bool fDirty;)
193 192
194 friend class GrBatchAtlas; 193 friend class GrBatchAtlas;
195 194
(...skipping 23 matching lines...) Expand all
219 /////////////////////////////////////////////////////////////////////////////// 218 ///////////////////////////////////////////////////////////////////////////////
220 219
221 GrBatchAtlas::GrBatchAtlas(GrTexture* texture, int numPlotsX, int numPlotsY) 220 GrBatchAtlas::GrBatchAtlas(GrTexture* texture, int numPlotsX, int numPlotsY)
222 : fTexture(texture) 221 : fTexture(texture)
223 , fNumPlotsX(numPlotsX) 222 , fNumPlotsX(numPlotsX)
224 , fNumPlotsY(numPlotsY) 223 , fNumPlotsY(numPlotsY)
225 , fPlotWidth(texture->width() / numPlotsX) 224 , fPlotWidth(texture->width() / numPlotsX)
226 , fPlotHeight(texture->height() / numPlotsY) 225 , fPlotHeight(texture->height() / numPlotsY)
227 , fAtlasGeneration(kInvalidAtlasGeneration + 1) { 226 , fAtlasGeneration(kInvalidAtlasGeneration + 1) {
228 SkASSERT(fNumPlotsX * fNumPlotsY <= BulkUseTokenUpdater::kMaxPlots); 227 SkASSERT(fNumPlotsX * fNumPlotsY <= BulkUseTokenUpdater::kMaxPlots);
229 SkASSERT(fPlotWidth * fNumPlotsX == texture->width()); 228 SkASSERT(fPlotWidth * fNumPlotsX == static_cast<uint32_t>(texture->width())) ;
230 SkASSERT(fPlotHeight * fNumPlotsY == texture->height()); 229 SkASSERT(fPlotHeight * fNumPlotsY == static_cast<uint32_t>(texture->height() ));
231 230
232 // We currently do not support compressed atlases... 231 // We currently do not support compressed atlases...
233 SkASSERT(!GrPixelConfigIsCompressed(texture->desc().fConfig)); 232 SkASSERT(!GrPixelConfigIsCompressed(texture->desc().fConfig));
234 233
235 // set up allocated plots 234 // set up allocated plots
236 fBPP = GrBytesPerPixel(texture->desc().fConfig); 235 fBPP = GrBytesPerPixel(texture->desc().fConfig);
237 fPlotArray = SkNEW_ARRAY(SkAutoTUnref<BatchPlot>, (fNumPlotsX * fNumPlotsY)) ; 236 fPlotArray = SkNEW_ARRAY(SkAutoTUnref<BatchPlot>, (fNumPlotsX * fNumPlotsY)) ;
238 237
239 SkAutoTUnref<BatchPlot>* currPlot = fPlotArray; 238 SkAutoTUnref<BatchPlot>* currPlot = fPlotArray;
240 for (int y = fNumPlotsY - 1, r = 0; y >= 0; --y, ++r) { 239 for (int y = fNumPlotsY - 1, r = 0; y >= 0; --y, ++r) {
241 for (int x = fNumPlotsX - 1, c = 0; x >= 0; --x, ++c) { 240 for (int x = fNumPlotsX - 1, c = 0; x >= 0; --x, ++c) {
242 int id = r * fNumPlotsX + c; 241 uint32_t id = r * fNumPlotsX + c;
243 currPlot->reset(SkNEW(BatchPlot)); 242 currPlot->reset(SkNEW(BatchPlot));
244 (*currPlot)->init(this, texture, id, 1, x, y, fPlotWidth, fPlotHeigh t, fBPP); 243 (*currPlot)->init(this, texture, id, 1, x, y, fPlotWidth, fPlotHeigh t, fBPP);
245 244
246 // build LRU list 245 // build LRU list
247 fPlotList.addToHead(currPlot->get()); 246 fPlotList.addToHead(currPlot->get());
248 ++currPlot; 247 ++currPlot;
249 } 248 }
250 } 249 }
251 } 250 }
252 251
(...skipping 27 matching lines...) Expand all
280 plot->setLastUploadToken(batchTarget->asapToken()); 279 plot->setLastUploadToken(batchTarget->asapToken());
281 SkAutoTUnref<GrPlotUploader> uploader(SkNEW_ARGS(GrPlotUploader, (plot)) ); 280 SkAutoTUnref<GrPlotUploader> uploader(SkNEW_ARGS(GrPlotUploader, (plot)) );
282 batchTarget->upload(uploader); 281 batchTarget->upload(uploader);
283 } 282 }
284 *id = plot->id(); 283 *id = plot->id();
285 } 284 }
286 285
287 bool GrBatchAtlas::addToAtlas(AtlasID* id, GrBatchTarget* batchTarget, 286 bool GrBatchAtlas::addToAtlas(AtlasID* id, GrBatchTarget* batchTarget,
288 int width, int height, const void* image, SkIPoint 16* loc) { 287 int width, int height, const void* image, SkIPoint 16* loc) {
289 // We should already have a texture, TODO clean this up 288 // We should already have a texture, TODO clean this up
290 SkASSERT(fTexture && width <= fPlotWidth && height <= fPlotHeight); 289 SkASSERT(fTexture &&
290 static_cast<uint32_t>(width) <= fPlotWidth &&
291 static_cast<uint32_t>(height) <= fPlotHeight);
291 292
292 // now look through all allocated plots for one we can share, in Most Recent ly Refed order 293 // now look through all allocated plots for one we can share, in Most Recent ly Refed order
293 GrBatchPlotList::Iter plotIter; 294 GrBatchPlotList::Iter plotIter;
294 plotIter.init(fPlotList, GrBatchPlotList::Iter::kHead_IterStart); 295 plotIter.init(fPlotList, GrBatchPlotList::Iter::kHead_IterStart);
295 BatchPlot* plot; 296 BatchPlot* plot;
296 while ((plot = plotIter.get())) { 297 while ((plot = plotIter.get())) {
297 if (plot->addSubImage(width, height, image, loc, fBPP * width)) { 298 if (plot->addSubImage(width, height, image, loc, fBPP * width)) {
298 this->updatePlot(batchTarget, id, plot); 299 this->updatePlot(batchTarget, id, plot);
299 return true; 300 return true;
300 } 301 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 newPlot->setLastUploadToken(batchTarget->currentToken()); 346 newPlot->setLastUploadToken(batchTarget->currentToken());
346 SkAutoTUnref<GrPlotUploader> uploader(SkNEW_ARGS(GrPlotUploader, (newPlot))) ; 347 SkAutoTUnref<GrPlotUploader> uploader(SkNEW_ARGS(GrPlotUploader, (newPlot))) ;
347 batchTarget->upload(uploader); 348 batchTarget->upload(uploader);
348 *id = newPlot->id(); 349 *id = newPlot->id();
349 plot->unref(); 350 plot->unref();
350 fAtlasGeneration++; 351 fAtlasGeneration++;
351 return true; 352 return true;
352 } 353 }
353 354
354 bool GrBatchAtlas::hasID(AtlasID id) { 355 bool GrBatchAtlas::hasID(AtlasID id) {
355 int index = GetIndexFromID(id); 356 uint32_t index = GetIndexFromID(id);
356 SkASSERT(index < fNumPlotsX * fNumPlotsY); 357 SkASSERT(index < fNumPlotsX * fNumPlotsY);
357 return fPlotArray[index]->genID() == GetGenerationFromID(id); 358 return fPlotArray[index]->genID() == GetGenerationFromID(id);
358 } 359 }
359 360
360 void GrBatchAtlas::setLastUseToken(AtlasID id, BatchToken batchToken) { 361 void GrBatchAtlas::setLastUseToken(AtlasID id, BatchToken batchToken) {
361 SkASSERT(this->hasID(id)); 362 SkASSERT(this->hasID(id));
362 int index = GetIndexFromID(id); 363 uint32_t index = GetIndexFromID(id);
363 SkASSERT(index < fNumPlotsX * fNumPlotsY); 364 SkASSERT(index < fNumPlotsX * fNumPlotsY);
364 this->makeMRU(fPlotArray[index]); 365 this->makeMRU(fPlotArray[index]);
365 fPlotArray[index]->setLastUseToken(batchToken); 366 fPlotArray[index]->setLastUseToken(batchToken);
366 } 367 }
367 368
368 void GrBatchAtlas::setLastUseTokenBulk(const BulkUseTokenUpdater& updater, Batch Token batchToken) { 369 void GrBatchAtlas::setLastUseTokenBulk(const BulkUseTokenUpdater& updater, Batch Token batchToken) {
369 int count = updater.fPlotsToUpdate.count(); 370 int count = updater.fPlotsToUpdate.count();
370 for (int i = 0; i < count; i++) { 371 for (int i = 0; i < count; i++) {
371 BatchPlot* plot = fPlotArray[updater.fPlotsToUpdate[i]]; 372 BatchPlot* plot = fPlotArray[updater.fPlotsToUpdate[i]];
372 this->makeMRU(plot); 373 this->makeMRU(plot);
373 plot->setLastUseToken(batchToken); 374 plot->setLastUseToken(batchToken);
374 } 375 }
375 } 376 }
OLDNEW
« src/gpu/GrBatchAtlas.h ('K') | « src/gpu/GrBatchAtlas.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698