OLD | NEW |
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 Loading... |
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 Loading... |
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 |
OLD | NEW |