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

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::Make(clip_device_bounds);
429 inverse.mapRectScaleTranslate(&clip_rect, clip_rect);
430 return rr.contains(clip_rect);
431 }
432
413 void AnalysisCanvas::onClipRRect(const SkRRect& rrect, 433 void AnalysisCanvas::onClipRRect(const SkRRect& rrect,
414 SkRegion::Op op, 434 SkRegion::Op op,
415 ClipEdgeStyle edge_style) { 435 ClipEdgeStyle edge_style) {
436 SkIRect clip_device_bounds;
437 if (getClipDeviceBounds(&clip_device_bounds) &&
438 doesCoverCanvas(rrect, getTotalMatrix(), clip_device_bounds)) {
439 // If the canvas is fully contained within the clip, it is as if we weren't
440 // clipped at all, so bail early.
441 return;
442 }
443
416 OnComplexClip(); 444 OnComplexClip();
417 INHERITED::onClipRect(rrect.getBounds(), op, edge_style); 445 INHERITED::onClipRect(rrect.getBounds(), op, edge_style);
418 } 446 }
419 447
420 void AnalysisCanvas::onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op) { 448 void AnalysisCanvas::onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op) {
421 const ClipEdgeStyle edge_style = kHard_ClipEdgeStyle; 449 const ClipEdgeStyle edge_style = kHard_ClipEdgeStyle;
422 if (deviceRgn.isRect()) { 450 if (deviceRgn.isRect()) {
423 onClipRect(SkRect::MakeFromIRect(deviceRgn.getBounds()), op, edge_style); 451 onClipRect(SkRect::MakeFromIRect(deviceRgn.getBounds()), op, edge_style);
424 return; 452 return;
425 } 453 }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 force_not_transparent_stack_level_ = kNoLayer; 514 force_not_transparent_stack_level_ = kNoLayer;
487 } 515 }
488 } 516 }
489 517
490 INHERITED::willRestore(); 518 INHERITED::willRestore();
491 } 519 }
492 520
493 } // namespace skia 521 } // namespace skia
494 522
495 523
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