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

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: nearest filtering for the gm 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
« no previous file with comments | « 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 // Attempts to crop a rect and optional local rect to the clip boundaries.
274 // Returns false if the draw can be skipped entirely.
275 static bool crop_filled_rect(const GrRenderTarget* rt, const GrClip& clip,
276 const SkMatrix& viewMatrix, SkRect* rect,
277 SkRect* localRect = nullptr) {
278 if (!viewMatrix.rectStaysRect()) {
279 return true;
280 }
281
282 SkMatrix inverseViewMatrix;
283 if (!viewMatrix.invert(&inverseViewMatrix)) {
284 return false;
285 }
286
287 SkIRect clipDevBounds;
288 SkRect clipBounds;
289 SkASSERT(inverseViewMatrix.rectStaysRect());
290
291 clip.getConservativeBounds(rt->width(), rt->height(), &clipDevBounds);
292 inverseViewMatrix.mapRect(&clipBounds, SkRect::Make(clipDevBounds));
293
294 if (localRect) {
295 if (!rect->intersects(clipBounds)) {
296 return false;
297 }
298 const SkScalar dx = localRect->width() / rect->width();
299 const SkScalar dy = localRect->height() / rect->height();
300 if (clipBounds.fLeft > rect->fLeft) {
301 localRect->fLeft += (clipBounds.fLeft - rect->fLeft) * dx;
302 rect->fLeft = clipBounds.fLeft;
303 }
304 if (clipBounds.fTop > rect->fTop) {
305 localRect->fTop += (clipBounds.fTop - rect->fTop) * dy;
306 rect->fTop = clipBounds.fTop;
307 }
308 if (clipBounds.fRight < rect->fRight) {
309 localRect->fRight -= (rect->fRight - clipBounds.fRight) * dx;
310 rect->fRight = clipBounds.fRight;
311 }
312 if (clipBounds.fBottom < rect->fBottom) {
313 localRect->fBottom -= (rect->fBottom - clipBounds.fBottom) * dy;
314 rect->fBottom = clipBounds.fBottom;
315 }
316 return true;
317 }
318
319 return rect->intersect(clipBounds);
320 }
321
273 bool GrDrawContext::drawFilledRect(const GrClip& clip, 322 bool GrDrawContext::drawFilledRect(const GrClip& clip,
274 const GrPaint& paint, 323 const GrPaint& paint,
275 const SkMatrix& viewMatrix, 324 const SkMatrix& viewMatrix,
276 const SkRect& rect, 325 const SkRect& rect,
277 const GrUserStencilSettings* ss) { 326 const GrUserStencilSettings* ss) {
327 SkRect croppedRect = rect;
328 if (!crop_filled_rect(fRenderTarget.get(), clip, viewMatrix, &croppedRect)) {
329 return true;
330 }
278 331
279 SkAutoTUnref<GrDrawBatch> batch; 332 SkAutoTUnref<GrDrawBatch> batch;
280 bool useHWAA; 333 bool useHWAA;
281 334
282 if (InstancedRendering* ir = this->getDrawTarget()->instancedRendering()) { 335 if (InstancedRendering* ir = this->getDrawTarget()->instancedRendering()) {
283 batch.reset(ir->recordRect(rect, viewMatrix, paint.getColor(), 336 batch.reset(ir->recordRect(croppedRect, viewMatrix, paint.getColor(),
284 paint.isAntiAlias(), fInstancedPipelineInfo, 337 paint.isAntiAlias(), fInstancedPipelineInfo,
285 &useHWAA)); 338 &useHWAA));
286 if (batch) { 339 if (batch) {
287 GrPipelineBuilder pipelineBuilder(paint, useHWAA); 340 GrPipelineBuilder pipelineBuilder(paint, useHWAA);
288 if (ss) { 341 if (ss) {
289 pipelineBuilder.setUserStencil(ss); 342 pipelineBuilder.setUserStencil(ss);
290 } 343 }
291 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch) ; 344 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch) ;
292 return true; 345 return true;
293 } 346 }
294 } 347 }
295 348
296 if (should_apply_coverage_aa(paint, fRenderTarget.get(), &useHWAA)) { 349 if (should_apply_coverage_aa(paint, fRenderTarget.get(), &useHWAA)) {
297 // The fill path can handle rotation but not skew. 350 // The fill path can handle rotation but not skew.
298 if (view_matrix_ok_for_aa_fill_rect(viewMatrix)) { 351 if (view_matrix_ok_for_aa_fill_rect(viewMatrix)) {
299 SkRect devBoundRect; 352 SkRect devBoundRect;
300 viewMatrix.mapRect(&devBoundRect, rect); 353 viewMatrix.mapRect(&devBoundRect, croppedRect);
301 354
302 batch.reset(GrRectBatchFactory::CreateAAFill(paint.getColor(), viewM atrix, 355 batch.reset(GrRectBatchFactory::CreateAAFill(paint.getColor(), viewM atrix,
303 rect, devBoundRect)); 356 croppedRect, devBoundRe ct));
304 if (batch) { 357 if (batch) {
305 GrPipelineBuilder pipelineBuilder(paint, useHWAA); 358 GrPipelineBuilder pipelineBuilder(paint, useHWAA);
306 if (ss) { 359 if (ss) {
307 pipelineBuilder.setUserStencil(ss); 360 pipelineBuilder.setUserStencil(ss);
308 } 361 }
309 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, ba tch); 362 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, ba tch);
310 return true; 363 return true;
311 } 364 }
312 } 365 }
313 } else { 366 } else {
314 this->drawNonAAFilledRect(clip, paint, viewMatrix, rect, nullptr, nullpt r, ss); 367 this->drawNonAAFilledRect(clip, paint, viewMatrix, croppedRect, nullptr, nullptr, ss);
315 return true; 368 return true;
316 } 369 }
317 370
318 return false; 371 return false;
319 } 372 }
320 373
321 void GrDrawContext::drawRect(const GrClip& clip, 374 void GrDrawContext::drawRect(const GrClip& clip,
322 const GrPaint& paint, 375 const GrPaint& paint,
323 const SkMatrix& viewMatrix, 376 const SkMatrix& viewMatrix,
324 const SkRect& rect, 377 const SkRect& rect,
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 void GrDrawContext::fillRectToRect(const GrClip& clip, 568 void GrDrawContext::fillRectToRect(const GrClip& clip,
516 const GrPaint& paint, 569 const GrPaint& paint,
517 const SkMatrix& viewMatrix, 570 const SkMatrix& viewMatrix,
518 const SkRect& rectToDraw, 571 const SkRect& rectToDraw,
519 const SkRect& localRect) { 572 const SkRect& localRect) {
520 ASSERT_SINGLE_OWNER 573 ASSERT_SINGLE_OWNER
521 RETURN_IF_ABANDONED 574 RETURN_IF_ABANDONED
522 SkDEBUGCODE(this->validate();) 575 SkDEBUGCODE(this->validate();)
523 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::fillRectToRect"); 576 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::fillRectToRect");
524 577
578 SkRect croppedRect = rectToDraw;
579 SkRect croppedLocalRect = localRect;
580 if (!crop_filled_rect(fRenderTarget.get(), clip, viewMatrix, &croppedRect, & croppedLocalRect)) {
581 return;
582 }
583
525 AutoCheckFlush acf(fDrawingManager); 584 AutoCheckFlush acf(fDrawingManager);
526 SkAutoTUnref<GrDrawBatch> batch; 585 SkAutoTUnref<GrDrawBatch> batch;
527 bool useHWAA; 586 bool useHWAA;
528 587
529 if (InstancedRendering* ir = this->getDrawTarget()->instancedRendering()) { 588 if (InstancedRendering* ir = this->getDrawTarget()->instancedRendering()) {
530 batch.reset(ir->recordRect(rectToDraw, viewMatrix, paint.getColor(), loc alRect, 589 batch.reset(ir->recordRect(croppedRect, viewMatrix, paint.getColor(), cr oppedLocalRect,
531 paint.isAntiAlias(), fInstancedPipelineInfo, &useHWAA)); 590 paint.isAntiAlias(), fInstancedPipelineInfo, &useHWAA));
532 if (batch) { 591 if (batch) {
533 GrPipelineBuilder pipelineBuilder(paint, useHWAA); 592 GrPipelineBuilder pipelineBuilder(paint, useHWAA);
534 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch) ; 593 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch) ;
535 return; 594 return;
536 } 595 }
537 } 596 }
538 597
539 if (should_apply_coverage_aa(paint, fRenderTarget.get(), &useHWAA) && 598 if (should_apply_coverage_aa(paint, fRenderTarget.get(), &useHWAA) &&
540 view_matrix_ok_for_aa_fill_rect(viewMatrix)) { 599 view_matrix_ok_for_aa_fill_rect(viewMatrix)) {
541 batch.reset(GrAAFillRectBatch::CreateWithLocalRect(paint.getColor(), vie wMatrix, rectToDraw, 600 batch.reset(GrAAFillRectBatch::CreateWithLocalRect(paint.getColor(), vie wMatrix,
542 localRect)); 601 croppedRect, croppedL ocalRect));
543 if (batch) { 602 if (batch) {
544 GrPipelineBuilder pipelineBuilder(paint, useHWAA); 603 GrPipelineBuilder pipelineBuilder(paint, useHWAA);
545 this->drawBatch(pipelineBuilder, clip, batch); 604 this->drawBatch(pipelineBuilder, clip, batch);
546 return; 605 return;
547 } 606 }
548 } else { 607 } else {
549 this->drawNonAAFilledRect(clip, paint, viewMatrix, rectToDraw, &localRec t, 608 this->drawNonAAFilledRect(clip, paint, viewMatrix, croppedRect, &cropped LocalRect,
550 nullptr, nullptr); 609 nullptr, nullptr);
551 } 610 }
552 611
553 } 612 }
554 613
555 void GrDrawContext::fillRectWithLocalMatrix(const GrClip& clip, 614 void GrDrawContext::fillRectWithLocalMatrix(const GrClip& clip,
556 const GrPaint& paint, 615 const GrPaint& paint,
557 const SkMatrix& viewMatrix, 616 const SkMatrix& viewMatrix,
558 const SkRect& rectToDraw, 617 const SkRect& rectToDraw,
559 const SkMatrix& localMatrix) { 618 const SkMatrix& localMatrix) {
560 ASSERT_SINGLE_OWNER 619 ASSERT_SINGLE_OWNER
561 RETURN_IF_ABANDONED 620 RETURN_IF_ABANDONED
562 SkDEBUGCODE(this->validate();) 621 SkDEBUGCODE(this->validate();)
563 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::fillRectWithLocalMatr ix"); 622 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::fillRectWithLocalMatr ix");
564 623
624 SkRect croppedRect = rectToDraw;
625 if (!crop_filled_rect(fRenderTarget.get(), clip, viewMatrix, &croppedRect)) {
626 return;
627 }
628
565 AutoCheckFlush acf(fDrawingManager); 629 AutoCheckFlush acf(fDrawingManager);
566 SkAutoTUnref<GrDrawBatch> batch; 630 SkAutoTUnref<GrDrawBatch> batch;
567 bool useHWAA; 631 bool useHWAA;
568 632
569 if (InstancedRendering* ir = this->getDrawTarget()->instancedRendering()) { 633 if (InstancedRendering* ir = this->getDrawTarget()->instancedRendering()) {
570 batch.reset(ir->recordRect(rectToDraw, viewMatrix, paint.getColor(), loc alMatrix, 634 batch.reset(ir->recordRect(croppedRect, viewMatrix, paint.getColor(), lo calMatrix,
571 paint.isAntiAlias(), fInstancedPipelineInfo, &useHWAA)); 635 paint.isAntiAlias(), fInstancedPipelineInfo, &useHWAA));
572 if (batch) { 636 if (batch) {
573 GrPipelineBuilder pipelineBuilder(paint, useHWAA); 637 GrPipelineBuilder pipelineBuilder(paint, useHWAA);
574 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch) ; 638 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch) ;
575 return; 639 return;
576 } 640 }
577 } 641 }
578 642
579 if (should_apply_coverage_aa(paint, fRenderTarget.get(), &useHWAA) && 643 if (should_apply_coverage_aa(paint, fRenderTarget.get(), &useHWAA) &&
580 view_matrix_ok_for_aa_fill_rect(viewMatrix)) { 644 view_matrix_ok_for_aa_fill_rect(viewMatrix)) {
581 batch.reset(GrAAFillRectBatch::Create(paint.getColor(), viewMatrix, loca lMatrix, 645 batch.reset(GrAAFillRectBatch::Create(paint.getColor(), viewMatrix, loca lMatrix,
582 rectToDraw)); 646 croppedRect));
583 GrPipelineBuilder pipelineBuilder(paint, useHWAA); 647 GrPipelineBuilder pipelineBuilder(paint, useHWAA);
584 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch); 648 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch);
585 } else { 649 } else {
586 this->drawNonAAFilledRect(clip, paint, viewMatrix, rectToDraw, nullptr, 650 this->drawNonAAFilledRect(clip, paint, viewMatrix, croppedRect, nullptr,
587 &localMatrix, nullptr); 651 &localMatrix, nullptr);
588 } 652 }
589 653
590 } 654 }
591 655
592 void GrDrawContext::drawVertices(const GrClip& clip, 656 void GrDrawContext::drawVertices(const GrClip& clip,
593 const GrPaint& paint, 657 const GrPaint& paint,
594 const SkMatrix& viewMatrix, 658 const SkMatrix& viewMatrix,
595 GrPrimitiveType primitiveType, 659 GrPrimitiveType primitiveType,
596 int vertexCount, 660 int vertexCount,
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after
1146 1210
1147 void GrDrawContext::drawBatch(const GrPipelineBuilder& pipelineBuilder, const Gr Clip& clip, 1211 void GrDrawContext::drawBatch(const GrPipelineBuilder& pipelineBuilder, const Gr Clip& clip,
1148 GrDrawBatch* batch) { 1212 GrDrawBatch* batch) {
1149 ASSERT_SINGLE_OWNER 1213 ASSERT_SINGLE_OWNER
1150 RETURN_IF_ABANDONED 1214 RETURN_IF_ABANDONED
1151 SkDEBUGCODE(this->validate();) 1215 SkDEBUGCODE(this->validate();)
1152 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawBatch"); 1216 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawBatch");
1153 1217
1154 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch); 1218 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch);
1155 } 1219 }
OLDNEW
« no previous file with comments | « src/gpu/GrClipMaskManager.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698