Chromium Code Reviews| 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 #ifndef GrBatchAtlas_DEFINED | 8 #ifndef GrBatchAtlas_DEFINED |
| 9 #define GrBatchAtlas_DEFINED | 9 #define GrBatchAtlas_DEFINED |
| 10 | 10 |
| 11 #include "GrTexture.h" | 11 #include "GrTexture.h" |
| 12 #include "SkPoint.h" | 12 #include "SkPoint.h" |
| 13 #include "SkTDArray.h" | 13 #include "SkTDArray.h" |
| 14 #include "SkTInternalLList.h" | 14 #include "SkTInternalLList.h" |
| 15 | 15 |
| 16 class BatchPlot; | 16 class BatchPlot; |
| 17 class GrBatchTarget; | 17 class GrBatchTarget; |
| 18 class GrRectanizer; | 18 class GrRectanizer; |
| 19 | 19 |
| 20 typedef SkTInternalLList<BatchPlot> GrBatchPlotList; | 20 typedef SkTInternalLList<BatchPlot> GrBatchPlotList; |
| 21 | 21 |
| 22 class GrBatchAtlas { | 22 class GrBatchAtlas { |
| 23 public: | 23 public: |
| 24 typedef uint64_t BatchToken; | 24 typedef uint64_t BatchToken; |
| 25 // An AtlasID is an opaque handle which callers can use to determine if the atlas contains | 25 // An AtlasID is an opaque handle which callers can use to determine if the atlas contains |
|
bsalomon
2015/04/01 20:21:31
I think this comment should be updated to indicate
| |
| 26 // a specific piece of data | 26 // a specific piece of data |
| 27 typedef uint32_t AtlasID; | 27 typedef uint32_t AtlasID; |
| 28 static const uint32_t kInvalidAtlasID = 0; | 28 static const uint32_t kInvalidAtlasID = 0; |
| 29 static const uint64_t kInvalidAtlasGeneration = 0; | 29 static const uint64_t kInvalidAtlasGeneration = 0; |
| 30 | 30 |
| 31 // A function pointer for use as a callback during eviction. Whenever GrBat chAtlas evicts a | 31 // A function pointer for use as a callback during eviction. Whenever GrBat chAtlas evicts a |
| 32 // specific AtlasID, it will call all of the registered listeners so they ca n optionally process | 32 // specific AtlasID, it will call all of the registered listeners so they ca n optionally process |
| 33 // the eviction | 33 // the eviction |
| 34 typedef void (*EvictionFunc)(GrBatchAtlas::AtlasID, void*); | 34 typedef void (*EvictionFunc)(GrBatchAtlas::AtlasID, void*); |
| 35 | 35 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 47 | 47 |
| 48 uint64_t atlasGeneration() const { return fAtlasGeneration; } | 48 uint64_t atlasGeneration() const { return fAtlasGeneration; } |
| 49 bool hasID(AtlasID id); | 49 bool hasID(AtlasID id); |
| 50 void setLastRefToken(AtlasID id, BatchToken batchToken); | 50 void setLastRefToken(AtlasID id, BatchToken batchToken); |
| 51 void registerEvictionCallback(EvictionFunc func, void* userData) { | 51 void registerEvictionCallback(EvictionFunc func, void* userData) { |
| 52 EvictionData* data = fEvictionCallbacks.append(); | 52 EvictionData* data = fEvictionCallbacks.append(); |
| 53 data->fFunc = func; | 53 data->fFunc = func; |
| 54 data->fData = userData; | 54 data->fData = userData; |
| 55 } | 55 } |
| 56 | 56 |
| 57 /* | |
| 58 * A class which can be handed back to GrBatchAtlas for updating in bulk las t ref tokens. | |
| 59 * NOTE: This class assumes you want to set the same BatchToken for each plo t. | |
| 60 */ | |
| 61 class BulkTokenReffer { | |
|
bsalomon
2015/04/01 20:21:31
I find the use of "Ref" confusing in this class. I
| |
| 62 public: | |
| 63 BulkTokenReffer() : fPlotAlreadyUpdated(0), fBatchToken(0) {} | |
| 64 void setRefToken(GrBatchAtlas* atlas, AtlasID id, BatchToken token) { | |
|
bsalomon
2015/04/01 20:21:31
Does this mean it sets here and when setLastRefTok
| |
| 65 int index = GrBatchAtlas::GetIndexFromID(id); | |
| 66 if (!this->find(index)) { | |
| 67 this->set(index); | |
| 68 atlas->setLastRefTokenInternal(index, token); | |
| 69 fBatchToken = token; | |
| 70 } | |
| 71 } | |
| 72 | |
| 73 void reset() { | |
| 74 fPlotsToUpdate.reset(); | |
| 75 fPlotAlreadyUpdated = 0; | |
| 76 } | |
| 77 | |
| 78 private: | |
| 79 bool find(int index) const { | |
| 80 return (fPlotAlreadyUpdated >> index) & 1; | |
| 81 } | |
| 82 void set(int index) { | |
| 83 SkASSERT(!this->find(index)); | |
| 84 fPlotAlreadyUpdated = fPlotAlreadyUpdated | (1 << index); | |
| 85 fPlotsToUpdate.push_back(index); | |
| 86 } | |
| 87 | |
| 88 static const int kMaxPlots = 32; | |
| 89 uint32_t fPlotAlreadyUpdated; | |
| 90 BatchToken fBatchToken; | |
| 91 SkSTArray<4, int, true> fPlotsToUpdate; | |
| 92 | |
| 93 friend class GrBatchAtlas; | |
| 94 }; | |
| 95 | |
| 96 void setLastRefTokenBulk(const BulkTokenReffer& reffer); | |
| 97 | |
| 57 private: | 98 private: |
| 58 int getIndexFromID(AtlasID id) { | 99 static int GetIndexFromID(AtlasID id) { |
| 59 return id & 0xffff; | 100 return id & 0xffff; |
| 60 } | 101 } |
| 61 | 102 |
| 62 int getGenerationFromID(AtlasID id) { | 103 static int GetGenerationFromID(AtlasID id) { |
| 63 return (id >> 16) & 0xffff; | 104 return (id >> 16) & 0xffff; |
| 64 } | 105 } |
| 65 | 106 |
| 66 inline void updatePlot(GrBatchTarget*, AtlasID*, BatchPlot*); | 107 inline void updatePlot(GrBatchTarget*, AtlasID*, BatchPlot*); |
| 67 | 108 |
| 68 inline void makeMRU(BatchPlot* plot); | 109 inline void makeMRU(BatchPlot* plot); |
| 69 | 110 |
| 70 inline void processEviction(AtlasID); | 111 inline void processEviction(AtlasID); |
| 71 | 112 |
| 113 void setLastRefTokenInternal(int index, BatchToken); | |
| 114 | |
| 72 GrTexture* fTexture; | 115 GrTexture* fTexture; |
| 73 int fNumPlotsX; | 116 int fNumPlotsX; |
| 74 int fNumPlotsY; | 117 int fNumPlotsY; |
| 75 int fPlotWidth; | 118 int fPlotWidth; |
| 76 int fPlotHeight; | 119 int fPlotHeight; |
| 77 size_t fBPP; | 120 size_t fBPP; |
| 78 uint64_t fAtlasGeneration; | 121 uint64_t fAtlasGeneration; |
| 79 | 122 |
| 80 struct EvictionData { | 123 struct EvictionData { |
| 81 EvictionFunc fFunc; | 124 EvictionFunc fFunc; |
| 82 void* fData; | 125 void* fData; |
| 83 }; | 126 }; |
| 84 | 127 |
| 85 SkTDArray<EvictionData> fEvictionCallbacks; | 128 SkTDArray<EvictionData> fEvictionCallbacks; |
| 86 // allocated array of GrBatchPlots | 129 // allocated array of GrBatchPlots |
| 87 SkAutoTUnref<BatchPlot>* fPlotArray; | 130 SkAutoTUnref<BatchPlot>* fPlotArray; |
| 88 // LRU list of GrPlots (MRU at head - LRU at tail) | 131 // LRU list of GrPlots (MRU at head - LRU at tail) |
| 89 GrBatchPlotList fPlotList; | 132 GrBatchPlotList fPlotList; |
| 133 | |
| 134 friend class BulkTokenReffer; | |
| 90 }; | 135 }; |
| 91 | 136 |
| 92 #endif | 137 #endif |
| OLD | NEW |