Adding immediate mode draw target for debug

BUG=skia:

Review URL: https://codereview.chromium.org/1126043007
This commit is contained in:
joshualitt 2015-05-19 14:28:04 -07:00 committed by Commit bot
parent 50bc051007
commit bb87b2104b
5 changed files with 204 additions and 2 deletions

View File

@ -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',

View File

@ -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));

View File

@ -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);
}
}

View File

@ -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

View 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 {