Add unique ID to GrPlot
authorrobertphillips <robertphillips@google.com>
Wed, 16 Jul 2014 20:26:24 +0000 (13:26 -0700)
committerCommit bot <commit-bot@chromium.org>
Wed, 16 Jul 2014 20:26:24 +0000 (13:26 -0700)
This is calved off of (Add atlased layer purging - https://codereview.chromium.org/367073002/) where it is used for plot lifetime management (i.e., tracking which plots are locked).

R=jvanverth@google.com

Author: robertphillips@google.com

Review URL: https://codereview.chromium.org/391153002

src/gpu/GrAtlas.cpp
src/gpu/GrAtlas.h

index a9b8ae9..353bf55 100644 (file)
 static int g_UploadCount = 0;
 #endif
 
-GrPlot::GrPlot() : fDrawToken(NULL, 0)
-                 , fTexture(NULL)
-                 , fRects(NULL)
-                 , fAtlas(NULL)
-                 , fBytesPerPixel(1)
-                 , fDirty(false)
-                 , fBatchUploads(false)
+GrPlot::GrPlot() 
+    : fDrawToken(NULL, 0)
+    , fID(-1)
+    , fTexture(NULL)
+    , fRects(NULL)
+    , fAtlas(NULL)
+    , fBytesPerPixel(1)
+    , fDirty(false)
+    , fBatchUploads(false)
 {
     fOffset.set(0, 0);
 }
@@ -37,8 +39,9 @@ GrPlot::~GrPlot() {
     delete fRects;
 }
 
-void GrPlot::init(GrAtlas* atlas, int offX, int offY, int width, int height, size_t bpp,
+void GrPlot::init(GrAtlas* atlas, int id, int offX, int offY, int width, int height, size_t bpp,
                   bool batchUploads) {
+    fID = id;
     fRects = GrRectanizer::Factory(width, height);
     fAtlas = atlas;
     fOffset.set(offX * width, offY * height);
@@ -178,7 +181,7 @@ GrAtlas::GrAtlas(GrGpu* gpu, GrPixelConfig config, GrTextureFlags flags,
     GrPlot* currPlot = fPlotArray;
     for (int y = numPlotsY-1; y >= 0; --y) {
         for (int x = numPlotsX-1; x >= 0; --x) {
-            currPlot->init(this, x, y, plotWidth, plotHeight, bpp, batchUploads);
+            currPlot->init(this, y*numPlotsX+x, x, y, plotWidth, plotHeight, bpp, batchUploads);
 
             // build LRU list
             fPlotList.addToHead(currPlot);
index f990408..2248f67 100644 (file)
@@ -32,6 +32,10 @@ class GrPlot {
 public:
     SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrPlot);
 
+    // This returns a plot ID unique to each plot in a given GrAtlas. They are
+    // consecutive and start at 0.
+    int id() const { return fID; }
+
     GrTexture* texture() const { return fTexture; }
 
     bool addSubImage(int width, int height, const void*, SkIPoint16*);
@@ -46,12 +50,13 @@ public:
 private:
     GrPlot();
     ~GrPlot(); // does not try to delete the fNext field
-    void init(GrAtlas* atlas, int offX, int offY, int width, int height, size_t bpp,
+    void init(GrAtlas* atlas, int id, int offX, int offY, int width, int height, size_t bpp,
               bool batchUploads);
 
     // for recycling
     GrDrawTarget::DrawToken fDrawToken;
 
+    int                     fID;
     unsigned char*          fPlotData;
     GrTexture*              fTexture;
     GrRectanizer*           fRects;