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