Index: src/gpu/GrBatchAtlas.h |
diff --git a/src/gpu/GrBatchAtlas.h b/src/gpu/GrBatchAtlas.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..e491a6ebf2baf7836ae7966a57be05f85376c9da |
--- /dev/null |
+++ b/src/gpu/GrBatchAtlas.h |
@@ -0,0 +1,75 @@ |
+/* |
+ * Copyright 2015 Google Inc. |
+ * |
+ * Use of this source code is governed by a BSD-style license that can be |
+ * found in the LICENSE file. |
+ */ |
+ |
+#ifndef GrBatchAtlas_DEFINED |
+#define GrBatchAtlas_DEFINED |
+ |
+#include "GrDrawTarget.h" |
+#include "GrTexture.h" |
+#include "SkPoint.h" |
+#include "SkTInternalLList.h" |
+ |
+class GrBatchAtlas; |
+class GrBatchPlot; |
+class GrBatchTarget; |
+class GrRectanizer; |
+class GrTextureUploader; |
+ |
+typedef SkTInternalLList<GrBatchPlot> GrBatchPlotList; |
+ |
+class GrBatchAtlas { |
+public: |
+ typedef GrDrawTarget::BatchToken BatchToken; |
+ // An AtlasID is an opaque handle which callers can use to determine if the atlas contains |
+ // a specific piece of data |
+ typedef uint32_t AtlasID; |
+ |
+ GrBatchAtlas(GrTexture*, int numPlotsX, int numPlotsY); |
+ ~GrBatchAtlas(); |
+ |
+ // Adds a width x height subimage to the atlas. Upon success it returns |
+ // 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. |
+ bool addToAtlas(AtlasID*, GrBatchTarget*, int width, int height, const void* image, |
+ SkIPoint16* loc); |
+ |
+ GrTexture* getTexture() const { return fTexture; } |
+ |
+ bool hasID(AtlasID id); |
+ void setLastRefToken(AtlasID id, BatchToken batchToken); |
+ |
+ SkDEBUGCODE(void uploadPlotsToTexture(GrTextureUploader);) |
+ |
+private: |
+ int getIndexFromID(AtlasID id) { |
+ return id & 0xffff; |
+ } |
+ |
+ int getGenerationFromID(AtlasID id) { |
+ return (id >> 16) & 0xffff; |
+ } |
+ |
+ inline void updatePlot(GrBatchTarget*, AtlasID*, GrBatchPlot*); |
+ |
+ void makeMRU(GrBatchPlot* plot); |
+ |
+ GrTexture* fTexture; |
+ int fNumPlotsX; |
+ int fNumPlotsY; |
+ int fPlotWidth; |
+ int fPlotHeight; |
+ size_t fBPP; |
+ |
+ // allocated array of GrBatchPlots |
+ SkAutoTUnref<GrBatchPlot>* fPlotArray; |
+ // LRU list of GrPlots (MRU at head - LRU at tail) |
+ GrBatchPlotList fPlotList; |
+ |
+}; |
+ |
+#endif |