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 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 | 58 |
59 uint64_t atlasGeneration() const { return fAtlasGeneration; } | 59 uint64_t atlasGeneration() const { return fAtlasGeneration; } |
60 | 60 |
61 inline bool hasID(AtlasID id) { | 61 inline bool hasID(AtlasID id) { |
62 uint32_t index = GetIndexFromID(id); | 62 uint32_t index = GetIndexFromID(id); |
63 SkASSERT(index < fNumPlots); | 63 SkASSERT(index < fNumPlots); |
64 return fPlotArray[index]->genID() == GetGenerationFromID(id); | 64 return fPlotArray[index]->genID() == GetGenerationFromID(id); |
65 } | 65 } |
66 | 66 |
67 // To ensure the atlas does not evict a given entry, the client must set the
last use token | 67 // To ensure the atlas does not evict a given entry, the client must set the
last use token |
68 inline void setLastUseToken(AtlasID id, GrBatchToken batchToken) { | 68 inline void setLastUseToken(AtlasID id, GrBatchDrawToken batchToken) { |
69 SkASSERT(this->hasID(id)); | 69 SkASSERT(this->hasID(id)); |
70 uint32_t index = GetIndexFromID(id); | 70 uint32_t index = GetIndexFromID(id); |
71 SkASSERT(index < fNumPlots); | 71 SkASSERT(index < fNumPlots); |
72 this->makeMRU(fPlotArray[index]); | 72 this->makeMRU(fPlotArray[index]); |
73 fPlotArray[index]->setLastUseToken(batchToken); | 73 fPlotArray[index]->setLastUseToken(batchToken); |
74 } | 74 } |
75 | 75 |
76 inline void registerEvictionCallback(EvictionFunc func, void* userData) { | 76 inline void registerEvictionCallback(EvictionFunc func, void* userData) { |
77 EvictionData* data = fEvictionCallbacks.append(); | 77 EvictionData* data = fEvictionCallbacks.append(); |
78 data->fFunc = func; | 78 data->fFunc = func; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 } | 117 } |
118 | 118 |
119 static const int kMinItems = 4; | 119 static const int kMinItems = 4; |
120 static const int kMaxPlots = 32; | 120 static const int kMaxPlots = 32; |
121 SkSTArray<kMinItems, int, true> fPlotsToUpdate; | 121 SkSTArray<kMinItems, int, true> fPlotsToUpdate; |
122 uint32_t fPlotAlreadyUpdated; | 122 uint32_t fPlotAlreadyUpdated; |
123 | 123 |
124 friend class GrBatchAtlas; | 124 friend class GrBatchAtlas; |
125 }; | 125 }; |
126 | 126 |
127 void setLastUseTokenBulk(const BulkUseTokenUpdater& updater, GrBatchToken ba
tchToken) { | 127 void setLastUseTokenBulk(const BulkUseTokenUpdater& updater, GrBatchDrawToke
n batchToken) { |
128 int count = updater.fPlotsToUpdate.count(); | 128 int count = updater.fPlotsToUpdate.count(); |
129 for (int i = 0; i < count; i++) { | 129 for (int i = 0; i < count; i++) { |
130 BatchPlot* plot = fPlotArray[updater.fPlotsToUpdate[i]]; | 130 BatchPlot* plot = fPlotArray[updater.fPlotsToUpdate[i]]; |
131 this->makeMRU(plot); | 131 this->makeMRU(plot); |
132 plot->setLastUseToken(batchToken); | 132 plot->setLastUseToken(batchToken); |
133 } | 133 } |
134 } | 134 } |
135 | 135 |
136 static const int kGlyphMaxDim = 256; | 136 static const int kGlyphMaxDim = 256; |
137 static bool GlyphTooLargeForAtlas(int width, int height) { | 137 static bool GlyphTooLargeForAtlas(int width, int height) { |
(...skipping 22 matching lines...) Expand all Loading... |
160 } | 160 } |
161 SkDEBUGCODE(size_t bpp() const { return fBytesPerPixel; }) | 161 SkDEBUGCODE(size_t bpp() const { return fBytesPerPixel; }) |
162 | 162 |
163 bool addSubImage(int width, int height, const void* image, SkIPoint16* l
oc); | 163 bool addSubImage(int width, int height, const void* image, SkIPoint16* l
oc); |
164 | 164 |
165 // To manage the lifetime of a plot, we use two tokens. We use the last
upload token to | 165 // To manage the lifetime of a plot, we use two tokens. We use the last
upload token to |
166 // know when we can 'piggy back' uploads, ie if the last upload hasn't b
een flushed to gpu, | 166 // know when we can 'piggy back' uploads, ie if the last upload hasn't b
een flushed to gpu, |
167 // we don't need to issue a new upload even if we update the cpu backing
store. We use | 167 // we don't need to issue a new upload even if we update the cpu backing
store. We use |
168 // lastUse to determine when we can evict a plot from the cache, ie if t
he last use has | 168 // lastUse to determine when we can evict a plot from the cache, ie if t
he last use has |
169 // already flushed through the gpu then we can reuse the plot. | 169 // already flushed through the gpu then we can reuse the plot. |
170 GrBatchToken lastUploadToken() const { return fLastUpload; } | 170 GrBatchDrawToken lastUploadToken() const { return fLastUpload; } |
171 GrBatchToken lastUseToken() const { return fLastUse; } | 171 GrBatchDrawToken lastUseToken() const { return fLastUse; } |
172 void setLastUploadToken(GrBatchToken batchToken) { | 172 void setLastUploadToken(GrBatchDrawToken batchToken) { fLastUpload = bat
chToken; } |
173 SkASSERT(batchToken >= fLastUpload); | 173 void setLastUseToken(GrBatchDrawToken batchToken) { fLastUse = batchToke
n; } |
174 fLastUpload = batchToken; | |
175 } | |
176 void setLastUseToken(GrBatchToken batchToken) { | |
177 SkASSERT(batchToken >= fLastUse); | |
178 fLastUse = batchToken; | |
179 } | |
180 | 174 |
181 void uploadToTexture(GrBatchUploader::TextureUploader* uploader, GrTextu
re* texture); | 175 void uploadToTexture(GrDrawBatch::WritePixelsFn&, GrTexture* texture); |
182 void resetRects(); | 176 void resetRects(); |
183 | 177 |
184 private: | 178 private: |
185 BatchPlot(int index, uint64_t genID, int offX, int offY, int width, int
height, | 179 BatchPlot(int index, uint64_t genID, int offX, int offY, int width, int
height, |
186 GrPixelConfig config); | 180 GrPixelConfig config); |
187 | 181 |
188 ~BatchPlot() override; | 182 ~BatchPlot() override; |
189 | 183 |
190 // Create a clone of this plot. The cloned plot will take the place of t
he | 184 // Create a clone of this plot. The cloned plot will take the place of t
he |
191 // current plot in the atlas. | 185 // current plot in the atlas. |
192 BatchPlot* clone() const { | 186 BatchPlot* clone() const { |
193 return new BatchPlot(fIndex, fGenID+1, fX, fY, fWidth, fHeight, fCon
fig); | 187 return new BatchPlot(fIndex, fGenID+1, fX, fY, fWidth, fHeight, fCon
fig); |
194 } | 188 } |
195 | 189 |
196 static GrBatchAtlas::AtlasID CreateId(uint32_t index, uint64_t generatio
n) { | 190 static GrBatchAtlas::AtlasID CreateId(uint32_t index, uint64_t generatio
n) { |
197 SkASSERT(index < (1 << 16)); | 191 SkASSERT(index < (1 << 16)); |
198 SkASSERT(generation < ((uint64_t)1 << 48)); | 192 SkASSERT(generation < ((uint64_t)1 << 48)); |
199 return generation << 16 | index; | 193 return generation << 16 | index; |
200 } | 194 } |
201 | 195 |
202 GrBatchToken fLastUpload; | 196 GrBatchDrawToken fLastUpload; |
203 GrBatchToken fLastUse; | 197 GrBatchDrawToken fLastUse; |
204 | 198 |
205 const uint32_t fIndex; | 199 const uint32_t fIndex; |
206 uint64_t fGenID; | 200 uint64_t fGenID; |
207 GrBatchAtlas::AtlasID fID; | 201 GrBatchAtlas::AtlasID fID; |
208 unsigned char* fData; | 202 unsigned char* fData; |
209 const int fWidth; | 203 const int fWidth; |
210 const int fHeight; | 204 const int fHeight; |
211 const int fX; | 205 const int fX; |
212 const int fY; | 206 const int fY; |
213 GrRectanizer* fRects; | 207 GrRectanizer* fRects; |
(...skipping 25 matching lines...) Expand all Loading... |
239 if (fPlotList.head() == plot) { | 233 if (fPlotList.head() == plot) { |
240 return; | 234 return; |
241 } | 235 } |
242 | 236 |
243 fPlotList.remove(plot); | 237 fPlotList.remove(plot); |
244 fPlotList.addToHead(plot); | 238 fPlotList.addToHead(plot); |
245 } | 239 } |
246 | 240 |
247 inline void processEviction(AtlasID); | 241 inline void processEviction(AtlasID); |
248 | 242 |
249 friend class GrPlotUploader; // to access GrBatchPlot | |
250 | |
251 GrTexture* fTexture; | 243 GrTexture* fTexture; |
252 SkDEBUGCODE(uint32_t fNumPlots;) | 244 SkDEBUGCODE(uint32_t fNumPlots;) |
253 | 245 |
254 uint64_t fAtlasGeneration; | 246 uint64_t fAtlasGeneration; |
255 | 247 |
256 struct EvictionData { | 248 struct EvictionData { |
257 EvictionFunc fFunc; | 249 EvictionFunc fFunc; |
258 void* fData; | 250 void* fData; |
259 }; | 251 }; |
260 | 252 |
261 SkTDArray<EvictionData> fEvictionCallbacks; | 253 SkTDArray<EvictionData> fEvictionCallbacks; |
262 // allocated array of GrBatchPlots | 254 // allocated array of GrBatchPlots |
263 SkAutoTUnref<BatchPlot>* fPlotArray; | 255 SkAutoTUnref<BatchPlot>* fPlotArray; |
264 // LRU list of GrPlots (MRU at head - LRU at tail) | 256 // LRU list of GrPlots (MRU at head - LRU at tail) |
265 GrBatchPlotList fPlotList; | 257 GrBatchPlotList fPlotList; |
266 }; | 258 }; |
267 | 259 |
268 #endif | 260 #endif |
OLD | NEW |