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

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

Issue 2132073002: Pre-crop filled rects to avoid scissor (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Pre-crop filled rects to avoid scissor Created 4 years, 5 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
« gm/croppedrects.cpp ('K') | « src/gpu/GrClipMaskManager.cpp ('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 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 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 } 263 }
264 return false; 264 return false;
265 } else { 265 } else {
266 if (useHWAA) { 266 if (useHWAA) {
267 *useHWAA = rt->isUnifiedMultisampled(); 267 *useHWAA = rt->isUnifiedMultisampled();
268 } 268 }
269 return !rt->isUnifiedMultisampled(); 269 return !rt->isUnifiedMultisampled();
270 } 270 }
271 } 271 }
272 272
273 enum class CropResult {
274 kSkip,
275 kDidCrop,
276 kDidNotCrop
277 };
278
279 static CropResult crop_fill_rect(const GrRenderTarget* rt, const GrClip& clip,
280 const SkMatrix& viewMatrix, SkRect* rect) {
281 if (!viewMatrix.rectStaysRect()) {
282 return CropResult::kDidNotCrop;
283 }
284 SkMatrix inverseViewMatrix;
285 if (!viewMatrix.invert(&inverseViewMatrix)) {
286 return CropResult::kSkip;
287 }
288 SkASSERT(inverseViewMatrix.rectStaysRect());
289 SkIRect clipDevBounds;
290 clip.getConservativeBounds(rt->width(), rt->height(), &clipDevBounds);
291 SkRect clipUserSpaceBounds;
292 inverseViewMatrix.mapRect(&clipUserSpaceBounds, SkRect::Make(clipDevBounds)) ;
293 if (!rect->intersect(clipUserSpaceBounds)) {
294 return CropResult::kSkip;
295 }
296 return CropResult::kDidCrop;
297 }
298
273 bool GrDrawContext::drawFilledRect(const GrClip& clip, 299 bool GrDrawContext::drawFilledRect(const GrClip& clip,
274 const GrPaint& paint, 300 const GrPaint& paint,
275 const SkMatrix& viewMatrix, 301 const SkMatrix& viewMatrix,
276 const SkRect& rect, 302 const SkRect& rect,
277 const GrUserStencilSettings* ss) { 303 const GrUserStencilSettings* ss) {
304 SkRect croppedRect = rect;
305 if (CropResult::kSkip == crop_fill_rect(fRenderTarget.get(), clip, viewMatri x, &croppedRect)) {
306 return true;
307 }
278 308
279 SkAutoTUnref<GrDrawBatch> batch; 309 SkAutoTUnref<GrDrawBatch> batch;
280 bool useHWAA; 310 bool useHWAA;
281 311
282 if (InstancedRendering* ir = this->getDrawTarget()->instancedRendering()) { 312 if (InstancedRendering* ir = this->getDrawTarget()->instancedRendering()) {
283 batch.reset(ir->recordRect(rect, viewMatrix, paint.getColor(), 313 batch.reset(ir->recordRect(croppedRect, viewMatrix, paint.getColor(),
284 paint.isAntiAlias(), fInstancedPipelineInfo, 314 paint.isAntiAlias(), fInstancedPipelineInfo,
285 &useHWAA)); 315 &useHWAA));
286 if (batch) { 316 if (batch) {
287 GrPipelineBuilder pipelineBuilder(paint, useHWAA); 317 GrPipelineBuilder pipelineBuilder(paint, useHWAA);
288 if (ss) { 318 if (ss) {
289 pipelineBuilder.setUserStencil(ss); 319 pipelineBuilder.setUserStencil(ss);
290 } 320 }
291 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch) ; 321 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch) ;
292 return true; 322 return true;
293 } 323 }
294 } 324 }
295 325
296 if (should_apply_coverage_aa(paint, fRenderTarget.get(), &useHWAA)) { 326 if (should_apply_coverage_aa(paint, fRenderTarget.get(), &useHWAA)) {
297 // The fill path can handle rotation but not skew. 327 // The fill path can handle rotation but not skew.
298 if (view_matrix_ok_for_aa_fill_rect(viewMatrix)) { 328 if (view_matrix_ok_for_aa_fill_rect(viewMatrix)) {
299 SkRect devBoundRect; 329 SkRect devBoundRect;
300 viewMatrix.mapRect(&devBoundRect, rect); 330 viewMatrix.mapRect(&devBoundRect, croppedRect);
301 331
302 batch.reset(GrRectBatchFactory::CreateAAFill(paint.getColor(), viewM atrix, 332 batch.reset(GrRectBatchFactory::CreateAAFill(paint.getColor(), viewM atrix,
303 rect, devBoundRect)); 333 croppedRect, devBoundRe ct));
304 if (batch) { 334 if (batch) {
305 GrPipelineBuilder pipelineBuilder(paint, useHWAA); 335 GrPipelineBuilder pipelineBuilder(paint, useHWAA);
306 if (ss) { 336 if (ss) {
307 pipelineBuilder.setUserStencil(ss); 337 pipelineBuilder.setUserStencil(ss);
308 } 338 }
309 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, ba tch); 339 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, ba tch);
310 return true; 340 return true;
311 } 341 }
312 } 342 }
313 } else { 343 } else {
314 this->drawNonAAFilledRect(clip, paint, viewMatrix, rect, nullptr, nullpt r, ss); 344 this->drawNonAAFilledRect(clip, paint, viewMatrix, croppedRect, nullptr, nullptr, ss);
315 return true; 345 return true;
316 } 346 }
317 347
318 return false; 348 return false;
319 } 349 }
320 350
321 void GrDrawContext::drawRect(const GrClip& clip, 351 void GrDrawContext::drawRect(const GrClip& clip,
322 const GrPaint& paint, 352 const GrPaint& paint,
323 const SkMatrix& viewMatrix, 353 const SkMatrix& viewMatrix,
324 const SkRect& rect, 354 const SkRect& rect,
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 void GrDrawContext::fillRectToRect(const GrClip& clip, 545 void GrDrawContext::fillRectToRect(const GrClip& clip,
516 const GrPaint& paint, 546 const GrPaint& paint,
517 const SkMatrix& viewMatrix, 547 const SkMatrix& viewMatrix,
518 const SkRect& rectToDraw, 548 const SkRect& rectToDraw,
519 const SkRect& localRect) { 549 const SkRect& localRect) {
520 ASSERT_SINGLE_OWNER 550 ASSERT_SINGLE_OWNER
521 RETURN_IF_ABANDONED 551 RETURN_IF_ABANDONED
522 SkDEBUGCODE(this->validate();) 552 SkDEBUGCODE(this->validate();)
523 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::fillRectToRect"); 553 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::fillRectToRect");
524 554
555 SkRect croppedRect = rectToDraw;
556 CropResult cropResult = crop_fill_rect(fRenderTarget.get(), clip, viewMatrix , &croppedRect);
557 if (CropResult::kSkip == cropResult) {
558 return;
559 }
560 SkRect croppedLocalRect = localRect;
bsalomon 2016/07/11 13:52:23 What do you think about making this an optional pa
csmartdalton 2016/07/11 16:37:10 Done.
561 if (CropResult::kDidCrop == cropResult) {
562 const SkScalar dx = localRect.width() / rectToDraw.width();
563 const SkScalar dy = localRect.height() / rectToDraw.height();
564 croppedLocalRect.fLeft += (croppedRect.fLeft - rectToDraw.fLeft) * dx;
565 croppedLocalRect.fTop += (croppedRect.fTop - rectToDraw.fTop) * dy;
566 croppedLocalRect.fRight -= (rectToDraw.fRight - croppedRect.fRight) * dx ;
567 croppedLocalRect.fBottom -= (rectToDraw.fBottom - croppedRect.fBottom) * dy;
568 }
569
525 AutoCheckFlush acf(fDrawingManager); 570 AutoCheckFlush acf(fDrawingManager);
526 SkAutoTUnref<GrDrawBatch> batch; 571 SkAutoTUnref<GrDrawBatch> batch;
527 bool useHWAA; 572 bool useHWAA;
528 573
529 if (InstancedRendering* ir = this->getDrawTarget()->instancedRendering()) { 574 if (InstancedRendering* ir = this->getDrawTarget()->instancedRendering()) {
530 batch.reset(ir->recordRect(rectToDraw, viewMatrix, paint.getColor(), loc alRect, 575 batch.reset(ir->recordRect(croppedRect, viewMatrix, paint.getColor(), cr oppedLocalRect,
531 paint.isAntiAlias(), fInstancedPipelineInfo, &useHWAA)); 576 paint.isAntiAlias(), fInstancedPipelineInfo, &useHWAA));
532 if (batch) { 577 if (batch) {
533 GrPipelineBuilder pipelineBuilder(paint, useHWAA); 578 GrPipelineBuilder pipelineBuilder(paint, useHWAA);
534 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch) ; 579 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch) ;
535 return; 580 return;
536 } 581 }
537 } 582 }
538 583
539 if (should_apply_coverage_aa(paint, fRenderTarget.get(), &useHWAA) && 584 if (should_apply_coverage_aa(paint, fRenderTarget.get(), &useHWAA) &&
540 view_matrix_ok_for_aa_fill_rect(viewMatrix)) { 585 view_matrix_ok_for_aa_fill_rect(viewMatrix)) {
541 batch.reset(GrAAFillRectBatch::CreateWithLocalRect(paint.getColor(), vie wMatrix, rectToDraw, 586 batch.reset(GrAAFillRectBatch::CreateWithLocalRect(paint.getColor(), vie wMatrix,
542 localRect)); 587 croppedRect, croppedL ocalRect));
543 if (batch) { 588 if (batch) {
544 GrPipelineBuilder pipelineBuilder(paint, useHWAA); 589 GrPipelineBuilder pipelineBuilder(paint, useHWAA);
545 this->drawBatch(pipelineBuilder, clip, batch); 590 this->drawBatch(pipelineBuilder, clip, batch);
546 return; 591 return;
547 } 592 }
548 } else { 593 } else {
549 this->drawNonAAFilledRect(clip, paint, viewMatrix, rectToDraw, &localRec t, 594 this->drawNonAAFilledRect(clip, paint, viewMatrix, croppedRect, &cropped LocalRect,
550 nullptr, nullptr); 595 nullptr, nullptr);
551 } 596 }
552 597
553 } 598 }
554 599
555 void GrDrawContext::fillRectWithLocalMatrix(const GrClip& clip, 600 void GrDrawContext::fillRectWithLocalMatrix(const GrClip& clip,
556 const GrPaint& paint, 601 const GrPaint& paint,
557 const SkMatrix& viewMatrix, 602 const SkMatrix& viewMatrix,
558 const SkRect& rectToDraw, 603 const SkRect& rectToDraw,
559 const SkMatrix& localMatrix) { 604 const SkMatrix& localMatrix) {
560 ASSERT_SINGLE_OWNER 605 ASSERT_SINGLE_OWNER
561 RETURN_IF_ABANDONED 606 RETURN_IF_ABANDONED
562 SkDEBUGCODE(this->validate();) 607 SkDEBUGCODE(this->validate();)
563 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::fillRectWithLocalMatr ix"); 608 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::fillRectWithLocalMatr ix");
564 609
610 SkRect croppedRect = rectToDraw;
611 if (CropResult::kSkip == crop_fill_rect(fRenderTarget.get(), clip, viewMatri x, &croppedRect)) {
612 return;
613 }
614
565 AutoCheckFlush acf(fDrawingManager); 615 AutoCheckFlush acf(fDrawingManager);
566 SkAutoTUnref<GrDrawBatch> batch; 616 SkAutoTUnref<GrDrawBatch> batch;
567 bool useHWAA; 617 bool useHWAA;
568 618
569 if (InstancedRendering* ir = this->getDrawTarget()->instancedRendering()) { 619 if (InstancedRendering* ir = this->getDrawTarget()->instancedRendering()) {
570 batch.reset(ir->recordRect(rectToDraw, viewMatrix, paint.getColor(), loc alMatrix, 620 batch.reset(ir->recordRect(croppedRect, viewMatrix, paint.getColor(), lo calMatrix,
571 paint.isAntiAlias(), fInstancedPipelineInfo, &useHWAA)); 621 paint.isAntiAlias(), fInstancedPipelineInfo, &useHWAA));
572 if (batch) { 622 if (batch) {
573 GrPipelineBuilder pipelineBuilder(paint, useHWAA); 623 GrPipelineBuilder pipelineBuilder(paint, useHWAA);
574 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch) ; 624 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch) ;
575 return; 625 return;
576 } 626 }
577 } 627 }
578 628
579 if (should_apply_coverage_aa(paint, fRenderTarget.get(), &useHWAA) && 629 if (should_apply_coverage_aa(paint, fRenderTarget.get(), &useHWAA) &&
580 view_matrix_ok_for_aa_fill_rect(viewMatrix)) { 630 view_matrix_ok_for_aa_fill_rect(viewMatrix)) {
581 batch.reset(GrAAFillRectBatch::Create(paint.getColor(), viewMatrix, loca lMatrix, 631 batch.reset(GrAAFillRectBatch::Create(paint.getColor(), viewMatrix, loca lMatrix,
582 rectToDraw)); 632 croppedRect));
583 GrPipelineBuilder pipelineBuilder(paint, useHWAA); 633 GrPipelineBuilder pipelineBuilder(paint, useHWAA);
584 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch); 634 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch);
585 } else { 635 } else {
586 this->drawNonAAFilledRect(clip, paint, viewMatrix, rectToDraw, nullptr, 636 this->drawNonAAFilledRect(clip, paint, viewMatrix, croppedRect, nullptr,
587 &localMatrix, nullptr); 637 &localMatrix, nullptr);
588 } 638 }
589 639
590 } 640 }
591 641
592 void GrDrawContext::drawVertices(const GrClip& clip, 642 void GrDrawContext::drawVertices(const GrClip& clip,
593 const GrPaint& paint, 643 const GrPaint& paint,
594 const SkMatrix& viewMatrix, 644 const SkMatrix& viewMatrix,
595 GrPrimitiveType primitiveType, 645 GrPrimitiveType primitiveType,
596 int vertexCount, 646 int vertexCount,
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after
1146 1196
1147 void GrDrawContext::drawBatch(const GrPipelineBuilder& pipelineBuilder, const Gr Clip& clip, 1197 void GrDrawContext::drawBatch(const GrPipelineBuilder& pipelineBuilder, const Gr Clip& clip,
1148 GrDrawBatch* batch) { 1198 GrDrawBatch* batch) {
1149 ASSERT_SINGLE_OWNER 1199 ASSERT_SINGLE_OWNER
1150 RETURN_IF_ABANDONED 1200 RETURN_IF_ABANDONED
1151 SkDEBUGCODE(this->validate();) 1201 SkDEBUGCODE(this->validate();)
1152 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawBatch"); 1202 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawBatch");
1153 1203
1154 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch); 1204 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch);
1155 } 1205 }
OLDNEW
« gm/croppedrects.cpp ('K') | « src/gpu/GrClipMaskManager.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698