gfx/skia/trunk/src/gpu/GrInOrderDrawBuffer.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /*
michael@0 2 * Copyright 2011 Google Inc.
michael@0 3 *
michael@0 4 * Use of this source code is governed by a BSD-style license that can be
michael@0 5 * found in the LICENSE file.
michael@0 6 */
michael@0 7
michael@0 8 #ifndef GrInOrderDrawBuffer_DEFINED
michael@0 9 #define GrInOrderDrawBuffer_DEFINED
michael@0 10
michael@0 11 #include "GrDrawTarget.h"
michael@0 12 #include "GrAllocPool.h"
michael@0 13 #include "GrAllocator.h"
michael@0 14 #include "GrPath.h"
michael@0 15
michael@0 16 #include "SkClipStack.h"
michael@0 17 #include "SkTemplates.h"
michael@0 18 #include "SkTypes.h"
michael@0 19
michael@0 20 class GrGpu;
michael@0 21 class GrIndexBufferAllocPool;
michael@0 22 class GrVertexBufferAllocPool;
michael@0 23
michael@0 24 /**
michael@0 25 * GrInOrderDrawBuffer is an implementation of GrDrawTarget that queues up draws for eventual
michael@0 26 * playback into a GrGpu. In theory one draw buffer could playback into another. When index or
michael@0 27 * vertex buffers are used as geometry sources it is the callers the draw buffer only holds
michael@0 28 * references to the buffers. It is the callers responsibility to ensure that the data is still
michael@0 29 * valid when the draw buffer is played back into a GrGpu. Similarly, it is the caller's
michael@0 30 * responsibility to ensure that all referenced textures, buffers, and render-targets are associated
michael@0 31 * in the GrGpu object that the buffer is played back into. The buffer requires VB and IB pools to
michael@0 32 * store geometry.
michael@0 33 */
michael@0 34 class GrInOrderDrawBuffer : public GrDrawTarget {
michael@0 35 public:
michael@0 36
michael@0 37 /**
michael@0 38 * Creates a GrInOrderDrawBuffer
michael@0 39 *
michael@0 40 * @param gpu the gpu object that this draw buffer flushes to.
michael@0 41 * @param vertexPool pool where vertices for queued draws will be saved when
michael@0 42 * the vertex source is either reserved or array.
michael@0 43 * @param indexPool pool where indices for queued draws will be saved when
michael@0 44 * the index source is either reserved or array.
michael@0 45 */
michael@0 46 GrInOrderDrawBuffer(GrGpu* gpu,
michael@0 47 GrVertexBufferAllocPool* vertexPool,
michael@0 48 GrIndexBufferAllocPool* indexPool);
michael@0 49
michael@0 50 virtual ~GrInOrderDrawBuffer();
michael@0 51
michael@0 52 /**
michael@0 53 * Empties the draw buffer of any queued up draws. This must not be called while inside an
michael@0 54 * unbalanced pushGeometrySource(). The current draw state and clip are preserved.
michael@0 55 */
michael@0 56 void reset();
michael@0 57
michael@0 58 /**
michael@0 59 * This plays the queued up draws to its GrGpu target. It also resets this object (i.e. flushing
michael@0 60 * is destructive). This buffer must not have an active reserved vertex or index source. Any
michael@0 61 * reserved geometry on the target will be finalized because it's geometry source will be pushed
michael@0 62 * before flushing and popped afterwards.
michael@0 63 */
michael@0 64 void flush();
michael@0 65
michael@0 66 // tracking for draws
michael@0 67 virtual DrawToken getCurrentDrawToken() { return DrawToken(this, fDrawID); }
michael@0 68
michael@0 69 // overrides from GrDrawTarget
michael@0 70 virtual bool geometryHints(int* vertexCount,
michael@0 71 int* indexCount) const SK_OVERRIDE;
michael@0 72 virtual void clear(const SkIRect* rect,
michael@0 73 GrColor color,
michael@0 74 bool canIgnoreRect,
michael@0 75 GrRenderTarget* renderTarget = NULL) SK_OVERRIDE;
michael@0 76
michael@0 77 virtual void initCopySurfaceDstDesc(const GrSurface* src, GrTextureDesc* desc) SK_OVERRIDE;
michael@0 78
michael@0 79 protected:
michael@0 80 virtual void clipWillBeSet(const GrClipData* newClip) SK_OVERRIDE;
michael@0 81
michael@0 82 private:
michael@0 83 enum Cmd {
michael@0 84 kDraw_Cmd = 1,
michael@0 85 kStencilPath_Cmd = 2,
michael@0 86 kSetState_Cmd = 3,
michael@0 87 kSetClip_Cmd = 4,
michael@0 88 kClear_Cmd = 5,
michael@0 89 kCopySurface_Cmd = 6,
michael@0 90 kDrawPath_Cmd = 7,
michael@0 91 };
michael@0 92
michael@0 93 class DrawRecord : public DrawInfo {
michael@0 94 public:
michael@0 95 DrawRecord(const DrawInfo& info) : DrawInfo(info) {}
michael@0 96 const GrVertexBuffer* fVertexBuffer;
michael@0 97 const GrIndexBuffer* fIndexBuffer;
michael@0 98 };
michael@0 99
michael@0 100 struct StencilPath : public ::SkNoncopyable {
michael@0 101 StencilPath();
michael@0 102
michael@0 103 SkAutoTUnref<const GrPath> fPath;
michael@0 104 SkPath::FillType fFill;
michael@0 105 };
michael@0 106
michael@0 107 struct DrawPath : public ::SkNoncopyable {
michael@0 108 DrawPath();
michael@0 109
michael@0 110 SkAutoTUnref<const GrPath> fPath;
michael@0 111 SkPath::FillType fFill;
michael@0 112 GrDeviceCoordTexture fDstCopy;
michael@0 113 };
michael@0 114
michael@0 115 struct Clear : public ::SkNoncopyable {
michael@0 116 Clear() : fRenderTarget(NULL) {}
michael@0 117 ~Clear() { SkSafeUnref(fRenderTarget); }
michael@0 118
michael@0 119 SkIRect fRect;
michael@0 120 GrColor fColor;
michael@0 121 bool fCanIgnoreRect;
michael@0 122 GrRenderTarget* fRenderTarget;
michael@0 123 };
michael@0 124
michael@0 125 struct CopySurface : public ::SkNoncopyable {
michael@0 126 SkAutoTUnref<GrSurface> fDst;
michael@0 127 SkAutoTUnref<GrSurface> fSrc;
michael@0 128 SkIRect fSrcRect;
michael@0 129 SkIPoint fDstPoint;
michael@0 130 };
michael@0 131
michael@0 132 // overrides from GrDrawTarget
michael@0 133 virtual void onDraw(const DrawInfo&) SK_OVERRIDE;
michael@0 134 virtual void onDrawRect(const SkRect& rect,
michael@0 135 const SkMatrix* matrix,
michael@0 136 const SkRect* localRect,
michael@0 137 const SkMatrix* localMatrix) SK_OVERRIDE;
michael@0 138
michael@0 139 virtual void onStencilPath(const GrPath*, SkPath::FillType) SK_OVERRIDE;
michael@0 140 virtual void onDrawPath(const GrPath*, SkPath::FillType,
michael@0 141 const GrDeviceCoordTexture* dstCopy) SK_OVERRIDE;
michael@0 142
michael@0 143 virtual bool onReserveVertexSpace(size_t vertexSize,
michael@0 144 int vertexCount,
michael@0 145 void** vertices) SK_OVERRIDE;
michael@0 146 virtual bool onReserveIndexSpace(int indexCount,
michael@0 147 void** indices) SK_OVERRIDE;
michael@0 148 virtual void releaseReservedVertexSpace() SK_OVERRIDE;
michael@0 149 virtual void releaseReservedIndexSpace() SK_OVERRIDE;
michael@0 150 virtual void onSetVertexSourceToArray(const void* vertexArray,
michael@0 151 int vertexCount) SK_OVERRIDE;
michael@0 152 virtual void onSetIndexSourceToArray(const void* indexArray,
michael@0 153 int indexCount) SK_OVERRIDE;
michael@0 154 virtual void releaseVertexArray() SK_OVERRIDE;
michael@0 155 virtual void releaseIndexArray() SK_OVERRIDE;
michael@0 156 virtual void geometrySourceWillPush() SK_OVERRIDE;
michael@0 157 virtual void geometrySourceWillPop(const GeometrySrcState& restoredState) SK_OVERRIDE;
michael@0 158 virtual void willReserveVertexAndIndexSpace(int vertexCount,
michael@0 159 int indexCount) SK_OVERRIDE;
michael@0 160 virtual bool onCopySurface(GrSurface* dst,
michael@0 161 GrSurface* src,
michael@0 162 const SkIRect& srcRect,
michael@0 163 const SkIPoint& dstPoint) SK_OVERRIDE;
michael@0 164 virtual bool onCanCopySurface(GrSurface* dst,
michael@0 165 GrSurface* src,
michael@0 166 const SkIRect& srcRect,
michael@0 167 const SkIPoint& dstPoint) SK_OVERRIDE;
michael@0 168
michael@0 169 bool quickInsideClip(const SkRect& devBounds);
michael@0 170
michael@0 171 virtual void onInstantGpuTraceEvent(const char* marker) SK_OVERRIDE;
michael@0 172 virtual void onPushGpuTraceEvent(const char* marker) SK_OVERRIDE;
michael@0 173 virtual void onPopGpuTraceEvent() SK_OVERRIDE;
michael@0 174
michael@0 175
michael@0 176 // Attempts to concat instances from info onto the previous draw. info must represent an
michael@0 177 // instanced draw. The caller must have already recorded a new draw state and clip if necessary.
michael@0 178 int concatInstancedDraw(const DrawInfo& info);
michael@0 179
michael@0 180 // we lazily record state and clip changes in order to skip clips and states that have no
michael@0 181 // effect.
michael@0 182 bool needsNewState() const;
michael@0 183 bool needsNewClip() const;
michael@0 184
michael@0 185 // these functions record a command
michael@0 186 void recordState();
michael@0 187 void recordClip();
michael@0 188 DrawRecord* recordDraw(const DrawInfo&);
michael@0 189 StencilPath* recordStencilPath();
michael@0 190 DrawPath* recordDrawPath();
michael@0 191 Clear* recordClear();
michael@0 192 CopySurface* recordCopySurface();
michael@0 193
michael@0 194 // TODO: Use a single allocator for commands and records
michael@0 195 enum {
michael@0 196 kCmdPreallocCnt = 32,
michael@0 197 kDrawPreallocCnt = 8,
michael@0 198 kStencilPathPreallocCnt = 8,
michael@0 199 kDrawPathPreallocCnt = 8,
michael@0 200 kStatePreallocCnt = 8,
michael@0 201 kClipPreallocCnt = 8,
michael@0 202 kClearPreallocCnt = 4,
michael@0 203 kGeoPoolStatePreAllocCnt = 4,
michael@0 204 kCopySurfacePreallocCnt = 4,
michael@0 205 };
michael@0 206
michael@0 207 SkSTArray<kCmdPreallocCnt, uint8_t, true> fCmds;
michael@0 208 GrSTAllocator<kDrawPreallocCnt, DrawRecord> fDraws;
michael@0 209 GrSTAllocator<kStatePreallocCnt, StencilPath> fStencilPaths;
michael@0 210 GrSTAllocator<kStatePreallocCnt, DrawPath> fDrawPaths;
michael@0 211 GrSTAllocator<kStatePreallocCnt, GrDrawState::DeferredState> fStates;
michael@0 212 GrSTAllocator<kClearPreallocCnt, Clear> fClears;
michael@0 213 GrSTAllocator<kCopySurfacePreallocCnt, CopySurface> fCopySurfaces;
michael@0 214 GrSTAllocator<kClipPreallocCnt, SkClipStack> fClips;
michael@0 215 GrSTAllocator<kClipPreallocCnt, SkIPoint> fClipOrigins;
michael@0 216
michael@0 217 GrDrawTarget* fDstGpu;
michael@0 218
michael@0 219 bool fClipSet;
michael@0 220
michael@0 221 enum ClipProxyState {
michael@0 222 kUnknown_ClipProxyState,
michael@0 223 kValid_ClipProxyState,
michael@0 224 kInvalid_ClipProxyState
michael@0 225 };
michael@0 226 ClipProxyState fClipProxyState;
michael@0 227 SkRect fClipProxy;
michael@0 228
michael@0 229 GrVertexBufferAllocPool& fVertexPool;
michael@0 230
michael@0 231 GrIndexBufferAllocPool& fIndexPool;
michael@0 232
michael@0 233 struct GeometryPoolState {
michael@0 234 const GrVertexBuffer* fPoolVertexBuffer;
michael@0 235 int fPoolStartVertex;
michael@0 236 const GrIndexBuffer* fPoolIndexBuffer;
michael@0 237 int fPoolStartIndex;
michael@0 238 // caller may conservatively over reserve vertices / indices.
michael@0 239 // we release unused space back to allocator if possible
michael@0 240 // can only do this if there isn't an intervening pushGeometrySource()
michael@0 241 size_t fUsedPoolVertexBytes;
michael@0 242 size_t fUsedPoolIndexBytes;
michael@0 243 };
michael@0 244 SkSTArray<kGeoPoolStatePreAllocCnt, GeometryPoolState> fGeoPoolStateStack;
michael@0 245
michael@0 246 virtual bool isIssued(uint32_t drawID) { return drawID != fDrawID; }
michael@0 247
michael@0 248 bool fFlushing;
michael@0 249 uint32_t fDrawID;
michael@0 250
michael@0 251 typedef GrDrawTarget INHERITED;
michael@0 252 };
michael@0 253
michael@0 254 #endif

mercurial