Chromium Code Reviews| Index: cc/trees/occlusion_checker.cc |
| diff --git a/cc/trees/occlusion_checker.cc b/cc/trees/occlusion_checker.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..483a2dff164e16b056bd02e0800fc6fa3b531147 |
| --- /dev/null |
| +++ b/cc/trees/occlusion_checker.cc |
| @@ -0,0 +1,56 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "cc/trees/occlusion_checker.h" |
| + |
| +#include "cc/base/math_util.h" |
| + |
| +namespace cc { |
| + |
| +template <typename LayerType> |
| +OcclusionChecker<LayerType>::OcclusionChecker() { |
|
danakj
2014/09/09 15:14:39
wdyt of just naming this "Occlusion"? or maybe tha
vmpstr
2014/09/09 21:56:56
Done.
|
| +} |
| + |
| +template <typename LayerType> |
| +OcclusionChecker<LayerType>::OcclusionChecker( |
| + const gfx::Transform& draw_transform, |
| + const SimpleEnclosedRegion& occlusion_from_outside_target, |
| + const SimpleEnclosedRegion& occlusion_from_inside_target) |
| + : draw_transform_(draw_transform), |
| + occlusion_from_outside_target_(occlusion_from_outside_target), |
| + occlusion_from_inside_target_(occlusion_from_inside_target) { |
| +} |
| + |
| +template <typename LayerType> |
| +bool OcclusionChecker<LayerType>::Occluded( |
|
danakj
2014/09/09 15:14:39
nit: IsOccluded
vmpstr
2014/09/09 21:56:56
Done.
|
| + const gfx::Rect& content_rect) const { |
| + if (content_rect.IsEmpty()) |
| + return true; |
| + |
| + if (occlusion_from_inside_target_.IsEmpty() && |
| + occlusion_from_outside_target_.IsEmpty()) { |
| + return false; |
| + } |
| + |
| + // Take the ToEnclosingRect at each step, as we want to contain any unoccluded |
| + // partial pixels in the resulting Rect. |
| + gfx::Rect unoccluded_rect_in_target_surface = |
| + MathUtil::MapEnclosingClippedRect(draw_transform_, content_rect); |
| + DCHECK_LE(occlusion_from_inside_target_.GetRegionComplexity(), 1u); |
| + DCHECK_LE(occlusion_from_outside_target_.GetRegionComplexity(), 1u); |
| + // These subtract operations are more lossy than if we did both operations at |
| + // once. |
| + unoccluded_rect_in_target_surface.Subtract( |
| + occlusion_from_inside_target_.bounds()); |
| + unoccluded_rect_in_target_surface.Subtract( |
| + occlusion_from_outside_target_.bounds()); |
| + |
| + return unoccluded_rect_in_target_surface.IsEmpty(); |
| +} |
| + |
| +// Instantiate (and export) templates here for the linker. |
| +template class OcclusionChecker<Layer>; |
| +template class OcclusionChecker<LayerImpl>; |
| + |
| +} // namespace cc |