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