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

Unified 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, 9 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 side-by-side diff with in-line comments
Download patch
Index: src/gpu/GrBatchAtlas.h
diff --git a/src/gpu/GrBatchAtlas.h b/src/gpu/GrBatchAtlas.h
index cd8123f140980fdb581ceb9789948098c85d7452..4ff3cd620fccb2dbcac1c3028b8d83470e4709e6 100644
--- a/src/gpu/GrBatchAtlas.h
+++ b/src/gpu/GrBatchAtlas.h
@@ -40,6 +40,9 @@ public:
// the containing GrPlot and absolute location in the backing texture.
// NULL is returned if the subimage cannot fit in the atlas.
// If provided, the image data will be written to the CPU-side backing bitmap.
+ // NOTE: If the client intends to refer to the atlas, they should immediately call 'setUseToken'
+ // with the currentToken from the batch target, otherwise the next call to addToAtlas might
+ // cause an eviction
bool addToAtlas(AtlasID*, GrBatchTarget*, int width, int height, const void* image,
SkIPoint16* loc);
@@ -47,19 +50,58 @@ public:
uint64_t atlasGeneration() const { return fAtlasGeneration; }
bool hasID(AtlasID id);
- void setLastRefToken(AtlasID id, BatchToken batchToken);
+
+ // To ensure the atlas does not evict a given entry, the client must set the last use token
+ void setLastUseToken(AtlasID id, BatchToken batchToken);
void registerEvictionCallback(EvictionFunc func, void* userData) {
EvictionData* data = fEvictionCallbacks.append();
data->fFunc = func;
data->fData = userData;
}
+ /*
+ * A class which can be handed back to GrBatchAtlas for updating in bulk last use tokens.
robertphillips 2015/04/07 12:18:33 Maybe a comment re the maxplots limit (e.g., for t
+ */
+ class BulkUseTokenUpdater {
+ public:
+ BulkUseTokenUpdater() : fPlotAlreadyUpdated(0) {}
+ void add(AtlasID id) {
+ int index = GrBatchAtlas::GetIndexFromID(id);
+ if (!this->find(index)) {
+ this->set(index);
+ }
+ }
+
+ void reset() {
+ fPlotsToUpdate.reset();
+ fPlotAlreadyUpdated = 0;
+ }
+
+ private:
+ bool find(int index) const {
robertphillips 2015/04/07 12:18:33 SkASSERT(index < kMaxPlots); ?
+ return (fPlotAlreadyUpdated >> index) & 1;
+ }
+ void set(int index) {
+ SkASSERT(!this->find(index));
+ fPlotAlreadyUpdated = fPlotAlreadyUpdated | (1 << index);
+ fPlotsToUpdate.push_back(index);
+ }
+
+ static const int kMaxPlots = 32;
+ uint32_t fPlotAlreadyUpdated;
+ SkSTArray<4, int, true> fPlotsToUpdate;
+
+ friend class GrBatchAtlas;
+ };
+
+ void setLastUseTokenBulk(const BulkUseTokenUpdater& reffer, BatchToken);
+
private:
- int getIndexFromID(AtlasID id) {
+ static int GetIndexFromID(AtlasID id) {
return id & 0xffff;
}
- int getGenerationFromID(AtlasID id) {
+ static int GetGenerationFromID(AtlasID id) {
return (id >> 16) & 0xffff;
}

Powered by Google App Engine
This is Rietveld 408576698