Adding immediate mode draw target for debug
authorjoshualitt <joshualitt@chromium.org>
Tue, 19 May 2015 21:28:04 +0000 (14:28 -0700)
committerCommit bot <commit-bot@chromium.org>
Tue, 19 May 2015 21:28:04 +0000 (14:28 -0700)
BUG=skia:

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

gyp/gpu.gypi
src/gpu/GrContext.cpp
src/gpu/GrImmediateDrawTarget.cpp [new file with mode: 0644]
src/gpu/GrImmediateDrawTarget.h [new file with mode: 0644]
src/gpu/GrInOrderDrawBuffer.h

index f54c9da88320181d9c261154445261173f496bee..ad8e401ae09231473c91980e33a36f846647c716 100644 (file)
       '<(skia_src_path)/gpu/GrGpuResource.cpp',
       '<(skia_src_path)/gpu/GrGpuFactory.cpp',
       '<(skia_src_path)/gpu/GrGpuFactory.h',
+      '<(skia_src_path)/gpu/GrImmediateDrawTarget.cpp',
+      '<(skia_src_path)/gpu/GrImmediateDrawTarget.h',
       '<(skia_src_path)/gpu/GrIndexBuffer.h',
       '<(skia_src_path)/gpu/GrInvariantOutput.cpp',
       '<(skia_src_path)/gpu/GrInOrderCommandBuilder.cpp',
index 1609efb440f18b4e87907f41178e44e6a0e2decc..18f26efc65f9964845ed43234879b4a03b420205 100755 (executable)
@@ -19,6 +19,7 @@
 #include "GrGpuResourcePriv.h"
 #include "GrDrawTargetCaps.h"
 #include "GrGpu.h"
+#include "GrImmediateDrawTarget.h"
 #include "GrIndexBuffer.h"
 #include "GrInOrderDrawBuffer.h"
 #include "GrLayerCache.h"
@@ -132,7 +133,11 @@ void GrContext::initCommon() {
 
     fDidTestPMConversions = false;
 
+#ifdef IMMEDIATE_MODE
+    fDrawBuffer = SkNEW_ARGS(GrImmediateDrawTarget, (this));
+#else
     fDrawBuffer = SkNEW_ARGS(GrInOrderDrawBuffer, (this));
+#endif
 
     // GrBatchFontCache will eventually replace GrFontCache
     fBatchFontCache = SkNEW_ARGS(GrBatchFontCache, (this));
diff --git a/src/gpu/GrImmediateDrawTarget.cpp b/src/gpu/GrImmediateDrawTarget.cpp
new file mode 100644 (file)
index 0000000..4c42a30
--- /dev/null
@@ -0,0 +1,106 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "GrImmediateDrawTarget.h"
+
+#include "GrBatch.h"
+#include "GrGpu.h"
+#include "GrPipeline.h"
+#include "GrRenderTarget.h"
+#include "SkRect.h"
+#include "SkTypes.h"
+
+GrImmediateDrawTarget::GrImmediateDrawTarget(GrContext* context)
+    : INHERITED(context)
+    , fBatchTarget(this->getGpu())
+    , fDrawID(0) {
+}
+
+GrImmediateDrawTarget::~GrImmediateDrawTarget() {
+    this->reset();
+}
+
+void GrImmediateDrawTarget::onDrawBatch(GrBatch* batch,
+                                        const PipelineInfo& pipelineInfo) {
+    SkAlignedSStorage<sizeof(GrPipeline)> pipelineStorage;
+    GrPipeline* pipeline = reinterpret_cast<GrPipeline*>(pipelineStorage.get());
+    if (!this->setupPipelineAndShouldDraw(pipeline, pipelineInfo)) {
+        pipeline->~GrPipeline();
+        return;
+    }
+
+    batch->initBatchTracker(pipeline->getInitBatchTracker());
+
+    fBatchTarget.resetNumberOfDraws();
+
+    batch->generateGeometry(&fBatchTarget, pipeline);
+    batch->setNumberOfDraws(fBatchTarget.numberOfDraws());
+
+    fBatchTarget.preFlush();
+    fBatchTarget.flushNext(batch->numberOfDraws());
+    fBatchTarget.postFlush();
+
+    pipeline->~GrPipeline();
+}
+
+void GrImmediateDrawTarget::onClear(const SkIRect* rect, GrColor color,
+                                    bool canIgnoreRect, GrRenderTarget* renderTarget) {
+    this->getGpu()->clear(rect, color, canIgnoreRect, renderTarget);
+}
+
+void GrImmediateDrawTarget::onCopySurface(GrSurface* dst,
+                                          GrSurface* src,
+                                          const SkIRect& srcRect,
+                                          const SkIPoint& dstPoint) {
+    SkASSERT(this->getGpu()->canCopySurface(dst, src, srcRect, dstPoint));
+    this->getGpu()->copySurface(dst, src, srcRect, dstPoint);
+}
+
+void GrImmediateDrawTarget::clearStencilClip(const SkIRect& rect,
+                                             bool insideClip,
+                                             GrRenderTarget* renderTarget) {
+    this->getGpu()->clearStencilClip(rect, insideClip, renderTarget);
+}
+
+void GrImmediateDrawTarget::discard(GrRenderTarget* renderTarget) {
+    if (!this->caps()->discardRenderTargetSupport()) {
+        return;
+    }
+
+    this->getGpu()->discard(renderTarget);
+}
+
+void GrImmediateDrawTarget::onReset() {
+    fBatchTarget.reset();
+}
+
+void GrImmediateDrawTarget::onFlush() {
+    ++fDrawID;
+}
+
+bool
+GrImmediateDrawTarget::setupPipelineAndShouldDraw(GrPipeline* pipeline,
+                                                  const GrDrawTarget::PipelineInfo& pipelineInfo) {
+    this->setupPipeline(pipelineInfo, pipeline);
+
+    if (pipeline->mustSkip()) {
+        return false;
+    }
+
+    this->recordXferBarrierIfNecessary(pipeline);
+    return true;
+}
+
+void GrImmediateDrawTarget::recordXferBarrierIfNecessary(const GrPipeline* pipeline) {
+    const GrXferProcessor& xp = *pipeline->getXferProcessor();
+    GrRenderTarget* rt = pipeline->getRenderTarget();
+
+    GrXferBarrierType barrierType;
+    if (xp.willNeedXferBarrier(rt, *this->caps(), &barrierType)) {
+        this->getGpu()->xferBarrier(rt, barrierType);
+    }
+}
diff --git a/src/gpu/GrImmediateDrawTarget.h b/src/gpu/GrImmediateDrawTarget.h
new file mode 100644 (file)
index 0000000..d04c081
--- /dev/null
@@ -0,0 +1,91 @@
+/*
+ * 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 GrImmediateDrawTarget_DEFINED
+#define GrImmediateDrawTarget_DEFINED
+
+#include "GrDrawTarget.h"
+
+#include "GrBatchTarget.h"
+
+/**
+ * A debug GrDrawTarget which immediately flushes every command it receives
+ */
+class GrImmediateDrawTarget : public GrClipTarget {
+public:
+
+    /**
+     * Creates a GrImmediateDrawTarget
+     *
+     * @param context    the context object that owns this draw buffer.
+     */
+    GrImmediateDrawTarget(GrContext* context);
+
+    ~GrImmediateDrawTarget() override;
+
+    // tracking for draws
+    DrawToken getCurrentDrawToken() override { return DrawToken(this, fDrawID); }
+
+    void clearStencilClip(const SkIRect& rect,
+                          bool insideClip,
+                          GrRenderTarget* renderTarget) override;
+
+    void discard(GrRenderTarget*) override;
+
+private:
+    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 {
+        SkFAIL("Only batch implemented\n");
+    }
+    void onDrawPath(const GrPathProcessor*,
+                    const GrPath*,
+                    const GrStencilSettings&,
+                    const PipelineInfo&) override {
+        SkFAIL("Only batch implemented\n");
+    }
+    void onDrawPaths(const GrPathProcessor*,
+                     const GrPathRange*,
+                     const void* indices,
+                     PathIndexType,
+                     const float transformValues[],
+                     PathTransformType,
+                     int count,
+                     const GrStencilSettings&,
+                     const PipelineInfo&) override {
+        SkFAIL("Only batch implemented\n");
+    }
+    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;
+
+    bool isIssued(uint32_t drawID) override { return drawID != fDrawID; }
+
+    bool SK_WARN_UNUSED_RESULT setupPipelineAndShouldDraw(GrPipeline*,
+                                                          const GrDrawTarget::PipelineInfo&);
+
+    void recordXferBarrierIfNecessary(const GrPipeline*);
+
+    GrBatchTarget fBatchTarget;
+    uint32_t fDrawID;
+
+    typedef GrClipTarget INHERITED;
+};
+
+#endif
index b3de1925a07256405c7edd936a126b39e911f0d4..4c60b691b043b1e5fe8d7660833613311d59466a 100644 (file)
@@ -112,8 +112,6 @@ private:
                        const SkIRect& srcRect,
                        const SkIPoint& dstPoint) override;
 
-    // We lazily record clip changes in order to skip clips that have no effect.
-    void recordClipIfNecessary();
     // Records any trace markers for a command
     void recordTraceMarkersIfNecessary(GrTargetCommands::Cmd*);
     SkString getCmdString(int index) const {