Cleanup GrDrawTarget now that all paths lead to GrBatch

Review URL: https://codereview.chromium.org/1315513008
This commit is contained in:
bsalomon 2015-09-10 10:42:55 -07:00 committed by Commit bot
parent 4a37d08382
commit 512be5340c
17 changed files with 93 additions and 523 deletions

View File

@ -76,8 +76,6 @@
'<(skia_src_path)/gpu/GrBlurUtils.h',
'<(skia_src_path)/gpu/GrBufferAllocPool.cpp',
'<(skia_src_path)/gpu/GrBufferAllocPool.h',
'<(skia_src_path)/gpu/GrBufferedDrawTarget.cpp',
'<(skia_src_path)/gpu/GrBufferedDrawTarget.h',
'<(skia_src_path)/gpu/GrCaps.cpp',
'<(skia_src_path)/gpu/GrClip.cpp',
'<(skia_src_path)/gpu/GrClipMaskCache.h',
@ -85,8 +83,6 @@
'<(skia_src_path)/gpu/GrClipMaskManager.h',
'<(skia_src_path)/gpu/GrClipMaskManager.cpp',
'<(skia_src_path)/gpu/GrContext.cpp',
'<(skia_src_path)/gpu/GrCommandBuilder.h',
'<(skia_src_path)/gpu/GrCommandBuilder.cpp',
'<(skia_src_path)/gpu/GrCoordTransform.cpp',
'<(skia_src_path)/gpu/GrDefaultGeoProcFactory.cpp',
'<(skia_src_path)/gpu/GrDefaultGeoProcFactory.h',
@ -105,12 +101,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',
'<(skia_src_path)/gpu/GrInOrderCommandBuilder.h',
'<(skia_src_path)/gpu/GrLayerCache.cpp',
'<(skia_src_path)/gpu/GrLayerCache.h',
'<(skia_src_path)/gpu/GrLayerHoister.cpp',
@ -160,8 +152,6 @@
'<(skia_src_path)/gpu/GrRenderTargetPriv.h',
'<(skia_src_path)/gpu/GrReducedClip.cpp',
'<(skia_src_path)/gpu/GrReducedClip.h',
'<(skia_src_path)/gpu/GrReorderCommandBuilder.h',
'<(skia_src_path)/gpu/GrReorderCommandBuilder.cpp',
'<(skia_src_path)/gpu/GrResourceCache.cpp',
'<(skia_src_path)/gpu/GrResourceCache.h',
'<(skia_src_path)/gpu/GrResourceProvider.cpp',
@ -174,8 +164,6 @@
'<(skia_src_path)/gpu/GrStencilAttachment.h',
'<(skia_src_path)/gpu/GrStrokeInfo.cpp',
'<(skia_src_path)/gpu/GrStrokeInfo.h',
'<(skia_src_path)/gpu/GrTargetCommands.cpp',
'<(skia_src_path)/gpu/GrTargetCommands.h',
'<(skia_src_path)/gpu/GrTraceMarker.cpp',
'<(skia_src_path)/gpu/GrTraceMarker.h',
'<(skia_src_path)/gpu/GrTracing.h',

View File

@ -1,37 +0,0 @@
/*
* Copyright 2011 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "GrBufferedDrawTarget.h"
// We will use the reordering buffer, unless we have NVPR.
// TODO move NVPR to batch so we can reorder
static inline bool allow_reordering(const GrCaps* caps) {
return caps && caps->shaderCaps() && !caps->shaderCaps()->pathRenderingSupport();
}
GrBufferedDrawTarget::GrBufferedDrawTarget(GrContext* context)
: INHERITED(context)
, fCommands(GrCommandBuilder::Create(context->getGpu(), allow_reordering(context->caps())))
, fDrawID(0) {
}
GrBufferedDrawTarget::~GrBufferedDrawTarget() {
this->reset();
}
void GrBufferedDrawTarget::onDrawBatch(GrBatch* batch) {
fCommands->recordDrawBatch(batch, *this->caps());
}
void GrBufferedDrawTarget::onFlush() {
fCommands->flush(this->getGpu(), this->getContext()->resourceProvider());
++fDrawID;
}
void GrBufferedDrawTarget::onReset() {
fCommands->reset();
}

View File

@ -1,45 +0,0 @@
/*
* Copyright 2011 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef GrBufferedDrawTarget_DEFINED
#define GrBufferedDrawTarget_DEFINED
#include "GrDrawTarget.h"
#include "GrCommandBuilder.h"
#include "SkChunkAlloc.h"
/**
* GrBufferedDrawTarget is an implementation of GrDrawTarget that queues up draws for eventual
* playback into a GrGpu. In theory one draw buffer could playback into another. Similarly, it is
* the caller's responsibility to ensure that all referenced textures, buffers, and render-targets
* are associated in the GrGpu object that the buffer is played back into.
*/
class GrBufferedDrawTarget : public GrClipTarget {
public:
/**
* Creates a GrBufferedDrawTarget
*
* @param context the context object that owns this draw buffer.
*/
GrBufferedDrawTarget(GrContext* context);
~GrBufferedDrawTarget() override;
protected:
void onDrawBatch(GrBatch*) override;
private:
void onReset() override;
void onFlush() override;
SkAutoTDelete<GrCommandBuilder> fCommands;
uint32_t fDrawID;
typedef GrClipTarget INHERITED;
};
#endif

View File

@ -11,15 +11,14 @@
#include "GrBatchFontCache.h"
#include "GrBatchFlushState.h"
#include "GrBatchTest.h"
#include "GrBufferedDrawTarget.h"
#include "GrCaps.h"
#include "GrContextOptions.h"
#include "GrDefaultGeoProcFactory.h"
#include "GrDrawContext.h"
#include "GrDrawTarget.h"
#include "GrGpuResource.h"
#include "GrGpuResourcePriv.h"
#include "GrGpu.h"
#include "GrImmediateDrawTarget.h"
#include "GrIndexBuffer.h"
#include "GrLayerCache.h"
#include "GrOvalRenderer.h"
@ -61,12 +60,7 @@
void GrContext::DrawingMgr::init(GrContext* context) {
fContext = context;
#ifdef IMMEDIATE_MODE
fDrawTarget = new GrImmediateDrawTarget(context);
#else
fDrawTarget = new GrBufferedDrawTarget(context);
#endif
fDrawTarget = new GrClipTarget(context);
}
void GrContext::DrawingMgr::cleanup() {

View File

@ -36,7 +36,8 @@ GrDrawTarget::GrDrawTarget(GrGpu* gpu, GrResourceProvider* resourceProvider)
: fGpu(SkRef(gpu))
, fCaps(SkRef(gpu->caps()))
, fResourceProvider(resourceProvider)
, fFlushing(false) {
, fFlushing(false)
, fLastFlushToken(0) {
}
GrDrawTarget::~GrDrawTarget() {
@ -119,12 +120,31 @@ void GrDrawTarget::flush() {
}
fFlushing = true;
this->onFlush();
GrBatchFlushState flushState(fGpu, fResourceProvider, fLastFlushToken);
// Loop over all batches and generate geometry
for (int i = 0; i < fBatches.count(); ++i) {
fBatches[i]->prepare(&flushState);
}
// Upload all data to the GPU
flushState.preIssueDraws();
// Draw all the generated geometry.
for (int i = 0; i < fBatches.count(); ++i) {
fBatches[i]->draw(&flushState);
}
fLastFlushToken = flushState.lastFlushedToken();
fFlushing = false;
this->reset();
}
void GrDrawTarget::reset() {
fBatches.reset();
}
void GrDrawTarget::drawBatch(const GrPipelineBuilder& pipelineBuilder, GrDrawBatch* batch) {
// Setup clip
GrScissorState scissorState;
@ -148,7 +168,7 @@ void GrDrawTarget::drawBatch(const GrPipelineBuilder& pipelineBuilder, GrDrawBat
if (!batch->installPipeline(pipelineInfo.pipelineCreateArgs())) {
return;
}
this->onDrawBatch(batch);
this->recordBatch(batch);
}
static const GrStencilSettings& winding_path_stencil_settings() {
@ -213,7 +233,7 @@ void GrDrawTarget::stencilPath(const GrPipelineBuilder& pipelineBuilder,
stencilSettings, scissorState,
pipelineBuilder.getRenderTarget(),
path);
this->onDrawBatch(batch);
this->recordBatch(batch);
batch->unref();
}
@ -269,7 +289,7 @@ void GrDrawTarget::drawPathBatch(const GrPipelineBuilder& pipelineBuilder,
return;
}
this->onDrawBatch(batch);
this->recordBatch(batch);
}
void GrDrawTarget::drawNonAARect(const GrPipelineBuilder& pipelineBuilder,
@ -344,7 +364,7 @@ void GrDrawTarget::clear(const SkIRect* rect,
this->drawNonAARect(pipelineBuilder, color, SkMatrix::I(), *rect);
} else {
GrBatch* batch = new GrClearBatch(*rect, color, renderTarget);
this->onDrawBatch(batch);
this->recordBatch(batch);
batch->unref();
}
}
@ -352,7 +372,7 @@ void GrDrawTarget::clear(const SkIRect* rect,
void GrDrawTarget::discard(GrRenderTarget* renderTarget) {
if (this->caps()->discardRenderTargetSupport()) {
GrBatch* batch = new GrDiscardBatch(renderTarget);
this->onDrawBatch(batch);
this->recordBatch(batch);
batch->unref();
}
}
@ -365,11 +385,67 @@ void GrDrawTarget::copySurface(GrSurface* dst,
const SkIPoint& dstPoint) {
GrBatch* batch = GrCopySurfaceBatch::Create(dst, src, srcRect, dstPoint);
if (batch) {
this->onDrawBatch(batch);
this->recordBatch(batch);
batch->unref();
}
}
template <class Left, class Right> static bool intersect(const Left& a, const Right& b) {
SkASSERT(a.fLeft <= a.fRight && a.fTop <= a.fBottom &&
b.fLeft <= b.fRight && b.fTop <= b.fBottom);
return a.fLeft < b.fRight && b.fLeft < a.fRight && a.fTop < b.fBottom && b.fTop < a.fBottom;
}
void GrDrawTarget::recordBatch(GrBatch* batch) {
// Check if there is a Batch Draw we can batch with by linearly searching back until we either
// 1) check every draw
// 2) intersect with something
// 3) find a 'blocker'
// Experimentally we have found that most batching occurs within the first 10 comparisons.
static const int kMaxLookback = 10;
GrBATCH_INFO("Re-Recording (%s, B%u)\n"
"\tBounds (%f, %f, %f, %f)\n",
batch->name(),
batch->uniqueID(),
batch->bounds().fLeft, batch->bounds().fRight,
batch->bounds().fTop, batch->bounds().fBottom);
GrBATCH_INFO(SkTabString(batch->dumpInfo(), 1).c_str());
GrBATCH_INFO("\tOutcome:\n");
int maxCandidates = SkTMin(kMaxLookback, fBatches.count());
if (maxCandidates) {
int i = 0;
while (true) {
GrBatch* candidate = fBatches.fromBack(i);
// We cannot continue to search backwards if the render target changes
if (candidate->renderTargetUniqueID() != batch->renderTargetUniqueID()) {
GrBATCH_INFO("\t\tBreaking because of (%s, B%u) Rendertarget\n",
candidate->name(), candidate->uniqueID());
break;
}
if (candidate->combineIfPossible(batch, *this->caps())) {
GrBATCH_INFO("\t\tCombining with (%s, B%u)\n", candidate->name(),
candidate->uniqueID());
return;
}
// Stop going backwards if we would cause a painter's order violation.
if (intersect(candidate->bounds(), batch->bounds())) {
GrBATCH_INFO("\t\tIntersects with (%s, B%u)\n", candidate->name(),
candidate->uniqueID());
break;
}
++i;
if (i == maxCandidates) {
GrBATCH_INFO("\t\tReached max lookback or beginning of batch array %d\n", i);
break;
}
}
} else {
GrBATCH_INFO("\t\tFirstBatch\n");
}
fBatches.push_back().reset(SkRef(batch));
}
///////////////////////////////////////////////////////////////////////////////
GrDrawTarget::PipelineInfo::PipelineInfo(const GrPipelineBuilder* pipelineBuilder,
@ -416,6 +492,6 @@ void GrClipTarget::purgeResources() {
void GrClipTarget::clearStencilClip(const SkIRect& rect, bool insideClip, GrRenderTarget* rt) {
GrBatch* batch = new GrClearStencilClipBatch(rect, insideClip, rt);
this->onDrawBatch(batch);
this->recordBatch(batch);
batch->unref();
}

View File

@ -39,23 +39,16 @@ class GrPathRangeDraw;
class GrDrawTarget : public SkRefCnt {
public:
typedef GrPathRange::PathIndexType PathIndexType;
typedef GrPathRendering::PathTransformType PathTransformType;
///////////////////////////////////////////////////////////////////////////
// The context may not be fully constructed and should not be used during GrDrawTarget
// construction.
GrDrawTarget(GrGpu* gpu, GrResourceProvider*);
virtual ~GrDrawTarget();
~GrDrawTarget() override;
/**
* Empties the draw buffer of any queued up draws.
*/
void reset() { this->onReset(); }
void reset();
/**
* This plays any queued up draws to its GrGpu target. It also resets this object (i.e. flushing
@ -211,12 +204,10 @@ protected:
GrXferProcessor::DstTexture*,
const SkRect* drawBounds);
virtual void onDrawBatch(GrBatch*) = 0;
void recordBatch(GrBatch*);
private:
virtual void onReset() = 0;
virtual void onFlush() = 0;
SkSTArray<256, SkAutoTUnref<GrBatch>, true> fBatches;
void drawPathBatch(const GrPipelineBuilder& pipelineBuilder, GrDrawPathBatchBase* batch,
GrPathRendering::FillType fill);
@ -235,6 +226,7 @@ private:
const GrCaps* fCaps;
GrResourceProvider* fResourceProvider;
bool fFlushing;
GrBatchToken fLastFlushToken;
typedef SkRefCnt INHERITED;
};

View File

@ -1,47 +0,0 @@
/*
* 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 "GrGpu.h"
#include "GrPipeline.h"
#include "GrRenderTarget.h"
#include "SkRect.h"
#include "SkTypes.h"
#include "batches/GrDrawBatch.h"
#include "batches/GrVertexBatch.h"
GrImmediateDrawTarget::GrImmediateDrawTarget(GrContext* context)
: INHERITED(context)
, fDrawID(0) {
}
GrImmediateDrawTarget::~GrImmediateDrawTarget() {
this->reset();
}
void GrImmediateDrawTarget::onDrawBatch(GrBatch* batch) {
#if 0
// TODO: encapsulate the specialization of GrVertexBatch in GrVertexBatch so that we can
// remove this cast. Currently all GrDrawBatches are in fact GrVertexBatch.
GrVertexBatch* vertexBatch = static_cast<GrVertexBatch*>(batch);
vertexBatch->prepareDraws(&fBatchTarget);
vertexBatch->setNumberOfDraws(fBatchTarget.numberOfDraws());
fBatchTarget.preFlush();
fBatchTarget.flushNext(vertexBatch->numberOfDraws());
fBatchTarget.postFlush();
#endif
}
void GrImmediateDrawTarget::onReset() {}
void GrImmediateDrawTarget::onFlush() {
++fDrawID;
}

View File

@ -1,41 +0,0 @@
/*
* 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 "GrBatchFlushState.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;
protected:
void onDrawBatch(GrBatch*) override;
private:
void onReset() override;
void onFlush() override;
uint32_t fDrawID;
typedef GrClipTarget INHERITED;
};
#endif

View File

@ -1,29 +0,0 @@
/*
* 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 "GrInOrderCommandBuilder.h"
#include "GrBufferedDrawTarget.h"
#include "GrColor.h"
#include "SkPoint.h"
GrTargetCommands::Cmd* GrInOrderCommandBuilder::recordDrawBatch(GrBatch* batch,
const GrCaps& caps) {
GrBATCH_INFO("In-Recording (%s, %u)\n", batch->name(), batch->uniqueID());
if (!this->cmdBuffer()->empty() &&
Cmd::kDrawBatch_CmdType == this->cmdBuffer()->back().type()) {
DrawBatch* previous = static_cast<DrawBatch*>(&this->cmdBuffer()->back());
if (previous->batch()->combineIfPossible(batch, caps)) {
GrBATCH_INFO("\tBatching with (%s, %u)\n",
previous->batch()->name(), previous->batch()->uniqueID());
return nullptr;
}
}
return GrNEW_APPEND_TO_RECORDER(*this->cmdBuffer(), DrawBatch, (batch));
}

View File

@ -1,26 +0,0 @@
/*
* 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 GrInOrderCommandBuilder_DEFINED
#define GrInOrderCommandBuilder_DEFINED
#include "GrCommandBuilder.h"
class GrInOrderCommandBuilder : public GrCommandBuilder {
public:
typedef GrCommandBuilder::Cmd Cmd;
GrInOrderCommandBuilder() : INHERITED() { }
Cmd* recordDrawBatch(GrBatch*, const GrCaps&) override;
private:
typedef GrCommandBuilder INHERITED;
};
#endif

View File

@ -1,82 +0,0 @@
/*
* 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 "GrReorderCommandBuilder.h"
#include "SkStringUtils.h"
template <class Left, class Right>
static bool intersect(const Left& a, const Right& b) {
SkASSERT(a.fLeft <= a.fRight && a.fTop <= a.fBottom &&
b.fLeft <= b.fRight && b.fTop <= b.fBottom);
return a.fLeft < b.fRight && b.fLeft < a.fRight &&
a.fTop < b.fBottom && b.fTop < a.fBottom;
}
GrTargetCommands::Cmd* GrReorderCommandBuilder::recordDrawBatch(GrBatch* batch,
const GrCaps& caps) {
// Check if there is a Batch Draw we can batch with by linearly searching back until we either
// 1) check every draw
// 2) intersect with something
// 3) find a 'blocker'
// Experimentally we have found that most batching occurs within the first 10 comparisons.
static const int kMaxLookback = 10;
int i = 0;
GrBATCH_INFO("Re-Recording (%s, B%u)\n"
"\tBounds (%f, %f, %f, %f)\n",
batch->name(),
batch->uniqueID(),
batch->bounds().fLeft, batch->bounds().fRight,
batch->bounds().fTop, batch->bounds().fBottom);
GrBATCH_INFO(SkTabString(batch->dumpInfo(), 1).c_str());
GrBATCH_INFO("\tOutcome:\n");
if (!this->cmdBuffer()->empty()) {
GrTargetCommands::CmdBuffer::ReverseIter reverseIter(*this->cmdBuffer());
do {
if (Cmd::kDrawBatch_CmdType == reverseIter->type()) {
DrawBatch* previous = static_cast<DrawBatch*>(reverseIter.get());
if (previous->batch()->renderTargetUniqueID() != batch->renderTargetUniqueID()) {
GrBATCH_INFO("\t\tBreaking because of (%s, B%u) Rendertarget\n",
previous->batch()->name(), previous->batch()->uniqueID());
break;
}
// We cannot continue to search backwards if the render target changes
if (previous->batch()->combineIfPossible(batch, caps)) {
GrBATCH_INFO("\t\tCombining with (%s, B%u)\n",
previous->batch()->name(), previous->batch()->uniqueID());
return nullptr;
}
if (intersect(previous->batch()->bounds(), batch->bounds())) {
GrBATCH_INFO("\t\tIntersects with (%s, B%u)\n",
previous->batch()->name(), previous->batch()->uniqueID());
break;
}
} else {
GrBATCH_INFO("\t\tBreaking because of other %08x\n", reverseIter->type());
// TODO temporary until we only have batches.
break;
}
} while (reverseIter.previous() && ++i < kMaxLookback);
#if GR_BATCH_SPEW
if (!reverseIter.get()) {
GrBATCH_INFO("\t\tNo more commands to try and batch with\n");
} else if (i >= kMaxLookback) {
GrBATCH_INFO("\t\tReached max lookback %d\n", i);
}
#endif
}
#if GR_BATCH_SPEW
else {
GrBATCH_INFO("\t\tBreaking because empty command buffer\n");
}
#endif
return GrNEW_APPEND_TO_RECORDER(*this->cmdBuffer(), DrawBatch, (batch));
}

View File

@ -1,25 +0,0 @@
/*
* 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 GrReorderCommandBuilder_DEFINED
#define GrReorderCommandBuilder_DEFINED
#include "GrCommandBuilder.h"
class GrReorderCommandBuilder : public GrCommandBuilder {
public:
typedef GrCommandBuilder::Cmd Cmd;
GrReorderCommandBuilder() : INHERITED() {}
Cmd* recordDrawBatch(GrBatch*, const GrCaps&) override;
private:
typedef GrCommandBuilder INHERITED;
};
#endif

View File

@ -1,48 +0,0 @@
/*
* 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 "GrTargetCommands.h"
#include "GrBatchFlushState.h"
#include "GrGpu.h"
#include "GrPathRendering.h"
#include "batches/GrDrawBatch.h"
#include "batches/GrVertexBatch.h"
GrBATCH_SPEW(int32_t GrTargetCommands::Cmd::gUniqueID = 0;)
void GrTargetCommands::reset() {
fCmdBuffer.reset();
}
void GrTargetCommands::flush(GrGpu* gpu, GrResourceProvider* resourceProvider) {
GrBATCH_INFO("Flushing\n");
if (fCmdBuffer.empty()) {
return;
}
GrBatchFlushState flushState(gpu, resourceProvider, fLastFlushToken);
// Loop over all batches and generate geometry
CmdBuffer::Iter genIter(fCmdBuffer);
while (genIter.next()) {
if (Cmd::kDrawBatch_CmdType == genIter->type()) {
DrawBatch* db = reinterpret_cast<DrawBatch*>(genIter.get());
db->batch()->prepare(&flushState);
}
}
flushState.preIssueDraws();
CmdBuffer::Iter iter(fCmdBuffer);
while (iter.next()) {
iter->execute(&flushState);
}
fLastFlushToken = flushState.lastFlushedToken();
}
void GrTargetCommands::DrawBatch::execute(GrBatchFlushState* state) {
fBatch->draw(state);
}

View File

@ -1,99 +0,0 @@
/*
* 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 GrTargetCommands_DEFINED
#define GrTargetCommands_DEFINED
#include "GrDrawTarget.h"
#include "GrPath.h"
#include "GrPendingProgramElement.h"
#include "GrPrimitiveProcessor.h"
#include "GrRenderTarget.h"
#include "GrTRecorder.h"
#include "batches/GrBatch.h"
#include "SkRect.h"
class GrResourceProvider;
class GrBatchFlushState;
// TODO: Convert all commands into GrBatch and remove this class.
class GrTargetCommands : ::SkNoncopyable {
public:
GrTargetCommands() : fCmdBuffer(kCmdBufferInitialSizeInBytes), fLastFlushToken(0) {}
class Cmd : ::SkNoncopyable {
public:
enum CmdType {
kDrawBatch_CmdType = 4,
};
Cmd(CmdType type)
: fType(type)
#if GR_BATCH_SPEW
, fUniqueID(GenID(&gUniqueID))
#endif
{}
virtual ~Cmd() {}
virtual void execute(GrBatchFlushState*) = 0;
CmdType type() const { return fType; }
GrBATCH_SPEW(uint32_t uniqueID() const { return fUniqueID;} )
private:
// TODO move this to a common header so it can be shared with GrBatch
static uint32_t GenID(int32_t* idCounter) {
uint32_t id = static_cast<uint32_t>(sk_atomic_inc(idCounter)) + 1;
if (!id) {
SkFAIL("This should never wrap\n");
}
return id;
}
CmdType fType;
GrBATCH_SPEW(uint32_t fUniqueID);
GrBATCH_SPEW(static int32_t gUniqueID;)
};
void reset();
void flush(GrGpu*, GrResourceProvider*);
private:
friend class GrCommandBuilder;
friend class GrBufferedDrawTarget; // This goes away when State becomes just a pipeline
friend class GrReorderCommandBuilder;
typedef GrGpu::DrawArgs DrawArgs;
struct DrawBatch : public Cmd {
DrawBatch(GrBatch* batch)
: Cmd(kDrawBatch_CmdType)
, fBatch(SkRef(batch)){
SkASSERT(!batch->isUsed());
}
GrBatch* batch() { return fBatch; }
void execute(GrBatchFlushState*) override;
private:
SkAutoTUnref<GrBatch> fBatch;
};
static const int kCmdBufferInitialSizeInBytes = 8 * 1024;
typedef void* TCmdAlign; // This wouldn't be enough align if a command used long double.
typedef GrTRecorder<Cmd, TCmdAlign> CmdBuffer;
CmdBuffer* cmdBuffer() { return &fCmdBuffer; }
CmdBuffer fCmdBuffer;
GrBatchToken fLastFlushToken;
};
#endif

View File

@ -10,7 +10,6 @@
#include "GrBatchAtlas.h"
#include "GrBatchFontCache.h"
#include "GrBufferedDrawTarget.h"
#include "GrContextOptions.h"
#include "GrGpuResourceCacheAccess.h"
#include "GrResourceCache.h"

View File

@ -8,7 +8,6 @@
#ifndef GrTracing_DEFINED
#define GrTracing_DEFINED
#include "GrBufferedDrawTarget.h"
#include "GrDrawTarget.h"
#include "GrGpu.h"
#include "GrTraceMarker.h"

View File

@ -50,6 +50,7 @@ private:
, fRenderTarget(renderTarget)
, fPath(path) {
this->initClassID<GrStencilPathBatch>();
fBounds = path->getBounds();
}
bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { return false; }