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

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

Issue 2035823002: Make GrClipMaskManager stateless and push GrPipelineBuilder construction downstack (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Address code review comments Created 4 years, 6 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
OLDNEW
1 /* 1 /*
2 * Copyright 2015 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 "GrBatchTest.h" 8 #include "GrBatchTest.h"
9 #include "GrColor.h" 9 #include "GrColor.h"
10 #include "GrDrawContext.h" 10 #include "GrDrawContext.h"
(...skipping 18 matching lines...) Expand all
29 #include "text/GrStencilAndCoverTextContext.h" 29 #include "text/GrStencilAndCoverTextContext.h"
30 30
31 #include "../private/GrAuditTrail.h" 31 #include "../private/GrAuditTrail.h"
32 32
33 #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == fDrawingM anager->getContext()) 33 #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == fDrawingM anager->getContext())
34 #define ASSERT_SINGLE_OWNER \ 34 #define ASSERT_SINGLE_OWNER \
35 SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fSingleOwner);) 35 SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fSingleOwner);)
36 #define ASSERT_SINGLE_OWNER_PRIV \ 36 #define ASSERT_SINGLE_OWNER_PRIV \
37 SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fDrawContext->fSing leOwner);) 37 SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fDrawContext->fSing leOwner);)
38 #define RETURN_IF_ABANDONED if (fDrawingManager->wasAbandoned()) { return ; } 38 #define RETURN_IF_ABANDONED if (fDrawingManager->wasAbandoned()) { return ; }
39 #define RETURN_IF_ABANDONED_PRIV if (fDrawContext->fDrawingManager->wasAbandon ed()) { return; }
39 #define RETURN_FALSE_IF_ABANDONED if (fDrawingManager->wasAbandoned()) { return false; } 40 #define RETURN_FALSE_IF_ABANDONED if (fDrawingManager->wasAbandoned()) { return false; }
40 #define RETURN_FALSE_IF_ABANDONED_PRIV if (fDrawContext->fDrawingManager->wasAb andoned()) { return false; } 41 #define RETURN_FALSE_IF_ABANDONED_PRIV if (fDrawContext->fDrawingManager->wasAb andoned()) { return false; }
41 #define RETURN_NULL_IF_ABANDONED if (fDrawingManager->wasAbandoned()) { return nullptr; } 42 #define RETURN_NULL_IF_ABANDONED if (fDrawingManager->wasAbandoned()) { return nullptr; }
42 43
43 class AutoCheckFlush { 44 class AutoCheckFlush {
44 public: 45 public:
45 AutoCheckFlush(GrDrawingManager* drawingManager) : fDrawingManager(drawingMa nager) { 46 AutoCheckFlush(GrDrawingManager* drawingManager) : fDrawingManager(drawingMa nager) {
46 SkASSERT(fDrawingManager); 47 SkASSERT(fDrawingManager);
47 } 48 }
48 ~AutoCheckFlush() { fDrawingManager->getContext()->flushIfNecessary(); } 49 ~AutoCheckFlush() { fDrawingManager->getContext()->flushIfNecessary(); }
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 183
183 void GrDrawContext::clear(const SkIRect* rect, 184 void GrDrawContext::clear(const SkIRect* rect,
184 const GrColor color, 185 const GrColor color,
185 bool canIgnoreRect) { 186 bool canIgnoreRect) {
186 ASSERT_SINGLE_OWNER 187 ASSERT_SINGLE_OWNER
187 RETURN_IF_ABANDONED 188 RETURN_IF_ABANDONED
188 SkDEBUGCODE(this->validate();) 189 SkDEBUGCODE(this->validate();)
189 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::clear"); 190 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::clear");
190 191
191 AutoCheckFlush acf(fDrawingManager); 192 AutoCheckFlush acf(fDrawingManager);
192 this->getDrawTarget()->clear(rect, color, canIgnoreRect, fRenderTarget.get() ); 193 this->getDrawTarget()->clear(rect, color, canIgnoreRect, this);
193 } 194 }
194 195
195 196
196 void GrDrawContext::drawPaint(const GrClip& clip, 197 void GrDrawContext::drawPaint(const GrClip& clip,
197 const GrPaint& origPaint, 198 const GrPaint& origPaint,
198 const SkMatrix& viewMatrix) { 199 const SkMatrix& viewMatrix) {
199 ASSERT_SINGLE_OWNER 200 ASSERT_SINGLE_OWNER
200 RETURN_IF_ABANDONED 201 RETURN_IF_ABANDONED
201 SkDEBUGCODE(this->validate();) 202 SkDEBUGCODE(this->validate();)
202 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawPaint"); 203 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawPaint");
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 return; 235 return;
235 } 236 }
236 237
237 AutoCheckFlush acf(fDrawingManager); 238 AutoCheckFlush acf(fDrawingManager);
238 239
239 SkAutoTUnref<GrDrawBatch> batch( 240 SkAutoTUnref<GrDrawBatch> batch(
240 GrRectBatchFactory::CreateNonAAFill(paint->getColor(), SkMatrix: :I(), r, nullptr, 241 GrRectBatchFactory::CreateNonAAFill(paint->getColor(), SkMatrix: :I(), r, nullptr,
241 &localMatrix)); 242 &localMatrix));
242 GrPipelineBuilder pipelineBuilder(*paint, this->isUnifiedMultisampled()) ; 243 GrPipelineBuilder pipelineBuilder(*paint, this->isUnifiedMultisampled()) ;
243 pipelineBuilder.setRenderTarget(fRenderTarget.get()); 244 pipelineBuilder.setRenderTarget(fRenderTarget.get());
244 this->getDrawTarget()->drawBatch(pipelineBuilder, clip, batch); 245 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch);
245 } 246 }
246 } 247 }
247 248
248 static inline bool rect_contains_inclusive(const SkRect& rect, const SkPoint& po int) { 249 static inline bool rect_contains_inclusive(const SkRect& rect, const SkPoint& po int) {
249 return point.fX >= rect.fLeft && point.fX <= rect.fRight && 250 return point.fX >= rect.fLeft && point.fX <= rect.fRight &&
250 point.fY >= rect.fTop && point.fY <= rect.fBottom; 251 point.fY >= rect.fTop && point.fY <= rect.fBottom;
251 } 252 }
252 253
253 static bool view_matrix_ok_for_aa_fill_rect(const SkMatrix& viewMatrix) { 254 static bool view_matrix_ok_for_aa_fill_rect(const SkMatrix& viewMatrix) {
254 return viewMatrix.preservesRightAngles(); 255 return viewMatrix.preservesRightAngles();
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 // Does the rect bound the RT? 316 // Does the rect bound the RT?
316 SkPoint srcSpaceRTQuad[4]; 317 SkPoint srcSpaceRTQuad[4];
317 invM.mapRectToQuad(srcSpaceRTQuad, rtRect); 318 invM.mapRectToQuad(srcSpaceRTQuad, rtRect);
318 if (rect_contains_inclusive(rect, srcSpaceRTQuad[0]) && 319 if (rect_contains_inclusive(rect, srcSpaceRTQuad[0]) &&
319 rect_contains_inclusive(rect, srcSpaceRTQuad[1]) && 320 rect_contains_inclusive(rect, srcSpaceRTQuad[1]) &&
320 rect_contains_inclusive(rect, srcSpaceRTQuad[2]) && 321 rect_contains_inclusive(rect, srcSpaceRTQuad[2]) &&
321 rect_contains_inclusive(rect, srcSpaceRTQuad[3])) { 322 rect_contains_inclusive(rect, srcSpaceRTQuad[3])) {
322 // Will it blend? 323 // Will it blend?
323 GrColor clearColor; 324 GrColor clearColor;
324 if (paint.isConstantBlendedColor(&clearColor)) { 325 if (paint.isConstantBlendedColor(&clearColor)) {
325 this->getDrawTarget()->clear(nullptr, clearColor, true, fRen derTarget.get()); 326 this->getDrawTarget()->clear(nullptr, clearColor, true, this );
326 return; 327 return;
327 } 328 }
328 } 329 }
329 } 330 }
330 } 331 }
331 332
332 bool snapToPixelCenters = false; 333 bool snapToPixelCenters = false;
333 SkAutoTUnref<GrDrawBatch> batch; 334 SkAutoTUnref<GrDrawBatch> batch;
334 if (width < 0) { 335 if (width < 0) {
335 batch.reset(this->getFillRectBatch(paint, viewMatrix, rect)); 336 batch.reset(this->getFillRectBatch(paint, viewMatrix, rect));
(...skipping 21 matching lines...) Expand all
357 358
358 if (batch) { 359 if (batch) {
359 GrPipelineBuilder pipelineBuilder(paint, this->isUnifiedMultisampled()) ; 360 GrPipelineBuilder pipelineBuilder(paint, this->isUnifiedMultisampled()) ;
360 pipelineBuilder.setRenderTarget(fRenderTarget.get()); 361 pipelineBuilder.setRenderTarget(fRenderTarget.get());
361 362
362 if (snapToPixelCenters) { 363 if (snapToPixelCenters) {
363 pipelineBuilder.setState(GrPipelineBuilder::kSnapVerticesToPixelCent ers_Flag, 364 pipelineBuilder.setState(GrPipelineBuilder::kSnapVerticesToPixelCent ers_Flag,
364 snapToPixelCenters); 365 snapToPixelCenters);
365 } 366 }
366 367
367 this->getDrawTarget()->drawBatch(pipelineBuilder, clip, batch); 368 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch);
368 return; 369 return;
369 } 370 }
370 371
371 SkPath path; 372 SkPath path;
372 path.setIsVolatile(true); 373 path.setIsVolatile(true);
373 path.addRect(rect); 374 path.addRect(rect);
374 this->internalDrawPath(clip, paint, viewMatrix, path, *style); 375 this->internalDrawPath(clip, paint, viewMatrix, path, *style);
375 } 376 }
376 377
378 void GrDrawContextPriv::clearStencilClip(const SkIRect& rect, bool insideClip) {
379 ASSERT_SINGLE_OWNER_PRIV
380 RETURN_IF_ABANDONED_PRIV
381 SkDEBUGCODE(fDrawContext->validate();)
382 GR_AUDIT_TRAIL_AUTO_FRAME(fDrawContext->fAuditTrail, "GrDrawContextPriv::cle arStencilClip");
383
384 AutoCheckFlush acf(fDrawContext->fDrawingManager);
385 fDrawContext->getDrawTarget()->clearStencilClip(rect, insideClip,
386 fDrawContext->accessRenderTa rget());
387 }
388
389 void GrDrawContextPriv::stencilPath(const GrPipelineBuilder& pipelineBuilder,
390 const GrClip& clip,
391 const SkMatrix& viewMatrix,
392 const GrPath* path,
393 GrPathRendering::FillType fill) {
394 fDrawContext->getDrawTarget()->stencilPath(pipelineBuilder, fDrawContext,
395 clip, viewMatrix, path, fill);
396 }
397
398 void GrDrawContextPriv::stencilRect(const GrFixedClip& clip,
399 const GrUserStencilSettings* ss,
400 bool doAA,
401 const SkMatrix& viewMatrix,
402 const SkRect& rect) {
403 ASSERT_SINGLE_OWNER_PRIV
404 RETURN_IF_ABANDONED_PRIV
405 SkDEBUGCODE(fDrawContext->validate();)
406 GR_AUDIT_TRAIL_AUTO_FRAME(fDrawContext->fAuditTrail, "GrDrawContext::stencil Rect");
407
408 AutoCheckFlush acf(fDrawContext->fDrawingManager);
409
410 GrPaint paint;
411 paint.setAntiAlias(doAA);
412 paint.setXPFactory(GrDisableColorXPFactory::Create());
bungeman-skia 2016/06/03 21:11:12 bug: leaks
413
414 SkAutoTUnref<GrDrawBatch> batch(fDrawContext->getFillRectBatch(paint, viewMa trix, rect));
415 SkASSERT(batch);
416
417 GrPipelineBuilder pipelineBuilder(paint, fDrawContext->isUnifiedMultisampled ());
418 pipelineBuilder.setRenderTarget(fDrawContext->accessRenderTarget());
419 pipelineBuilder.setUserStencil(ss);
420
421 fDrawContext->getDrawTarget()->drawBatch(pipelineBuilder, fDrawContext, clip , batch);
422 }
423
377 bool GrDrawContextPriv::drawAndStencilRect(const GrFixedClip& clip, 424 bool GrDrawContextPriv::drawAndStencilRect(const GrFixedClip& clip,
378 const GrUserStencilSettings* ss, 425 const GrUserStencilSettings* ss,
379 SkRegion::Op op, 426 SkRegion::Op op,
380 bool invert, 427 bool invert,
381 bool doAA, 428 bool doAA,
382 const SkMatrix& viewMatrix, 429 const SkMatrix& viewMatrix,
383 const SkRect& rect) { 430 const SkRect& rect) {
384 ASSERT_SINGLE_OWNER_PRIV 431 ASSERT_SINGLE_OWNER_PRIV
385 RETURN_FALSE_IF_ABANDONED_PRIV 432 RETURN_FALSE_IF_ABANDONED_PRIV
386 SkDEBUGCODE(fDrawContext->validate();) 433 SkDEBUGCODE(fDrawContext->validate();)
387 GR_AUDIT_TRAIL_AUTO_FRAME(fDrawContext->fAuditTrail, "GrDrawContext::stencil Rect"); 434 GR_AUDIT_TRAIL_AUTO_FRAME(fDrawContext->fAuditTrail, "GrDrawContext::stencil Rect");
388 435
389 AutoCheckFlush acf(fDrawContext->fDrawingManager); 436 AutoCheckFlush acf(fDrawContext->fDrawingManager);
390 437
391 GrPaint paint; 438 GrPaint paint;
392 paint.setAntiAlias(doAA); 439 paint.setAntiAlias(doAA);
393 paint.setCoverageSetOpXPFactory(op, invert); 440 paint.setCoverageSetOpXPFactory(op, invert);
394 441
395 SkAutoTUnref<GrDrawBatch> batch(fDrawContext->getFillRectBatch(paint, viewMa trix, rect)); 442 SkAutoTUnref<GrDrawBatch> batch(fDrawContext->getFillRectBatch(paint, viewMa trix, rect));
396 if (batch) { 443 if (batch) {
397 GrPipelineBuilder pipelineBuilder(paint, fDrawContext->isUnifiedMultisam pled()); 444 GrPipelineBuilder pipelineBuilder(paint, fDrawContext->isUnifiedMultisam pled());
398 pipelineBuilder.setRenderTarget(fDrawContext->accessRenderTarget()); 445 pipelineBuilder.setRenderTarget(fDrawContext->accessRenderTarget());
399 pipelineBuilder.setUserStencil(ss); 446 pipelineBuilder.setUserStencil(ss);
400 447
401 fDrawContext->getDrawTarget()->drawBatch(pipelineBuilder, clip, batch); 448 fDrawContext->getDrawTarget()->drawBatch(pipelineBuilder, fDrawContext, clip, batch);
402 return true; 449 return true;
403 } 450 }
404 451
405 SkPath path; 452 SkPath path;
406 path.setIsVolatile(true); 453 path.setIsVolatile(true);
407 path.addRect(rect); 454 path.addRect(rect);
408 return this->drawAndStencilPath(clip, ss, op, invert, doAA, viewMatrix, path ); 455 return this->drawAndStencilPath(clip, ss, op, invert, doAA, viewMatrix, path );
409 } 456 }
410 457
411 void GrDrawContext::fillRectToRect(const GrClip& clip, 458 void GrDrawContext::fillRectToRect(const GrClip& clip,
(...skipping 14 matching lines...) Expand all
426 batch.reset(GrAAFillRectBatch::CreateWithLocalRect(paint.getColor(), vie wMatrix, rectToDraw, 473 batch.reset(GrAAFillRectBatch::CreateWithLocalRect(paint.getColor(), vie wMatrix, rectToDraw,
427 localRect)); 474 localRect));
428 } else { 475 } else {
429 batch.reset(GrRectBatchFactory::CreateNonAAFill(paint.getColor(), viewMa trix, rectToDraw, 476 batch.reset(GrRectBatchFactory::CreateNonAAFill(paint.getColor(), viewMa trix, rectToDraw,
430 &localRect, nullptr)); 477 &localRect, nullptr));
431 } 478 }
432 479
433 if (batch) { 480 if (batch) {
434 GrPipelineBuilder pipelineBuilder(paint, this->isUnifiedMultisampled()); 481 GrPipelineBuilder pipelineBuilder(paint, this->isUnifiedMultisampled());
435 pipelineBuilder.setRenderTarget(fRenderTarget.get()); 482 pipelineBuilder.setRenderTarget(fRenderTarget.get());
436 this->drawBatch(&pipelineBuilder, clip, batch); 483 this->drawBatch(pipelineBuilder, clip, batch);
437 } 484 }
438 } 485 }
439 486
440 void GrDrawContext::fillRectWithLocalMatrix(const GrClip& clip, 487 void GrDrawContext::fillRectWithLocalMatrix(const GrClip& clip,
441 const GrPaint& paint, 488 const GrPaint& paint,
442 const SkMatrix& viewMatrix, 489 const SkMatrix& viewMatrix,
443 const SkRect& rectToDraw, 490 const SkRect& rectToDraw,
444 const SkMatrix& localMatrix) { 491 const SkMatrix& localMatrix) {
445 ASSERT_SINGLE_OWNER 492 ASSERT_SINGLE_OWNER
446 RETURN_IF_ABANDONED 493 RETURN_IF_ABANDONED
447 SkDEBUGCODE(this->validate();) 494 SkDEBUGCODE(this->validate();)
448 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::fillRectWithLocalMatr ix"); 495 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::fillRectWithLocalMatr ix");
449 496
450 AutoCheckFlush acf(fDrawingManager); 497 AutoCheckFlush acf(fDrawingManager);
451 498
452 SkAutoTUnref<GrDrawBatch> batch; 499 SkAutoTUnref<GrDrawBatch> batch;
453 if (should_apply_coverage_aa(paint, fRenderTarget.get()) && 500 if (should_apply_coverage_aa(paint, fRenderTarget.get()) &&
454 view_matrix_ok_for_aa_fill_rect(viewMatrix)) { 501 view_matrix_ok_for_aa_fill_rect(viewMatrix)) {
455 batch.reset(GrAAFillRectBatch::Create(paint.getColor(), viewMatrix, loca lMatrix, 502 batch.reset(GrAAFillRectBatch::Create(paint.getColor(), viewMatrix, loca lMatrix,
456 rectToDraw)); 503 rectToDraw));
457 } else { 504 } else {
458 batch.reset(GrRectBatchFactory::CreateNonAAFill(paint.getColor(), viewMa trix, rectToDraw, 505 batch.reset(GrRectBatchFactory::CreateNonAAFill(paint.getColor(), viewMa trix, rectToDraw,
459 nullptr, &localMatrix)); 506 nullptr, &localMatrix));
460 } 507 }
461 508
462 GrPipelineBuilder pipelineBuilder(paint, this->isUnifiedMultisampled()); 509 GrPipelineBuilder pipelineBuilder(paint, this->isUnifiedMultisampled());
463 pipelineBuilder.setRenderTarget(fRenderTarget.get()); 510 pipelineBuilder.setRenderTarget(fRenderTarget.get());
464 this->getDrawTarget()->drawBatch(pipelineBuilder, clip, batch); 511 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch);
465 } 512 }
466 513
467 void GrDrawContext::drawVertices(const GrClip& clip, 514 void GrDrawContext::drawVertices(const GrClip& clip,
468 const GrPaint& paint, 515 const GrPaint& paint,
469 const SkMatrix& viewMatrix, 516 const SkMatrix& viewMatrix,
470 GrPrimitiveType primitiveType, 517 GrPrimitiveType primitiveType,
471 int vertexCount, 518 int vertexCount,
472 const SkPoint positions[], 519 const SkPoint positions[],
473 const SkPoint texCoords[], 520 const SkPoint texCoords[],
474 const GrColor colors[], 521 const GrColor colors[],
(...skipping 25 matching lines...) Expand all
500 547
501 GrDrawVerticesBatch::Geometry geometry; 548 GrDrawVerticesBatch::Geometry geometry;
502 geometry.fColor = paint.getColor(); 549 geometry.fColor = paint.getColor();
503 SkAutoTUnref<GrDrawBatch> batch(GrDrawVerticesBatch::Create(geometry, primit iveType, viewMatrix, 550 SkAutoTUnref<GrDrawBatch> batch(GrDrawVerticesBatch::Create(geometry, primit iveType, viewMatrix,
504 positions, verte xCount, indices, 551 positions, verte xCount, indices,
505 indexCount, colo rs, texCoords, 552 indexCount, colo rs, texCoords,
506 bounds)); 553 bounds));
507 554
508 GrPipelineBuilder pipelineBuilder(paint, this->isUnifiedMultisampled()); 555 GrPipelineBuilder pipelineBuilder(paint, this->isUnifiedMultisampled());
509 pipelineBuilder.setRenderTarget(fRenderTarget.get()); 556 pipelineBuilder.setRenderTarget(fRenderTarget.get());
510 this->getDrawTarget()->drawBatch(pipelineBuilder, clip, batch); 557 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch);
511 } 558 }
512 559
513 /////////////////////////////////////////////////////////////////////////////// 560 ///////////////////////////////////////////////////////////////////////////////
514 561
515 void GrDrawContext::drawAtlas(const GrClip& clip, 562 void GrDrawContext::drawAtlas(const GrClip& clip,
516 const GrPaint& paint, 563 const GrPaint& paint,
517 const SkMatrix& viewMatrix, 564 const SkMatrix& viewMatrix,
518 int spriteCount, 565 int spriteCount,
519 const SkRSXform xform[], 566 const SkRSXform xform[],
520 const SkRect texRect[], 567 const SkRect texRect[],
521 const SkColor colors[]) { 568 const SkColor colors[]) {
522 ASSERT_SINGLE_OWNER 569 ASSERT_SINGLE_OWNER
523 RETURN_IF_ABANDONED 570 RETURN_IF_ABANDONED
524 SkDEBUGCODE(this->validate();) 571 SkDEBUGCODE(this->validate();)
525 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawAtlas"); 572 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawAtlas");
526 573
527 AutoCheckFlush acf(fDrawingManager); 574 AutoCheckFlush acf(fDrawingManager);
528 575
529 GrDrawAtlasBatch::Geometry geometry; 576 GrDrawAtlasBatch::Geometry geometry;
530 geometry.fColor = paint.getColor(); 577 geometry.fColor = paint.getColor();
531 SkAutoTUnref<GrDrawBatch> batch(GrDrawAtlasBatch::Create(geometry, viewMatri x, spriteCount, 578 SkAutoTUnref<GrDrawBatch> batch(GrDrawAtlasBatch::Create(geometry, viewMatri x, spriteCount,
532 xform, texRect, col ors)); 579 xform, texRect, col ors));
533 580
534 GrPipelineBuilder pipelineBuilder(paint, this->isUnifiedMultisampled()); 581 GrPipelineBuilder pipelineBuilder(paint, this->isUnifiedMultisampled());
535 pipelineBuilder.setRenderTarget(fRenderTarget.get()); 582 pipelineBuilder.setRenderTarget(fRenderTarget.get());
536 this->getDrawTarget()->drawBatch(pipelineBuilder, clip, batch); 583 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch);
537 } 584 }
538 585
539 /////////////////////////////////////////////////////////////////////////////// 586 ///////////////////////////////////////////////////////////////////////////////
540 587
541 void GrDrawContext::drawRRect(const GrClip& clip, 588 void GrDrawContext::drawRRect(const GrClip& clip,
542 const GrPaint& paint, 589 const GrPaint& paint,
543 const SkMatrix& viewMatrix, 590 const SkMatrix& viewMatrix,
544 const SkRRect& rrect, 591 const SkRRect& rrect,
545 const GrStyle& style) { 592 const GrStyle& style) {
546 ASSERT_SINGLE_OWNER 593 ASSERT_SINGLE_OWNER
(...skipping 13 matching lines...) Expand all
560 GrShaderCaps* shaderCaps = fContext->caps()->shaderCaps(); 607 GrShaderCaps* shaderCaps = fContext->caps()->shaderCaps();
561 608
562 SkAutoTUnref<GrDrawBatch> batch(GrOvalRenderer::CreateRRectBatch(paint.g etColor(), 609 SkAutoTUnref<GrDrawBatch> batch(GrOvalRenderer::CreateRRectBatch(paint.g etColor(),
563 viewMat rix, 610 viewMat rix,
564 rrect, 611 rrect,
565 stroke, 612 stroke,
566 shaderC aps)); 613 shaderC aps));
567 if (batch) { 614 if (batch) {
568 GrPipelineBuilder pipelineBuilder(paint, this->isUnifiedMultisample d()); 615 GrPipelineBuilder pipelineBuilder(paint, this->isUnifiedMultisample d());
569 pipelineBuilder.setRenderTarget(fRenderTarget.get()); 616 pipelineBuilder.setRenderTarget(fRenderTarget.get());
570 this->getDrawTarget()->drawBatch(pipelineBuilder, clip, batch); 617 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch) ;
571 return; 618 return;
572 } 619 }
573 } 620 }
574 621
575 SkPath path; 622 SkPath path;
576 path.setIsVolatile(true); 623 path.setIsVolatile(true);
577 path.addRRect(rrect); 624 path.addRRect(rrect);
578 this->internalDrawPath(clip, paint, viewMatrix, path, style); 625 this->internalDrawPath(clip, paint, viewMatrix, path, style);
579 } 626 }
580 627
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
686 if (should_apply_coverage_aa(paint, fRenderTarget.get())) { 733 if (should_apply_coverage_aa(paint, fRenderTarget.get())) {
687 GrShaderCaps* shaderCaps = fContext->caps()->shaderCaps(); 734 GrShaderCaps* shaderCaps = fContext->caps()->shaderCaps();
688 SkAutoTUnref<GrDrawBatch> batch(GrOvalRenderer::CreateOvalBatch(paint.ge tColor(), 735 SkAutoTUnref<GrDrawBatch> batch(GrOvalRenderer::CreateOvalBatch(paint.ge tColor(),
689 viewMatr ix, 736 viewMatr ix,
690 oval, 737 oval,
691 stroke, 738 stroke,
692 shaderCa ps)); 739 shaderCa ps));
693 if (batch) { 740 if (batch) {
694 GrPipelineBuilder pipelineBuilder(paint, this->isUnifiedMultisample d()); 741 GrPipelineBuilder pipelineBuilder(paint, this->isUnifiedMultisample d());
695 pipelineBuilder.setRenderTarget(fRenderTarget.get()); 742 pipelineBuilder.setRenderTarget(fRenderTarget.get());
696 this->getDrawTarget()->drawBatch(pipelineBuilder, clip, batch); 743 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch) ;
697 return; 744 return;
698 } 745 }
699 } 746 }
700 747
701 SkPath path; 748 SkPath path;
702 path.setIsVolatile(true); 749 path.setIsVolatile(true);
703 path.addOval(oval); 750 path.addOval(oval);
704 this->internalDrawPath(clip, paint, viewMatrix, path, style); 751 this->internalDrawPath(clip, paint, viewMatrix, path, style);
705 } 752 }
706 753
(...skipping 10 matching lines...) Expand all
717 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawImageNine"); 764 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawImageNine");
718 765
719 AutoCheckFlush acf(fDrawingManager); 766 AutoCheckFlush acf(fDrawingManager);
720 767
721 SkAutoTUnref<GrDrawBatch> batch(GrNinePatch::CreateNonAA(paint.getColor(), v iewMatrix, 768 SkAutoTUnref<GrDrawBatch> batch(GrNinePatch::CreateNonAA(paint.getColor(), v iewMatrix,
722 imageWidth, imageHe ight, 769 imageWidth, imageHe ight,
723 center, dst)); 770 center, dst));
724 771
725 GrPipelineBuilder pipelineBuilder(paint, this->isUnifiedMultisampled()); 772 GrPipelineBuilder pipelineBuilder(paint, this->isUnifiedMultisampled());
726 pipelineBuilder.setRenderTarget(fRenderTarget.get()); 773 pipelineBuilder.setRenderTarget(fRenderTarget.get());
727 this->getDrawTarget()->drawBatch(pipelineBuilder, clip, batch); 774 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch);
728 } 775 }
729 776
730 777
731 // Can 'path' be drawn as a pair of filled nested rectangles? 778 // Can 'path' be drawn as a pair of filled nested rectangles?
732 static bool fills_as_nested_rects(const SkMatrix& viewMatrix, const SkPath& path , SkRect rects[2]) { 779 static bool fills_as_nested_rects(const SkMatrix& viewMatrix, const SkPath& path , SkRect rects[2]) {
733 780
734 if (path.isInverseFillType()) { 781 if (path.isInverseFillType()) {
735 return false; 782 return false;
736 } 783 }
737 784
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
778 const GrPaint& paint, GrDrawBatch* batch) { 825 const GrPaint& paint, GrDrawBatch* batch) {
779 ASSERT_SINGLE_OWNER 826 ASSERT_SINGLE_OWNER
780 RETURN_IF_ABANDONED 827 RETURN_IF_ABANDONED
781 SkDEBUGCODE(this->validate();) 828 SkDEBUGCODE(this->validate();)
782 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawBatch"); 829 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawBatch");
783 830
784 AutoCheckFlush acf(fDrawingManager); 831 AutoCheckFlush acf(fDrawingManager);
785 832
786 GrPipelineBuilder pipelineBuilder(paint, this->isUnifiedMultisampled()); 833 GrPipelineBuilder pipelineBuilder(paint, this->isUnifiedMultisampled());
787 pipelineBuilder.setRenderTarget(fRenderTarget.get()); 834 pipelineBuilder.setRenderTarget(fRenderTarget.get());
788 this->getDrawTarget()->drawBatch(pipelineBuilder, clip, batch); 835 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch);
789 } 836 }
790 837
791 void GrDrawContext::drawPath(const GrClip& clip, 838 void GrDrawContext::drawPath(const GrClip& clip,
792 const GrPaint& paint, 839 const GrPaint& paint,
793 const SkMatrix& viewMatrix, 840 const SkMatrix& viewMatrix,
794 const SkPath& path, 841 const SkPath& path,
795 const GrStyle& style) { 842 const GrStyle& style) {
796 ASSERT_SINGLE_OWNER 843 ASSERT_SINGLE_OWNER
797 RETURN_IF_ABANDONED 844 RETURN_IF_ABANDONED
798 SkDEBUGCODE(this->validate();) 845 SkDEBUGCODE(this->validate();)
(...skipping 12 matching lines...) Expand all
811 if (style.isSimpleFill() && !path.isConvex()) { 858 if (style.isSimpleFill() && !path.isConvex()) {
812 // Concave AA paths are expensive - try to avoid them for special ca ses 859 // Concave AA paths are expensive - try to avoid them for special ca ses
813 SkRect rects[2]; 860 SkRect rects[2];
814 861
815 if (fills_as_nested_rects(viewMatrix, path, rects)) { 862 if (fills_as_nested_rects(viewMatrix, path, rects)) {
816 SkAutoTUnref<GrDrawBatch> batch(GrRectBatchFactory::CreateAAFill NestedRects( 863 SkAutoTUnref<GrDrawBatch> batch(GrRectBatchFactory::CreateAAFill NestedRects(
817 paint.getColor(), viewMatrix, rects)); 864 paint.getColor(), viewMatrix, rects));
818 if (batch) { 865 if (batch) {
819 GrPipelineBuilder pipelineBuilder(paint, this->isUnifiedMul tisampled()); 866 GrPipelineBuilder pipelineBuilder(paint, this->isUnifiedMul tisampled());
820 pipelineBuilder.setRenderTarget(fRenderTarget.get()); 867 pipelineBuilder.setRenderTarget(fRenderTarget.get());
821 this->getDrawTarget()->drawBatch(pipelineBuilder, clip, batc h); 868 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip , batch);
822 } 869 }
823 return; 870 return;
824 } 871 }
825 } 872 }
826 SkRect ovalRect; 873 SkRect ovalRect;
827 bool isOval = path.isOval(&ovalRect); 874 bool isOval = path.isOval(&ovalRect);
828 875
829 if (isOval && !path.isInverseFillType()) { 876 if (isOval && !path.isInverseFillType()) {
830 GrShaderCaps* shaderCaps = fContext->caps()->shaderCaps(); 877 GrShaderCaps* shaderCaps = fContext->caps()->shaderCaps();
831 SkAutoTUnref<GrDrawBatch> batch(GrOvalRenderer::CreateOvalBatch(pain t.getColor(), 878 SkAutoTUnref<GrDrawBatch> batch(GrOvalRenderer::CreateOvalBatch(pain t.getColor(),
832 view Matrix, 879 view Matrix,
833 oval Rect, 880 oval Rect,
834 styl e.strokeRec(), 881 styl e.strokeRec(),
835 shad erCaps)); 882 shad erCaps));
836 if (batch) { 883 if (batch) {
837 GrPipelineBuilder pipelineBuilder(paint, this->isUnifiedMultisa mpled()); 884 GrPipelineBuilder pipelineBuilder(paint, this->isUnifiedMultisa mpled());
838 pipelineBuilder.setRenderTarget(fRenderTarget.get()); 885 pipelineBuilder.setRenderTarget(fRenderTarget.get());
839 this->getDrawTarget()->drawBatch(pipelineBuilder, clip, batch); 886 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, ba tch);
840 return; 887 return;
841 } 888 }
842 } 889 }
843 } 890 }
844 891
845 // Note that internalDrawPath may sw-rasterize the path into a scratch textu re. 892 // Note that internalDrawPath may sw-rasterize the path into a scratch textu re.
846 // Scratch textures can be recycled after they are returned to the texture 893 // Scratch textures can be recycled after they are returned to the texture
847 // cache. This presents a potential hazard for buffered drawing. However, 894 // cache. This presents a potential hazard for buffered drawing. However,
848 // the writePixels that uploads to the scratch will perform a flush so we're 895 // the writePixels that uploads to the scratch will perform a flush so we're
849 // OK. 896 // OK.
(...skipping 19 matching lines...) Expand all
869 return true; 916 return true;
870 } 917 }
871 918
872 AutoCheckFlush acf(fDrawContext->fDrawingManager); 919 AutoCheckFlush acf(fDrawContext->fDrawingManager);
873 920
874 // An Assumption here is that path renderer would use some form of tweaking 921 // An Assumption here is that path renderer would use some form of tweaking
875 // the src color (either the input alpha or in the frag shader) to implement 922 // the src color (either the input alpha or in the frag shader) to implement
876 // aa. If we have some future driver-mojo path AA that can do the right 923 // aa. If we have some future driver-mojo path AA that can do the right
877 // thing WRT to the blend then we'll need some query on the PR. 924 // thing WRT to the blend then we'll need some query on the PR.
878 bool useCoverageAA = doAA && !fDrawContext->fRenderTarget->isUnifiedMultisam pled(); 925 bool useCoverageAA = doAA && !fDrawContext->fRenderTarget->isUnifiedMultisam pled();
879 bool hasUserStencilSettings = (&GrUserStencilSettings::kUnused != ss); 926 bool hasUserStencilSettings = !ss->isUnused();
880 bool isStencilBufferMSAA = fDrawContext->fRenderTarget->isStencilBufferMulti sampled(); 927 bool isStencilBufferMSAA = fDrawContext->fRenderTarget->isStencilBufferMulti sampled();
881 928
882 const GrPathRendererChain::DrawType type = 929 const GrPathRendererChain::DrawType type =
883 useCoverageAA ? GrPathRendererChain::kColorAntiAlias_DrawType 930 useCoverageAA ? GrPathRendererChain::kColorAntiAlias_DrawType
884 : GrPathRendererChain::kColor_DrawType; 931 : GrPathRendererChain::kColor_DrawType;
885 932
886 GrPathRenderer::CanDrawPathArgs canDrawArgs; 933 GrPathRenderer::CanDrawPathArgs canDrawArgs;
887 canDrawArgs.fShaderCaps = fDrawContext->fDrawingManager->getContext()->caps( )->shaderCaps(); 934 canDrawArgs.fShaderCaps = fDrawContext->fDrawingManager->getContext()->caps( )->shaderCaps();
888 canDrawArgs.fViewMatrix = &viewMatrix; 935 canDrawArgs.fViewMatrix = &viewMatrix;
889 canDrawArgs.fPath = &path; 936 canDrawArgs.fPath = &path;
890 canDrawArgs.fStyle = &GrStyle::SimpleFill(); 937 canDrawArgs.fStyle = &GrStyle::SimpleFill();
891 canDrawArgs.fAntiAlias = useCoverageAA; 938 canDrawArgs.fAntiAlias = useCoverageAA;
892 canDrawArgs.fHasUserStencilSettings = hasUserStencilSettings; 939 canDrawArgs.fHasUserStencilSettings = hasUserStencilSettings;
893 canDrawArgs.fIsStencilBufferMSAA = isStencilBufferMSAA; 940 canDrawArgs.fIsStencilBufferMSAA = isStencilBufferMSAA;
894 941
895 // Don't allow the SW renderer 942 // Don't allow the SW renderer
896 GrPathRenderer* pr = fDrawContext->fDrawingManager->getPathRenderer(canDrawA rgs, false, type); 943 GrPathRenderer* pr = fDrawContext->fDrawingManager->getPathRenderer(canDrawA rgs, false, type);
897 if (!pr) { 944 if (!pr) {
898 return false; 945 return false;
899 } 946 }
900 947
901 GrPaint paint; 948 GrPaint paint;
902 paint.setCoverageSetOpXPFactory(op, invert); 949 paint.setCoverageSetOpXPFactory(op, invert);
903 950
904 GrPipelineBuilder pipelineBuilder(paint, fDrawContext->isUnifiedMultisample d());
905 pipelineBuilder.setRenderTarget(fDrawContext->accessRenderTarget());
906 pipelineBuilder.setUserStencil(ss);
907
908 GrPathRenderer::DrawPathArgs args; 951 GrPathRenderer::DrawPathArgs args;
909 args.fTarget = fDrawContext->getDrawTarget();
910 args.fResourceProvider = fDrawContext->fDrawingManager->getContext()->resour ceProvider(); 952 args.fResourceProvider = fDrawContext->fDrawingManager->getContext()->resour ceProvider();
911 args.fPipelineBuilder = &pipelineBuilder; 953 args.fPaint = &paint;
954 args.fUserStencilSettings = ss;
955 args.fDrawContext = fDrawContext;
912 args.fClip = &clip; 956 args.fClip = &clip;
913 args.fColor = GrColor_WHITE; 957 args.fColor = GrColor_WHITE;
914 args.fViewMatrix = &viewMatrix; 958 args.fViewMatrix = &viewMatrix;
915 args.fPath = &path; 959 args.fPath = &path;
916 args.fStyle = &GrStyle::SimpleFill(); 960 args.fStyle = &GrStyle::SimpleFill();
917 args.fAntiAlias = useCoverageAA; 961 args.fAntiAlias = useCoverageAA;
918 args.fGammaCorrect = fDrawContext->isGammaCorrect(); 962 args.fGammaCorrect = fDrawContext->isGammaCorrect();
919 pr->drawPath(args); 963 pr->drawPath(args);
920 return true; 964 return true;
921 } 965 }
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1001 pr = fDrawingManager->getPathRenderer(canDrawArgs, true, type); 1045 pr = fDrawingManager->getPathRenderer(canDrawArgs, true, type);
1002 } 1046 }
1003 1047
1004 if (nullptr == pr) { 1048 if (nullptr == pr) {
1005 #ifdef SK_DEBUG 1049 #ifdef SK_DEBUG
1006 SkDebugf("Unable to find path renderer compatible with path.\n"); 1050 SkDebugf("Unable to find path renderer compatible with path.\n");
1007 #endif 1051 #endif
1008 return; 1052 return;
1009 } 1053 }
1010 1054
1011 GrPipelineBuilder pipelineBuilder(paint, this->isUnifiedMultisampled());
1012 pipelineBuilder.setRenderTarget(fRenderTarget.get());
1013
1014 GrPathRenderer::DrawPathArgs args; 1055 GrPathRenderer::DrawPathArgs args;
1015 args.fTarget = this->getDrawTarget();
1016 args.fResourceProvider = fDrawingManager->getContext()->resourceProvider(); 1056 args.fResourceProvider = fDrawingManager->getContext()->resourceProvider();
1017 args.fPipelineBuilder = &pipelineBuilder; 1057 args.fPaint = &paint;
1058 args.fUserStencilSettings = &GrUserStencilSettings::kUnused;
1059 args.fDrawContext = this;
1018 args.fClip = &clip; 1060 args.fClip = &clip;
1019 args.fColor = paint.getColor(); 1061 args.fColor = paint.getColor();
1020 args.fViewMatrix = &viewMatrix; 1062 args.fViewMatrix = &viewMatrix;
1021 args.fPath = canDrawArgs.fPath; 1063 args.fPath = canDrawArgs.fPath;
1022 args.fStyle = canDrawArgs.fStyle; 1064 args.fStyle = canDrawArgs.fStyle;
1023 args.fAntiAlias = useCoverageAA; 1065 args.fAntiAlias = useCoverageAA;
1024 args.fGammaCorrect = this->isGammaCorrect(); 1066 args.fGammaCorrect = this->isGammaCorrect();
1025 pr->drawPath(args); 1067 pr->drawPath(args);
1026 } 1068 }
1027 1069
1028 void GrDrawContext::drawBatch(GrPipelineBuilder* pipelineBuilder, const GrClip& clip, 1070 void GrDrawContext::drawBatch(const GrPipelineBuilder& pipelineBuilder, const Gr Clip& clip,
1029 GrDrawBatch* batch) { 1071 GrDrawBatch* batch) {
1030 ASSERT_SINGLE_OWNER 1072 ASSERT_SINGLE_OWNER
1031 RETURN_IF_ABANDONED 1073 RETURN_IF_ABANDONED
1032 SkDEBUGCODE(this->validate();) 1074 SkDEBUGCODE(this->validate();)
1033 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawBatch"); 1075 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawBatch");
1034 1076
1035 this->getDrawTarget()->drawBatch(*pipelineBuilder, clip, batch); 1077 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch);
1036 } 1078 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698