Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(799)

Side by Side Diff: src/gpu/GrBatchAtlas.h

Issue 1050113004: Adding bulk plot reffer to cached textblobs (Closed) Base URL: https://skia.googlesource.com/skia.git@atlastext
Patch Set: cleanup Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 22 matching lines...) Expand all
33 // the eviction 33 // the eviction
34 typedef void (*EvictionFunc)(GrBatchAtlas::AtlasID, void*); 34 typedef void (*EvictionFunc)(GrBatchAtlas::AtlasID, void*);
35 35
36 GrBatchAtlas(GrTexture*, int numPlotsX, int numPlotsY); 36 GrBatchAtlas(GrTexture*, int numPlotsX, int numPlotsY);
37 ~GrBatchAtlas(); 37 ~GrBatchAtlas();
38 38
39 // 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
40 // the containing GrPlot and absolute location in the backing texture. 40 // the containing GrPlot and absolute location in the backing texture.
41 // NULL is returned if the subimage cannot fit in the atlas. 41 // 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. 42 // 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'
44 // with the currentToken from the batch target, otherwise the next call to a ddToAtlas might
45 // cause an eviction
43 bool addToAtlas(AtlasID*, GrBatchTarget*, int width, int height, const void* image, 46 bool addToAtlas(AtlasID*, GrBatchTarget*, int width, int height, const void* image,
44 SkIPoint16* loc); 47 SkIPoint16* loc);
45 48
46 GrTexture* getTexture() const { return fTexture; } 49 GrTexture* getTexture() const { return fTexture; }
47 50
48 uint64_t atlasGeneration() const { return fAtlasGeneration; } 51 uint64_t atlasGeneration() const { return fAtlasGeneration; }
49 bool hasID(AtlasID id); 52 bool hasID(AtlasID id);
50 void setLastRefToken(AtlasID id, BatchToken batchToken); 53
54 // 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);
51 void registerEvictionCallback(EvictionFunc func, void* userData) { 56 void registerEvictionCallback(EvictionFunc func, void* userData) {
52 EvictionData* data = fEvictionCallbacks.append(); 57 EvictionData* data = fEvictionCallbacks.append();
53 data->fFunc = func; 58 data->fFunc = func;
54 data->fData = userData; 59 data->fData = userData;
55 } 60 }
56 61
62 /*
63 * A class which can be handed back to GrBatchAtlas for updating in bulk las t use tokens.
robertphillips 2015/04/07 12:18:33 Maybe a comment re the maxplots limit (e.g., for t
64 */
65 class BulkUseTokenUpdater {
66 public:
67 BulkUseTokenUpdater() : fPlotAlreadyUpdated(0) {}
68 void add(AtlasID id) {
69 int index = GrBatchAtlas::GetIndexFromID(id);
70 if (!this->find(index)) {
71 this->set(index);
72 }
73 }
74
75 void reset() {
76 fPlotsToUpdate.reset();
77 fPlotAlreadyUpdated = 0;
78 }
79
80 private:
81 bool find(int index) const {
robertphillips 2015/04/07 12:18:33 SkASSERT(index < kMaxPlots); ?
82 return (fPlotAlreadyUpdated >> index) & 1;
83 }
84 void set(int index) {
85 SkASSERT(!this->find(index));
86 fPlotAlreadyUpdated = fPlotAlreadyUpdated | (1 << index);
87 fPlotsToUpdate.push_back(index);
88 }
89
90 static const int kMaxPlots = 32;
91 uint32_t fPlotAlreadyUpdated;
92 SkSTArray<4, int, true> fPlotsToUpdate;
93
94 friend class GrBatchAtlas;
95 };
96
97 void setLastUseTokenBulk(const BulkUseTokenUpdater& reffer, BatchToken);
98
57 private: 99 private:
58 int getIndexFromID(AtlasID id) { 100 static int GetIndexFromID(AtlasID id) {
59 return id & 0xffff; 101 return id & 0xffff;
60 } 102 }
61 103
62 int getGenerationFromID(AtlasID id) { 104 static int GetGenerationFromID(AtlasID id) {
63 return (id >> 16) & 0xffff; 105 return (id >> 16) & 0xffff;
64 } 106 }
65 107
66 inline void updatePlot(GrBatchTarget*, AtlasID*, BatchPlot*); 108 inline void updatePlot(GrBatchTarget*, AtlasID*, BatchPlot*);
67 109
68 inline void makeMRU(BatchPlot* plot); 110 inline void makeMRU(BatchPlot* plot);
69 111
70 inline void processEviction(AtlasID); 112 inline void processEviction(AtlasID);
71 113
72 GrTexture* fTexture; 114 GrTexture* fTexture;
(...skipping 10 matching lines...) Expand all
83 }; 125 };
84 126
85 SkTDArray<EvictionData> fEvictionCallbacks; 127 SkTDArray<EvictionData> fEvictionCallbacks;
86 // allocated array of GrBatchPlots 128 // allocated array of GrBatchPlots
87 SkAutoTUnref<BatchPlot>* fPlotArray; 129 SkAutoTUnref<BatchPlot>* fPlotArray;
88 // LRU list of GrPlots (MRU at head - LRU at tail) 130 // LRU list of GrPlots (MRU at head - LRU at tail)
89 GrBatchPlotList fPlotList; 131 GrBatchPlotList fPlotList;
90 }; 132 };
91 133
92 #endif 134 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698