Add GrSTAllocator subclass, hide cons in GrTAllocator that takes ptr
authorbsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Wed, 28 Sep 2011 17:52:15 +0000 (17:52 +0000)
committerbsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Wed, 28 Sep 2011 17:52:15 +0000 (17:52 +0000)
Review URL: http://codereview.appspot.com/5147045/

git-svn-id: http://skia.googlecode.com/svn/trunk@2355 2bbb7eff-a529-9590-31e7-b0007b416f81

gpu/include/GrAllocator.h
gpu/src/GrInOrderDrawBuffer.cpp
gpu/src/GrInOrderDrawBuffer.h

index 7f1fe5b..21c79ec 100755 (executable)
@@ -14,9 +14,9 @@
 #include "GrConfig.h"
 #include "SkTArray.h"
 
-class GrAllocator {
+class GrAllocator : GrNoncopyable {
 public:
-    virtual ~GrAllocator() {
+    ~GrAllocator() {
         reset();
     }
 
@@ -133,13 +133,13 @@ private:
     int                                     fItemsPerBlock;
     bool                                    fOwnFirstBlock;
     int                                     fCount;
+
+    typedef GrNoncopyable INHERITED;
 };
 
 template <typename T>
-class GrTAllocator {
-private:
-    GrAllocator fAllocator;
-    
+class GrTAllocator : GrNoncopyable {
+
 public:
     virtual ~GrTAllocator() {};
 
@@ -151,20 +151,10 @@ public:
      *                          Must be at least size(T)*itemsPerBlock sized.
      *                          Caller is responsible for freeing this memory.
      */
-    explicit GrTAllocator(int itemsPerBlock, void* initialBlock = NULL)
-        : fAllocator(sizeof(T), itemsPerBlock, initialBlock) {}
+    explicit GrTAllocator(int itemsPerBlock)
+        : fAllocator(sizeof(T), itemsPerBlock, NULL) {}
 
     /**
-     * Create an allocator using a GrAlignedTAlloc as the initial block.
-     *
-     * @param   initialBlock    specifies the storage for the initial block
-     *                          and the size of subsequent blocks.
-     */
-    template <int N>
-    explicit GrTAllocator(SkAlignedSTStorage<N,T>* initialBlock)
-        : fAllocator(sizeof(T), N, initialBlock->get()) {}
-    
-    /**
      * Adds an item and returns it.
      *
      * @return the added item.
@@ -232,7 +222,28 @@ public:
      */
     const T& operator[] (int i) const {
         return *(const T*)(fAllocator[i]);
-    }    
+    }
+
+protected:
+    GrTAllocator(int itemsPerBlock, void* initialBlock)
+        : fAllocator(sizeof(T), itemsPerBlock, initialBlock) {
+    }
+
+private:
+    GrAllocator fAllocator;
+    typedef GrNoncopyable INHERITED;
+};
+
+template <int N, typename T> class GrSTAllocator : public GrTAllocator<T> {
+private:
+    typedef GrTAllocator<T> INHERITED;
+
+public:
+    GrSTAllocator() : INHERITED(N, fStorage.get()) {
+    }
+
+private:
+    SkAlignedSTStorage<N, T> fStorage;
 };
 
 #endif
index 3d78da3..946d31c 100644 (file)
 GrInOrderDrawBuffer::GrInOrderDrawBuffer(const GrGpu* gpu,
                                          GrVertexBufferAllocPool* vertexPool,
                                          GrIndexBufferAllocPool* indexPool)
-    : fDraws(&fDrawStorage)
-    , fStates(&fStateStorage)
-    , fClears(&fClearStorage)
-    , fClips(&fClipStorage)
-    , fClipSet(true)
-
+    : fClipSet(true)
     , fLastRectVertexLayout(0)
     , fQuadIndexBuffer(NULL)
     , fMaxQuads(0)
     , fCurrQuad(0)
-
     , fVertexPool(*vertexPool)
     , fIndexPool(*indexPool) {
 
index 122be53..3d1ec8c 100644 (file)
@@ -144,13 +144,22 @@ private:
 
     void pushState();
     void pushClip();
+    
+    enum {
+        kDrawPreallocCnt         = 8,
+        kStatePreallocCnt        = 8,
+        kClipPreallocCnt         = 8,
+        kClearPreallocCnt        = 4,
+        kGeoPoolStatePreAllocCnt = 4,
+    };
 
     const GrGpu*                    fGpu;
-    GrTAllocator<Draw>              fDraws;
-    GrTAllocator<SavedDrawState>    fStates;
-    GrTAllocator<Clear>             fClears;
 
-    GrTAllocator<GrClip>            fClips;
+    GrSTAllocator<kDrawPreallocCnt, Draw>               fDraws;
+    GrSTAllocator<kStatePreallocCnt, SavedDrawState>    fStates;
+    GrSTAllocator<kClearPreallocCnt, Clear>             fClears;
+    GrSTAllocator<kClipPreallocCnt, GrClip>             fClips;
+    
     bool                            fClipSet;
 
     GrVertexLayout                  fLastRectVertexLayout;
@@ -162,14 +171,6 @@ private:
 
     GrIndexBufferAllocPool&         fIndexPool;
 
-    enum {
-        kDrawPreallocCnt         = 8,
-        kStatePreallocCnt        = 8,
-        kClipPreallocCnt         = 8,
-        kClearPreallocCnt        = 4,
-        kGeoPoolStatePreAllocCnt = 4,
-    };
-
     struct GeometryPoolState {
         const GrVertexBuffer*           fPoolVertexBuffer;
         int                             fPoolStartVertex;
@@ -183,11 +184,6 @@ private:
     };
     SkSTArray<kGeoPoolStatePreAllocCnt, GeometryPoolState> fGeoPoolStateStack;
 
-    SkAlignedSTStorage<kDrawPreallocCnt, Draw>              fDrawStorage;
-    SkAlignedSTStorage<kStatePreallocCnt, SavedDrawState>   fStateStorage;
-    SkAlignedSTStorage<kClipPreallocCnt, GrClip>            fClipStorage;
-    SkAlignedSTStorage<kClearPreallocCnt, Clear>            fClearStorage;
-
     typedef GrDrawTarget INHERITED;
 };