Change DtmfSenderHandler to handle events on the signaling thread.
[chromium-blink-merge.git] / cc / trees / occlusion.cc
blob14168f9699f11eddaab5c9af683fbcddccea81b9
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
3 // found in the LICENSE file.
5 #include "cc/trees/occlusion.h"
7 #include "cc/base/math_util.h"
8 #include "ui/gfx/geometry/rect.h"
10 namespace cc {
12 Occlusion::Occlusion() {
15 Occlusion::Occlusion(const gfx::Transform& draw_transform,
16 const SimpleEnclosedRegion& occlusion_from_outside_target,
17 const SimpleEnclosedRegion& occlusion_from_inside_target)
18 : draw_transform_(draw_transform),
19 occlusion_from_outside_target_(occlusion_from_outside_target),
20 occlusion_from_inside_target_(occlusion_from_inside_target) {
23 Occlusion Occlusion::GetOcclusionWithGivenDrawTransform(
24 const gfx::Transform& transform) const {
25 return Occlusion(
26 transform, occlusion_from_outside_target_, occlusion_from_inside_target_);
29 bool Occlusion::HasOcclusion() const {
30 return !occlusion_from_inside_target_.IsEmpty() ||
31 !occlusion_from_outside_target_.IsEmpty();
34 bool Occlusion::IsOccluded(const gfx::Rect& content_rect) const {
35 if (content_rect.IsEmpty())
36 return true;
38 if (!HasOcclusion())
39 return false;
41 gfx::Rect unoccluded_rect_in_target_surface =
42 GetUnoccludedRectInTargetSurface(content_rect);
43 return unoccluded_rect_in_target_surface.IsEmpty();
46 gfx::Rect Occlusion::GetUnoccludedContentRect(
47 const gfx::Rect& content_rect) const {
48 if (content_rect.IsEmpty())
49 return content_rect;
51 if (!HasOcclusion())
52 return content_rect;
54 gfx::Rect unoccluded_rect_in_target_surface =
55 GetUnoccludedRectInTargetSurface(content_rect);
56 if (unoccluded_rect_in_target_surface.IsEmpty())
57 return gfx::Rect();
59 gfx::Transform inverse_draw_transform(gfx::Transform::kSkipInitialization);
60 bool ok = draw_transform_.GetInverse(&inverse_draw_transform);
61 DCHECK(ok);
63 gfx::Rect unoccluded_rect = MathUtil::ProjectEnclosingClippedRect(
64 inverse_draw_transform, unoccluded_rect_in_target_surface);
65 unoccluded_rect.Intersect(content_rect);
67 return unoccluded_rect;
70 gfx::Rect Occlusion::GetUnoccludedRectInTargetSurface(
71 const gfx::Rect& content_rect) const {
72 // Take the ToEnclosingRect at each step, as we want to contain any unoccluded
73 // partial pixels in the resulting Rect.
74 gfx::Rect unoccluded_rect_in_target_surface =
75 MathUtil::MapEnclosingClippedRect(draw_transform_, content_rect);
76 DCHECK_LE(occlusion_from_inside_target_.GetRegionComplexity(), 1u);
77 DCHECK_LE(occlusion_from_outside_target_.GetRegionComplexity(), 1u);
78 // These subtract operations are more lossy than if we did both operations at
79 // once.
80 unoccluded_rect_in_target_surface.Subtract(
81 occlusion_from_inside_target_.bounds());
82 unoccluded_rect_in_target_surface.Subtract(
83 occlusion_from_outside_target_.bounds());
85 return unoccluded_rect_in_target_surface;
88 } // namespace cc