2 * Copyright 2014 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #ifndef GrFlushToGpuDrawTarget_DEFINED
9 #define GrFlushToGpuDrawTarget_DEFINED
11 #include "GrDrawTarget.h"
13 class GrIndexBufferAllocPool;
14 class GrVertexBufferAllocPool;
18 * Base class for draw targets that accumulate index and vertex data in buffers for deferred.
19 * When draw target clients reserve geometry this subclass will place that geometry into
20 * preallocated vertex/index buffers in the order the requests are made (assuming the requests fit
21 * in the preallocated buffers).
23 class GrFlushToGpuDrawTarget : public GrClipTarget {
25 GrFlushToGpuDrawTarget(GrGpu*, GrVertexBufferAllocPool*,GrIndexBufferAllocPool*);
27 ~GrFlushToGpuDrawTarget() SK_OVERRIDE;
30 * Empties the draw buffer of any queued up draws. This must not be called while inside an
31 * unbalanced pushGeometrySource().
36 * This plays any queued up draws to its GrGpu target. It also resets this object (i.e. flushing
37 * is destructive). This buffer must not have an active reserved vertex or index source. Any
38 * reserved geometry on the target will be finalized because it's geometry source will be pushed
39 * before flushing and popped afterwards.
43 bool geometryHints(size_t vertexStride, int* vertexCount, int* indexCount) const SK_OVERRIDE;
46 GrGpu* getGpu() { return fGpu; }
47 const GrGpu* getGpu() const{ return fGpu; }
49 GrVertexBufferAllocPool* getVertexAllocPool() { return fVertexPool; }
50 GrIndexBufferAllocPool* getIndexAllocPool() { return fIndexPool; }
52 // TODO all of this goes away when batch is everywhere
54 kGeoPoolStatePreAllocCnt = 4,
57 struct GeometryPoolState {
58 const GrVertexBuffer* fPoolVertexBuffer;
60 const GrIndexBuffer* fPoolIndexBuffer;
62 // caller may conservatively over reserve vertices / indices.
63 // we release unused space back to allocator if possible
64 // can only do this if there isn't an intervening pushGeometrySource()
65 size_t fUsedPoolVertexBytes;
66 size_t fUsedPoolIndexBytes;
69 typedef SkSTArray<kGeoPoolStatePreAllocCnt, GeometryPoolState> GeoPoolStateStack;
70 const GeoPoolStateStack& getGeoPoolStateStack() const { return fGeoPoolStateStack; }
72 void willReserveVertexAndIndexSpace(int vertexCount,
74 int indexCount) SK_OVERRIDE;
77 virtual void onReset() = 0;
79 virtual void onFlush() = 0;
81 void setDrawBuffers(DrawInfo*, size_t stride) SK_OVERRIDE;
82 bool onReserveVertexSpace(size_t vertexSize, int vertexCount, void** vertices) SK_OVERRIDE;
83 bool onReserveIndexSpace(int indexCount, void** indices) SK_OVERRIDE;
84 void releaseReservedVertexSpace() SK_OVERRIDE;
85 void releaseReservedIndexSpace() SK_OVERRIDE;
86 void geometrySourceWillPush() SK_OVERRIDE;
87 void geometrySourceWillPop(const GeometrySrcState& restoredState) SK_OVERRIDE;
88 bool onCanCopySurface(const GrSurface* dst,
90 const SkIRect& srcRect,
91 const SkIPoint& dstPoint) SK_OVERRIDE;
92 bool onInitCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* desc) SK_OVERRIDE;
94 GeoPoolStateStack fGeoPoolStateStack;
95 SkAutoTUnref<GrGpu> fGpu;
96 GrVertexBufferAllocPool* fVertexPool;
97 GrIndexBufferAllocPool* fIndexPool;
100 typedef GrClipTarget INHERITED;