| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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_tracker.h" | 5 #include "cc/trees/occlusion_tracker.h" |
| 6 | 6 |
| 7 #include "cc/animation/layer_animation_controller.h" | 7 #include "cc/animation/layer_animation_controller.h" |
| 8 #include "cc/base/math_util.h" | 8 #include "cc/base/math_util.h" |
| 9 #include "cc/layers/layer.h" | 9 #include "cc/layers/layer.h" |
| 10 #include "cc/layers/layer_impl.h" | 10 #include "cc/layers/layer_impl.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 namespace cc { | 28 namespace cc { |
| 29 namespace { | 29 namespace { |
| 30 | 30 |
| 31 class TestContentLayerImpl : public LayerImpl { | 31 class TestContentLayerImpl : public LayerImpl { |
| 32 public: | 32 public: |
| 33 TestContentLayerImpl(LayerTreeImpl* tree_impl, int id) | 33 TestContentLayerImpl(LayerTreeImpl* tree_impl, int id) |
| 34 : LayerImpl(tree_impl, id), override_opaque_contents_rect_(false) { | 34 : LayerImpl(tree_impl, id), override_opaque_contents_rect_(false) { |
| 35 SetDrawsContent(true); | 35 SetDrawsContent(true); |
| 36 } | 36 } |
| 37 | 37 |
| 38 SimpleEnclosedRegion VisibleContentOpaqueRegion() const override { | 38 SimpleEnclosedRegion VisibleOpaqueRegion() const override { |
| 39 if (override_opaque_contents_rect_) { | 39 if (override_opaque_contents_rect_) { |
| 40 return SimpleEnclosedRegion( | 40 return SimpleEnclosedRegion( |
| 41 gfx::IntersectRects(opaque_contents_rect_, visible_content_rect())); | 41 gfx::IntersectRects(opaque_contents_rect_, visible_layer_rect())); |
| 42 } | 42 } |
| 43 return LayerImpl::VisibleContentOpaqueRegion(); | 43 return LayerImpl::VisibleOpaqueRegion(); |
| 44 } | 44 } |
| 45 void SetOpaqueContentsRect(const gfx::Rect& opaque_contents_rect) { | 45 void SetOpaqueContentsRect(const gfx::Rect& opaque_contents_rect) { |
| 46 override_opaque_contents_rect_ = true; | 46 override_opaque_contents_rect_ = true; |
| 47 opaque_contents_rect_ = opaque_contents_rect; | 47 opaque_contents_rect_ = opaque_contents_rect; |
| 48 } | 48 } |
| 49 | 49 |
| 50 private: | 50 private: |
| 51 bool override_opaque_contents_rect_; | 51 bool override_opaque_contents_rect_; |
| 52 gfx::Rect opaque_contents_rect_; | 52 gfx::Rect opaque_contents_rect_; |
| 53 }; | 53 }; |
| 54 | 54 |
| 55 class TestOcclusionTrackerWithClip : public TestOcclusionTracker { | 55 class TestOcclusionTrackerWithClip : public TestOcclusionTracker { |
| 56 public: | 56 public: |
| 57 explicit TestOcclusionTrackerWithClip(const gfx::Rect& viewport_rect) | 57 explicit TestOcclusionTrackerWithClip(const gfx::Rect& viewport_rect) |
| 58 : TestOcclusionTracker(viewport_rect) {} | 58 : TestOcclusionTracker(viewport_rect) {} |
| 59 | 59 |
| 60 bool OccludedLayer(const LayerImpl* layer, | 60 bool OccludedLayer(const LayerImpl* layer, |
| 61 const gfx::Rect& content_rect) const { | 61 const gfx::Rect& content_rect) const { |
| 62 DCHECK(layer->visible_content_rect().Contains(content_rect)); | 62 DCHECK(layer->visible_layer_rect().Contains(content_rect)); |
| 63 return this->GetCurrentOcclusionForLayer(layer->draw_transform()) | 63 return this->GetCurrentOcclusionForLayer(layer->draw_transform()) |
| 64 .IsOccluded(content_rect); | 64 .IsOccluded(content_rect); |
| 65 } | 65 } |
| 66 | 66 |
| 67 // Gives an unoccluded sub-rect of |content_rect| in the content space of the | 67 // Gives an unoccluded sub-rect of |content_rect| in the content space of the |
| 68 // layer. Simple wrapper around GetUnoccludedContentRect. | 68 // layer. Simple wrapper around GetUnoccludedContentRect. |
| 69 gfx::Rect UnoccludedLayerContentRect(const LayerImpl* layer, | 69 gfx::Rect UnoccludedLayerContentRect(const LayerImpl* layer, |
| 70 const gfx::Rect& content_rect) const { | 70 const gfx::Rect& content_rect) const { |
| 71 DCHECK(layer->visible_content_rect().Contains(content_rect)); | 71 DCHECK(layer->visible_layer_rect().Contains(content_rect)); |
| 72 return this->GetCurrentOcclusionForLayer(layer->draw_transform()) | 72 return this->GetCurrentOcclusionForLayer(layer->draw_transform()) |
| 73 .GetUnoccludedContentRect(content_rect); | 73 .GetUnoccludedContentRect(content_rect); |
| 74 } | 74 } |
| 75 | 75 |
| 76 gfx::Rect UnoccludedSurfaceContentRect(const LayerImpl* layer, | 76 gfx::Rect UnoccludedSurfaceContentRect(const LayerImpl* layer, |
| 77 const gfx::Rect& content_rect) const { | 77 const gfx::Rect& content_rect) const { |
| 78 RenderSurfaceImpl* surface = layer->render_surface(); | 78 RenderSurfaceImpl* surface = layer->render_surface(); |
| 79 return this->GetCurrentOcclusionForContributingSurface( | 79 return this->GetCurrentOcclusionForContributingSurface( |
| 80 surface->draw_transform()) | 80 surface->draw_transform()) |
| 81 .GetUnoccludedContentRect(content_rect); | 81 .GetUnoccludedContentRect(content_rect); |
| (...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 637 root, this->identity_matrix, gfx::PointF(), gfx::Size(100, 100), true); | 637 root, this->identity_matrix, gfx::PointF(), gfx::Size(100, 100), true); |
| 638 LayerImpl* child = this->CreateSurface( | 638 LayerImpl* child = this->CreateSurface( |
| 639 parent, child_transform, gfx::PointF(30.f, 30.f), gfx::Size(500, 500)); | 639 parent, child_transform, gfx::PointF(30.f, 30.f), gfx::Size(500, 500)); |
| 640 TestContentLayerImpl* layer = this->CreateDrawingLayer( | 640 TestContentLayerImpl* layer = this->CreateDrawingLayer( |
| 641 child, layer_transform, gfx::PointF(), gfx::Size(500, 500), true); | 641 child, layer_transform, gfx::PointF(), gfx::Size(500, 500), true); |
| 642 this->CalcDrawEtc(root); | 642 this->CalcDrawEtc(root); |
| 643 | 643 |
| 644 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000)); | 644 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000)); |
| 645 | 645 |
| 646 gfx::Rect clipped_layer_in_child = MathUtil::MapEnclosingClippedRect( | 646 gfx::Rect clipped_layer_in_child = MathUtil::MapEnclosingClippedRect( |
| 647 layer_transform, layer->visible_content_rect()); | 647 layer_transform, layer->visible_layer_rect()); |
| 648 | 648 |
| 649 this->VisitLayer(layer, &occlusion); | 649 this->VisitLayer(layer, &occlusion); |
| 650 this->EnterContributingSurface(child, &occlusion); | 650 this->EnterContributingSurface(child, &occlusion); |
| 651 | 651 |
| 652 EXPECT_EQ(gfx::Rect().ToString(), | 652 EXPECT_EQ(gfx::Rect().ToString(), |
| 653 occlusion.occlusion_from_outside_target().ToString()); | 653 occlusion.occlusion_from_outside_target().ToString()); |
| 654 EXPECT_EQ(clipped_layer_in_child.ToString(), | 654 EXPECT_EQ(clipped_layer_in_child.ToString(), |
| 655 occlusion.occlusion_from_inside_target().ToString()); | 655 occlusion.occlusion_from_inside_target().ToString()); |
| 656 | 656 |
| 657 this->LeaveContributingSurface(child, &occlusion); | 657 this->LeaveContributingSurface(child, &occlusion); |
| (...skipping 1852 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2510 EXPECT_EQ(gfx::Rect(), | 2510 EXPECT_EQ(gfx::Rect(), |
| 2511 occlusion.UnoccludedSurfaceContentRect( | 2511 occlusion.UnoccludedSurfaceContentRect( |
| 2512 surface, gfx::Rect(80, 70, 50, 50))); | 2512 surface, gfx::Rect(80, 70, 50, 50))); |
| 2513 } | 2513 } |
| 2514 }; | 2514 }; |
| 2515 | 2515 |
| 2516 ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestUnoccludedSurfaceQuery) | 2516 ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestUnoccludedSurfaceQuery) |
| 2517 | 2517 |
| 2518 } // namespace | 2518 } // namespace |
| 2519 } // namespace cc | 2519 } // namespace cc |
| OLD | NEW |