diff options
author | joshualitt <joshualitt@chromium.org> | 2015-05-19 14:28:04 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-05-19 14:28:04 -0700 |
commit | bb87b2104b5fe5f61c88756af6e25fbd3f5ca773 (patch) | |
tree | d2aea5870485d859153d40dcc5ec7f2e0090d7f6 /src/gpu/GrImmediateDrawTarget.cpp | |
parent | 50bc0510078b599c25a9bd2d34f1701521a0e142 (diff) |
Adding immediate mode draw target for debug
BUG=skia:
Review URL: https://codereview.chromium.org/1126043007
Diffstat (limited to 'src/gpu/GrImmediateDrawTarget.cpp')
-rw-r--r-- | src/gpu/GrImmediateDrawTarget.cpp | 106 |
1 files changed, 106 insertions, 0 deletions
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); + } +} |