OLD | NEW |
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 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 } | 267 } |
268 return false; | 268 return false; |
269 } else { | 269 } else { |
270 if (useHWAA) { | 270 if (useHWAA) { |
271 *useHWAA = rt->isUnifiedMultisampled(); | 271 *useHWAA = rt->isUnifiedMultisampled(); |
272 } | 272 } |
273 return !rt->isUnifiedMultisampled(); | 273 return !rt->isUnifiedMultisampled(); |
274 } | 274 } |
275 } | 275 } |
276 | 276 |
277 GrDrawBatch* GrDrawContext::getFillRectBatch(const GrPaint& paint, | 277 enum class TrimResult { |
278 const SkMatrix& viewMatrix, | 278 kSkipDraw, |
279 const SkRect& rect, | 279 kDidTrim, |
280 bool* useHWAA) { | 280 kDidNotTrim |
| 281 }; |
| 282 |
| 283 static TrimResult trim_fill_rect(const GrClip& clip, const GrRenderTarget* rt, |
| 284 const SkMatrix& viewMatrix, SkRect* rect) { |
| 285 SkMatrix inverseVM; |
| 286 if (viewMatrix.rectStaysRect() && viewMatrix.invert(&inverseVM)) { |
| 287 SkASSERT(inverseVM.rectStaysRect()); |
| 288 SkIRect clipDevBounds; |
| 289 clip.getConservativeBounds(rt->width(), rt->height(), &clipDevBounds); |
| 290 SkRect clipUserSpaceBounds; |
| 291 inverseVM.mapRect(&clipUserSpaceBounds, SkRect::Make(clipDevBounds)); |
| 292 if (!rect->intersect(clipUserSpaceBounds)) { |
| 293 return TrimResult::kSkipDraw; |
| 294 } |
| 295 return TrimResult::kDidTrim; |
| 296 } |
| 297 return TrimResult::kDidNotTrim; |
| 298 } |
| 299 |
| 300 bool GrDrawContext::getFillRectBatch(const GrClip& clip, |
| 301 const GrPaint& paint, |
| 302 const SkMatrix& viewMatrix, |
| 303 const SkRect& rect, |
| 304 SkAutoTUnref<GrDrawBatch>* batch, |
| 305 bool* useHWAA) { |
| 306 SkRect trimRect = rect; |
| 307 if (TrimResult::kSkipDraw == trim_fill_rect(clip, fRenderTarget.get(), viewM
atrix, &trimRect)) { |
| 308 return false; |
| 309 } |
| 310 |
281 if (InstancedRendering* ir = this->getDrawTarget()->instancedRendering()) { | 311 if (InstancedRendering* ir = this->getDrawTarget()->instancedRendering()) { |
282 if (GrDrawBatch* batch = ir->recordRect(rect, viewMatrix, paint.getColor
(), | 312 batch->reset(ir->recordRect(trimRect, viewMatrix, paint.getColor(), pain
t.isAntiAlias(), |
283 paint.isAntiAlias(), fInstancedP
ipelineInfo, | 313 fInstancedPipelineInfo, useHWAA)); |
284 useHWAA)) { | 314 if (batch) { |
285 return batch; | 315 return true; |
286 } | 316 } |
287 } | 317 } |
288 | 318 |
289 if (should_apply_coverage_aa(paint, fRenderTarget.get(), useHWAA)) { | 319 if (should_apply_coverage_aa(paint, fRenderTarget.get(), useHWAA)) { |
290 // The fill path can handle rotation but not skew. | 320 // The fill path can handle rotation but not skew. |
291 if (view_matrix_ok_for_aa_fill_rect(viewMatrix)) { | 321 if (view_matrix_ok_for_aa_fill_rect(viewMatrix)) { |
292 SkRect devBoundRect; | 322 SkRect devBoundRect; |
293 viewMatrix.mapRect(&devBoundRect, rect); | 323 viewMatrix.mapRect(&devBoundRect, trimRect); |
294 return GrRectBatchFactory::CreateAAFill(paint.getColor(), viewMatrix
, | 324 batch->reset(GrRectBatchFactory::CreateAAFill(paint.getColor(), view
Matrix, trimRect, |
295 rect, devBoundRect); | 325 devBoundRect)); |
296 } | 326 } |
297 } else { | 327 } else { |
298 // filled BW rect | 328 // filled BW rect |
299 return GrRectBatchFactory::CreateNonAAFill(paint.getColor(), viewMatrix,
rect, | 329 batch->reset(GrRectBatchFactory::CreateNonAAFill(paint.getColor(), viewM
atrix, trimRect, |
300 nullptr, nullptr); | 330 nullptr, nullptr)); |
301 } | 331 } |
302 | 332 |
303 return nullptr; | 333 return true; |
304 } | 334 } |
305 | 335 |
306 void GrDrawContext::drawRect(const GrClip& clip, | 336 void GrDrawContext::drawRect(const GrClip& clip, |
307 const GrPaint& paint, | 337 const GrPaint& paint, |
308 const SkMatrix& viewMatrix, | 338 const SkMatrix& viewMatrix, |
309 const SkRect& rect, | 339 const SkRect& rect, |
310 const GrStyle* style) { | 340 const GrStyle* style) { |
311 if (!style) { | 341 if (!style) { |
312 style = &GrStyle::SimpleFill(); | 342 style = &GrStyle::SimpleFill(); |
313 } | 343 } |
(...skipping 30 matching lines...) Expand all Loading... |
344 rect_contains_inclusive(rect, srcSpaceRTQuad[2]) && | 374 rect_contains_inclusive(rect, srcSpaceRTQuad[2]) && |
345 rect_contains_inclusive(rect, srcSpaceRTQuad[3])) { | 375 rect_contains_inclusive(rect, srcSpaceRTQuad[3])) { |
346 // Will it blend? | 376 // Will it blend? |
347 GrColor clearColor; | 377 GrColor clearColor; |
348 if (paint.isConstantBlendedColor(&clearColor)) { | 378 if (paint.isConstantBlendedColor(&clearColor)) { |
349 this->getDrawTarget()->clear(nullptr, clearColor, true, this
); | 379 this->getDrawTarget()->clear(nullptr, clearColor, true, this
); |
350 return; | 380 return; |
351 } | 381 } |
352 } | 382 } |
353 } | 383 } |
354 batch.reset(this->getFillRectBatch(paint, viewMatrix, rect, &useHWAA)); | 384 if (!this->getFillRectBatch(clip, paint, viewMatrix, rect, &batch, &useH
WAA)) { |
| 385 return; |
| 386 } |
355 } else if (stroke.getStyle() == SkStrokeRec::kStroke_Style || | 387 } else if (stroke.getStyle() == SkStrokeRec::kStroke_Style || |
356 stroke.getStyle() == SkStrokeRec::kHairline_Style) { | 388 stroke.getStyle() == SkStrokeRec::kHairline_Style) { |
357 if ((!rect.width() || !rect.height()) && | 389 if ((!rect.width() || !rect.height()) && |
358 SkStrokeRec::kHairline_Style != stroke.getStyle()) { | 390 SkStrokeRec::kHairline_Style != stroke.getStyle()) { |
359 SkScalar r = stroke.getWidth() / 2; | 391 SkScalar r = stroke.getWidth() / 2; |
360 // TODO: Move these stroke->fill fallbacks to GrShape? | 392 // TODO: Move these stroke->fill fallbacks to GrShape? |
361 switch (stroke.getJoin()) { | 393 switch (stroke.getJoin()) { |
362 case SkPaint::kMiter_Join: | 394 case SkPaint::kMiter_Join: |
363 this->drawRect(clip, paint, viewMatrix, | 395 this->drawRect(clip, paint, viewMatrix, |
364 {rect.fLeft - r, rect.fTop - r, | 396 {rect.fLeft - r, rect.fTop - r, |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 SkDEBUGCODE(fDrawContext->validate();) | 511 SkDEBUGCODE(fDrawContext->validate();) |
480 GR_AUDIT_TRAIL_AUTO_FRAME(fDrawContext->fAuditTrail, "GrDrawContext::drawAnd
StencilRect"); | 512 GR_AUDIT_TRAIL_AUTO_FRAME(fDrawContext->fAuditTrail, "GrDrawContext::drawAnd
StencilRect"); |
481 | 513 |
482 AutoCheckFlush acf(fDrawContext->fDrawingManager); | 514 AutoCheckFlush acf(fDrawContext->fDrawingManager); |
483 | 515 |
484 GrPaint paint; | 516 GrPaint paint; |
485 paint.setAntiAlias(doAA); | 517 paint.setAntiAlias(doAA); |
486 paint.setCoverageSetOpXPFactory(op, invert); | 518 paint.setCoverageSetOpXPFactory(op, invert); |
487 | 519 |
488 bool useHWAA; | 520 bool useHWAA; |
489 SkAutoTUnref<GrDrawBatch> batch( | 521 SkAutoTUnref<GrDrawBatch> batch; |
490 fDrawContext->getFillRectBatch(paint, viewMatrix, rect, &useHWAA)); | 522 if (!fDrawContext->getFillRectBatch(clip, paint, viewMatrix, rect, &batch, &
useHWAA)) { |
| 523 return true; |
| 524 } |
491 if (batch) { | 525 if (batch) { |
492 GrPipelineBuilder pipelineBuilder(paint, useHWAA); | 526 GrPipelineBuilder pipelineBuilder(paint, useHWAA); |
493 pipelineBuilder.setUserStencil(ss); | 527 pipelineBuilder.setUserStencil(ss); |
494 | 528 |
495 fDrawContext->getDrawTarget()->drawBatch(pipelineBuilder, fDrawContext,
clip, batch); | 529 fDrawContext->getDrawTarget()->drawBatch(pipelineBuilder, fDrawContext,
clip, batch); |
496 return true; | 530 return true; |
497 } | 531 } |
498 | 532 |
499 SkPath path; | 533 SkPath path; |
500 path.setIsVolatile(true); | 534 path.setIsVolatile(true); |
501 path.addRect(rect); | 535 path.addRect(rect); |
502 return this->drawAndStencilPath(clip, ss, op, invert, doAA, viewMatrix, path
); | 536 return this->drawAndStencilPath(clip, ss, op, invert, doAA, viewMatrix, path
); |
503 } | 537 } |
504 | 538 |
505 void GrDrawContext::fillRectToRect(const GrClip& clip, | 539 void GrDrawContext::fillRectToRect(const GrClip& clip, |
506 const GrPaint& paint, | 540 const GrPaint& paint, |
507 const SkMatrix& viewMatrix, | 541 const SkMatrix& viewMatrix, |
508 const SkRect& rectToDraw, | 542 const SkRect& rectToDraw, |
509 const SkRect& localRect) { | 543 const SkRect& localRect) { |
510 ASSERT_SINGLE_OWNER | 544 ASSERT_SINGLE_OWNER |
511 RETURN_IF_ABANDONED | 545 RETURN_IF_ABANDONED |
512 SkDEBUGCODE(this->validate();) | 546 SkDEBUGCODE(this->validate();) |
513 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::fillRectToRect"); | 547 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::fillRectToRect"); |
514 | 548 |
515 AutoCheckFlush acf(fDrawingManager); | 549 AutoCheckFlush acf(fDrawingManager); |
516 SkAutoTUnref<GrDrawBatch> batch; | 550 SkAutoTUnref<GrDrawBatch> batch; |
517 bool useHWAA; | 551 bool useHWAA; |
518 | 552 |
| 553 SkRect trimRect = rectToDraw; |
| 554 TrimResult trimResult = trim_fill_rect(clip, fRenderTarget.get(), viewMatrix
, &trimRect); |
| 555 if (TrimResult::kSkipDraw == trimResult) { |
| 556 return; |
| 557 } |
| 558 SkRect trimLocalRect = localRect; |
| 559 if (TrimResult::kDidTrim == trimResult) { |
| 560 SkScalar dx = localRect.width() / rectToDraw.width(); |
| 561 SkScalar dy = localRect.height() / rectToDraw.height(); |
| 562 trimLocalRect.fLeft += (trimRect.fLeft - rectToDraw.fLeft) * dx; |
| 563 trimLocalRect.fTop += (trimRect.fTop - rectToDraw.fTop) * dy; |
| 564 trimLocalRect.fRight -= (rectToDraw.fRight - trimRect.fRight) * dx; |
| 565 trimLocalRect.fTop -= (rectToDraw.fTop - trimRect.fTop) * dy; |
| 566 } |
| 567 |
519 if (InstancedRendering* ir = this->getDrawTarget()->instancedRendering()) { | 568 if (InstancedRendering* ir = this->getDrawTarget()->instancedRendering()) { |
520 batch.reset(ir->recordRect(rectToDraw, viewMatrix, paint.getColor(), loc
alRect, | 569 batch.reset(ir->recordRect(trimRect, viewMatrix, paint.getColor(), trimL
ocalRect, |
521 paint.isAntiAlias(), fInstancedPipelineInfo,
&useHWAA)); | 570 paint.isAntiAlias(), fInstancedPipelineInfo,
&useHWAA)); |
522 if (batch) { | 571 if (batch) { |
523 GrPipelineBuilder pipelineBuilder(paint, useHWAA); | 572 GrPipelineBuilder pipelineBuilder(paint, useHWAA); |
524 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch)
; | 573 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch)
; |
525 return; | 574 return; |
526 } | 575 } |
527 } | 576 } |
528 | 577 |
529 if (should_apply_coverage_aa(paint, fRenderTarget.get(), &useHWAA) && | 578 if (should_apply_coverage_aa(paint, fRenderTarget.get(), &useHWAA) && |
530 view_matrix_ok_for_aa_fill_rect(viewMatrix)) { | 579 view_matrix_ok_for_aa_fill_rect(viewMatrix)) { |
531 batch.reset(GrAAFillRectBatch::CreateWithLocalRect(paint.getColor(), vie
wMatrix, rectToDraw, | 580 batch.reset(GrAAFillRectBatch::CreateWithLocalRect(paint.getColor(), vie
wMatrix, trimRect, |
532 localRect)); | 581 trimLocalRect)); |
533 } else { | 582 } else { |
534 batch.reset(GrRectBatchFactory::CreateNonAAFill(paint.getColor(), viewMa
trix, rectToDraw, | 583 batch.reset(GrRectBatchFactory::CreateNonAAFill(paint.getColor(), viewMa
trix, trimRect, |
535 &localRect, nullptr)); | 584 &trimLocalRect, nullptr)
); |
536 } | 585 } |
537 | 586 |
538 if (batch) { | 587 if (batch) { |
539 GrPipelineBuilder pipelineBuilder(paint, useHWAA); | 588 GrPipelineBuilder pipelineBuilder(paint, useHWAA); |
540 this->drawBatch(pipelineBuilder, clip, batch); | 589 this->drawBatch(pipelineBuilder, clip, batch); |
541 } | 590 } |
542 } | 591 } |
543 | 592 |
544 void GrDrawContext::fillRectWithLocalMatrix(const GrClip& clip, | 593 void GrDrawContext::fillRectWithLocalMatrix(const GrClip& clip, |
545 const GrPaint& paint, | 594 const GrPaint& paint, |
546 const SkMatrix& viewMatrix, | 595 const SkMatrix& viewMatrix, |
547 const SkRect& rectToDraw, | 596 const SkRect& rectToDraw, |
548 const SkMatrix& localMatrix) { | 597 const SkMatrix& localMatrix) { |
549 ASSERT_SINGLE_OWNER | 598 ASSERT_SINGLE_OWNER |
550 RETURN_IF_ABANDONED | 599 RETURN_IF_ABANDONED |
551 SkDEBUGCODE(this->validate();) | 600 SkDEBUGCODE(this->validate();) |
552 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::fillRectWithLocalMatr
ix"); | 601 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::fillRectWithLocalMatr
ix"); |
553 | 602 |
554 AutoCheckFlush acf(fDrawingManager); | 603 AutoCheckFlush acf(fDrawingManager); |
555 SkAutoTUnref<GrDrawBatch> batch; | 604 SkAutoTUnref<GrDrawBatch> batch; |
556 bool useHWAA; | 605 bool useHWAA; |
557 | 606 |
| 607 SkRect trimRect = rectToDraw; |
| 608 if (TrimResult::kSkipDraw == trim_fill_rect(clip, fRenderTarget.get(), viewM
atrix, &trimRect)) { |
| 609 return; |
| 610 } |
| 611 |
558 if (InstancedRendering* ir = this->getDrawTarget()->instancedRendering()) { | 612 if (InstancedRendering* ir = this->getDrawTarget()->instancedRendering()) { |
559 batch.reset(ir->recordRect(rectToDraw, viewMatrix, paint.getColor(), loc
alMatrix, | 613 batch.reset(ir->recordRect(trimRect, viewMatrix, paint.getColor(), local
Matrix, |
560 paint.isAntiAlias(), fInstancedPipelineInfo,
&useHWAA)); | 614 paint.isAntiAlias(), fInstancedPipelineInfo,
&useHWAA)); |
561 if (batch) { | 615 if (batch) { |
562 GrPipelineBuilder pipelineBuilder(paint, useHWAA); | 616 GrPipelineBuilder pipelineBuilder(paint, useHWAA); |
563 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch)
; | 617 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch)
; |
564 return; | 618 return; |
565 } | 619 } |
566 } | 620 } |
567 | 621 |
568 if (should_apply_coverage_aa(paint, fRenderTarget.get(), &useHWAA) && | 622 if (should_apply_coverage_aa(paint, fRenderTarget.get(), &useHWAA) && |
569 view_matrix_ok_for_aa_fill_rect(viewMatrix)) { | 623 view_matrix_ok_for_aa_fill_rect(viewMatrix)) { |
570 batch.reset(GrAAFillRectBatch::Create(paint.getColor(), viewMatrix, loca
lMatrix, | 624 batch.reset(GrAAFillRectBatch::Create(paint.getColor(), viewMatrix, loca
lMatrix, trimRect)); |
571 rectToDraw)); | |
572 } else { | 625 } else { |
573 batch.reset(GrRectBatchFactory::CreateNonAAFill(paint.getColor(), viewMa
trix, rectToDraw, | 626 batch.reset(GrRectBatchFactory::CreateNonAAFill(paint.getColor(), viewMa
trix, trimRect, |
574 nullptr, &localMatrix)); | 627 nullptr, &localMatrix)); |
575 } | 628 } |
576 | 629 |
577 GrPipelineBuilder pipelineBuilder(paint, useHWAA); | 630 GrPipelineBuilder pipelineBuilder(paint, useHWAA); |
578 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch); | 631 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch); |
579 } | 632 } |
580 | 633 |
581 void GrDrawContext::drawVertices(const GrClip& clip, | 634 void GrDrawContext::drawVertices(const GrClip& clip, |
582 const GrPaint& paint, | 635 const GrPaint& paint, |
583 const SkMatrix& viewMatrix, | 636 const SkMatrix& viewMatrix, |
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1118 | 1171 |
1119 void GrDrawContext::drawBatch(const GrPipelineBuilder& pipelineBuilder, const Gr
Clip& clip, | 1172 void GrDrawContext::drawBatch(const GrPipelineBuilder& pipelineBuilder, const Gr
Clip& clip, |
1120 GrDrawBatch* batch) { | 1173 GrDrawBatch* batch) { |
1121 ASSERT_SINGLE_OWNER | 1174 ASSERT_SINGLE_OWNER |
1122 RETURN_IF_ABANDONED | 1175 RETURN_IF_ABANDONED |
1123 SkDEBUGCODE(this->validate();) | 1176 SkDEBUGCODE(this->validate();) |
1124 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawBatch"); | 1177 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawBatch"); |
1125 | 1178 |
1126 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch); | 1179 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch); |
1127 } | 1180 } |
OLD | NEW |