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 #include "GrInOrderDrawBuffer.h" | |
9 | |
10 // We will use the reordering buffer, unless we have NVPR. | |
11 // TODO move NVPR to batch so we can reorder | |
12 static inline bool allow_reordering(const GrCaps* caps) { | |
13 return caps && caps->shaderCaps() && !caps->shaderCaps()->pathRenderingSuppo
rt(); | |
14 } | |
15 | |
16 GrInOrderDrawBuffer::GrInOrderDrawBuffer(GrContext* context) | |
17 : INHERITED(context) | |
18 , fCommands(GrCommandBuilder::Create(context->getGpu(), allow_reordering(con
text->caps()))) | |
19 , fPathIndexBuffer(kPathIdxBufferMinReserve * sizeof(char)/4) | |
20 , fPathTransformBuffer(kPathXformBufferMinReserve * sizeof(float)/4) | |
21 , fPipelineBuffer(kPipelineBufferMinReserve) | |
22 , fDrawID(0) { | |
23 } | |
24 | |
25 GrInOrderDrawBuffer::~GrInOrderDrawBuffer() { | |
26 this->reset(); | |
27 } | |
28 | |
29 void GrInOrderDrawBuffer::onDrawBatch(GrBatch* batch, | |
30 const PipelineInfo& pipelineInfo) { | |
31 State* state = this->setupPipelineAndShouldDraw(batch, pipelineInfo); | |
32 if (!state) { | |
33 return; | |
34 } | |
35 | |
36 GrTargetCommands::Cmd* cmd = fCommands->recordDrawBatch(state, batch); | |
37 this->recordTraceMarkersIfNecessary(cmd); | |
38 } | |
39 | |
40 void GrInOrderDrawBuffer::onStencilPath(const GrPipelineBuilder& pipelineBuilder
, | |
41 const GrPathProcessor* pathProc, | |
42 const GrPath* path, | |
43 const GrScissorState& scissorState, | |
44 const GrStencilSettings& stencilSettings
) { | |
45 GrTargetCommands::Cmd* cmd = fCommands->recordStencilPath(pipelineBuilder, | |
46 pathProc, path, sc
issorState, | |
47 stencilSettings); | |
48 this->recordTraceMarkersIfNecessary(cmd); | |
49 } | |
50 | |
51 void GrInOrderDrawBuffer::onDrawPath(const GrPathProcessor* pathProc, | |
52 const GrPath* path, | |
53 const GrStencilSettings& stencilSettings, | |
54 const PipelineInfo& pipelineInfo) { | |
55 State* state = this->setupPipelineAndShouldDraw(pathProc, pipelineInfo); | |
56 if (!state) { | |
57 return; | |
58 } | |
59 GrTargetCommands::Cmd* cmd = fCommands->recordDrawPath(state, pathProc, path
, stencilSettings); | |
60 this->recordTraceMarkersIfNecessary(cmd); | |
61 } | |
62 | |
63 void GrInOrderDrawBuffer::onDrawPaths(const GrPathProcessor* pathProc, | |
64 const GrPathRange* pathRange, | |
65 const void* indices, | |
66 PathIndexType indexType, | |
67 const float transformValues[], | |
68 PathTransformType transformType, | |
69 int count, | |
70 const GrStencilSettings& stencilSettings, | |
71 const PipelineInfo& pipelineInfo) { | |
72 State* state = this->setupPipelineAndShouldDraw(pathProc, pipelineInfo); | |
73 if (!state) { | |
74 return; | |
75 } | |
76 GrTargetCommands::Cmd* cmd = fCommands->recordDrawPaths(state, this, pathPro
c, pathRange, | |
77 indices, indexType,
transformValues, | |
78 transformType, count
, | |
79 stencilSettings, pip
elineInfo); | |
80 this->recordTraceMarkersIfNecessary(cmd); | |
81 } | |
82 | |
83 void GrInOrderDrawBuffer::onClear(const SkIRect* rect, GrColor color, | |
84 bool canIgnoreRect, GrRenderTarget* renderTarg
et) { | |
85 GrTargetCommands::Cmd* cmd = fCommands->recordClear(rect, color, canIgnoreRe
ct, renderTarget); | |
86 this->recordTraceMarkersIfNecessary(cmd); | |
87 } | |
88 | |
89 void GrInOrderDrawBuffer::clearStencilClip(const SkIRect& rect, | |
90 bool insideClip, | |
91 GrRenderTarget* renderTarget) { | |
92 GrTargetCommands::Cmd* cmd = fCommands->recordClearStencilClip(rect, insideC
lip, renderTarget); | |
93 this->recordTraceMarkersIfNecessary(cmd); | |
94 } | |
95 | |
96 void GrInOrderDrawBuffer::discard(GrRenderTarget* renderTarget) { | |
97 if (!this->caps()->discardRenderTargetSupport()) { | |
98 return; | |
99 } | |
100 | |
101 GrTargetCommands::Cmd* cmd = fCommands->recordDiscard(renderTarget); | |
102 this->recordTraceMarkersIfNecessary(cmd); | |
103 } | |
104 | |
105 void GrInOrderDrawBuffer::onReset() { | |
106 fCommands->reset(); | |
107 fPathIndexBuffer.rewind(); | |
108 fPathTransformBuffer.rewind(); | |
109 fGpuCmdMarkers.reset(); | |
110 | |
111 fPrevState.reset(NULL); | |
112 // Note, fPrevState points into fPipelineBuffer's allocation, so we have to
reset first. | |
113 // Furthermore, we have to reset fCommands before fPipelineBuffer too. | |
114 if (fDrawID % kPipelineBufferHighWaterMark) { | |
115 fPipelineBuffer.rewind(); | |
116 } else { | |
117 fPipelineBuffer.reset(); | |
118 } | |
119 } | |
120 | |
121 void GrInOrderDrawBuffer::onFlush() { | |
122 fCommands->flush(this); | |
123 ++fDrawID; | |
124 } | |
125 | |
126 void GrInOrderDrawBuffer::onCopySurface(GrSurface* dst, | |
127 GrSurface* src, | |
128 const SkIRect& srcRect, | |
129 const SkIPoint& dstPoint) { | |
130 GrTargetCommands::Cmd* cmd = fCommands->recordCopySurface(dst, src, srcRect,
dstPoint); | |
131 this->recordTraceMarkersIfNecessary(cmd); | |
132 } | |
133 | |
134 void GrInOrderDrawBuffer::recordTraceMarkersIfNecessary(GrTargetCommands::Cmd* c
md) { | |
135 if (!cmd) { | |
136 return; | |
137 } | |
138 const GrTraceMarkerSet& activeTraceMarkers = this->getActiveTraceMarkers(); | |
139 if (activeTraceMarkers.count() > 0) { | |
140 if (cmd->isTraced()) { | |
141 fGpuCmdMarkers[cmd->markerID()].addSet(activeTraceMarkers); | |
142 } else { | |
143 cmd->setMarkerID(fGpuCmdMarkers.count()); | |
144 fGpuCmdMarkers.push_back(activeTraceMarkers); | |
145 } | |
146 } | |
147 } | |
148 | |
149 GrTargetCommands::State* | |
150 GrInOrderDrawBuffer::setupPipelineAndShouldDraw(const GrPrimitiveProcessor* prim
Proc, | |
151 const GrDrawTarget::PipelineInfo
& pipelineInfo) { | |
152 State* state = this->allocState(primProc); | |
153 this->setupPipeline(pipelineInfo, state->pipelineLocation()); | |
154 | |
155 if (state->getPipeline()->mustSkip()) { | |
156 this->unallocState(state); | |
157 return NULL; | |
158 } | |
159 | |
160 state->fPrimitiveProcessor->initBatchTracker( | |
161 &state->fBatchTracker, state->getPipeline()->infoForPrimitiveProcessor()
); | |
162 | |
163 if (fPrevState && fPrevState->fPrimitiveProcessor.get() && | |
164 fPrevState->fPrimitiveProcessor->canMakeEqual(fPrevState->fBatchTracker, | |
165 *state->fPrimitiveProcesso
r, | |
166 state->fBatchTracker) && | |
167 fPrevState->getPipeline()->isEqual(*state->getPipeline())) { | |
168 this->unallocState(state); | |
169 } else { | |
170 fPrevState.reset(state); | |
171 } | |
172 | |
173 this->recordTraceMarkersIfNecessary( | |
174 fCommands->recordXferBarrierIfNecessary(*fPrevState->getPipeline(),
*this->caps())); | |
175 return fPrevState; | |
176 } | |
177 | |
178 GrTargetCommands::State* | |
179 GrInOrderDrawBuffer::setupPipelineAndShouldDraw(GrBatch* batch, | |
180 const GrDrawTarget::PipelineInfo
& pipelineInfo) { | |
181 State* state = this->allocState(); | |
182 this->setupPipeline(pipelineInfo, state->pipelineLocation()); | |
183 | |
184 if (state->getPipeline()->mustSkip()) { | |
185 this->unallocState(state); | |
186 return NULL; | |
187 } | |
188 | |
189 batch->initBatchTracker(state->getPipeline()->infoForPrimitiveProcessor()); | |
190 | |
191 if (fPrevState && !fPrevState->fPrimitiveProcessor.get() && | |
192 fPrevState->getPipeline()->isEqual(*state->getPipeline())) { | |
193 this->unallocState(state); | |
194 } else { | |
195 fPrevState.reset(state); | |
196 } | |
197 | |
198 this->recordTraceMarkersIfNecessary( | |
199 fCommands->recordXferBarrierIfNecessary(*fPrevState->getPipeline(),
*this->caps())); | |
200 return fPrevState; | |
201 } | |
OLD | NEW |