Rename GrInOrderDrawBuffer to GrBufferedDrawTarget
authorjoshualitt <joshualitt@chromium.org>
Tue, 28 Jul 2015 16:58:39 +0000 (09:58 -0700)
committerCommit bot <commit-bot@chromium.org>
Tue, 28 Jul 2015 16:58:39 +0000 (09:58 -0700)
BUG=skia:

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

16 files changed:
gyp/gpu.gypi
samplecode/SampleManyRects.cpp
src/gpu/GrBufferedDrawTarget.cpp [new file with mode: 0644]
src/gpu/GrBufferedDrawTarget.h [new file with mode: 0644]
src/gpu/GrClipMaskManager.cpp
src/gpu/GrCommandBuilder.h
src/gpu/GrContext.cpp
src/gpu/GrInOrderCommandBuilder.cpp
src/gpu/GrInOrderCommandBuilder.h
src/gpu/GrInOrderDrawBuffer.cpp [deleted file]
src/gpu/GrInOrderDrawBuffer.h [deleted file]
src/gpu/GrReorderCommandBuilder.h
src/gpu/GrTargetCommands.cpp
src/gpu/GrTargetCommands.h
src/gpu/GrTest.cpp
src/gpu/GrTracing.h

index 762c414a22279eefd55f77f691d0107a50d97773..07f8d20a09ead219a3d0577d33ab37b8d9401693 100644 (file)
@@ -90,6 +90,8 @@
       '<(skia_src_path)/gpu/GrBlurUtils.h',
       '<(skia_src_path)/gpu/GrBufferAllocPool.cpp',
       '<(skia_src_path)/gpu/GrBufferAllocPool.h',
+      '<(skia_src_path)/gpu/GrBufferedDrawTarget.cpp',
+      '<(skia_src_path)/gpu/GrBufferedDrawTarget.h',
       '<(skia_src_path)/gpu/GrCaps.cpp',
       '<(skia_src_path)/gpu/GrClip.cpp',
       '<(skia_src_path)/gpu/GrClipMaskCache.h',
       '<(skia_src_path)/gpu/GrInvariantOutput.cpp',
       '<(skia_src_path)/gpu/GrInOrderCommandBuilder.cpp',
       '<(skia_src_path)/gpu/GrInOrderCommandBuilder.h',
-      '<(skia_src_path)/gpu/GrInOrderDrawBuffer.cpp',
-      '<(skia_src_path)/gpu/GrInOrderDrawBuffer.h',
       '<(skia_src_path)/gpu/GrLayerCache.cpp',
       '<(skia_src_path)/gpu/GrLayerCache.h',
       '<(skia_src_path)/gpu/GrLayerHoister.cpp',
index a570853a030d8d4da0728c76af1cc1f4ac0cacc5..9c9e985206e2672c3f2ad58642bb867f78b2e1e3 100644 (file)
@@ -14,7 +14,7 @@
 #include "SkView.h"
 
 /**
- * Animated sample used to develop batched rect implementation in GrInOrderDrawBuffer.
+ * Animated sample used to develop batched rect implementation in GrBufferedDrawTarget.
  */
 class ManyRectsView : public SampleView {
 private:
diff --git a/src/gpu/GrBufferedDrawTarget.cpp b/src/gpu/GrBufferedDrawTarget.cpp
new file mode 100644 (file)
index 0000000..f2d9367
--- /dev/null
@@ -0,0 +1,201 @@
+/*
+ * Copyright 2011 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "GrBufferedDrawTarget.h"
+
+// We will use the reordering buffer, unless we have NVPR.
+// TODO move NVPR to batch so we can reorder
+static inline bool allow_reordering(const GrCaps* caps) {
+    return caps && caps->shaderCaps() && !caps->shaderCaps()->pathRenderingSupport();
+}
+
+GrBufferedDrawTarget::GrBufferedDrawTarget(GrContext* context)
+    : INHERITED(context)
+    , fCommands(GrCommandBuilder::Create(context->getGpu(), allow_reordering(context->caps())))
+    , fPathIndexBuffer(kPathIdxBufferMinReserve * sizeof(char)/4)
+    , fPathTransformBuffer(kPathXformBufferMinReserve * sizeof(float)/4)
+    , fPipelineBuffer(kPipelineBufferMinReserve)
+    , fDrawID(0) {
+}
+
+GrBufferedDrawTarget::~GrBufferedDrawTarget() {
+    this->reset();
+}
+
+void GrBufferedDrawTarget::onDrawBatch(GrBatch* batch,
+                                       const PipelineInfo& pipelineInfo) {
+    State* state = this->setupPipelineAndShouldDraw(batch, pipelineInfo);
+    if (!state) {
+        return;
+    }
+
+    GrTargetCommands::Cmd* cmd = fCommands->recordDrawBatch(state, batch);
+    this->recordTraceMarkersIfNecessary(cmd);
+}
+
+void GrBufferedDrawTarget::onStencilPath(const GrPipelineBuilder& pipelineBuilder,
+                                         const GrPathProcessor* pathProc,
+                                         const GrPath* path,
+                                         const GrScissorState& scissorState,
+                                         const GrStencilSettings& stencilSettings) {
+    GrTargetCommands::Cmd* cmd = fCommands->recordStencilPath(pipelineBuilder,
+                                                              pathProc, path, scissorState,
+                                                              stencilSettings);
+    this->recordTraceMarkersIfNecessary(cmd);
+}
+
+void GrBufferedDrawTarget::onDrawPath(const GrPathProcessor* pathProc,
+                                      const GrPath* path,
+                                      const GrStencilSettings& stencilSettings,
+                                      const PipelineInfo& pipelineInfo) {
+    State* state = this->setupPipelineAndShouldDraw(pathProc, pipelineInfo);
+    if (!state) {
+        return;
+    }
+    GrTargetCommands::Cmd* cmd = fCommands->recordDrawPath(state, pathProc, path, stencilSettings);
+    this->recordTraceMarkersIfNecessary(cmd);
+}
+
+void GrBufferedDrawTarget::onDrawPaths(const GrPathProcessor* pathProc,
+                                       const GrPathRange* pathRange,
+                                       const void* indices,
+                                       PathIndexType indexType,
+                                       const float transformValues[],
+                                       PathTransformType transformType,
+                                       int count,
+                                       const GrStencilSettings& stencilSettings,
+                                       const PipelineInfo& pipelineInfo) {
+    State* state = this->setupPipelineAndShouldDraw(pathProc, pipelineInfo);
+    if (!state) {
+        return;
+    }
+    GrTargetCommands::Cmd* cmd = fCommands->recordDrawPaths(state, this, pathProc, pathRange,
+                                                            indices, indexType, transformValues,
+                                                            transformType, count,
+                                                            stencilSettings, pipelineInfo);
+    this->recordTraceMarkersIfNecessary(cmd);
+}
+
+void GrBufferedDrawTarget::onClear(const SkIRect* rect, GrColor color,
+                                  bool canIgnoreRect, GrRenderTarget* renderTarget) {
+    GrTargetCommands::Cmd* cmd = fCommands->recordClear(rect, color, canIgnoreRect, renderTarget);
+    this->recordTraceMarkersIfNecessary(cmd);
+}
+
+void GrBufferedDrawTarget::clearStencilClip(const SkIRect& rect,
+                                            bool insideClip,
+                                            GrRenderTarget* renderTarget) {
+    GrTargetCommands::Cmd* cmd = fCommands->recordClearStencilClip(rect, insideClip, renderTarget);
+    this->recordTraceMarkersIfNecessary(cmd);
+}
+
+void GrBufferedDrawTarget::discard(GrRenderTarget* renderTarget) {
+    if (!this->caps()->discardRenderTargetSupport()) {
+        return;
+    }
+
+    GrTargetCommands::Cmd* cmd = fCommands->recordDiscard(renderTarget);
+    this->recordTraceMarkersIfNecessary(cmd);
+}
+
+void GrBufferedDrawTarget::onReset() {
+    fCommands->reset();
+    fPathIndexBuffer.rewind();
+    fPathTransformBuffer.rewind();
+    fGpuCmdMarkers.reset();
+
+    fPrevState.reset(NULL);
+    // Note, fPrevState points into fPipelineBuffer's allocation, so we have to reset first.
+    // Furthermore, we have to reset fCommands before fPipelineBuffer too.
+    if (fDrawID % kPipelineBufferHighWaterMark) {
+        fPipelineBuffer.rewind();
+    } else {
+        fPipelineBuffer.reset();
+    }
+}
+
+void GrBufferedDrawTarget::onFlush() {
+    fCommands->flush(this);
+    ++fDrawID;
+}
+
+void GrBufferedDrawTarget::onCopySurface(GrSurface* dst,
+                                         GrSurface* src,
+                                         const SkIRect& srcRect,
+                                         const SkIPoint& dstPoint) {
+    GrTargetCommands::Cmd* cmd = fCommands->recordCopySurface(dst, src, srcRect, dstPoint);
+    this->recordTraceMarkersIfNecessary(cmd);
+}
+
+void GrBufferedDrawTarget::recordTraceMarkersIfNecessary(GrTargetCommands::Cmd* cmd) {
+    if (!cmd) {
+        return;
+    }
+    const GrTraceMarkerSet& activeTraceMarkers = this->getActiveTraceMarkers();
+    if (activeTraceMarkers.count() > 0) {
+        if (cmd->isTraced()) {
+            fGpuCmdMarkers[cmd->markerID()].addSet(activeTraceMarkers);
+        } else {
+            cmd->setMarkerID(fGpuCmdMarkers.count());
+            fGpuCmdMarkers.push_back(activeTraceMarkers);
+        }
+    }
+}
+
+GrTargetCommands::State*
+GrBufferedDrawTarget::setupPipelineAndShouldDraw(const GrPrimitiveProcessor* primProc,
+                                                 const GrDrawTarget::PipelineInfo& pipelineInfo) {
+    State* state = this->allocState(primProc);
+    this->setupPipeline(pipelineInfo, state->pipelineLocation());
+
+    if (state->getPipeline()->mustSkip()) {
+        this->unallocState(state);
+        return NULL;
+    }
+
+    state->fPrimitiveProcessor->initBatchTracker(
+        &state->fBatchTracker, state->getPipeline()->infoForPrimitiveProcessor());
+
+    if (fPrevState && fPrevState->fPrimitiveProcessor.get() &&
+        fPrevState->fPrimitiveProcessor->canMakeEqual(fPrevState->fBatchTracker,
+                                                      *state->fPrimitiveProcessor,
+                                                      state->fBatchTracker) &&
+        fPrevState->getPipeline()->isEqual(*state->getPipeline())) {
+        this->unallocState(state);
+    } else {
+        fPrevState.reset(state);
+    }
+
+    this->recordTraceMarkersIfNecessary(
+            fCommands->recordXferBarrierIfNecessary(*fPrevState->getPipeline(), *this->caps()));
+    return fPrevState;
+}
+
+GrTargetCommands::State*
+GrBufferedDrawTarget::setupPipelineAndShouldDraw(GrBatch* batch,
+                                                 const GrDrawTarget::PipelineInfo& pipelineInfo) {
+    State* state = this->allocState();
+    this->setupPipeline(pipelineInfo, state->pipelineLocation());
+
+    if (state->getPipeline()->mustSkip()) {
+        this->unallocState(state);
+        return NULL;
+    }
+
+    batch->initBatchTracker(state->getPipeline()->infoForPrimitiveProcessor());
+
+    if (fPrevState && !fPrevState->fPrimitiveProcessor.get() &&
+        fPrevState->getPipeline()->isEqual(*state->getPipeline())) {
+        this->unallocState(state);
+    } else {
+        fPrevState.reset(state);
+    }
+
+    this->recordTraceMarkersIfNecessary(
+            fCommands->recordXferBarrierIfNecessary(*fPrevState->getPipeline(), *this->caps()));
+    return fPrevState;
+}
diff --git a/src/gpu/GrBufferedDrawTarget.h b/src/gpu/GrBufferedDrawTarget.h
new file mode 100644 (file)
index 0000000..df9ad46
--- /dev/null
@@ -0,0 +1,143 @@
+/*
+ * Copyright 2011 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef GrBufferedDrawTarget_DEFINED
+#define GrBufferedDrawTarget_DEFINED
+
+#include "GrDrawTarget.h"
+#include "GrCommandBuilder.h"
+#include "SkChunkAlloc.h"
+
+/**
+ * GrBufferedDrawTarget is an implementation of GrDrawTarget that queues up draws for eventual
+ * playback into a GrGpu. In theory one draw buffer could playback into another. Similarly, it is
+ * the caller's responsibility to ensure that all referenced textures, buffers, and render-targets
+ * are associated in the GrGpu object that the buffer is played back into.
+ */
+class GrBufferedDrawTarget : public GrClipTarget {
+public:
+
+    /**
+     * Creates a GrBufferedDrawTarget
+     *
+     * @param context    the context object that owns this draw buffer.
+     */
+    GrBufferedDrawTarget(GrContext* context);
+
+    ~GrBufferedDrawTarget() override;
+
+    void clearStencilClip(const SkIRect& rect,
+                          bool insideClip,
+                          GrRenderTarget* renderTarget) override;
+
+    void discard(GrRenderTarget*) override;
+
+protected:
+    void appendIndicesAndTransforms(const void* indexValues, PathIndexType indexType, 
+                                    const float* transformValues, PathTransformType transformType,
+                                    int count, char** indicesLocation, float** xformsLocation) {
+        int indexBytes = GrPathRange::PathIndexSizeInBytes(indexType);
+        *indicesLocation = (char*) fPathIndexBuffer.alloc(count * indexBytes,
+                                                          SkChunkAlloc::kThrow_AllocFailType);
+        SkASSERT(SkIsAlign4((uintptr_t)*indicesLocation));
+        memcpy(*indicesLocation, reinterpret_cast<const char*>(indexValues), count * indexBytes);
+
+        const int xformBytes = GrPathRendering::PathTransformSize(transformType) * sizeof(float);
+        *xformsLocation = NULL;
+
+        if (0 != xformBytes) {
+            *xformsLocation = (float*) fPathTransformBuffer.alloc(count * xformBytes,
+                                                               SkChunkAlloc::kThrow_AllocFailType);
+            SkASSERT(SkIsAlign4((uintptr_t)*xformsLocation));
+            memcpy(*xformsLocation, transformValues, count * xformBytes);
+        }
+    }
+
+private:
+    friend class GrInOrderCommandBuilder;
+    friend class GrTargetCommands;
+
+    typedef GrTargetCommands::State State;
+
+    State* allocState(const GrPrimitiveProcessor* primProc = NULL) {
+        void* allocation = fPipelineBuffer.alloc(sizeof(State), SkChunkAlloc::kThrow_AllocFailType);
+        return SkNEW_PLACEMENT_ARGS(allocation, State, (primProc));
+    }
+
+    void unallocState(State* state) {
+        state->unref();
+        fPipelineBuffer.unalloc(state);
+    }
+
+    void onReset() override;
+    void onFlush() override;
+
+    // overrides from GrDrawTarget
+    void onDrawBatch(GrBatch*, const PipelineInfo&) override;
+    void onStencilPath(const GrPipelineBuilder&,
+                       const GrPathProcessor*,
+                       const GrPath*,
+                       const GrScissorState&,
+                       const GrStencilSettings&) override;
+    void onDrawPath(const GrPathProcessor*,
+                    const GrPath*,
+                    const GrStencilSettings&,
+                    const PipelineInfo&) override;
+    void onDrawPaths(const GrPathProcessor*,
+                     const GrPathRange*,
+                     const void* indices,
+                     PathIndexType,
+                     const float transformValues[],
+                     PathTransformType,
+                     int count,
+                     const GrStencilSettings&,
+                     const PipelineInfo&) override;
+    void onClear(const SkIRect* rect,
+                 GrColor color,
+                 bool canIgnoreRect,
+                 GrRenderTarget* renderTarget) override;
+    void onCopySurface(GrSurface* dst,
+                       GrSurface* src,
+                       const SkIRect& srcRect,
+                       const SkIPoint& dstPoint) override;
+
+    // Records any trace markers for a command
+    void recordTraceMarkersIfNecessary(GrTargetCommands::Cmd*);
+    SkString getCmdString(int index) const {
+        SkASSERT(index < fGpuCmdMarkers.count());
+        return fGpuCmdMarkers[index].toString();
+    }
+    bool isIssued(uint32_t drawID) override { return drawID != fDrawID; }
+
+    State* SK_WARN_UNUSED_RESULT setupPipelineAndShouldDraw(const GrPrimitiveProcessor*,
+                                                            const GrDrawTarget::PipelineInfo&);
+    State* SK_WARN_UNUSED_RESULT setupPipelineAndShouldDraw(GrBatch*,
+                                                            const GrDrawTarget::PipelineInfo&);
+
+    // TODO: Use a single allocator for commands and records
+    enum {
+        kPathIdxBufferMinReserve     = 2 * 64,  // 64 uint16_t's
+        kPathXformBufferMinReserve   = 2 * 64,  // 64 two-float transforms
+        kPipelineBufferMinReserve    = 32 * sizeof(State),
+    };
+
+    // every 100 flushes we should reset our fPipelineBuffer to prevent us from holding at a
+    // highwater mark
+    static const int kPipelineBufferHighWaterMark = 100;
+
+    SkAutoTDelete<GrCommandBuilder>     fCommands;
+    SkTArray<GrTraceMarkerSet, false>   fGpuCmdMarkers;
+    SkChunkAlloc                        fPathIndexBuffer;
+    SkChunkAlloc                        fPathTransformBuffer;
+    SkChunkAlloc                        fPipelineBuffer;
+    uint32_t                            fDrawID;
+    SkAutoTUnref<State>                 fPrevState;
+
+    typedef GrClipTarget INHERITED;
+};
+
+#endif
index b15bee9939d0019a81ec1d85b721b6a1a52c6063..ec833c8bd65fcaa08fc389560a06c5c76ee61339 100644 (file)
@@ -349,7 +349,7 @@ bool GrClipMaskManager::setupClipping(const GrPipelineBuilder& pipelineBuilder,
     // Either a hard (stencil buffer) clip was explicitly requested or an anti-aliased clip couldn't
     // be created. In either case, free up the texture in the anti-aliased mask cache.
     // TODO: this may require more investigation. Ganesh performs a lot of utility draws (e.g.,
-    // clears, InOrderDrawBuffer playbacks) that hit the stencil buffer path. These may be
+    // clears, GrBufferedDrawTarget playbacks) that hit the stencil buffer path. These may be
     // "incorrectly" clearing the AA cache.
     fAACache.reset();
 
index a94a439dcd2ce6aa514b645cef84e57f5077def9..c709586d4886f790816a968b0aeea9a2d72b4722 100644 (file)
@@ -10,7 +10,7 @@
 
 #include "GrTargetCommands.h"
 
-class GrInOrderDrawBuffer;
+class GrBufferedDrawTarget;
 
 class GrCommandBuilder : ::SkNoncopyable {
 public:
@@ -22,7 +22,7 @@ public:
     virtual ~GrCommandBuilder() {}
 
     void reset() { fCommands.reset(); }
-    void flush(GrInOrderDrawBuffer* iodb) { fCommands.flush(iodb); }
+    void flush(GrBufferedDrawTarget* bufferedDrawTarget) { fCommands.flush(bufferedDrawTarget); }
 
     virtual Cmd* recordClearStencilClip(const SkIRect& rect,
                                         bool insideClip,
@@ -39,7 +39,7 @@ public:
                                 const GrPath*,
                                 const GrStencilSettings&) = 0;
     virtual Cmd* recordDrawPaths(State*,
-                                 GrInOrderDrawBuffer*,
+                                 GrBufferedDrawTarget*,
                                  const GrPathProcessor*,
                                  const GrPathRange*,
                                  const void*,
index adbde946c55adbc4303af55e95fd12d9058adc47..9e1d904dca10f7d1f21d804369f77ffbae8a6a2f 100755 (executable)
@@ -13,6 +13,7 @@
 #include "GrBatchFontCache.h"
 #include "GrBatchTarget.h"
 #include "GrBatchTest.h"
+#include "GrBufferedDrawTarget.h"
 #include "GrCaps.h"
 #include "GrContextOptions.h"
 #include "GrDefaultGeoProcFactory.h"
@@ -22,7 +23,6 @@
 #include "GrGpu.h"
 #include "GrImmediateDrawTarget.h"
 #include "GrIndexBuffer.h"
-#include "GrInOrderDrawBuffer.h"
 #include "GrLayerCache.h"
 #include "GrOvalRenderer.h"
 #include "GrPathRenderer.h"
@@ -66,7 +66,7 @@ void GrContext::DrawingMgr::init(GrContext* context) {
 #ifdef IMMEDIATE_MODE
     fDrawTarget = SkNEW_ARGS(GrImmediateDrawTarget, (context));
 #else
-    fDrawTarget = SkNEW_ARGS(GrInOrderDrawBuffer, (context));
+    fDrawTarget = SkNEW_ARGS(GrBufferedDrawTarget, (context));
 #endif    
 }
 
@@ -276,7 +276,7 @@ void GrContext::OverBudgetCB(void* data) {
 
     GrContext* context = reinterpret_cast<GrContext*>(data);
 
-    // Flush the InOrderDrawBuffer to possibly free up some textures
+    // Flush the GrBufferedDrawTarget to possibly free up some textures
     context->fFlushToReduceCacheSize = true;
 }
 
index 6cd60822c6b4c459148effd454d478714db1e0cf..d8e84c035f92af16d8ec4bb4b1eeb5eedfc8b8ca 100644 (file)
@@ -7,8 +7,9 @@
 
 #include "GrInOrderCommandBuilder.h"
 
+#include "GrBufferedDrawTarget.h"
+
 #include "GrColor.h"
-#include "GrInOrderDrawBuffer.h"
 #include "SkPoint.h"
 
 static bool path_fill_type_is_winding(const GrStencilSettings& pathStencilSettings) {
@@ -67,7 +68,7 @@ GrInOrderCommandBuilder::recordDrawPath(State* state,
 
 GrTargetCommands::Cmd*
 GrInOrderCommandBuilder::recordDrawPaths(State* state,
-                                         GrInOrderDrawBuffer* iodb,
+                                         GrBufferedDrawTarget* bufferedDrawTarget,
                                          const GrPathProcessor* pathProc,
                                          const GrPathRange* pathRange,
                                          const void* indexValues,
@@ -84,9 +85,9 @@ GrInOrderCommandBuilder::recordDrawPaths(State* state,
     char* savedIndices;
     float* savedTransforms;
 
-    iodb->appendIndicesAndTransforms(indexValues, indexType,
-                                     transformValues, transformType,
-                                     count, &savedIndices, &savedTransforms);
+    bufferedDrawTarget->appendIndicesAndTransforms(indexValues, indexType,
+                                                   transformValues, transformType,
+                                                   count, &savedIndices, &savedTransforms);
 
     if (!this->cmdBuffer()->empty() &&
         Cmd::kDrawPaths_CmdType == this->cmdBuffer()->back().type()) {
index 164db92811cf20fd8289f54757eed2eb47ef2cce..f992cc51d86814a3245056f4dc662e1e25f19378 100644 (file)
@@ -28,7 +28,7 @@ public:
                         const GrPath*,
                         const GrStencilSettings&) override;
     Cmd* recordDrawPaths(State*,
-                         GrInOrderDrawBuffer*,
+                         GrBufferedDrawTarget*,
                          const GrPathProcessor*,
                          const GrPathRange*,
                          const void*,
diff --git a/src/gpu/GrInOrderDrawBuffer.cpp b/src/gpu/GrInOrderDrawBuffer.cpp
deleted file mode 100644 (file)
index 0b4dab1..0000000
+++ /dev/null
@@ -1,201 +0,0 @@
-/*
- * Copyright 2011 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "GrInOrderDrawBuffer.h"
-
-// We will use the reordering buffer, unless we have NVPR.
-// TODO move NVPR to batch so we can reorder
-static inline bool allow_reordering(const GrCaps* caps) {
-    return caps && caps->shaderCaps() && !caps->shaderCaps()->pathRenderingSupport();
-}
-
-GrInOrderDrawBuffer::GrInOrderDrawBuffer(GrContext* context)
-    : INHERITED(context)
-    , fCommands(GrCommandBuilder::Create(context->getGpu(), allow_reordering(context->caps())))
-    , fPathIndexBuffer(kPathIdxBufferMinReserve * sizeof(char)/4)
-    , fPathTransformBuffer(kPathXformBufferMinReserve * sizeof(float)/4)
-    , fPipelineBuffer(kPipelineBufferMinReserve)
-    , fDrawID(0) {
-}
-
-GrInOrderDrawBuffer::~GrInOrderDrawBuffer() {
-    this->reset();
-}
-
-void GrInOrderDrawBuffer::onDrawBatch(GrBatch* batch,
-                                      const PipelineInfo& pipelineInfo) {
-    State* state = this->setupPipelineAndShouldDraw(batch, pipelineInfo);
-    if (!state) {
-        return;
-    }
-
-    GrTargetCommands::Cmd* cmd = fCommands->recordDrawBatch(state, batch);
-    this->recordTraceMarkersIfNecessary(cmd);
-}
-
-void GrInOrderDrawBuffer::onStencilPath(const GrPipelineBuilder& pipelineBuilder,
-                                        const GrPathProcessor* pathProc,
-                                        const GrPath* path,
-                                        const GrScissorState& scissorState,
-                                        const GrStencilSettings& stencilSettings) {
-    GrTargetCommands::Cmd* cmd = fCommands->recordStencilPath(pipelineBuilder,
-                                                              pathProc, path, scissorState,
-                                                              stencilSettings);
-    this->recordTraceMarkersIfNecessary(cmd);
-}
-
-void GrInOrderDrawBuffer::onDrawPath(const GrPathProcessor* pathProc,
-                                     const GrPath* path,
-                                     const GrStencilSettings& stencilSettings,
-                                     const PipelineInfo& pipelineInfo) {
-    State* state = this->setupPipelineAndShouldDraw(pathProc, pipelineInfo);
-    if (!state) {
-        return;
-    }
-    GrTargetCommands::Cmd* cmd = fCommands->recordDrawPath(state, pathProc, path, stencilSettings);
-    this->recordTraceMarkersIfNecessary(cmd);
-}
-
-void GrInOrderDrawBuffer::onDrawPaths(const GrPathProcessor* pathProc,
-                                      const GrPathRange* pathRange,
-                                      const void* indices,
-                                      PathIndexType indexType,
-                                      const float transformValues[],
-                                      PathTransformType transformType,
-                                      int count,
-                                      const GrStencilSettings& stencilSettings,
-                                      const PipelineInfo& pipelineInfo) {
-    State* state = this->setupPipelineAndShouldDraw(pathProc, pipelineInfo);
-    if (!state) {
-        return;
-    }
-    GrTargetCommands::Cmd* cmd = fCommands->recordDrawPaths(state, this, pathProc, pathRange,
-                                                            indices, indexType, transformValues,
-                                                            transformType, count,
-                                                            stencilSettings, pipelineInfo);
-    this->recordTraceMarkersIfNecessary(cmd);
-}
-
-void GrInOrderDrawBuffer::onClear(const SkIRect* rect, GrColor color,
-                                  bool canIgnoreRect, GrRenderTarget* renderTarget) {
-    GrTargetCommands::Cmd* cmd = fCommands->recordClear(rect, color, canIgnoreRect, renderTarget);
-    this->recordTraceMarkersIfNecessary(cmd);
-}
-
-void GrInOrderDrawBuffer::clearStencilClip(const SkIRect& rect,
-                                           bool insideClip,
-                                           GrRenderTarget* renderTarget) {
-    GrTargetCommands::Cmd* cmd = fCommands->recordClearStencilClip(rect, insideClip, renderTarget);
-    this->recordTraceMarkersIfNecessary(cmd);
-}
-
-void GrInOrderDrawBuffer::discard(GrRenderTarget* renderTarget) {
-    if (!this->caps()->discardRenderTargetSupport()) {
-        return;
-    }
-
-    GrTargetCommands::Cmd* cmd = fCommands->recordDiscard(renderTarget);
-    this->recordTraceMarkersIfNecessary(cmd);
-}
-
-void GrInOrderDrawBuffer::onReset() {
-    fCommands->reset();
-    fPathIndexBuffer.rewind();
-    fPathTransformBuffer.rewind();
-    fGpuCmdMarkers.reset();
-
-    fPrevState.reset(NULL);
-    // Note, fPrevState points into fPipelineBuffer's allocation, so we have to reset first.
-    // Furthermore, we have to reset fCommands before fPipelineBuffer too.
-    if (fDrawID % kPipelineBufferHighWaterMark) {
-        fPipelineBuffer.rewind();
-    } else {
-        fPipelineBuffer.reset();
-    }
-}
-
-void GrInOrderDrawBuffer::onFlush() {
-    fCommands->flush(this);
-    ++fDrawID;
-}
-
-void GrInOrderDrawBuffer::onCopySurface(GrSurface* dst,
-                                        GrSurface* src,
-                                        const SkIRect& srcRect,
-                                        const SkIPoint& dstPoint) {
-    GrTargetCommands::Cmd* cmd = fCommands->recordCopySurface(dst, src, srcRect, dstPoint);
-    this->recordTraceMarkersIfNecessary(cmd);
-}
-
-void GrInOrderDrawBuffer::recordTraceMarkersIfNecessary(GrTargetCommands::Cmd* cmd) {
-    if (!cmd) {
-        return;
-    }
-    const GrTraceMarkerSet& activeTraceMarkers = this->getActiveTraceMarkers();
-    if (activeTraceMarkers.count() > 0) {
-        if (cmd->isTraced()) {
-            fGpuCmdMarkers[cmd->markerID()].addSet(activeTraceMarkers);
-        } else {
-            cmd->setMarkerID(fGpuCmdMarkers.count());
-            fGpuCmdMarkers.push_back(activeTraceMarkers);
-        }
-    }
-}
-
-GrTargetCommands::State*
-GrInOrderDrawBuffer::setupPipelineAndShouldDraw(const GrPrimitiveProcessor* primProc,
-                                                const GrDrawTarget::PipelineInfo& pipelineInfo) {
-    State* state = this->allocState(primProc);
-    this->setupPipeline(pipelineInfo, state->pipelineLocation());
-
-    if (state->getPipeline()->mustSkip()) {
-        this->unallocState(state);
-        return NULL;
-    }
-
-    state->fPrimitiveProcessor->initBatchTracker(
-        &state->fBatchTracker, state->getPipeline()->infoForPrimitiveProcessor());
-
-    if (fPrevState && fPrevState->fPrimitiveProcessor.get() &&
-        fPrevState->fPrimitiveProcessor->canMakeEqual(fPrevState->fBatchTracker,
-                                                      *state->fPrimitiveProcessor,
-                                                      state->fBatchTracker) &&
-        fPrevState->getPipeline()->isEqual(*state->getPipeline())) {
-        this->unallocState(state);
-    } else {
-        fPrevState.reset(state);
-    }
-
-    this->recordTraceMarkersIfNecessary(
-            fCommands->recordXferBarrierIfNecessary(*fPrevState->getPipeline(), *this->caps()));
-    return fPrevState;
-}
-
-GrTargetCommands::State*
-GrInOrderDrawBuffer::setupPipelineAndShouldDraw(GrBatch* batch,
-                                                const GrDrawTarget::PipelineInfo& pipelineInfo) {
-    State* state = this->allocState();
-    this->setupPipeline(pipelineInfo, state->pipelineLocation());
-
-    if (state->getPipeline()->mustSkip()) {
-        this->unallocState(state);
-        return NULL;
-    }
-
-    batch->initBatchTracker(state->getPipeline()->infoForPrimitiveProcessor());
-
-    if (fPrevState && !fPrevState->fPrimitiveProcessor.get() &&
-        fPrevState->getPipeline()->isEqual(*state->getPipeline())) {
-        this->unallocState(state);
-    } else {
-        fPrevState.reset(state);
-    }
-
-    this->recordTraceMarkersIfNecessary(
-            fCommands->recordXferBarrierIfNecessary(*fPrevState->getPipeline(), *this->caps()));
-    return fPrevState;
-}
diff --git a/src/gpu/GrInOrderDrawBuffer.h b/src/gpu/GrInOrderDrawBuffer.h
deleted file mode 100644 (file)
index 908632c..0000000
+++ /dev/null
@@ -1,147 +0,0 @@
-/*
- * Copyright 2011 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef GrInOrderDrawBuffer_DEFINED
-#define GrInOrderDrawBuffer_DEFINED
-
-#include "GrDrawTarget.h"
-#include "GrCommandBuilder.h"
-#include "SkChunkAlloc.h"
-
-/**
- * GrInOrderDrawBuffer is an implementation of GrDrawTarget that queues up draws for eventual
- * playback into a GrGpu. In theory one draw buffer could playback into another. When index or
- * vertex buffers are used as geometry sources it is the callers the draw buffer only holds
- * references to the buffers. It is the callers responsibility to ensure that the data is still
- * valid when the draw buffer is played back into a GrGpu. Similarly, it is the caller's
- * responsibility to ensure that all referenced textures, buffers, and render-targets are associated
- * in the GrGpu object that the buffer is played back into. The buffer requires VB and IB pools to
- * store geometry.
- */
-class GrInOrderDrawBuffer : public GrClipTarget {
-public:
-
-    /**
-     * Creates a GrInOrderDrawBuffer
-     *
-     * @param context    the context object that owns this draw buffer.
-     */
-    GrInOrderDrawBuffer(GrContext* context);
-
-    ~GrInOrderDrawBuffer() override;
-
-    void clearStencilClip(const SkIRect& rect,
-                          bool insideClip,
-                          GrRenderTarget* renderTarget) override;
-
-    void discard(GrRenderTarget*) override;
-
-protected:
-    void appendIndicesAndTransforms(const void* indexValues, PathIndexType indexType, 
-                                    const float* transformValues, PathTransformType transformType,
-                                    int count, char** indicesLocation, float** xformsLocation) {
-        int indexBytes = GrPathRange::PathIndexSizeInBytes(indexType);
-        *indicesLocation = (char*) fPathIndexBuffer.alloc(count * indexBytes,
-                                                          SkChunkAlloc::kThrow_AllocFailType);
-        SkASSERT(SkIsAlign4((uintptr_t)*indicesLocation));
-        memcpy(*indicesLocation, reinterpret_cast<const char*>(indexValues), count * indexBytes);
-
-        const int xformBytes = GrPathRendering::PathTransformSize(transformType) * sizeof(float);
-        *xformsLocation = NULL;
-
-        if (0 != xformBytes) {
-            *xformsLocation = (float*) fPathTransformBuffer.alloc(count * xformBytes,
-                                                               SkChunkAlloc::kThrow_AllocFailType);
-            SkASSERT(SkIsAlign4((uintptr_t)*xformsLocation));
-            memcpy(*xformsLocation, transformValues, count * xformBytes);
-        }
-    }
-
-private:
-    friend class GrInOrderCommandBuilder;
-    friend class GrTargetCommands;
-
-    typedef GrTargetCommands::State State;
-
-    State* allocState(const GrPrimitiveProcessor* primProc = NULL) {
-        void* allocation = fPipelineBuffer.alloc(sizeof(State), SkChunkAlloc::kThrow_AllocFailType);
-        return SkNEW_PLACEMENT_ARGS(allocation, State, (primProc));
-    }
-
-    void unallocState(State* state) {
-        state->unref();
-        fPipelineBuffer.unalloc(state);
-    }
-
-    void onReset() override;
-    void onFlush() override;
-
-    // overrides from GrDrawTarget
-    void onDrawBatch(GrBatch*, const PipelineInfo&) override;
-    void onStencilPath(const GrPipelineBuilder&,
-                       const GrPathProcessor*,
-                       const GrPath*,
-                       const GrScissorState&,
-                       const GrStencilSettings&) override;
-    void onDrawPath(const GrPathProcessor*,
-                    const GrPath*,
-                    const GrStencilSettings&,
-                    const PipelineInfo&) override;
-    void onDrawPaths(const GrPathProcessor*,
-                     const GrPathRange*,
-                     const void* indices,
-                     PathIndexType,
-                     const float transformValues[],
-                     PathTransformType,
-                     int count,
-                     const GrStencilSettings&,
-                     const PipelineInfo&) override;
-    void onClear(const SkIRect* rect,
-                 GrColor color,
-                 bool canIgnoreRect,
-                 GrRenderTarget* renderTarget) override;
-    void onCopySurface(GrSurface* dst,
-                       GrSurface* src,
-                       const SkIRect& srcRect,
-                       const SkIPoint& dstPoint) override;
-
-    // Records any trace markers for a command
-    void recordTraceMarkersIfNecessary(GrTargetCommands::Cmd*);
-    SkString getCmdString(int index) const {
-        SkASSERT(index < fGpuCmdMarkers.count());
-        return fGpuCmdMarkers[index].toString();
-    }
-    bool isIssued(uint32_t drawID) override { return drawID != fDrawID; }
-
-    State* SK_WARN_UNUSED_RESULT setupPipelineAndShouldDraw(const GrPrimitiveProcessor*,
-                                                            const GrDrawTarget::PipelineInfo&);
-    State* SK_WARN_UNUSED_RESULT setupPipelineAndShouldDraw(GrBatch*,
-                                                            const GrDrawTarget::PipelineInfo&);
-
-    // TODO: Use a single allocator for commands and records
-    enum {
-        kPathIdxBufferMinReserve     = 2 * 64,  // 64 uint16_t's
-        kPathXformBufferMinReserve   = 2 * 64,  // 64 two-float transforms
-        kPipelineBufferMinReserve    = 32 * sizeof(State),
-    };
-
-    // every 100 flushes we should reset our fPipelineBuffer to prevent us from holding at a
-    // highwater mark
-    static const int kPipelineBufferHighWaterMark = 100;
-
-    SkAutoTDelete<GrCommandBuilder>     fCommands;
-    SkTArray<GrTraceMarkerSet, false>   fGpuCmdMarkers;
-    SkChunkAlloc                        fPathIndexBuffer;
-    SkChunkAlloc                        fPathTransformBuffer;
-    SkChunkAlloc                        fPipelineBuffer;
-    uint32_t                            fDrawID;
-    SkAutoTUnref<State>                 fPrevState;
-
-    typedef GrClipTarget INHERITED;
-};
-
-#endif
index 99a2c11c27a2e12703997d240dfe0aae6cb26227..6ee11f9f2e37bd961a7f9b6cfdf41e9d58857f6d 100644 (file)
@@ -36,7 +36,7 @@ public:
     }
 
     Cmd* recordDrawPaths(State*,
-                         GrInOrderDrawBuffer*,
+                         GrBufferedDrawTarget*,
                          const GrPathProcessor*,
                          const GrPathRange*,
                          const void*,
index 84dbf9346e127d0036390c54ae04d70c2cc2cd4e..9585b655a3050050ee3309b3b803780cfd390e21 100644 (file)
@@ -7,19 +7,19 @@
 
 #include "GrTargetCommands.h"
 
-#include "GrInOrderDrawBuffer.h"
+#include "GrBufferedDrawTarget.h"
 
 void GrTargetCommands::reset() {
     fCmdBuffer.reset();
     fBatchTarget.reset();
 }
 
-void GrTargetCommands::flush(GrInOrderDrawBuffer* iodb) {
+void GrTargetCommands::flush(GrBufferedDrawTarget* bufferedDrawTarget) {
     if (fCmdBuffer.empty()) {
         return;
     }
 
-    GrGpu* gpu = iodb->getGpu();
+    GrGpu* gpu = bufferedDrawTarget->getGpu();
 
     // Loop over all batches and generate geometry
     CmdBuffer::Iter genIter(fCmdBuffer);
@@ -40,7 +40,7 @@ void GrTargetCommands::flush(GrInOrderDrawBuffer* iodb) {
         GrGpuTraceMarker newMarker("", -1);
         SkString traceString;
         if (iter->isTraced()) {
-            traceString = iodb->getCmdString(iter->markerID());
+            traceString = bufferedDrawTarget->getCmdString(iter->markerID());
             newMarker.fMarker = traceString.c_str();
             gpu->addGpuTraceMarker(&newMarker);
         }
index e5f3cd5a1196b2562d1d3c087445363ed67955fa..8b47cfdfa60088a12593e9ee63c330e3f1fcb321 100644 (file)
@@ -19,7 +19,7 @@
 #include "SkRect.h"
 #include "SkTypes.h"
 
-class GrInOrderDrawBuffer;
+class GrBufferedDrawTarget;
 
 
 class GrTargetCommands : ::SkNoncopyable {
@@ -61,16 +61,16 @@ public:
     };
 
     void reset();
-    void flush(GrInOrderDrawBuffer*);
+    void flush(GrBufferedDrawTarget*);
 
 private:
     friend class GrCommandBuilder;
-    friend class GrInOrderDrawBuffer; // This goes away when State becomes just a pipeline
+    friend class GrBufferedDrawTarget; // This goes away when State becomes just a pipeline
     friend class GrReorderCommandBuilder;
 
     typedef GrGpu::DrawArgs DrawArgs;
 
-    void recordXferBarrierIfNecessary(const GrPipeline&, GrInOrderDrawBuffer*);
+    void recordXferBarrierIfNecessary(const GrPipeline&, GrBufferedDrawTarget*);
 
     // TODO: This can be just a pipeline once paths are in batch, and it should live elsewhere
     struct State : public SkNVRefCnt<State> {
index 1bf13a1e598bedbe9828b1f7b5236673c43d67d6..fd2908eb766e2a519d21d5a6cb866c960cdda9cd 100644 (file)
@@ -7,9 +7,10 @@
  */
 
 #include "GrTest.h"
+
+#include "GrBufferedDrawTarget.h"
 #include "GrContextOptions.h"
 #include "GrGpuResourceCacheAccess.h"
-#include "GrInOrderDrawBuffer.h"
 #include "GrResourceCache.h"
 #include "SkString.h"
 
@@ -135,7 +136,6 @@ void GrResourceCache::changeTimestamp(uint32_t newTimestamp) { fTimestamp = newT
 // Code for the mock context. It's built on a mock GrGpu class that does nothing.
 ////
 
-#include "GrInOrderDrawBuffer.h"
 #include "GrGpu.h"
 
 class GrPipeline;
index 0f76f237c9057778d2552e12fe652951099c9e6b..5fea60bb9ed438684d2cd8771fa29cf93f086242 100644 (file)
@@ -8,9 +8,9 @@
 #ifndef GrTracing_DEFINED
 #define GrTracing_DEFINED
 
+#include "GrBufferedDrawTarget.h"
 #include "GrDrawTarget.h"
 #include "GrGpu.h"
-#include "GrInOrderDrawBuffer.h"
 #include "GrTraceMarker.h"
 #include "SkTraceEvent.h"