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

Side by Side Diff: skia/ext/analysis_canvas.cc

Issue 2449583002: Support rrect clips in analysis canvas (Closed)
Patch Set: Address reviewer feedback. Created 4 years, 1 month 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 | « no previous file | skia/ext/analysis_canvas_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/logging.h" 5 #include "base/logging.h"
6 #include "base/trace_event/trace_event.h" 6 #include "base/trace_event/trace_event.h"
7 #include "skia/ext/analysis_canvas.h" 7 #include "skia/ext/analysis_canvas.h"
8 #include "third_party/skia/include/core/SkDraw.h" 8 #include "third_party/skia/include/core/SkDraw.h"
9 #include "third_party/skia/include/core/SkPath.h" 9 #include "third_party/skia/include/core/SkPath.h"
10 #include "third_party/skia/include/core/SkRRect.h" 10 #include "third_party/skia/include/core/SkRRect.h"
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 INHERITED::onClipRect(rect, op, edge_style); 403 INHERITED::onClipRect(rect, op, edge_style);
404 } 404 }
405 405
406 void AnalysisCanvas::onClipPath(const SkPath& path, 406 void AnalysisCanvas::onClipPath(const SkPath& path,
407 SkRegion::Op op, 407 SkRegion::Op op,
408 ClipEdgeStyle edge_style) { 408 ClipEdgeStyle edge_style) {
409 OnComplexClip(); 409 OnComplexClip();
410 INHERITED::onClipRect(path.getBounds(), op, edge_style); 410 INHERITED::onClipRect(path.getBounds(), op, edge_style);
411 } 411 }
412 412
413 bool doesCoverCanvas(const SkRRect& rr,
414 const SkMatrix& total_matrix,
415 const SkIRect& clip_device_bounds) {
416 const SkRect& bounding_rect = rr.rect();
417
418 // We cannot handle non axis aligned rectangles at the moment.
419 if (!total_matrix.isScaleTranslate()) {
420 return false;
421 }
422
423 SkMatrix inverse;
424 if (!total_matrix.invert(&inverse)) {
425 return false;
426 }
427
428 SkRect clip_rect = SkRect::MakeFromIRect(clip_device_bounds);
f(malita) 2016/10/26 12:24:24 nit: MakeFromIRect is deprecated, you can use Make
Ian Vollick 2016/10/26 13:57:04 Done.
429 inverse.mapRectScaleTranslate(&clip_rect, clip_rect);
430 if (!clip_rect.isFinite()) {
f(malita) 2016/10/26 12:24:24 nit: Is this check needed? I think the contains t
Ian Vollick 2016/10/26 13:57:04 Nope, not necessary. Removed.
431 return false;
432 }
433
434 return rr.contains(clip_rect);
435 }
436
413 void AnalysisCanvas::onClipRRect(const SkRRect& rrect, 437 void AnalysisCanvas::onClipRRect(const SkRRect& rrect,
414 SkRegion::Op op, 438 SkRegion::Op op,
415 ClipEdgeStyle edge_style) { 439 ClipEdgeStyle edge_style) {
440 SkIRect clip_device_bounds;
441 if (getClipDeviceBounds(&clip_device_bounds) &&
442 doesCoverCanvas(rrect, getTotalMatrix(), clip_device_bounds)) {
443 // If the canvas is fully contained within the clip, it is as if we weren't
444 // clipped at all, so bail early.
445 return;
446 }
447
416 OnComplexClip(); 448 OnComplexClip();
417 INHERITED::onClipRect(rrect.getBounds(), op, edge_style); 449 INHERITED::onClipRect(rrect.getBounds(), op, edge_style);
418 } 450 }
419 451
420 void AnalysisCanvas::onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op) { 452 void AnalysisCanvas::onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op) {
421 const ClipEdgeStyle edge_style = kHard_ClipEdgeStyle; 453 const ClipEdgeStyle edge_style = kHard_ClipEdgeStyle;
422 if (deviceRgn.isRect()) { 454 if (deviceRgn.isRect()) {
423 onClipRect(SkRect::MakeFromIRect(deviceRgn.getBounds()), op, edge_style); 455 onClipRect(SkRect::MakeFromIRect(deviceRgn.getBounds()), op, edge_style);
424 return; 456 return;
425 } 457 }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 force_not_transparent_stack_level_ = kNoLayer; 518 force_not_transparent_stack_level_ = kNoLayer;
487 } 519 }
488 } 520 }
489 521
490 INHERITED::willRestore(); 522 INHERITED::willRestore();
491 } 523 }
492 524
493 } // namespace skia 525 } // namespace skia
494 526
495 527
OLDNEW
« no previous file with comments | « no previous file | skia/ext/analysis_canvas_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698