Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: src/gpu/GrRectBatch.cpp

Issue 1127713002: Move RectBatch to GrRectBatch (Closed) Base URL: https://skia.googlesource.com/skia.git@command-builder
Patch Set: more Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/GrRectBatch.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2015 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 "GrInOrderDrawBuffer.h" 8 #include "GrRectBatch.h"
9 9
10 #include "GrBatch.h"
11 #include "GrBatchTarget.h"
10 #include "GrDefaultGeoProcFactory.h" 12 #include "GrDefaultGeoProcFactory.h"
13 #include "GrPrimitiveProcessor.h"
11 #include "GrTemplates.h" 14 #include "GrTemplates.h"
12 15
13 GrInOrderDrawBuffer::GrInOrderDrawBuffer(GrContext* context,
14 GrVertexBufferAllocPool* vertexPool,
15 GrIndexBufferAllocPool* indexPool)
16 : INHERITED(context, vertexPool, indexPool)
17 , fCommands(SkNEW_ARGS(GrCommandBuilder, (context->getGpu(), vertexPool, ind exPool)))
18 , fPathIndexBuffer(kPathIdxBufferMinReserve * sizeof(char)/4)
19 , fPathTransformBuffer(kPathXformBufferMinReserve * sizeof(float)/4)
20 , fPipelineBuffer(kPipelineBufferMinReserve)
21 , fDrawID(0) {
22
23 SkASSERT(vertexPool);
24 SkASSERT(indexPool);
25 }
26
27 GrInOrderDrawBuffer::~GrInOrderDrawBuffer() {
28 this->reset();
29 }
30
31 ////////////////////////////////////////////////////////////////////////////////
32
33 /** We always use per-vertex colors so that rects can be batched across color ch anges. Sometimes we 16 /** We always use per-vertex colors so that rects can be batched across color ch anges. Sometimes we
34 have explicit local coords and sometimes not. We *could* always provide expl icit local coords 17 have explicit local coords and sometimes not. We *could* always provide expl icit local coords
35 and just duplicate the positions when the caller hasn't provided a local coo rd rect, but we 18 and just duplicate the positions when the caller hasn't provided a local coo rd rect, but we
36 haven't seen a use case which frequently switches between local rect and no local rect draws. 19 haven't seen a use case which frequently switches between local rect and no local rect draws.
37 20
38 The color param is used to determine whether the opaque hint can be set on t he draw state. 21 The color param is used to determine whether the opaque hint can be set on t he draw state.
39 The caller must populate the vertex colors itself. 22 The caller must populate the vertex colors itself.
40 23
41 The vertex attrib order is always pos, color, [local coords]. 24 The vertex attrib order is always pos, color, [local coords].
42 */ 25 */
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 GrColor fColor; 212 GrColor fColor;
230 bool fUsesLocalCoords; 213 bool fUsesLocalCoords;
231 bool fColorIgnored; 214 bool fColorIgnored;
232 bool fCoverageIgnored; 215 bool fCoverageIgnored;
233 }; 216 };
234 217
235 BatchTracker fBatch; 218 BatchTracker fBatch;
236 SkSTArray<1, Geometry, true> fGeoData; 219 SkSTArray<1, Geometry, true> fGeoData;
237 }; 220 };
238 221
239 void GrInOrderDrawBuffer::onDrawRect(GrPipelineBuilder* pipelineBuilder, 222 namespace GrRectBatch {
240 GrColor color, 223
241 const SkMatrix& viewMatrix, 224 GrBatch* Create(GrColor color,
242 const SkRect& rect, 225 const SkMatrix& viewMatrix,
243 const SkRect* localRect, 226 const SkRect& rect,
244 const SkMatrix* localMatrix) { 227 const SkRect* localRect,
228 const SkMatrix* localMatrix) {
245 RectBatch::Geometry geometry; 229 RectBatch::Geometry geometry;
246 geometry.fColor = color; 230 geometry.fColor = color;
247 geometry.fViewMatrix = viewMatrix; 231 geometry.fViewMatrix = viewMatrix;
248 geometry.fRect = rect; 232 geometry.fRect = rect;
249 233
250 if (localRect) { 234 if (localRect) {
251 geometry.fHasLocalRect = true; 235 geometry.fHasLocalRect = true;
252 geometry.fLocalRect = *localRect; 236 geometry.fLocalRect = *localRect;
253 } else { 237 } else {
254 geometry.fHasLocalRect = false; 238 geometry.fHasLocalRect = false;
255 } 239 }
256 240
257 if (localMatrix) { 241 if (localMatrix) {
258 geometry.fHasLocalMatrix = true; 242 geometry.fHasLocalMatrix = true;
259 geometry.fLocalMatrix = *localMatrix; 243 geometry.fLocalMatrix = *localMatrix;
260 } else { 244 } else {
261 geometry.fHasLocalMatrix = false; 245 geometry.fHasLocalMatrix = false;
262 } 246 }
263 247
264 SkAutoTUnref<GrBatch> batch(RectBatch::Create(geometry)); 248 return RectBatch::Create(geometry);
265 this->drawBatch(pipelineBuilder, batch);
266 } 249 }
267 250
268 void GrInOrderDrawBuffer::onDrawBatch(GrBatch* batch, 251 };
269 const PipelineInfo& pipelineInfo) {
270 State* state = this->setupPipelineAndShouldDraw(batch, pipelineInfo);
271 if (!state) {
272 return;
273 }
274
275 GrTargetCommands::Cmd* cmd = fCommands->recordDrawBatch(state, batch);
276 this->recordTraceMarkersIfNecessary(cmd);
277 }
278
279 void GrInOrderDrawBuffer::onStencilPath(const GrPipelineBuilder& pipelineBuilder ,
280 const GrPathProcessor* pathProc,
281 const GrPath* path,
282 const GrScissorState& scissorState,
283 const GrStencilSettings& stencilSettings ) {
284 GrTargetCommands::Cmd* cmd = fCommands->recordStencilPath(pipelineBuilder,
285 pathProc, path, sc issorState,
286 stencilSettings);
287 this->recordTraceMarkersIfNecessary(cmd);
288 }
289
290 void GrInOrderDrawBuffer::onDrawPath(const GrPathProcessor* pathProc,
291 const GrPath* path,
292 const GrStencilSettings& stencilSettings,
293 const PipelineInfo& pipelineInfo) {
294 State* state = this->setupPipelineAndShouldDraw(pathProc, pipelineInfo);
295 if (!state) {
296 return;
297 }
298 GrTargetCommands::Cmd* cmd = fCommands->recordDrawPath(state, pathProc, path , stencilSettings);
299 this->recordTraceMarkersIfNecessary(cmd);
300 }
301
302 void GrInOrderDrawBuffer::onDrawPaths(const GrPathProcessor* pathProc,
303 const GrPathRange* pathRange,
304 const void* indices,
305 PathIndexType indexType,
306 const float transformValues[],
307 PathTransformType transformType,
308 int count,
309 const GrStencilSettings& stencilSettings,
310 const PipelineInfo& pipelineInfo) {
311 State* state = this->setupPipelineAndShouldDraw(pathProc, pipelineInfo);
312 if (!state) {
313 return;
314 }
315 GrTargetCommands::Cmd* cmd = fCommands->recordDrawPaths(state, this, pathPro c, pathRange,
316 indices, indexType, transformValues,
317 transformType, count ,
318 stencilSettings, pip elineInfo);
319 this->recordTraceMarkersIfNecessary(cmd);
320 }
321
322 void GrInOrderDrawBuffer::onClear(const SkIRect* rect, GrColor color,
323 bool canIgnoreRect, GrRenderTarget* renderTarg et) {
324 GrTargetCommands::Cmd* cmd = fCommands->recordClear(rect, color, canIgnoreRe ct, renderTarget);
325 this->recordTraceMarkersIfNecessary(cmd);
326 }
327
328 void GrInOrderDrawBuffer::clearStencilClip(const SkIRect& rect,
329 bool insideClip,
330 GrRenderTarget* renderTarget) {
331 GrTargetCommands::Cmd* cmd = fCommands->recordClearStencilClip(rect, insideC lip, renderTarget);
332 this->recordTraceMarkersIfNecessary(cmd);
333 }
334
335 void GrInOrderDrawBuffer::discard(GrRenderTarget* renderTarget) {
336 if (!this->caps()->discardRenderTargetSupport()) {
337 return;
338 }
339
340 GrTargetCommands::Cmd* cmd = fCommands->recordDiscard(renderTarget);
341 this->recordTraceMarkersIfNecessary(cmd);
342 }
343
344 void GrInOrderDrawBuffer::onReset() {
345 fCommands->reset();
346 fPathIndexBuffer.rewind();
347 fPathTransformBuffer.rewind();
348 fGpuCmdMarkers.reset();
349
350 fPrevState.reset(NULL);
351 // Note, fPrevState points into fPipelineBuffer's allocation, so we have to reset first.
352 // Furthermore, we have to reset fCommands before fPipelineBuffer too.
353 if (fDrawID % kPipelineBufferHighWaterMark) {
354 fPipelineBuffer.rewind();
355 } else {
356 fPipelineBuffer.reset();
357 }
358 }
359
360 void GrInOrderDrawBuffer::onFlush() {
361 fCommands->flush(this);
362 ++fDrawID;
363 }
364
365 void GrInOrderDrawBuffer::onCopySurface(GrSurface* dst,
366 GrSurface* src,
367 const SkIRect& srcRect,
368 const SkIPoint& dstPoint) {
369 SkASSERT(this->getGpu()->canCopySurface(dst, src, srcRect, dstPoint));
370 GrTargetCommands::Cmd* cmd = fCommands->recordCopySurface(dst, src, srcRect, dstPoint);
371 this->recordTraceMarkersIfNecessary(cmd);
372 }
373
374 void GrInOrderDrawBuffer::recordTraceMarkersIfNecessary(GrTargetCommands::Cmd* c md) {
375 if (!cmd) {
376 return;
377 }
378 const GrTraceMarkerSet& activeTraceMarkers = this->getActiveTraceMarkers();
379 if (activeTraceMarkers.count() > 0) {
380 if (cmd->isTraced()) {
381 fGpuCmdMarkers[cmd->markerID()].addSet(activeTraceMarkers);
382 } else {
383 cmd->setMarkerID(fGpuCmdMarkers.count());
384 fGpuCmdMarkers.push_back(activeTraceMarkers);
385 }
386 }
387 }
388
389 GrTargetCommands::State*
390 GrInOrderDrawBuffer::setupPipelineAndShouldDraw(const GrPrimitiveProcessor* prim Proc,
391 const GrDrawTarget::PipelineInfo & pipelineInfo) {
392 State* state = this->allocState(primProc);
393 this->setupPipeline(pipelineInfo, state->pipelineLocation());
394
395 if (state->getPipeline()->mustSkip()) {
396 this->unallocState(state);
397 return NULL;
398 }
399
400 state->fPrimitiveProcessor->initBatchTracker(&state->fBatchTracker,
401 state->getPipeline()->getInitBa tchTracker());
402
403 if (fPrevState && fPrevState->fPrimitiveProcessor.get() &&
404 fPrevState->fPrimitiveProcessor->canMakeEqual(fPrevState->fBatchTracker,
405 *state->fPrimitiveProcesso r,
406 state->fBatchTracker) &&
407 fPrevState->getPipeline()->isEqual(*state->getPipeline())) {
408 this->unallocState(state);
409 } else {
410 fPrevState.reset(state);
411 }
412
413 this->recordTraceMarkersIfNecessary(
414 fCommands->recordXferBarrierIfNecessary(*fPrevState->getPipeline(), *this->caps()));
415 return fPrevState;
416 }
417
418 GrTargetCommands::State*
419 GrInOrderDrawBuffer::setupPipelineAndShouldDraw(GrBatch* batch,
420 const GrDrawTarget::PipelineInfo & pipelineInfo) {
421 State* state = this->allocState();
422 this->setupPipeline(pipelineInfo, state->pipelineLocation());
423
424 if (state->getPipeline()->mustSkip()) {
425 this->unallocState(state);
426 return NULL;
427 }
428
429 batch->initBatchTracker(state->getPipeline()->getInitBatchTracker());
430
431 if (fPrevState && !fPrevState->fPrimitiveProcessor.get() &&
432 fPrevState->getPipeline()->isEqual(*state->getPipeline())) {
433 this->unallocState(state);
434 } else {
435 fPrevState.reset(state);
436 }
437
438 this->recordTraceMarkersIfNecessary(
439 fCommands->recordXferBarrierIfNecessary(*fPrevState->getPipeline(), *this->caps()));
440 return fPrevState;
441 }
OLDNEW
« no previous file with comments | « src/gpu/GrRectBatch.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698