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 #include "batches/GrDrawBatch.h" | 16 #include "batches/GrDrawBatch.h" |
17 | 17 |
18 class GrRectanizer; | 18 class GrRectanizer; |
| 19 class GrResourceProvider; |
| 20 class GrBuffer; |
19 | 21 |
20 struct GrBatchAtlasConfig { | 22 struct GrBatchAtlasConfig { |
21 int numPlotsX() const { return fWidth / fPlotWidth; } | 23 int numPlotsX() const { return fWidth / fPlotWidth; } |
22 int numPlotsY() const { return fHeight / fPlotWidth; } | 24 int numPlotsY() const { return fHeight / fPlotWidth; } |
23 int fWidth; | 25 int fWidth; |
24 int fHeight; | 26 int fHeight; |
25 int fLog2Width; | 27 int fLog2Width; |
26 int fLog2Height; | 28 int fLog2Height; |
27 int fPlotWidth; | 29 int fPlotWidth; |
28 int fPlotHeight; | 30 int fPlotHeight; |
29 }; | 31 }; |
30 | 32 |
31 class GrBatchAtlas { | 33 class GrBatchAtlas { |
32 public: | 34 public: |
33 // An AtlasID is an opaque handle which callers can use to determine if the
atlas contains | 35 // An AtlasID is an opaque handle which callers can use to determine if the
atlas contains |
34 // a specific piece of data | 36 // a specific piece of data |
35 typedef uint64_t AtlasID; | 37 typedef uint64_t AtlasID; |
36 static const uint32_t kInvalidAtlasID = 0; | 38 static const uint32_t kInvalidAtlasID = 0; |
37 static const uint64_t kInvalidAtlasGeneration = 0; | 39 static const uint64_t kInvalidAtlasGeneration = 0; |
38 | 40 |
39 // A function pointer for use as a callback during eviction. Whenever GrBat
chAtlas evicts a | 41 // A function pointer for use as a callback during eviction. Whenever GrBat
chAtlas evicts a |
40 // specific AtlasID, it will call all of the registered listeners so they ca
n optionally process | 42 // specific AtlasID, it will call all of the registered listeners so they ca
n optionally process |
41 // the eviction | 43 // the eviction |
42 typedef void (*EvictionFunc)(GrBatchAtlas::AtlasID, void*); | 44 typedef void (*EvictionFunc)(GrBatchAtlas::AtlasID, void*); |
43 | 45 |
44 GrBatchAtlas(GrTexture*, int numPlotsX, int numPlotsY); | 46 GrBatchAtlas(GrResourceProvider*, GrTexture*, int numPlotsX, int numPlotsY); |
45 ~GrBatchAtlas(); | 47 ~GrBatchAtlas(); |
46 | 48 |
47 // Adds a width x height subimage to the atlas. Upon success it returns | 49 // Adds a width x height subimage to the atlas. Upon success it returns |
48 // the containing GrPlot and absolute location in the backing texture. | 50 // the containing GrPlot and absolute location in the backing texture. |
49 // nullptr is returned if the subimage cannot fit in the atlas. | 51 // nullptr is returned if the subimage cannot fit in the atlas. |
50 // If provided, the image data will be written to the CPU-side backing bitma
p. | 52 // If provided, the image data will be written to the CPU-side backing bitma
p. |
51 // NOTE: If the client intends to refer to the atlas, they should immediatel
y call 'setUseToken' | 53 // NOTE: If the client intends to refer to the atlas, they should immediatel
y call 'setUseToken' |
52 // with the currentToken from the batch target, otherwise the next call to a
ddToAtlas might | 54 // with the currentToken from the batch target, otherwise the next call to a
ddToAtlas might |
53 // cause an eviction | 55 // cause an eviction |
54 bool addToAtlas(AtlasID*, GrDrawBatch::Target*, int width, int height, const
void* image, | 56 bool addToAtlas(AtlasID*, GrDrawBatch::Target*, int width, int height, const
void* image, |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 // To manage the lifetime of a plot, we use two tokens. We use the last
upload token to | 167 // 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, | 168 // 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 | 169 // 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 | 170 // 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. | 171 // already flushed through the gpu then we can reuse the plot. |
170 GrBatchDrawToken lastUploadToken() const { return fLastUpload; } | 172 GrBatchDrawToken lastUploadToken() const { return fLastUpload; } |
171 GrBatchDrawToken lastUseToken() const { return fLastUse; } | 173 GrBatchDrawToken lastUseToken() const { return fLastUse; } |
172 void setLastUploadToken(GrBatchDrawToken batchToken) { fLastUpload = bat
chToken; } | 174 void setLastUploadToken(GrBatchDrawToken batchToken) { fLastUpload = bat
chToken; } |
173 void setLastUseToken(GrBatchDrawToken batchToken) { fLastUse = batchToke
n; } | 175 void setLastUseToken(GrBatchDrawToken batchToken) { fLastUse = batchToke
n; } |
174 | 176 |
175 void uploadToTexture(GrDrawBatch::WritePixelsFn&, GrTexture* texture); | 177 void uploadToTexture(GrDrawBatch::WritePixelsFn&, GrDrawBatch::TransferP
ixelsFn&, |
| 178 GrTexture* texture); |
176 void resetRects(); | 179 void resetRects(); |
177 | 180 |
178 private: | 181 private: |
179 BatchPlot(int index, uint64_t genID, int offX, int offY, int width, int
height, | 182 BatchPlot(int index, uint64_t genID, int offX, int offY, int width, int
height, |
180 GrPixelConfig config); | 183 GrPixelConfig config, GrResourceProvider* rp); |
181 | 184 |
182 ~BatchPlot() override; | 185 ~BatchPlot() override; |
183 | 186 |
184 // Create a clone of this plot. The cloned plot will take the place of t
he | 187 // Create a clone of this plot. The cloned plot will take the place of t
he |
185 // current plot in the atlas. | 188 // current plot in the atlas. |
186 BatchPlot* clone() const { | 189 BatchPlot* clone() const { |
187 return new BatchPlot(fIndex, fGenID+1, fX, fY, fWidth, fHeight, fCon
fig); | 190 return new BatchPlot(fIndex, fGenID+1, fX, fY, fWidth, fHeight, fCon
fig, |
| 191 fResourceProvider); |
188 } | 192 } |
189 | 193 |
190 static GrBatchAtlas::AtlasID CreateId(uint32_t index, uint64_t generatio
n) { | 194 static GrBatchAtlas::AtlasID CreateId(uint32_t index, uint64_t generatio
n) { |
191 SkASSERT(index < (1 << 16)); | 195 SkASSERT(index < (1 << 16)); |
192 SkASSERT(generation < ((uint64_t)1 << 48)); | 196 SkASSERT(generation < ((uint64_t)1 << 48)); |
193 return generation << 16 | index; | 197 return generation << 16 | index; |
194 } | 198 } |
195 | 199 |
| 200 // used to create transfer buffers |
| 201 GrResourceProvider* fResourceProvider; |
196 GrBatchDrawToken fLastUpload; | 202 GrBatchDrawToken fLastUpload; |
197 GrBatchDrawToken fLastUse; | 203 GrBatchDrawToken fLastUse; |
198 | 204 |
199 const uint32_t fIndex; | 205 const uint32_t fIndex; |
200 uint64_t fGenID; | 206 uint64_t fGenID; |
201 GrBatchAtlas::AtlasID fID; | 207 GrBatchAtlas::AtlasID fID; |
202 unsigned char* fData; | 208 unsigned char* fDataPtr; |
| 209 GrBuffer* fTransferBuffer; |
| 210 GrFence fTransferFence; |
203 const int fWidth; | 211 const int fWidth; |
204 const int fHeight; | 212 const int fHeight; |
205 const int fX; | 213 const int fX; |
206 const int fY; | 214 const int fY; |
207 GrRectanizer* fRects; | 215 GrRectanizer* fRects; |
208 const SkIPoint16 fOffset; // the offset of the plot in the b
acking texture | 216 const SkIPoint16 fOffset; // the offset of the plot in the b
acking texture |
209 const GrPixelConfig fConfig; | 217 const GrPixelConfig fConfig; |
210 const size_t fBytesPerPixel; | 218 const size_t fBytesPerPixel; |
211 SkIRect fDirtyRect; | 219 SkIRect fDirtyRect; |
212 SkDEBUGCODE(bool fDirty;) | 220 SkDEBUGCODE(bool fDirty;) |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 }; | 261 }; |
254 | 262 |
255 SkTDArray<EvictionData> fEvictionCallbacks; | 263 SkTDArray<EvictionData> fEvictionCallbacks; |
256 // allocated array of GrBatchPlots | 264 // allocated array of GrBatchPlots |
257 SkAutoTUnref<BatchPlot>* fPlotArray; | 265 SkAutoTUnref<BatchPlot>* fPlotArray; |
258 // LRU list of GrPlots (MRU at head - LRU at tail) | 266 // LRU list of GrPlots (MRU at head - LRU at tail) |
259 GrBatchPlotList fPlotList; | 267 GrBatchPlotList fPlotList; |
260 }; | 268 }; |
261 | 269 |
262 #endif | 270 #endif |
OLD | NEW |