| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef GrFlushToGpuDrawTarget_DEFINED | 8 #ifndef GrFlushToGpuDrawTarget_DEFINED |
| 9 #define GrFlushToGpuDrawTarget_DEFINED | 9 #define GrFlushToGpuDrawTarget_DEFINED |
| 10 | 10 |
| 11 #include "GrDrawTarget.h" | 11 #include "GrDrawTarget.h" |
| 12 | 12 |
| 13 class GrIndexBufferAllocPool; | 13 class GrIndexBufferAllocPool; |
| 14 class GrVertexBufferAllocPool; | 14 class GrVertexBufferAllocPool; |
| 15 class GrGpu; | 15 class GrGpu; |
| 16 | 16 |
| 17 /** | 17 /** |
| 18 * Base class for draw targets that accumulate index and vertex data in buffers
for deferred. | 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 geome
try into | 19 * When draw target clients reserve geometry this subclass will place that geome
try into |
| 20 * preallocated vertex/index buffers in the order the requests are made (assumin
g the requests fit | 20 * preallocated vertex/index buffers in the order the requests are made (assumin
g the requests fit |
| 21 * in the preallocated buffers). | 21 * in the preallocated buffers). |
| 22 */ | 22 */ |
| 23 class GrFlushToGpuDrawTarget : public GrClipTarget { | 23 class GrFlushToGpuDrawTarget : public GrClipTarget { |
| 24 public: | 24 public: |
| 25 GrFlushToGpuDrawTarget(GrGpu*, GrVertexBufferAllocPool*,GrIndexBufferAllocPo
ol*); | 25 GrFlushToGpuDrawTarget(GrGpu*, GrVertexBufferAllocPool*,GrIndexBufferAllocPo
ol*); |
| 26 | 26 |
| 27 ~GrFlushToGpuDrawTarget() override; | |
| 28 | |
| 29 /** | 27 /** |
| 30 * Empties the draw buffer of any queued up draws. This must not be called w
hile inside an | 28 * Empties the draw buffer of any queued up draws. This must not be called w
hile inside an |
| 31 * unbalanced pushGeometrySource(). | 29 * unbalanced pushGeometrySource(). |
| 32 */ | 30 */ |
| 33 void reset(); | 31 void reset(); |
| 34 | 32 |
| 35 /** | 33 /** |
| 36 * This plays any queued up draws to its GrGpu target. It also resets this o
bject (i.e. flushing | 34 * This plays any queued up draws to its GrGpu target. It also resets this o
bject (i.e. flushing |
| 37 * is destructive). This buffer must not have an active reserved vertex or i
ndex source. Any | 35 * is destructive). This buffer must not have an active reserved vertex or i
ndex source. Any |
| 38 * reserved geometry on the target will be finalized because it's geometry s
ource will be pushed | 36 * reserved geometry on the target will be finalized because it's geometry s
ource will be pushed |
| 39 * before flushing and popped afterwards. | 37 * before flushing and popped afterwards. |
| 40 */ | 38 */ |
| 41 void flush(); | 39 void flush(); |
| 42 | 40 |
| 43 bool geometryHints(size_t vertexStride, int* vertexCount, int* indexCount) c
onst override; | |
| 44 | |
| 45 protected: | 41 protected: |
| 46 GrGpu* getGpu() { return fGpu; } | 42 GrGpu* getGpu() { return fGpu; } |
| 47 const GrGpu* getGpu() const{ return fGpu; } | 43 const GrGpu* getGpu() const{ return fGpu; } |
| 48 | 44 |
| 49 GrVertexBufferAllocPool* getVertexAllocPool() { return fVertexPool; } | 45 GrVertexBufferAllocPool* getVertexAllocPool() { return fVertexPool; } |
| 50 GrIndexBufferAllocPool* getIndexAllocPool() { return fIndexPool; } | 46 GrIndexBufferAllocPool* getIndexAllocPool() { return fIndexPool; } |
| 51 | 47 |
| 52 // TODO all of this goes away when batch is everywhere | |
| 53 enum { | |
| 54 kGeoPoolStatePreAllocCnt = 4, | |
| 55 }; | |
| 56 | |
| 57 struct GeometryPoolState { | |
| 58 const GrVertexBuffer* fPoolVertexBuffer; | |
| 59 int fPoolStartVertex; | |
| 60 const GrIndexBuffer* fPoolIndexBuffer; | |
| 61 int fPoolStartIndex; | |
| 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; | |
| 67 }; | |
| 68 | |
| 69 typedef SkSTArray<kGeoPoolStatePreAllocCnt, GeometryPoolState> GeoPoolStateS
tack; | |
| 70 const GeoPoolStateStack& getGeoPoolStateStack() const { return fGeoPoolState
Stack; } | |
| 71 | |
| 72 void willReserveVertexAndIndexSpace(int vertexCount, | |
| 73 size_t vertexStride, | |
| 74 int indexCount) override; | |
| 75 | |
| 76 private: | 48 private: |
| 77 virtual void onReset() = 0; | 49 virtual void onReset() = 0; |
| 78 | 50 |
| 79 virtual void onFlush() = 0; | 51 virtual void onFlush() = 0; |
| 80 | 52 |
| 81 void setDrawBuffers(DrawInfo*, size_t stride) override; | |
| 82 bool onReserveVertexSpace(size_t vertexSize, int vertexCount, void** vertice
s) override; | |
| 83 bool onReserveIndexSpace(int indexCount, void** indices) override; | |
| 84 void releaseReservedVertexSpace() override; | |
| 85 void releaseReservedIndexSpace() override; | |
| 86 void geometrySourceWillPush() override; | |
| 87 void geometrySourceWillPop(const GeometrySrcState& restoredState) override; | |
| 88 bool onCanCopySurface(const GrSurface* dst, | 53 bool onCanCopySurface(const GrSurface* dst, |
| 89 const GrSurface* src, | 54 const GrSurface* src, |
| 90 const SkIRect& srcRect, | 55 const SkIRect& srcRect, |
| 91 const SkIPoint& dstPoint) override; | 56 const SkIPoint& dstPoint) override; |
| 92 bool onInitCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* desc) ove
rride; | 57 bool onInitCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* desc) ove
rride; |
| 93 | 58 |
| 94 GeoPoolStateStack fGeoPoolStateStack; | |
| 95 SkAutoTUnref<GrGpu> fGpu; | 59 SkAutoTUnref<GrGpu> fGpu; |
| 96 GrVertexBufferAllocPool* fVertexPool; | 60 GrVertexBufferAllocPool* fVertexPool; |
| 97 GrIndexBufferAllocPool* fIndexPool; | 61 GrIndexBufferAllocPool* fIndexPool; |
| 98 bool fFlushing; | 62 bool fFlushing; |
| 99 | 63 |
| 100 typedef GrClipTarget INHERITED; | 64 typedef GrClipTarget INHERITED; |
| 101 }; | 65 }; |
| 102 | 66 |
| 103 #endif | 67 #endif |
| OLD | NEW |