OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2011 Google Inc. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. |
| 6 */ |
| 7 |
| 8 #ifndef GrBufferedDrawTarget_DEFINED |
| 9 #define GrBufferedDrawTarget_DEFINED |
| 10 |
| 11 #include "GrDrawTarget.h" |
| 12 #include "GrCommandBuilder.h" |
| 13 #include "SkChunkAlloc.h" |
| 14 |
| 15 /** |
| 16 * GrBufferedDrawTarget is an implementation of GrDrawTarget that queues up draw
s for eventual |
| 17 * playback into a GrGpu. In theory one draw buffer could playback into another.
Similarly, it is |
| 18 * the caller's responsibility to ensure that all referenced textures, buffers,
and render-targets |
| 19 * are associated in the GrGpu object that the buffer is played back into. |
| 20 */ |
| 21 class GrBufferedDrawTarget : public GrClipTarget { |
| 22 public: |
| 23 |
| 24 bool isEmpty() const override { |
| 25 return fCommands->empty(); |
| 26 } |
| 27 |
| 28 /** |
| 29 * Creates a GrBufferedDrawTarget |
| 30 * |
| 31 * @param context the context object that owns this draw buffer. |
| 32 */ |
| 33 GrBufferedDrawTarget(GrDrawContext* dc, GrRenderTarget* rt, GrContext* conte
xt); |
| 34 |
| 35 ~GrBufferedDrawTarget() override; |
| 36 |
| 37 protected: |
| 38 void appendIndicesAndTransforms(const void* indexValues, PathIndexType index
Type, |
| 39 const float* transformValues, PathTransformT
ype transformType, |
| 40 int count, char** indicesLocation, float** x
formsLocation) { |
| 41 int indexBytes = GrPathRange::PathIndexSizeInBytes(indexType); |
| 42 *indicesLocation = (char*) fPathIndexBuffer.alloc(count * indexBytes, |
| 43 SkChunkAlloc::kThrow_A
llocFailType); |
| 44 SkASSERT(SkIsAlign4((uintptr_t)*indicesLocation)); |
| 45 memcpy(*indicesLocation, reinterpret_cast<const char*>(indexValues), cou
nt * indexBytes); |
| 46 |
| 47 const int xformBytes = GrPathRendering::PathTransformSize(transformType)
* sizeof(float); |
| 48 *xformsLocation = nullptr; |
| 49 |
| 50 if (0 != xformBytes) { |
| 51 *xformsLocation = (float*) fPathTransformBuffer.alloc(count * xformB
ytes, |
| 52 SkChunkAlloc::kTh
row_AllocFailType); |
| 53 SkASSERT(SkIsAlign4((uintptr_t)*xformsLocation)); |
| 54 memcpy(*xformsLocation, transformValues, count * xformBytes); |
| 55 } |
| 56 } |
| 57 |
| 58 void onDrawBatch(GrBatch*) override; |
| 59 |
| 60 private: |
| 61 friend class GrInOrderCommandBuilder; |
| 62 friend class GrTargetCommands; |
| 63 |
| 64 typedef GrTargetCommands::StateForPathDraw StateForPathDraw; |
| 65 |
| 66 StateForPathDraw* allocState(const GrPrimitiveProcessor* primProc = nullptr)
{ |
| 67 void* allocation = fPipelineBuffer.alloc(sizeof(StateForPathDraw), |
| 68 SkChunkAlloc::kThrow_AllocFailT
ype); |
| 69 return new (allocation) StateForPathDraw(primProc); |
| 70 } |
| 71 |
| 72 void unallocState(StateForPathDraw* state) { |
| 73 state->unref(); |
| 74 fPipelineBuffer.unalloc(state); |
| 75 } |
| 76 |
| 77 void onReset() override; |
| 78 void onFlush() override; |
| 79 |
| 80 void onDrawPaths(const GrPathProcessor*, |
| 81 const GrPathRange*, |
| 82 const void* indices, |
| 83 PathIndexType, |
| 84 const float transformValues[], |
| 85 PathTransformType, |
| 86 int count, |
| 87 const GrStencilSettings&, |
| 88 const PipelineInfo&) override; |
| 89 |
| 90 bool isIssued(uint32_t drawID) override { return drawID != fDrawID; } |
| 91 |
| 92 StateForPathDraw* SK_WARN_UNUSED_RESULT createStateForPathDraw( |
| 93 const GrPrimitiveProcessor*, |
| 94 const PipelineInfo&, |
| 95 GrPipelineOptimizations* opts); |
| 96 |
| 97 // TODO: Use a single allocator for commands and records |
| 98 enum { |
| 99 kPathIdxBufferMinReserve = 2 * 64, // 64 uint16_t's |
| 100 kPathXformBufferMinReserve = 2 * 64, // 64 two-float transforms |
| 101 kPipelineBufferMinReserve = 32 * sizeof(StateForPathDraw), |
| 102 }; |
| 103 |
| 104 // every 100 flushes we should reset our fPipelineBuffer to prevent us from
holding at a |
| 105 // highwater mark |
| 106 static const int kPipelineBufferHighWaterMark = 100; |
| 107 |
| 108 SkAutoTDelete<GrCommandBuilder> fCommands; |
| 109 SkChunkAlloc fPathIndexBuffer; |
| 110 SkChunkAlloc fPathTransformBuffer; |
| 111 SkChunkAlloc fPipelineBuffer; |
| 112 uint32_t fDrawID; |
| 113 SkAutoTUnref<StateForPathDraw> fPrevState; |
| 114 |
| 115 typedef GrClipTarget INHERITED; |
| 116 }; |
| 117 |
| 118 #endif |
OLD | NEW |