Remove GrFlushToGpuDrawTarget and move functionality up to GrDrawTarget.

Review URL: https://codereview.chromium.org/1117433002
This commit is contained in:
bsalomon 2015-04-28 13:35:17 -07:00 committed by Commit bot
parent 4eaf9cef5a
commit a73239a009
11 changed files with 101 additions and 218 deletions

View File

@ -93,8 +93,6 @@
'<(skia_src_path)/gpu/GrDrawTarget.cpp',
'<(skia_src_path)/gpu/GrDrawTarget.h',
'<(skia_src_path)/gpu/GrDrawTargetCaps.h',
'<(skia_src_path)/gpu/GrFlushToGpuDrawTarget.cpp',
'<(skia_src_path)/gpu/GrFlushToGpuDrawTarget.h',
'<(skia_src_path)/gpu/GrFontAtlasSizes.h',
'<(skia_src_path)/gpu/GrFontScaler.cpp',
'<(skia_src_path)/gpu/GrFontScaler.h',

View File

@ -26,7 +26,6 @@ class GrGpu;
class GrGpuTraceMarker;
class GrIndexBuffer;
class GrIndexBufferAllocPool;
class GrInOrderDrawBuffer;
class GrLayerCache;
class GrOvalRenderer;
class GrPath;
@ -701,7 +700,7 @@ private:
GrVertexBufferAllocPool* fDrawBufferVBAllocPool;
GrIndexBufferAllocPool* fDrawBufferIBAllocPool;
GrInOrderDrawBuffer* fDrawBuffer;
GrDrawTarget* fDrawBuffer;
// Set by OverbudgetCB() to request that GrContext flush before exiting a draw.
bool fFlushToReduceCacheSize;

View File

@ -1913,7 +1913,7 @@ void GrContext::setupDrawBuffer() {
DRAW_BUFFER_IBPOOL_BUFFER_SIZE,
DRAW_BUFFER_IBPOOL_PREALLOC_BUFFERS));
fDrawBuffer = SkNEW_ARGS(GrInOrderDrawBuffer, (fGpu,
fDrawBuffer = SkNEW_ARGS(GrInOrderDrawBuffer, (this,
fDrawBufferVBAllocPool,
fDrawBufferIBAllocPool));
}

View File

@ -9,6 +9,7 @@
#include "GrDrawTarget.h"
#include "GrBatch.h"
#include "GrBufferAllocPool.h"
#include "GrContext.h"
#include "GrDrawTargetCaps.h"
#include "GrPath.h"
@ -55,9 +56,15 @@ GrDrawTarget::DrawInfo& GrDrawTarget::DrawInfo::operator =(const DrawInfo& di) {
#define DEBUG_INVAL_BUFFER 0xdeadcafe
#define DEBUG_INVAL_START_IDX -1
GrDrawTarget::GrDrawTarget(GrContext* context)
GrDrawTarget::GrDrawTarget(GrContext* context,
GrVertexBufferAllocPool* vpool,
GrIndexBufferAllocPool* ipool)
: fContext(context)
, fGpuTraceMarkerCount(0) {
, fCaps(SkRef(context->getGpu()->caps()))
, fGpuTraceMarkerCount(0)
, fVertexPool(vpool)
, fIndexPool(ipool)
, fFlushing(false) {
SkASSERT(context);
}
@ -93,7 +100,13 @@ bool GrDrawTarget::setupDstReadIfNecessary(const GrPipelineBuilder& pipelineBuil
// MSAA consideration: When there is support for reading MSAA samples in the shader we could
// have per-sample dst values by making the copy multisampled.
GrSurfaceDesc desc;
this->initCopySurfaceDstDesc(rt, &desc);
if (!this->getGpu()->initCopySurfaceDstDesc(rt, &desc)) {
desc.fOrigin = kDefault_GrSurfaceOrigin;
desc.fFlags = kRenderTarget_GrSurfaceFlag;
desc.fConfig = rt->config();
}
desc.fWidth = copyRect.width();
desc.fHeight = copyRect.height();
@ -114,6 +127,29 @@ bool GrDrawTarget::setupDstReadIfNecessary(const GrPipelineBuilder& pipelineBuil
}
}
void GrDrawTarget::reset() {
fVertexPool->reset();
fIndexPool->reset();
this->onReset();
}
void GrDrawTarget::flush() {
if (fFlushing) {
return;
}
fFlushing = true;
this->getGpu()->saveActiveTraceMarkers();
this->onFlush();
this->getGpu()->restoreActiveTraceMarkers();
fFlushing = false;
this->reset();
}
void GrDrawTarget::drawBatch(GrPipelineBuilder* pipelineBuilder,
GrBatch* batch,
const SkRect* devBounds) {
@ -413,7 +449,8 @@ bool GrDrawTarget::copySurface(GrSurface* dst,
return true;
}
if (this->onCopySurface(dst, src, clippedSrcRect, clippedDstPoint)) {
if (this->getGpu()->canCopySurface(dst, src, clippedSrcRect, clippedDstPoint)) {
this->onCopySurface(dst, src, clippedSrcRect, clippedDstPoint);
return true;
}
@ -457,23 +494,8 @@ bool GrDrawTarget::canCopySurface(const GrSurface* dst,
&clippedDstPoint)) {
return true;
}
return this->internalCanCopySurface(dst, src, clippedSrcRect, clippedDstPoint);
}
bool GrDrawTarget::internalCanCopySurface(const GrSurface* dst,
const GrSurface* src,
const SkIRect& clippedSrcRect,
const SkIPoint& clippedDstPoint) {
// Check that the read/write rects are contained within the src/dst bounds.
SkASSERT(!clippedSrcRect.isEmpty());
SkASSERT(SkIRect::MakeWH(src->width(), src->height()).contains(clippedSrcRect));
SkASSERT(clippedDstPoint.fX >= 0 && clippedDstPoint.fY >= 0);
SkASSERT(clippedDstPoint.fX + clippedSrcRect.width() <= dst->width() &&
clippedDstPoint.fY + clippedSrcRect.height() <= dst->height());
// The base class can do it as a draw or the subclass may be able to handle it.
return ((dst != src) && dst->asRenderTarget() && src->asTexture()) ||
this->onCanCopySurface(dst, src, clippedSrcRect, clippedDstPoint);
this->getGpu()->canCopySurface(dst, src, clippedSrcRect, clippedDstPoint);
}
void GrDrawTarget::setupPipeline(const PipelineInfo& pipelineInfo,

View File

@ -31,9 +31,11 @@
class GrBatch;
class GrClip;
class GrDrawTargetCaps;
class GrIndexBufferAllocPool;
class GrPath;
class GrPathRange;
class GrPipeline;
class GrVertexBufferAllocPool;
class GrDrawTarget : public SkRefCnt {
public:
@ -46,9 +48,21 @@ public:
// The context may not be fully constructed and should not be used during GrDrawTarget
// construction.
GrDrawTarget(GrContext* context);
GrDrawTarget(GrContext* context, GrVertexBufferAllocPool*, GrIndexBufferAllocPool*);
virtual ~GrDrawTarget() {}
/**
* Empties the draw buffer of any queued up draws.
*/
void reset();
/**
* This plays any queued up draws to its GrGpu target. It also resets this object (i.e. flushing
* is destructive).
*/
void flush();
/**
* Gets the capabilities of the draw target.
*/
@ -301,8 +315,17 @@ protected:
GrContext* getContext() { return fContext; }
const GrContext* getContext() const { return fContext; }
// Subclass must initialize this in its constructor.
SkAutoTUnref<const GrDrawTargetCaps> fCaps;
GrGpu* getGpu() {
SkASSERT(fContext && fContext->getGpu());
return fContext->getGpu();
}
const GrGpu* getGpu() const {
SkASSERT(fContext && fContext->getGpu());
return fContext->getGpu();
}
GrVertexBufferAllocPool* getVertexAllocPool() { return fVertexPool; }
GrIndexBufferAllocPool* getIndexAllocPool() { return fIndexPool; }
const GrTraceMarkerSet& getActiveTraceMarkers() { return fActiveTraceMarkers; }
@ -342,24 +365,9 @@ protected:
void setupPipeline(const PipelineInfo& pipelineInfo, GrPipeline* pipeline);
private:
/**
* This will be called before allocating a texture as a dst for copySurface. This function
* populates the dstDesc's config, flags, and origin so as to maximize efficiency and guarantee
* success of the copySurface call.
*/
void initCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* dstDesc) {
if (!this->onInitCopySurfaceDstDesc(src, dstDesc)) {
dstDesc->fOrigin = kDefault_GrSurfaceOrigin;
dstDesc->fFlags = kRenderTarget_GrSurfaceFlag;
dstDesc->fConfig = src->config();
}
}
virtual void onReset() = 0;
/** Internal implementation of canCopySurface. */
bool internalCanCopySurface(const GrSurface* dst,
const GrSurface* src,
const SkIRect& clippedSrcRect,
const SkIPoint& clippedDstRect);
virtual void onFlush() = 0;
virtual void onDrawBatch(GrBatch*, const PipelineInfo&) = 0;
// TODO copy in order drawbuffer onDrawRect to here
@ -392,30 +400,13 @@ private:
virtual void onClear(const SkIRect* rect, GrColor color, bool canIgnoreRect,
GrRenderTarget* renderTarget) = 0;
/** The subclass will get a chance to copy the surface for falling back to the default
implementation, which simply draws a rectangle (and fails if dst isn't a render target). It
should assume that any clipping has already been performed on the rect and point. It won't
be called if the copy can be skipped. */
virtual bool onCopySurface(GrSurface* dst,
/** The subclass's copy surface implementation. It should assume that any clipping has already
been performed on the rect and point and that the GrGpu supports the copy. */
virtual void onCopySurface(GrSurface* dst,
GrSurface* src,
const SkIRect& srcRect,
const SkIPoint& dstPoint) = 0;
/** Indicates whether onCopySurface would succeed. It should assume that any clipping has
already been performed on the rect and point. It won't be called if the copy can be
skipped. */
virtual bool onCanCopySurface(const GrSurface* dst,
const GrSurface* src,
const SkIRect& srcRect,
const SkIPoint& dstPoint) = 0;
/**
* This will be called before allocating a texture to be a dst for onCopySurface. Only the
* dstDesc's config, flags, and origin need be set by the function. If the subclass cannot
* create a surface that would succeed its implementation of onCopySurface, it should return
* false. The base class will fall back to creating a render target to draw into using the src.
*/
virtual bool onInitCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* dstDesc) = 0;
// Check to see if this set of draw commands has been sent out
virtual bool isIssued(uint32_t drawID) { return true; }
void getPathStencilSettingsForFilltype(GrPathRendering::FillType,
@ -430,10 +421,14 @@ private:
// The context owns us, not vice-versa, so this ptr is not ref'ed by DrawTarget.
GrContext* fContext;
SkAutoTUnref<const GrDrawTargetCaps> fCaps;
// To keep track that we always have at least as many debug marker adds as removes
int fGpuTraceMarkerCount;
GrTraceMarkerSet fActiveTraceMarkers;
GrTraceMarkerSet fStoredTraceMarkers;
GrVertexBufferAllocPool* fVertexPool;
GrIndexBufferAllocPool* fIndexPool;
bool fFlushing;
typedef SkRefCnt INHERITED;
};
@ -443,7 +438,10 @@ private:
*/
class GrClipTarget : public GrDrawTarget {
public:
GrClipTarget(GrContext* context) : INHERITED(context) {
GrClipTarget(GrContext* context,
GrVertexBufferAllocPool* vpool,
GrIndexBufferAllocPool* ipool)
: INHERITED(context, vpool, ipool) {
fClipMaskManager.setClipTarget(this);
}

View File

@ -1,61 +0,0 @@
/*
* Copyright 2014 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "GrFlushToGpuDrawTarget.h"
#include "GrContext.h"
#include "GrGpu.h"
#include "GrBufferAllocPool.h"
GrFlushToGpuDrawTarget::GrFlushToGpuDrawTarget(GrGpu* gpu,
GrVertexBufferAllocPool* vertexPool,
GrIndexBufferAllocPool* indexPool)
: INHERITED(gpu->getContext())
, fGpu(SkRef(gpu))
, fVertexPool(vertexPool)
, fIndexPool(indexPool)
, fFlushing(false) {
fCaps.reset(SkRef(fGpu->caps()));
SkASSERT(vertexPool);
SkASSERT(indexPool);
}
void GrFlushToGpuDrawTarget::reset() {
fVertexPool->reset();
fIndexPool->reset();
this->onReset();
}
void GrFlushToGpuDrawTarget::flush() {
if (fFlushing) {
return;
}
fFlushing = true;
fGpu->saveActiveTraceMarkers();
this->onFlush();
fGpu->restoreActiveTraceMarkers();
fFlushing = false;
this->reset();
}
bool GrFlushToGpuDrawTarget::onCanCopySurface(const GrSurface* dst,
const GrSurface* src,
const SkIRect& srcRect,
const SkIPoint& dstPoint) {
return getGpu()->canCopySurface(dst, src, srcRect, dstPoint);
}
bool GrFlushToGpuDrawTarget::onInitCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* desc) {
return getGpu()->initCopySurfaceDstDesc(src, desc);
}

View File

@ -1,67 +0,0 @@
/*
* Copyright 2014 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef GrFlushToGpuDrawTarget_DEFINED
#define GrFlushToGpuDrawTarget_DEFINED
#include "GrDrawTarget.h"
class GrIndexBufferAllocPool;
class GrVertexBufferAllocPool;
class GrGpu;
/**
* Base class for draw targets that accumulate index and vertex data in buffers for deferred.
* When draw target clients reserve geometry this subclass will place that geometry into
* preallocated vertex/index buffers in the order the requests are made (assuming the requests fit
* in the preallocated buffers).
*/
class GrFlushToGpuDrawTarget : public GrClipTarget {
public:
GrFlushToGpuDrawTarget(GrGpu*, GrVertexBufferAllocPool*,GrIndexBufferAllocPool*);
/**
* Empties the draw buffer of any queued up draws. This must not be called while inside an
* unbalanced pushGeometrySource().
*/
void reset();
/**
* This plays any queued up draws to its GrGpu target. It also resets this object (i.e. flushing
* is destructive). This buffer must not have an active reserved vertex or index source. Any
* reserved geometry on the target will be finalized because it's geometry source will be pushed
* before flushing and popped afterwards.
*/
void flush();
protected:
GrGpu* getGpu() { return fGpu; }
const GrGpu* getGpu() const{ return fGpu; }
GrVertexBufferAllocPool* getVertexAllocPool() { return fVertexPool; }
GrIndexBufferAllocPool* getIndexAllocPool() { return fIndexPool; }
private:
virtual void onReset() = 0;
virtual void onFlush() = 0;
bool onCanCopySurface(const GrSurface* dst,
const GrSurface* src,
const SkIRect& srcRect,
const SkIPoint& dstPoint) override;
bool onInitCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* desc) override;
SkAutoTUnref<GrGpu> fGpu;
GrVertexBufferAllocPool* fVertexPool;
GrIndexBufferAllocPool* fIndexPool;
bool fFlushing;
typedef GrClipTarget INHERITED;
};
#endif

View File

@ -10,11 +10,11 @@
#include "GrDefaultGeoProcFactory.h"
#include "GrTemplates.h"
GrInOrderDrawBuffer::GrInOrderDrawBuffer(GrGpu* gpu,
GrInOrderDrawBuffer::GrInOrderDrawBuffer(GrContext* context,
GrVertexBufferAllocPool* vertexPool,
GrIndexBufferAllocPool* indexPool)
: INHERITED(gpu, vertexPool, indexPool)
, fCommands(gpu, vertexPool, indexPool)
: INHERITED(context, vertexPool, indexPool)
, fCommands(context->getGpu(), vertexPool, indexPool)
, fPathIndexBuffer(kPathIdxBufferMinReserve * sizeof(char)/4)
, fPathTransformBuffer(kPathXformBufferMinReserve * sizeof(float)/4)
, fDrawID(0) {
@ -376,14 +376,13 @@ void GrInOrderDrawBuffer::onFlush() {
++fDrawID;
}
bool GrInOrderDrawBuffer::onCopySurface(GrSurface* dst,
void GrInOrderDrawBuffer::onCopySurface(GrSurface* dst,
GrSurface* src,
const SkIRect& srcRect,
const SkIPoint& dstPoint) {
GrTargetCommands::Cmd* cmd = fCommands.recordCopySurface(this, dst, src,
srcRect, dstPoint);
SkASSERT(this->getGpu()->canCopySurface(dst, src, srcRect, dstPoint));
GrTargetCommands::Cmd* cmd = fCommands.recordCopySurface(dst, src, srcRect, dstPoint);
this->recordTraceMarkersIfNecessary(cmd);
return SkToBool(cmd);
}
void GrInOrderDrawBuffer::recordTraceMarkersIfNecessary(GrTargetCommands::Cmd* cmd) {

View File

@ -8,7 +8,7 @@
#ifndef GrInOrderDrawBuffer_DEFINED
#define GrInOrderDrawBuffer_DEFINED
#include "GrFlushToGpuDrawTarget.h"
#include "GrDrawTarget.h"
#include "GrTargetCommands.h"
#include "SkChunkAlloc.h"
@ -22,19 +22,19 @@
* in the GrGpu object that the buffer is played back into. The buffer requires VB and IB pools to
* store geometry.
*/
class GrInOrderDrawBuffer : public GrFlushToGpuDrawTarget {
class GrInOrderDrawBuffer : public GrClipTarget {
public:
/**
* Creates a GrInOrderDrawBuffer
*
* @param gpu the gpu object that this draw buffer flushes to.
* @param context the context object that owns this draw buffer.
* @param vertexPool pool where vertices for queued draws will be saved when
* the vertex source is either reserved or array.
* @param indexPool pool where indices for queued draws will be saved when
* the index source is either reserved or array.
*/
GrInOrderDrawBuffer(GrGpu* gpu,
GrInOrderDrawBuffer(GrContext* context,
GrVertexBufferAllocPool* vertexPool,
GrIndexBufferAllocPool* indexPool);
@ -107,7 +107,7 @@ private:
GrColor color,
bool canIgnoreRect,
GrRenderTarget* renderTarget) override;
bool onCopySurface(GrSurface* dst,
void onCopySurface(GrSurface* dst,
GrSurface* src,
const SkIRect& srcRect,
const SkIPoint& dstPoint) override;
@ -134,7 +134,7 @@ private:
SkChunkAlloc fPathTransformBuffer;
uint32_t fDrawID;
typedef GrFlushToGpuDrawTarget INHERITED;
typedef GrClipTarget INHERITED;
};
#endif

View File

@ -341,18 +341,14 @@ void GrTargetCommands::CopySurface::execute(GrGpu* gpu, const SetState*) {
gpu->copySurface(this->dst(), this->src(), fSrcRect, fDstPoint);
}
GrTargetCommands::Cmd* GrTargetCommands::recordCopySurface(GrInOrderDrawBuffer* iodb,
GrSurface* dst,
GrTargetCommands::Cmd* GrTargetCommands::recordCopySurface(GrSurface* dst,
GrSurface* src,
const SkIRect& srcRect,
const SkIPoint& dstPoint) {
if (iodb->getGpu()->canCopySurface(dst, src, srcRect, dstPoint)) {
CopySurface* cs = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, CopySurface, (dst, src));
cs->fSrcRect = srcRect;
cs->fDstPoint = dstPoint;
return cs;
}
return NULL;
CopySurface* cs = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, CopySurface, (dst, src));
cs->fSrcRect = srcRect;
cs->fDstPoint = dstPoint;
return cs;
}
bool GrTargetCommands::setupPipelineAndShouldDraw(GrInOrderDrawBuffer* iodb,

View File

@ -125,8 +125,7 @@ public:
GrColor,
bool canIgnoreRect,
GrRenderTarget*);
Cmd* recordCopySurface(GrInOrderDrawBuffer*,
GrSurface* dst,
Cmd* recordCopySurface(GrSurface* dst,
GrSurface* src,
const SkIRect& srcRect,
const SkIPoint& dstPoint);