| 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 "batches/GrDrawBatch.h" |
| 12 #include "SkPoint.h" | 13 #include "SkPoint.h" |
| 13 #include "SkTDArray.h" | 14 #include "SkTDArray.h" |
| 14 #include "SkTInternalLList.h" | 15 #include "SkTInternalLList.h" |
| 15 | 16 |
| 16 class BatchPlot; | 17 class BatchPlot; |
| 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; | |
| 25 // An AtlasID is an opaque handle which callers can use to determine if the
atlas contains | 24 // An AtlasID is an opaque handle which callers can use to determine if the
atlas contains |
| 26 // a specific piece of data | 25 // a specific piece of data |
| 27 typedef uint64_t AtlasID; | 26 typedef uint64_t AtlasID; |
| 28 static const uint32_t kInvalidAtlasID = 0; | 27 static const uint32_t kInvalidAtlasID = 0; |
| 29 static const uint64_t kInvalidAtlasGeneration = 0; | 28 static const uint64_t kInvalidAtlasGeneration = 0; |
| 30 | 29 |
| 31 // A function pointer for use as a callback during eviction. Whenever GrBat
chAtlas evicts a | 30 // 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 | 31 // specific AtlasID, it will call all of the registered listeners so they ca
n optionally process |
| 33 // the eviction | 32 // the eviction |
| 34 typedef void (*EvictionFunc)(GrBatchAtlas::AtlasID, void*); | 33 typedef void (*EvictionFunc)(GrBatchAtlas::AtlasID, void*); |
| 35 | 34 |
| 36 GrBatchAtlas(GrTexture*, int numPlotsX, int numPlotsY); | 35 GrBatchAtlas(GrTexture*, int numPlotsX, int numPlotsY); |
| 37 ~GrBatchAtlas(); | 36 ~GrBatchAtlas(); |
| 38 | 37 |
| 39 // Adds a width x height subimage to the atlas. Upon success it returns | 38 // Adds a width x height subimage to the atlas. Upon success it returns |
| 40 // the containing GrPlot and absolute location in the backing texture. | 39 // the containing GrPlot and absolute location in the backing texture. |
| 41 // NULL is returned if the subimage cannot fit in the atlas. | 40 // 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. | 41 // If provided, the image data will be written to the CPU-side backing bitma
p. |
| 43 // NOTE: If the client intends to refer to the atlas, they should immediatel
y call 'setUseToken' | 42 // NOTE: If the client intends to refer to the atlas, they should immediatel
y call 'setUseToken' |
| 44 // with the currentToken from the batch target, otherwise the next call to a
ddToAtlas might | 43 // with the currentToken from the batch target, otherwise the next call to a
ddToAtlas might |
| 45 // cause an eviction | 44 // cause an eviction |
| 46 bool addToAtlas(AtlasID*, GrBatchTarget*, int width, int height, const void*
image, | 45 bool addToAtlas(AtlasID*, GrDrawBatch::Target*, int width, int height, const
void* image, |
| 47 SkIPoint16* loc); | 46 SkIPoint16* loc); |
| 48 | 47 |
| 49 GrTexture* getTexture() const { return fTexture; } | 48 GrTexture* getTexture() const { return fTexture; } |
| 50 | 49 |
| 51 uint64_t atlasGeneration() const { return fAtlasGeneration; } | 50 uint64_t atlasGeneration() const { return fAtlasGeneration; } |
| 52 bool hasID(AtlasID id); | 51 bool hasID(AtlasID id); |
| 53 | 52 |
| 54 // To ensure the atlas does not evict a given entry, the client must set the
last use token | 53 // To ensure the atlas does not evict a given entry, the client must set the
last use token |
| 55 void setLastUseToken(AtlasID id, BatchToken batchToken); | 54 void setLastUseToken(AtlasID id, GrBatchToken batchToken); |
| 56 void registerEvictionCallback(EvictionFunc func, void* userData) { | 55 void registerEvictionCallback(EvictionFunc func, void* userData) { |
| 57 EvictionData* data = fEvictionCallbacks.append(); | 56 EvictionData* data = fEvictionCallbacks.append(); |
| 58 data->fFunc = func; | 57 data->fFunc = func; |
| 59 data->fData = userData; | 58 data->fData = userData; |
| 60 } | 59 } |
| 61 | 60 |
| 62 /* | 61 /* |
| 63 * A class which can be handed back to GrBatchAtlas for updating in bulk las
t use tokens. The | 62 * A class which can be handed back to GrBatchAtlas for updating in bulk las
t use tokens. The |
| 64 * current max number of plots the GrBatchAtlas can handle is 32, if in the
future this is | 63 * current max number of plots the GrBatchAtlas can handle is 32, if in the
future this is |
| 65 * insufficient then we can move to a 64 bit int | 64 * insufficient then we can move to a 64 bit int |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 } | 96 } |
| 98 | 97 |
| 99 static const int kMinItems = 4; | 98 static const int kMinItems = 4; |
| 100 static const int kMaxPlots = 32; | 99 static const int kMaxPlots = 32; |
| 101 SkSTArray<kMinItems, int, true> fPlotsToUpdate; | 100 SkSTArray<kMinItems, int, true> fPlotsToUpdate; |
| 102 uint32_t fPlotAlreadyUpdated; | 101 uint32_t fPlotAlreadyUpdated; |
| 103 | 102 |
| 104 friend class GrBatchAtlas; | 103 friend class GrBatchAtlas; |
| 105 }; | 104 }; |
| 106 | 105 |
| 107 void setLastUseTokenBulk(const BulkUseTokenUpdater& reffer, BatchToken); | 106 void setLastUseTokenBulk(const BulkUseTokenUpdater& reffer, GrBatchToken); |
| 108 | 107 |
| 109 static const int kGlyphMaxDim = 256; | 108 static const int kGlyphMaxDim = 256; |
| 110 static bool GlyphTooLargeForAtlas(int width, int height) { | 109 static bool GlyphTooLargeForAtlas(int width, int height) { |
| 111 return width > kGlyphMaxDim || height > kGlyphMaxDim; | 110 return width > kGlyphMaxDim || height > kGlyphMaxDim; |
| 112 } | 111 } |
| 113 | 112 |
| 114 private: | 113 private: |
| 115 static uint32_t GetIndexFromID(AtlasID id) { | 114 static uint32_t GetIndexFromID(AtlasID id) { |
| 116 return id & 0xffff; | 115 return id & 0xffff; |
| 117 } | 116 } |
| 118 | 117 |
| 119 // top 48 bits are reserved for the generation ID | 118 // top 48 bits are reserved for the generation ID |
| 120 static uint64_t GetGenerationFromID(AtlasID id) { | 119 static uint64_t GetGenerationFromID(AtlasID id) { |
| 121 return (id >> 16) & 0xffffffffffff; | 120 return (id >> 16) & 0xffffffffffff; |
| 122 } | 121 } |
| 123 | 122 |
| 124 inline void updatePlot(GrBatchTarget*, AtlasID*, BatchPlot*); | 123 inline void updatePlot(GrDrawBatch::Target*, AtlasID*, BatchPlot*); |
| 125 | 124 |
| 126 inline void makeMRU(BatchPlot* plot); | 125 inline void makeMRU(BatchPlot* plot); |
| 127 | 126 |
| 128 inline void processEviction(AtlasID); | 127 inline void processEviction(AtlasID); |
| 129 | 128 |
| 130 GrTexture* fTexture; | 129 GrTexture* fTexture; |
| 131 uint32_t fNumPlotsX; | 130 uint32_t fNumPlotsX; |
| 132 uint32_t fNumPlotsY; | 131 uint32_t fNumPlotsY; |
| 133 uint32_t fPlotWidth; | 132 uint32_t fPlotWidth; |
| 134 uint32_t fPlotHeight; | 133 uint32_t fPlotHeight; |
| 135 size_t fBPP; | 134 size_t fBPP; |
| 136 uint64_t fAtlasGeneration; | 135 uint64_t fAtlasGeneration; |
| 137 | 136 |
| 138 struct EvictionData { | 137 struct EvictionData { |
| 139 EvictionFunc fFunc; | 138 EvictionFunc fFunc; |
| 140 void* fData; | 139 void* fData; |
| 141 }; | 140 }; |
| 142 | 141 |
| 143 SkTDArray<EvictionData> fEvictionCallbacks; | 142 SkTDArray<EvictionData> fEvictionCallbacks; |
| 144 // allocated array of GrBatchPlots | 143 // allocated array of GrBatchPlots |
| 145 SkAutoTUnref<BatchPlot>* fPlotArray; | 144 SkAutoTUnref<BatchPlot>* fPlotArray; |
| 146 // LRU list of GrPlots (MRU at head - LRU at tail) | 145 // LRU list of GrPlots (MRU at head - LRU at tail) |
| 147 GrBatchPlotList fPlotList; | 146 GrBatchPlotList fPlotList; |
| 148 }; | 147 }; |
| 149 | 148 |
| 150 #endif | 149 #endif |
| OLD | NEW |