Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "cc/trees/occlusion.h" | 5 #include "cc/trees/occlusion.h" |
| 6 | 6 |
| 7 #include "cc/base/math_util.h" | 7 #include "cc/base/math_util.h" |
| 8 #include "ui/gfx/rect.h" | 8 #include "ui/gfx/rect.h" |
| 9 | 9 |
| 10 namespace cc { | 10 namespace cc { |
| 11 | 11 |
| 12 Occlusion::Occlusion() { | 12 Occlusion::Occlusion() { |
| 13 } | 13 } |
| 14 | 14 |
| 15 Occlusion::Occlusion(const gfx::Transform& draw_transform, | 15 Occlusion::Occlusion(const gfx::Transform& draw_transform, |
| 16 const SimpleEnclosedRegion& occlusion_from_outside_target, | 16 const SimpleEnclosedRegion& occlusion_from_outside_target, |
| 17 const SimpleEnclosedRegion& occlusion_from_inside_target) | 17 const SimpleEnclosedRegion& occlusion_from_inside_target) |
| 18 : draw_transform_(draw_transform), | 18 : draw_transform_(draw_transform), |
| 19 occlusion_from_outside_target_(occlusion_from_outside_target), | 19 occlusion_from_outside_target_(occlusion_from_outside_target), |
| 20 occlusion_from_inside_target_(occlusion_from_inside_target) { | 20 occlusion_from_inside_target_(occlusion_from_inside_target) { |
| 21 } | 21 } |
| 22 | 22 |
| 23 Occlusion Occlusion::GetOcclusionWithScaledDrawTransform(SkMScalar x, | |
| 24 SkMScalar y) { | |
| 25 gfx::Transform scaled_transform = draw_transform_; | |
| 26 scaled_transform.Scale(x, y); | |
|
danakj
2014/10/05 17:27:38
Rather than doing these matrix multiplies twice yo
vmpstr
2014/10/06 15:44:51
I think this is a great idea. I think I'll add som
| |
| 27 return Occlusion(scaled_transform, | |
| 28 occlusion_from_outside_target_, | |
| 29 occlusion_from_inside_target_); | |
| 30 } | |
| 31 | |
| 32 bool Occlusion::HasOcclusion() const { | |
| 33 return !occlusion_from_inside_target_.IsEmpty() || | |
| 34 !occlusion_from_outside_target_.IsEmpty(); | |
| 35 } | |
| 36 | |
| 23 bool Occlusion::IsOccluded(const gfx::Rect& content_rect) const { | 37 bool Occlusion::IsOccluded(const gfx::Rect& content_rect) const { |
| 24 if (content_rect.IsEmpty()) | 38 if (content_rect.IsEmpty()) |
| 25 return true; | 39 return true; |
| 26 | 40 |
| 27 if (occlusion_from_inside_target_.IsEmpty() && | 41 if (!HasOcclusion()) |
| 28 occlusion_from_outside_target_.IsEmpty()) { | |
| 29 return false; | 42 return false; |
| 30 } | |
| 31 | 43 |
| 32 gfx::Rect unoccluded_rect_in_target_surface = | 44 gfx::Rect unoccluded_rect_in_target_surface = |
| 33 GetUnoccludedRectInTargetSurface(content_rect); | 45 GetUnoccludedRectInTargetSurface(content_rect); |
| 34 return unoccluded_rect_in_target_surface.IsEmpty(); | 46 return unoccluded_rect_in_target_surface.IsEmpty(); |
| 35 } | 47 } |
| 36 | 48 |
| 37 gfx::Rect Occlusion::GetUnoccludedContentRect( | 49 gfx::Rect Occlusion::GetUnoccludedContentRect( |
| 38 const gfx::Rect& content_rect) const { | 50 const gfx::Rect& content_rect) const { |
| 39 if (content_rect.IsEmpty()) | 51 if (content_rect.IsEmpty()) |
| 40 return content_rect; | 52 return content_rect; |
| 41 | 53 |
| 42 if (occlusion_from_inside_target_.IsEmpty() && | 54 if (!HasOcclusion()) |
| 43 occlusion_from_outside_target_.IsEmpty()) { | |
| 44 return content_rect; | 55 return content_rect; |
| 45 } | |
| 46 | 56 |
| 47 gfx::Rect unoccluded_rect_in_target_surface = | 57 gfx::Rect unoccluded_rect_in_target_surface = |
| 48 GetUnoccludedRectInTargetSurface(content_rect); | 58 GetUnoccludedRectInTargetSurface(content_rect); |
| 49 if (unoccluded_rect_in_target_surface.IsEmpty()) | 59 if (unoccluded_rect_in_target_surface.IsEmpty()) |
| 50 return gfx::Rect(); | 60 return gfx::Rect(); |
| 51 | 61 |
| 52 gfx::Transform inverse_draw_transform(gfx::Transform::kSkipInitialization); | 62 gfx::Transform inverse_draw_transform(gfx::Transform::kSkipInitialization); |
| 53 bool ok = draw_transform_.GetInverse(&inverse_draw_transform); | 63 bool ok = draw_transform_.GetInverse(&inverse_draw_transform); |
| 54 DCHECK(ok); | 64 DCHECK(ok); |
| 55 | 65 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 72 // once. | 82 // once. |
| 73 unoccluded_rect_in_target_surface.Subtract( | 83 unoccluded_rect_in_target_surface.Subtract( |
| 74 occlusion_from_inside_target_.bounds()); | 84 occlusion_from_inside_target_.bounds()); |
| 75 unoccluded_rect_in_target_surface.Subtract( | 85 unoccluded_rect_in_target_surface.Subtract( |
| 76 occlusion_from_outside_target_.bounds()); | 86 occlusion_from_outside_target_.bounds()); |
| 77 | 87 |
| 78 return unoccluded_rect_in_target_surface; | 88 return unoccluded_rect_in_target_surface; |
| 79 } | 89 } |
| 80 | 90 |
| 81 } // namespace cc | 91 } // namespace cc |
| OLD | NEW |