diff options
Diffstat (limited to 'src/gpu/batches')
-rw-r--r-- | src/gpu/batches/GrBatch.h | 19 | ||||
-rw-r--r-- | src/gpu/batches/GrClearBatch.h | 55 | ||||
-rw-r--r-- | src/gpu/batches/GrDiscardBatch.h | 48 | ||||
-rw-r--r-- | src/gpu/batches/GrDrawBatch.h | 19 | ||||
-rw-r--r-- | src/gpu/batches/GrVertexBatch.cpp | 4 | ||||
-rw-r--r-- | src/gpu/batches/GrVertexBatch.h | 6 |
6 files changed, 146 insertions, 5 deletions
diff --git a/src/gpu/batches/GrBatch.h b/src/gpu/batches/GrBatch.h index 7bb6af1265..b6eec1f969 100644 --- a/src/gpu/batches/GrBatch.h +++ b/src/gpu/batches/GrBatch.h @@ -12,8 +12,10 @@ #include "GrNonAtomicRef.h" #include "SkRect.h" +#include "SkString.h" class GrCaps; +class GrBatchFlushState; /** * GrBatch is the base class for all Ganesh deferred geometry generators. To facilitate @@ -79,6 +81,20 @@ public: #endif SkDEBUGCODE(bool isUsed() const { return fUsed; }) + /** Called prior to drawing. The batch should perform any resource creation necessary to + to quickly issue its draw when draw is called. */ + void prepare(GrBatchFlushState* state) { this->onPrepare(state); } + + /** Issues the batches commands to GrGpu. */ + void draw(GrBatchFlushState* state) { this->onDraw(state); } + + /** Used to block batching across render target changes. Remove this once we store + GrBatches for different RTs in different targets. */ + virtual uint32_t renderTargetUniqueID() const = 0; + + /** Used for spewing information about batches when debugging. */ + virtual SkString dumpInfo() const = 0; + protected: template <typename PROC_SUBCLASS> void initClassID() { static uint32_t kClassID = GenID(&gCurrBatchClassID); @@ -98,6 +114,9 @@ protected: private: virtual bool onCombineIfPossible(GrBatch*, const GrCaps& caps) = 0; + virtual void onPrepare(GrBatchFlushState*) = 0; + virtual void onDraw(GrBatchFlushState*) = 0; + static uint32_t GenID(int32_t* idCounter) { // fCurrProcessorClassID has been initialized to kIllegalProcessorClassID. The // atomic inc returns the old value not the incremented value. So we add diff --git a/src/gpu/batches/GrClearBatch.h b/src/gpu/batches/GrClearBatch.h new file mode 100644 index 0000000000..b36a53f94d --- /dev/null +++ b/src/gpu/batches/GrClearBatch.h @@ -0,0 +1,55 @@ +/* + * 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 GrClearBatch_DEFINED +#define GrClearBatch_DEFINED + +#include "GrBatch.h" +#include "GrBatchFlushState.h" +#include "GrGpu.h" +#include "GrRenderTarget.h" + +class GrClearBatch final : public GrBatch { +public: + GrClearBatch(const SkIRect& rect, GrColor color, GrRenderTarget* rt) + : fRect(rect) + , fColor(color) + , fRenderTarget(rt) { + this->initClassID<GrClearBatch>(); + fBounds = SkRect::Make(rect); + } + + const char* name() const override { return "Clear"; } + + uint32_t renderTargetUniqueID() const override { return fRenderTarget.get()->getUniqueID(); } + + SkString dumpInfo() const { + SkString string; + string.printf("Color: 0x%08x, Rect [L: %d, T: %d, R: %d, B: %d], RT: 0x%p", + fColor, fRect.fLeft, fRect.fTop, fRect.fRight, fRect.fBottom, + fRenderTarget.get()); + return string; + } + +private: + bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { + // We could combine clears. TBD how much complexity to put here. + return false; + } + + void onPrepare(GrBatchFlushState*) override {} + + void onDraw(GrBatchFlushState* state) override { + state->gpu()->clear(fRect, fColor, fRenderTarget.get()); + } + + SkIRect fRect; + GrColor fColor; + GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget; +}; + +#endif diff --git a/src/gpu/batches/GrDiscardBatch.h b/src/gpu/batches/GrDiscardBatch.h new file mode 100644 index 0000000000..9d9570fe85 --- /dev/null +++ b/src/gpu/batches/GrDiscardBatch.h @@ -0,0 +1,48 @@ +/* + * 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 GrDiscardBatch_DEFINED +#define GrDiscardBatch_DEFINED + +#include "GrBatch.h" +#include "GrBatchFlushState.h" +#include "GrGpu.h" +#include "GrRenderTarget.h" + +class GrDiscardBatch final : public GrBatch { +public: + GrDiscardBatch(GrRenderTarget* rt) + : fRenderTarget(rt) { + this->initClassID<GrDiscardBatch>(); + fBounds = SkRect::MakeWH(SkIntToScalar(rt->width()), SkIntToScalar(rt->height())); + } + + const char* name() const override { return "Discard"; } + + uint32_t renderTargetUniqueID() const override { return fRenderTarget.get()->getUniqueID(); } + + SkString dumpInfo() const { + SkString string; + string.printf("RT: 0x%p", fRenderTarget.get()); + return string; + } + +private: + bool onCombineIfPossible(GrBatch* that, const GrCaps& caps) override { + return fRenderTarget == that->cast<GrDiscardBatch>()->fRenderTarget; + } + + void onPrepare(GrBatchFlushState*) override {} + + void onDraw(GrBatchFlushState* state) override { + state->gpu()->discard(fRenderTarget.get()); + } + + GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget; +}; + +#endif diff --git a/src/gpu/batches/GrDrawBatch.h b/src/gpu/batches/GrDrawBatch.h index bbebe5b98c..ed33816603 100644 --- a/src/gpu/batches/GrDrawBatch.h +++ b/src/gpu/batches/GrDrawBatch.h @@ -56,6 +56,25 @@ public: // TODO no GrPrimitiveProcessors yet read fragment position bool willReadFragmentPosition() const { return false; } + uint32_t renderTargetUniqueID() const final { + SkASSERT(fPipelineInstalled); + return this->pipeline()->getRenderTarget()->getUniqueID(); + } + + SkString dumpInfo() const override { + SkString string; + string.append("ColorStages:\n"); + for (int i = 0; i < this->pipeline()->numColorFragmentStages(); i++) { + string.appendf("\t\t%s\n", this->pipeline()->getColorStage(i).processor()->name()); + } + string.append("CoverageStages:\n"); + for (int i = 0; i < this->pipeline()->numCoverageFragmentStages(); i++) { + string.appendf("\t%s\n", this->pipeline()->getCoverageStage(i).processor()->name()); + } + string.appendf("XP: %s\n", this->pipeline()->getXferProcessor()->name()); + return string; + } + private: /** * initBatchTracker is a hook for the some additional overrides / optimization possibilities diff --git a/src/gpu/batches/GrVertexBatch.cpp b/src/gpu/batches/GrVertexBatch.cpp index 6081e26371..d61b51145a 100644 --- a/src/gpu/batches/GrVertexBatch.cpp +++ b/src/gpu/batches/GrVertexBatch.cpp @@ -11,7 +11,7 @@ GrVertexBatch::GrVertexBatch() : fDrawArrays(1) {} -void GrVertexBatch::prepareDraws(GrBatchFlushState* state) { +void GrVertexBatch::onPrepare(GrBatchFlushState* state) { Target target(state, this); this->onPrepareDraws(&target); } @@ -59,7 +59,7 @@ void* GrVertexBatch::QuadHelper::init(Target* target, size_t vertexStride, quadIndexBuffer, kVerticesPerQuad, kIndicesPerQuad, quadsToDraw); } -void GrVertexBatch::issueDraws(GrBatchFlushState* state) { +void GrVertexBatch::onDraw(GrBatchFlushState* state) { int uploadCnt = fInlineUploads.count(); int currUpload = 0; diff --git a/src/gpu/batches/GrVertexBatch.h b/src/gpu/batches/GrVertexBatch.h index b868962411..0ff5ac18bc 100644 --- a/src/gpu/batches/GrVertexBatch.h +++ b/src/gpu/batches/GrVertexBatch.h @@ -26,9 +26,6 @@ public: GrVertexBatch(); - void prepareDraws(GrBatchFlushState* state); - void issueDraws(GrBatchFlushState* state); - protected: /** Helper for rendering instances using an instanced index index buffer. This class creates the space for the vertices and flushes the draws to the batch target. */ @@ -65,6 +62,9 @@ protected: }; private: + void onPrepare(GrBatchFlushState* state) final; + void onDraw(GrBatchFlushState* state) final; + virtual void onPrepareDraws(Target*) = 0; // A set of contiguous draws with no inline uploads between them that all use the same |