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

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

Issue 1061713003: Revert of Adding bulk plot reffer to cached textblobs (Closed) Base URL: https://skia.googlesource.com/skia.git@atlastext
Patch Set: 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
« no previous file with comments | « src/gpu/GrAtlasTextContext.cpp ('k') | src/gpu/GrBatchAtlas.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
46 bool addToAtlas(AtlasID*, GrBatchTarget*, int width, int height, const void* image, 43 bool addToAtlas(AtlasID*, GrBatchTarget*, int width, int height, const void* image,
47 SkIPoint16* loc); 44 SkIPoint16* loc);
48 45
49 GrTexture* getTexture() const { return fTexture; } 46 GrTexture* getTexture() const { return fTexture; }
50 47
51 uint64_t atlasGeneration() const { return fAtlasGeneration; } 48 uint64_t atlasGeneration() const { return fAtlasGeneration; }
52 bool hasID(AtlasID id); 49 bool hasID(AtlasID id);
53 50 void setLastRefToken(AtlasID id, BatchToken batchToken);
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);
56 void registerEvictionCallback(EvictionFunc func, void* userData) { 51 void registerEvictionCallback(EvictionFunc func, void* userData) {
57 EvictionData* data = fEvictionCallbacks.append(); 52 EvictionData* data = fEvictionCallbacks.append();
58 data->fFunc = func; 53 data->fFunc = func;
59 data->fData = userData; 54 data->fData = userData;
60 } 55 }
61 56
62 /*
63 * 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
65 * insufficient then we can move to a 64 bit int
66 */
67 class BulkUseTokenUpdater {
68 public:
69 BulkUseTokenUpdater() : fPlotAlreadyUpdated(0) {}
70 void add(AtlasID id) {
71 int index = GrBatchAtlas::GetIndexFromID(id);
72 if (!this->find(index)) {
73 this->set(index);
74 }
75 }
76
77 void reset() {
78 fPlotsToUpdate.reset();
79 fPlotAlreadyUpdated = 0;
80 }
81
82 private:
83 bool find(int index) const {
84 SkASSERT(index < kMaxPlots);
85 return (fPlotAlreadyUpdated >> index) & 1;
86 }
87 void set(int index) {
88 SkASSERT(!this->find(index));
89 fPlotAlreadyUpdated = fPlotAlreadyUpdated | (1 << index);
90 fPlotsToUpdate.push_back(index);
91 }
92
93 static const int kMaxPlots = 32;
94 uint32_t fPlotAlreadyUpdated;
95 SkSTArray<4, int, true> fPlotsToUpdate;
96
97 friend class GrBatchAtlas;
98 };
99
100 void setLastUseTokenBulk(const BulkUseTokenUpdater& reffer, BatchToken);
101
102 private: 57 private:
103 static int GetIndexFromID(AtlasID id) { 58 int getIndexFromID(AtlasID id) {
104 return id & 0xffff; 59 return id & 0xffff;
105 } 60 }
106 61
107 static int GetGenerationFromID(AtlasID id) { 62 int getGenerationFromID(AtlasID id) {
108 return (id >> 16) & 0xffff; 63 return (id >> 16) & 0xffff;
109 } 64 }
110 65
111 inline void updatePlot(GrBatchTarget*, AtlasID*, BatchPlot*); 66 inline void updatePlot(GrBatchTarget*, AtlasID*, BatchPlot*);
112 67
113 inline void makeMRU(BatchPlot* plot); 68 inline void makeMRU(BatchPlot* plot);
114 69
115 inline void processEviction(AtlasID); 70 inline void processEviction(AtlasID);
116 71
117 GrTexture* fTexture; 72 GrTexture* fTexture;
(...skipping 10 matching lines...) Expand all
128 }; 83 };
129 84
130 SkTDArray<EvictionData> fEvictionCallbacks; 85 SkTDArray<EvictionData> fEvictionCallbacks;
131 // allocated array of GrBatchPlots 86 // allocated array of GrBatchPlots
132 SkAutoTUnref<BatchPlot>* fPlotArray; 87 SkAutoTUnref<BatchPlot>* fPlotArray;
133 // LRU list of GrPlots (MRU at head - LRU at tail) 88 // LRU list of GrPlots (MRU at head - LRU at tail)
134 GrBatchPlotList fPlotList; 89 GrBatchPlotList fPlotList;
135 }; 90 };
136 91
137 #endif 92 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrAtlasTextContext.cpp ('k') | src/gpu/GrBatchAtlas.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698