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 |
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; |
| 29 static const uint32_t kInvalidAtlasGeneration = 0; |
28 | 30 |
29 // 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 |
30 // 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 |
31 // the eviction | 33 // the eviction |
32 typedef void (*EvictionFunc)(GrBatchAtlas::AtlasID, void*); | 34 typedef void (*EvictionFunc)(GrBatchAtlas::AtlasID, void*); |
33 | 35 |
34 GrBatchAtlas(GrTexture*, int numPlotsX, int numPlotsY); | 36 GrBatchAtlas(GrTexture*, int numPlotsX, int numPlotsY); |
35 ~GrBatchAtlas(); | 37 ~GrBatchAtlas(); |
36 | 38 |
37 // Adds a width x height subimage to the atlas. Upon success it returns | 39 // Adds a width x height subimage to the atlas. Upon success it returns |
38 // the containing GrPlot and absolute location in the backing texture. | 40 // the containing GrPlot and absolute location in the backing texture. |
39 // NULL is returned if the subimage cannot fit in the atlas. | 41 // NULL is returned if the subimage cannot fit in the atlas. |
40 // If provided, the image data will be written to the CPU-side backing bitma
p. | 42 // If provided, the image data will be written to the CPU-side backing bitma
p. |
41 bool addToAtlas(AtlasID*, GrBatchTarget*, int width, int height, const void*
image, | 43 bool addToAtlas(AtlasID*, GrBatchTarget*, int width, int height, const void*
image, |
42 SkIPoint16* loc); | 44 SkIPoint16* loc); |
43 | 45 |
44 GrTexture* getTexture() const { return fTexture; } | 46 GrTexture* getTexture() const { return fTexture; } |
45 | 47 |
| 48 uint32_t atlasGeneration() const { return fAtlasGeneration; } |
46 bool hasID(AtlasID id); | 49 bool hasID(AtlasID id); |
47 void setLastRefToken(AtlasID id, BatchToken batchToken); | 50 void setLastRefToken(AtlasID id, BatchToken batchToken); |
48 void registerEvictionCallback(EvictionFunc func, void* userData) { | 51 void registerEvictionCallback(EvictionFunc func, void* userData) { |
49 EvictionData* data = fEvictionCallbacks.append(); | 52 EvictionData* data = fEvictionCallbacks.append(); |
50 data->fFunc = func; | 53 data->fFunc = func; |
51 data->fData = userData; | 54 data->fData = userData; |
52 } | 55 } |
53 | 56 |
54 private: | 57 private: |
55 int getIndexFromID(AtlasID id) { | 58 int getIndexFromID(AtlasID id) { |
56 return id & 0xffff; | 59 return id & 0xffff; |
57 } | 60 } |
58 | 61 |
59 int getGenerationFromID(AtlasID id) { | 62 int getGenerationFromID(AtlasID id) { |
60 return (id >> 16) & 0xffff; | 63 return (id >> 16) & 0xffff; |
61 } | 64 } |
62 | 65 |
63 inline void updatePlot(GrBatchTarget*, AtlasID*, BatchPlot*); | 66 inline void updatePlot(GrBatchTarget*, AtlasID*, BatchPlot*); |
64 | 67 |
65 inline void makeMRU(BatchPlot* plot); | 68 inline void makeMRU(BatchPlot* plot); |
66 | 69 |
67 inline void processEviction(AtlasID); | 70 inline void processEviction(AtlasID); |
68 | 71 |
69 GrTexture* fTexture; | 72 GrTexture* fTexture; |
70 int fNumPlotsX; | 73 int fNumPlotsX; |
71 int fNumPlotsY; | 74 int fNumPlotsY; |
72 int fPlotWidth; | 75 int fPlotWidth; |
73 int fPlotHeight; | 76 int fPlotHeight; |
74 size_t fBPP; | 77 size_t fBPP; |
| 78 uint32_t fAtlasGeneration; |
75 | 79 |
76 struct EvictionData { | 80 struct EvictionData { |
77 EvictionFunc fFunc; | 81 EvictionFunc fFunc; |
78 void* fData; | 82 void* fData; |
79 }; | 83 }; |
80 | 84 |
81 SkTDArray<EvictionData> fEvictionCallbacks; | 85 SkTDArray<EvictionData> fEvictionCallbacks; |
82 // allocated array of GrBatchPlots | 86 // allocated array of GrBatchPlots |
83 SkAutoTUnref<BatchPlot>* fPlotArray; | 87 SkAutoTUnref<BatchPlot>* fPlotArray; |
84 // LRU list of GrPlots (MRU at head - LRU at tail) | 88 // LRU list of GrPlots (MRU at head - LRU at tail) |
85 GrBatchPlotList fPlotList; | 89 GrBatchPlotList fPlotList; |
86 }; | 90 }; |
87 | 91 |
88 #endif | 92 #endif |
OLD | NEW |