diff options
-rw-r--r-- | gyp/gpu.gypi | 2 | ||||
-rwxr-xr-x | src/gpu/GrContext.cpp | 5 | ||||
-rw-r--r-- | src/gpu/GrImmediateDrawTarget.cpp | 106 | ||||
-rw-r--r-- | src/gpu/GrImmediateDrawTarget.h | 91 | ||||
-rw-r--r-- | src/gpu/GrInOrderDrawBuffer.h | 2 |
5 files changed, 204 insertions, 2 deletions
diff --git a/gyp/gpu.gypi b/gyp/gpu.gypi index f54c9da883..ad8e401ae0 100644 --- a/gyp/gpu.gypi +++ b/gyp/gpu.gypi @@ -113,6 +113,8 @@ '<(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', diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp index 1609efb440..18f26efc65 100755 --- a/src/gpu/GrContext.cpp +++ b/src/gpu/GrContext.cpp @@ -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 index 0000000000..4c42a30f86 --- /dev/null +++ b/src/gpu/GrImmediateDrawTarget.cpp @@ -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 index 0000000000..d04c08199e --- /dev/null +++ b/src/gpu/GrImmediateDrawTarget.h @@ -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 diff --git a/src/gpu/GrInOrderDrawBuffer.h b/src/gpu/GrInOrderDrawBuffer.h index b3de1925a0..4c60b691b0 100644 --- a/src/gpu/GrInOrderDrawBuffer.h +++ b/src/gpu/GrInOrderDrawBuffer.h @@ -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 { |