2010-12-22 21:39:39 +00:00
|
|
|
|
2011-07-28 14:26:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
2010-12-22 21:39:39 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2011-07-28 14:26:00 +00:00
|
|
|
|
2010-12-22 21:39:39 +00:00
|
|
|
#ifndef GrInOrderDrawBuffer_DEFINED
|
|
|
|
#define GrInOrderDrawBuffer_DEFINED
|
|
|
|
|
|
|
|
#include "GrDrawTarget.h"
|
|
|
|
#include "GrAllocPool.h"
|
|
|
|
#include "GrAllocator.h"
|
|
|
|
#include "GrClip.h"
|
|
|
|
|
|
|
|
class GrVertexBufferAllocPool;
|
2011-02-14 16:51:21 +00:00
|
|
|
class GrIndexBufferAllocPool;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GrInOrderDrawBuffer is an implementation of GrDrawTarget that queues up
|
|
|
|
* draws for eventual playback into a GrGpu. In theory one draw buffer could
|
|
|
|
* playback into another. When index or vertex buffers are used as geometry
|
|
|
|
* sources it is the callers the draw buffer only holds references to the
|
|
|
|
* buffers. It is the callers responsibility to ensure that the data is still
|
|
|
|
* valid when the draw buffer is played back into a GrGpu. Similarly, it is the
|
|
|
|
* caller's responsibility to ensure that all referenced textures, buffers,
|
|
|
|
* and rendertargets are associated in the GrGpu object that the buffer is
|
|
|
|
* played back into. The buffer requires VB and IB pools to store geometry.
|
|
|
|
*/
|
2010-12-22 21:39:39 +00:00
|
|
|
|
|
|
|
class GrInOrderDrawBuffer : public GrDrawTarget {
|
|
|
|
public:
|
|
|
|
|
2011-02-16 16:12:19 +00:00
|
|
|
/**
|
|
|
|
* Creates a GrInOrderDrawBuffer
|
|
|
|
*
|
|
|
|
* @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.
|
|
|
|
*/
|
2011-02-14 16:51:21 +00:00
|
|
|
GrInOrderDrawBuffer(GrVertexBufferAllocPool* vertexPool,
|
|
|
|
GrIndexBufferAllocPool* indexPool);
|
2010-12-22 21:39:39 +00:00
|
|
|
|
|
|
|
virtual ~GrInOrderDrawBuffer();
|
|
|
|
|
2011-02-16 16:12:19 +00:00
|
|
|
/**
|
|
|
|
* Copies the draw state and clip from target to this draw buffer.
|
|
|
|
*
|
|
|
|
* @param target the target whose clip and state should be copied.
|
|
|
|
*/
|
2010-12-22 21:39:39 +00:00
|
|
|
void initializeDrawStateAndClip(const GrDrawTarget& target);
|
|
|
|
|
2011-02-16 16:12:19 +00:00
|
|
|
/**
|
|
|
|
* Provides the buffer with an index buffer that can be used for quad rendering.
|
|
|
|
* The buffer may be able to batch consecutive drawRects if this is provided.
|
|
|
|
* @param indexBuffer index buffer with quad indices.
|
|
|
|
*/
|
|
|
|
void setQuadIndexBuffer(const GrIndexBuffer* indexBuffer);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Empties the draw buffer of any queued up draws.
|
|
|
|
*/
|
|
|
|
void reset();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* plays the queued up draws to another target. Does not empty this buffer so
|
|
|
|
* that it can be played back multiple times.
|
|
|
|
* @param target the target to receive the playback
|
|
|
|
*/
|
|
|
|
void playback(GrDrawTarget* target);
|
|
|
|
|
|
|
|
// overrides from GrDrawTarget
|
|
|
|
virtual void drawRect(const GrRect& rect,
|
|
|
|
const GrMatrix* matrix = NULL,
|
|
|
|
int stageEnableMask = 0,
|
|
|
|
const GrRect* srcRects[] = NULL,
|
|
|
|
const GrMatrix* srcMatrices[] = NULL);
|
|
|
|
|
2010-12-22 21:39:39 +00:00
|
|
|
virtual bool geometryHints(GrVertexLayout vertexLayout,
|
2011-02-14 16:51:21 +00:00
|
|
|
int* vertexCount,
|
|
|
|
int* indexCount) const;
|
2010-12-22 21:39:39 +00:00
|
|
|
|
2011-04-27 19:55:29 +00:00
|
|
|
virtual void clear(const GrIRect* rect, GrColor color);
|
2011-04-25 19:17:44 +00:00
|
|
|
|
2010-12-22 21:39:39 +00:00
|
|
|
private:
|
|
|
|
|
|
|
|
struct Draw {
|
2011-02-22 20:34:01 +00:00
|
|
|
GrPrimitiveType fPrimitiveType;
|
2011-02-14 16:51:21 +00:00
|
|
|
int fStartVertex;
|
|
|
|
int fStartIndex;
|
|
|
|
int fVertexCount;
|
|
|
|
int fIndexCount;
|
|
|
|
bool fStateChanged;
|
|
|
|
bool fClipChanged;
|
|
|
|
GrVertexLayout fVertexLayout;
|
|
|
|
const GrVertexBuffer* fVertexBuffer;
|
|
|
|
const GrIndexBuffer* fIndexBuffer;
|
2010-12-22 21:39:39 +00:00
|
|
|
};
|
|
|
|
|
2011-04-25 19:17:44 +00:00
|
|
|
struct Clear {
|
|
|
|
int fBeforeDrawIdx;
|
2011-04-27 19:55:29 +00:00
|
|
|
GrIRect fRect;
|
2011-04-25 19:17:44 +00:00
|
|
|
GrColor fColor;
|
|
|
|
};
|
|
|
|
|
2011-06-21 18:17:25 +00:00
|
|
|
// overrides from GrDrawTarget
|
|
|
|
virtual void onDrawIndexed(GrPrimitiveType primitiveType,
|
|
|
|
int startVertex,
|
|
|
|
int startIndex,
|
|
|
|
int vertexCount,
|
|
|
|
int indexCount);
|
|
|
|
virtual void onDrawNonIndexed(GrPrimitiveType primitiveType,
|
|
|
|
int startVertex,
|
|
|
|
int vertexCount);
|
|
|
|
virtual bool onReserveVertexSpace(GrVertexLayout layout,
|
|
|
|
int vertexCount,
|
|
|
|
void** vertices);
|
|
|
|
virtual bool onReserveIndexSpace(int indexCount, void** indices);
|
|
|
|
virtual void releaseReservedVertexSpace();
|
|
|
|
virtual void releaseReservedIndexSpace();
|
2011-04-12 15:40:00 +00:00
|
|
|
virtual void onSetVertexSourceToArray(const void* vertexArray,
|
2011-06-21 18:17:25 +00:00
|
|
|
int vertexCount);
|
2011-04-12 15:40:00 +00:00
|
|
|
virtual void onSetIndexSourceToArray(const void* indexArray,
|
|
|
|
int indexCount);
|
2011-06-21 18:17:25 +00:00
|
|
|
virtual void releaseVertexArray();
|
|
|
|
virtual void releaseIndexArray();
|
|
|
|
virtual void geometrySourceWillPush();
|
|
|
|
virtual void geometrySourceWillPop(const GeometrySrcState& restoredState);
|
|
|
|
virtual void clipWillBeSet(const GrClip& newClip);
|
2011-02-14 16:51:21 +00:00
|
|
|
|
2011-02-16 16:12:19 +00:00
|
|
|
bool needsNewState() const;
|
|
|
|
bool needsNewClip() const;
|
2010-12-22 21:39:39 +00:00
|
|
|
|
2011-02-16 16:12:19 +00:00
|
|
|
void pushState();
|
|
|
|
void pushClip();
|
2010-12-22 21:39:39 +00:00
|
|
|
|
|
|
|
GrTAllocator<Draw> fDraws;
|
|
|
|
GrTAllocator<SavedDrawState> fStates;
|
2011-04-25 19:17:44 +00:00
|
|
|
GrTAllocator<Clear> fClears;
|
2010-12-22 21:39:39 +00:00
|
|
|
|
|
|
|
GrTAllocator<GrClip> fClips;
|
2011-02-16 16:12:19 +00:00
|
|
|
bool fClipSet;
|
|
|
|
|
|
|
|
GrVertexLayout fLastRectVertexLayout;
|
|
|
|
const GrIndexBuffer* fQuadIndexBuffer;
|
|
|
|
int fMaxQuads;
|
|
|
|
int fCurrQuad;
|
2010-12-22 21:39:39 +00:00
|
|
|
|
2011-02-14 16:51:21 +00:00
|
|
|
GrVertexBufferAllocPool& fVertexPool;
|
|
|
|
|
|
|
|
GrIndexBufferAllocPool& fIndexPool;
|
2011-06-21 18:17:25 +00:00
|
|
|
struct GeometryPoolState {
|
|
|
|
const GrVertexBuffer* fPoolVertexBuffer;
|
|
|
|
int fPoolStartVertex;
|
|
|
|
const GrIndexBuffer* fPoolIndexBuffer;
|
|
|
|
int fPoolStartIndex;
|
|
|
|
// caller may conservatively over reserve vertices / indices.
|
|
|
|
// we release unused space back to allocator if possible
|
|
|
|
// can only do this if there isn't an intervening pushGeometrySource()
|
|
|
|
size_t fUsedPoolVertexBytes;
|
|
|
|
size_t fUsedPoolIndexBytes;
|
|
|
|
};
|
|
|
|
GrTArray<GeometryPoolState> fGeoPoolStateStack;
|
|
|
|
|
2011-04-20 15:47:04 +00:00
|
|
|
|
|
|
|
enum {
|
2011-06-21 18:17:25 +00:00
|
|
|
kDrawPreallocCnt = 8,
|
|
|
|
kStatePreallocCnt = 8,
|
|
|
|
kClipPreallocCnt = 8,
|
|
|
|
kClearPreallocCnt = 4,
|
|
|
|
kGeoPoolStatePreAllocCnt = 4,
|
2011-04-20 15:47:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
GrAlignedSTStorage<kDrawPreallocCnt, Draw> fDrawStorage;
|
|
|
|
GrAlignedSTStorage<kStatePreallocCnt, SavedDrawState> fStateStorage;
|
|
|
|
GrAlignedSTStorage<kClipPreallocCnt, GrClip> fClipStorage;
|
2011-04-25 19:17:44 +00:00
|
|
|
GrAlignedSTStorage<kClearPreallocCnt, Clear> fClearStorage;
|
2011-06-21 18:17:25 +00:00
|
|
|
GrAlignedSTStorage<kGeoPoolStatePreAllocCnt,
|
|
|
|
GeometryPoolState> fGeoStackStorage;
|
2010-12-22 21:39:39 +00:00
|
|
|
|
2011-02-16 16:12:19 +00:00
|
|
|
typedef GrDrawTarget INHERITED;
|
2010-12-22 21:39:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|