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

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

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