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 #include "GrBufferedDrawTarget.h" | 8 #include "GrBufferedDrawTarget.h" |
9 | 9 |
10 // We will use the reordering buffer, unless we have NVPR. | 10 // We will use the reordering buffer, unless we have NVPR. |
11 // TODO move NVPR to batch so we can reorder | 11 // TODO move NVPR to batch so we can reorder |
12 static inline bool allow_reordering(const GrCaps* caps) { | 12 static inline bool allow_reordering(const GrCaps* caps) { |
13 return caps && caps->shaderCaps() && !caps->shaderCaps()->pathRenderingSuppo
rt(); | 13 return caps && caps->shaderCaps() && !caps->shaderCaps()->pathRenderingSuppo
rt(); |
14 } | 14 } |
15 | 15 |
16 GrBufferedDrawTarget::GrBufferedDrawTarget(GrContext* context) | 16 GrBufferedDrawTarget::GrBufferedDrawTarget(GrContext* context) |
17 : INHERITED(context) | 17 : INHERITED(context) |
18 , fCommands(GrCommandBuilder::Create(context->getGpu(), allow_reordering(con
text->caps()))) | 18 , fCommands(GrCommandBuilder::Create(context->getGpu(), allow_reordering(con
text->caps()))) |
19 , fPathIndexBuffer(kPathIdxBufferMinReserve * sizeof(char)/4) | 19 , fPathIndexBuffer(kPathIdxBufferMinReserve * sizeof(char)/4) |
20 , fPathTransformBuffer(kPathXformBufferMinReserve * sizeof(float)/4) | 20 , fPathTransformBuffer(kPathXformBufferMinReserve * sizeof(float)/4) |
21 , fPipelineBuffer(kPipelineBufferMinReserve) | 21 , fPipelineBuffer(kPipelineBufferMinReserve) |
22 , fDrawID(0) { | 22 , fDrawID(0) { |
23 } | 23 } |
24 | 24 |
25 GrBufferedDrawTarget::~GrBufferedDrawTarget() { | 25 GrBufferedDrawTarget::~GrBufferedDrawTarget() { |
26 this->reset(); | 26 this->reset(); |
27 } | 27 } |
28 | 28 |
29 void GrBufferedDrawTarget::onDrawBatch(GrBatch* batch, | 29 void GrBufferedDrawTarget::onDrawBatch(GrBatch* batch) { |
30 const PipelineInfo& pipelineInfo) { | 30 this->recordTraceMarkersIfNecessary( |
31 GrPipelineOptimizations opts; | 31 fCommands->recordXferBarrierIfNecessary(*batch->pipeline(), *this->caps(
))); |
32 State* state = this->setupPipelineAndShouldDraw(batch, pipelineInfo, &opts); | |
33 if (!state) { | |
34 return; | |
35 } | |
36 | 32 |
37 GrTargetCommands::Cmd* cmd = fCommands->recordDrawBatch(state, opts, batch); | 33 GrTargetCommands::Cmd* cmd = fCommands->recordDrawBatch(batch); |
38 this->recordTraceMarkersIfNecessary(cmd); | 34 this->recordTraceMarkersIfNecessary(cmd); |
39 } | 35 } |
40 | 36 |
41 void GrBufferedDrawTarget::onStencilPath(const GrPipelineBuilder& pipelineBuilde
r, | 37 void GrBufferedDrawTarget::onStencilPath(const GrPipelineBuilder& pipelineBuilde
r, |
42 const GrPathProcessor* pathProc, | 38 const GrPathProcessor* pathProc, |
43 const GrPath* path, | 39 const GrPath* path, |
44 const GrScissorState& scissorState, | 40 const GrScissorState& scissorState, |
45 const GrStencilSettings& stencilSetting
s) { | 41 const GrStencilSettings& stencilSetting
s) { |
46 GrTargetCommands::Cmd* cmd = fCommands->recordStencilPath(pipelineBuilder, | 42 GrTargetCommands::Cmd* cmd = fCommands->recordStencilPath(pipelineBuilder, |
47 pathProc, path, sc
issorState, | 43 pathProc, path, sc
issorState, |
48 stencilSettings); | 44 stencilSettings); |
49 this->recordTraceMarkersIfNecessary(cmd); | 45 this->recordTraceMarkersIfNecessary(cmd); |
50 } | 46 } |
51 | 47 |
52 void GrBufferedDrawTarget::onDrawPath(const GrPathProcessor* pathProc, | 48 void GrBufferedDrawTarget::onDrawPath(const GrPathProcessor* pathProc, |
53 const GrPath* path, | 49 const GrPath* path, |
54 const GrStencilSettings& stencilSettings, | 50 const GrStencilSettings& stencilSettings, |
55 const PipelineInfo& pipelineInfo) { | 51 const PipelineInfo& pipelineInfo) { |
56 GrPipelineOptimizations opts; | 52 GrPipelineOptimizations opts; |
57 State* state = this->setupPipelineAndShouldDraw(pathProc, pipelineInfo, &opt
s); | 53 StateForPathDraw* state = this->createStateForPathDraw(pathProc, pipelineInf
o, &opts); |
58 if (!state) { | 54 if (!state) { |
59 return; | 55 return; |
60 } | 56 } |
61 GrTargetCommands::Cmd* cmd = fCommands->recordDrawPath(state, pathProc, path
, stencilSettings); | 57 GrTargetCommands::Cmd* cmd = fCommands->recordDrawPath(state, pathProc, path
, stencilSettings); |
62 this->recordTraceMarkersIfNecessary(cmd); | 58 this->recordTraceMarkersIfNecessary(cmd); |
63 } | 59 } |
64 | 60 |
65 void GrBufferedDrawTarget::onDrawPaths(const GrPathProcessor* pathProc, | 61 void GrBufferedDrawTarget::onDrawPaths(const GrPathProcessor* pathProc, |
66 const GrPathRange* pathRange, | 62 const GrPathRange* pathRange, |
67 const void* indices, | 63 const void* indices, |
68 PathIndexType indexType, | 64 PathIndexType indexType, |
69 const float transformValues[], | 65 const float transformValues[], |
70 PathTransformType transformType, | 66 PathTransformType transformType, |
71 int count, | 67 int count, |
72 const GrStencilSettings& stencilSettings, | 68 const GrStencilSettings& stencilSettings, |
73 const PipelineInfo& pipelineInfo) { | 69 const PipelineInfo& pipelineInfo) { |
74 GrPipelineOptimizations opts; | 70 GrPipelineOptimizations opts; |
75 State* state = this->setupPipelineAndShouldDraw(pathProc, pipelineInfo, &opt
s); | 71 StateForPathDraw* state = this->createStateForPathDraw(pathProc, pipelineInf
o, &opts); |
76 if (!state) { | 72 if (!state) { |
77 return; | 73 return; |
78 } | 74 } |
79 GrTargetCommands::Cmd* cmd = fCommands->recordDrawPaths(state, this, pathPro
c, pathRange, | 75 GrTargetCommands::Cmd* cmd = fCommands->recordDrawPaths(state, this, pathPro
c, pathRange, |
80 indices, indexType,
transformValues, | 76 indices, indexType,
transformValues, |
81 transformType, count
, | 77 transformType, count
, |
82 stencilSettings, pip
elineInfo); | 78 stencilSettings, pip
elineInfo); |
83 this->recordTraceMarkersIfNecessary(cmd); | 79 this->recordTraceMarkersIfNecessary(cmd); |
84 } | 80 } |
85 | 81 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 if (activeTraceMarkers.count() > 0) { | 138 if (activeTraceMarkers.count() > 0) { |
143 if (cmd->isTraced()) { | 139 if (cmd->isTraced()) { |
144 fGpuCmdMarkers[cmd->markerID()].addSet(activeTraceMarkers); | 140 fGpuCmdMarkers[cmd->markerID()].addSet(activeTraceMarkers); |
145 } else { | 141 } else { |
146 cmd->setMarkerID(fGpuCmdMarkers.count()); | 142 cmd->setMarkerID(fGpuCmdMarkers.count()); |
147 fGpuCmdMarkers.push_back(activeTraceMarkers); | 143 fGpuCmdMarkers.push_back(activeTraceMarkers); |
148 } | 144 } |
149 } | 145 } |
150 } | 146 } |
151 | 147 |
152 GrTargetCommands::State* | 148 GrTargetCommands::StateForPathDraw* |
153 GrBufferedDrawTarget::setupPipelineAndShouldDraw(const GrPrimitiveProcessor* pri
mProc, | 149 GrBufferedDrawTarget::createStateForPathDraw(const GrPrimitiveProcessor* primPro
c, |
154 const GrDrawTarget::PipelineInf
o& pipelineInfo, | 150 const GrDrawTarget::PipelineInfo& p
ipelineInfo, |
155 GrPipelineOptimizations* opts)
{ | 151 GrPipelineOptimizations* opts) { |
156 State* state = this->allocState(primProc); | 152 StateForPathDraw* state = this->allocState(primProc); |
157 this->setupPipeline(pipelineInfo, state->pipelineLocation(), opts); | 153 if (!GrPipeline::CreateAt(state->pipelineLocation(), pipelineInfo.pipelineCr
eateArgs(), opts)) { |
158 | |
159 if (state->getPipeline()->mustSkip()) { | |
160 this->unallocState(state); | 154 this->unallocState(state); |
161 return NULL; | 155 return NULL; |
162 } | 156 } |
163 | 157 |
164 state->fPrimitiveProcessor->initBatchTracker(&state->fBatchTracker, *opts); | 158 state->fPrimitiveProcessor->initBatchTracker(&state->fBatchTracker, *opts); |
165 | 159 |
166 if (fPrevState && fPrevState->fPrimitiveProcessor.get() && | 160 if (fPrevState && fPrevState->fPrimitiveProcessor.get() && |
167 fPrevState->fPrimitiveProcessor->canMakeEqual(fPrevState->fBatchTracker, | 161 fPrevState->fPrimitiveProcessor->canMakeEqual(fPrevState->fBatchTracker, |
168 *state->fPrimitiveProcesso
r, | 162 *state->fPrimitiveProcesso
r, |
169 state->fBatchTracker) && | 163 state->fBatchTracker) && |
170 fPrevState->getPipeline()->isEqual(*state->getPipeline())) { | 164 fPrevState->getPipeline()->isEqual(*state->getPipeline())) { |
171 this->unallocState(state); | 165 this->unallocState(state); |
172 } else { | 166 } else { |
173 fPrevState.reset(state); | 167 fPrevState.reset(state); |
174 } | 168 } |
175 | 169 |
176 this->recordTraceMarkersIfNecessary( | 170 this->recordTraceMarkersIfNecessary( |
177 fCommands->recordXferBarrierIfNecessary(*fPrevState->getPipeline(),
*this->caps())); | 171 fCommands->recordXferBarrierIfNecessary(*fPrevState->getPipeline(),
*this->caps())); |
178 return fPrevState; | 172 return fPrevState; |
179 } | 173 } |
180 | |
181 GrTargetCommands::State* | |
182 GrBufferedDrawTarget::setupPipelineAndShouldDraw(GrBatch* batch, | |
183 const GrDrawTarget::PipelineInf
o& pipelineInfo, | |
184 GrPipelineOptimizations* opts)
{ | |
185 State* state = this->allocState(); | |
186 this->setupPipeline(pipelineInfo, state->pipelineLocation(), opts); | |
187 | |
188 if (state->getPipeline()->mustSkip()) { | |
189 this->unallocState(state); | |
190 return NULL; | |
191 } | |
192 | |
193 if (fPrevState && !fPrevState->fPrimitiveProcessor.get() && | |
194 fPrevState->getPipeline()->isEqual(*state->getPipeline())) { | |
195 this->unallocState(state); | |
196 } else { | |
197 fPrevState.reset(state); | |
198 } | |
199 | |
200 this->recordTraceMarkersIfNecessary( | |
201 fCommands->recordXferBarrierIfNecessary(*fPrevState->getPipeline(),
*this->caps())); | |
202 return fPrevState; | |
203 } | |
OLD | NEW |