| 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/layer_tree_impl.h" | 5 #include "cc/trees/layer_tree_impl.h" |
| 6 | 6 |
| 7 #include "cc/layers/heads_up_display_layer_impl.h" | 7 #include "cc/layers/heads_up_display_layer_impl.h" |
| 8 #include "cc/layers/layer.h" | 8 #include "cc/layers/layer.h" |
| 9 #include "cc/test/fake_impl_proxy.h" | 9 #include "cc/test/fake_impl_proxy.h" |
| 10 #include "cc/test/fake_layer_tree_host_impl.h" | 10 #include "cc/test/fake_layer_tree_host_impl.h" |
| (...skipping 2080 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2091 host_impl().SetViewportSize(root->bounds()); | 2091 host_impl().SetViewportSize(root->bounds()); |
| 2092 host_impl().active_tree()->SetRootLayer(root.Pass()); | 2092 host_impl().active_tree()->SetRootLayer(root.Pass()); |
| 2093 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); | 2093 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); |
| 2094 | 2094 |
| 2095 // Sanity check the scenario we just created. | 2095 // Sanity check the scenario we just created. |
| 2096 ASSERT_EQ(1u, RenderSurfaceLayerList().size()); | 2096 ASSERT_EQ(1u, RenderSurfaceLayerList().size()); |
| 2097 ASSERT_EQ(1u, root_layer()->render_surface()->layer_list().size()); | 2097 ASSERT_EQ(1u, root_layer()->render_surface()->layer_list().size()); |
| 2098 | 2098 |
| 2099 LayerSelectionBound left_input; | 2099 LayerSelectionBound left_input; |
| 2100 left_input.type = SELECTION_BOUND_LEFT; | 2100 left_input.type = SELECTION_BOUND_LEFT; |
| 2101 left_input.layer_rect = gfx::RectF(10, 10, 5, 20); | 2101 left_input.edge_top = gfx::PointF(10, 10); |
| 2102 left_input.edge_bottom = gfx::PointF(10, 20); |
| 2102 left_input.layer_id = root_layer_id; | 2103 left_input.layer_id = root_layer_id; |
| 2103 | 2104 |
| 2104 LayerSelectionBound right_input; | 2105 LayerSelectionBound right_input; |
| 2105 right_input.type = SELECTION_BOUND_RIGHT; | 2106 right_input.type = SELECTION_BOUND_RIGHT; |
| 2106 right_input.layer_rect = gfx::RectF(50, 10, 5, 20); | 2107 right_input.edge_top = gfx::PointF(50, 10); |
| 2108 right_input.edge_bottom = gfx::PointF(50, 30); |
| 2107 right_input.layer_id = root_layer_id; | 2109 right_input.layer_id = root_layer_id; |
| 2108 | 2110 |
| 2109 ViewportSelectionBound left_output, right_output; | 2111 ViewportSelectionBound left_output, right_output; |
| 2110 | 2112 |
| 2111 // Empty input bounds should produce empty output bounds. | 2113 // Empty input bounds should produce empty output bounds. |
| 2112 host_impl().active_tree()->GetViewportSelection(&left_output, &right_output); | 2114 host_impl().active_tree()->GetViewportSelection(&left_output, &right_output); |
| 2113 EXPECT_EQ(ViewportSelectionBound(), left_output); | 2115 EXPECT_EQ(ViewportSelectionBound(), left_output); |
| 2114 EXPECT_EQ(ViewportSelectionBound(), right_output); | 2116 EXPECT_EQ(ViewportSelectionBound(), right_output); |
| 2115 | 2117 |
| 2116 // Selection bounds should produce distinct left and right bounds. | 2118 // Selection bounds should produce distinct left and right bounds. |
| 2117 host_impl().active_tree()->RegisterSelection(left_input, right_input); | 2119 host_impl().active_tree()->RegisterSelection(left_input, right_input); |
| 2118 host_impl().active_tree()->GetViewportSelection(&left_output, &right_output); | 2120 host_impl().active_tree()->GetViewportSelection(&left_output, &right_output); |
| 2119 EXPECT_EQ(left_input.type, left_output.type); | 2121 EXPECT_EQ(left_input.type, left_output.type); |
| 2120 EXPECT_EQ(left_input.layer_rect, left_output.viewport_rect); | 2122 EXPECT_EQ(left_input.edge_bottom, left_output.edge_bottom); |
| 2123 EXPECT_EQ(left_input.edge_top, left_output.edge_top); |
| 2121 EXPECT_TRUE(left_output.visible); | 2124 EXPECT_TRUE(left_output.visible); |
| 2122 EXPECT_EQ(right_input.type, right_output.type); | 2125 EXPECT_EQ(right_input.type, right_output.type); |
| 2123 EXPECT_EQ(right_input.layer_rect, right_output.viewport_rect); | 2126 EXPECT_EQ(right_input.edge_bottom, right_output.edge_bottom); |
| 2127 EXPECT_EQ(right_input.edge_top, right_output.edge_top); |
| 2124 EXPECT_TRUE(right_output.visible); | 2128 EXPECT_TRUE(right_output.visible); |
| 2125 | 2129 |
| 2126 // Insertion bounds should produce identical left and right bounds. | 2130 // Insertion bounds should produce identical left and right bounds. |
| 2127 LayerSelectionBound insertion_input; | 2131 LayerSelectionBound insertion_input; |
| 2128 insertion_input.type = SELECTION_BOUND_CENTER; | 2132 insertion_input.type = SELECTION_BOUND_CENTER; |
| 2129 insertion_input.layer_rect = gfx::RectF(10, 10, 5, 20); | 2133 insertion_input.edge_top = gfx::PointF(15, 10); |
| 2134 insertion_input.edge_bottom = gfx::PointF(15, 30); |
| 2130 insertion_input.layer_id = root_layer_id; | 2135 insertion_input.layer_id = root_layer_id; |
| 2131 host_impl().active_tree()->RegisterSelection(insertion_input, | 2136 host_impl().active_tree()->RegisterSelection(insertion_input, |
| 2132 LayerSelectionBound()); | 2137 LayerSelectionBound()); |
| 2133 host_impl().active_tree()->GetViewportSelection(&left_output, &right_output); | 2138 host_impl().active_tree()->GetViewportSelection(&left_output, &right_output); |
| 2134 EXPECT_EQ(insertion_input.type, left_output.type); | 2139 EXPECT_EQ(insertion_input.type, left_output.type); |
| 2135 EXPECT_EQ(insertion_input.layer_rect, left_output.viewport_rect); | 2140 EXPECT_EQ(insertion_input.edge_bottom, left_output.edge_bottom); |
| 2141 EXPECT_EQ(insertion_input.edge_top, left_output.edge_top); |
| 2136 EXPECT_TRUE(left_output.visible); | 2142 EXPECT_TRUE(left_output.visible); |
| 2137 EXPECT_EQ(left_output, right_output); | 2143 EXPECT_EQ(left_output, right_output); |
| 2138 } | 2144 } |
| 2139 | 2145 |
| 2140 TEST_F(LayerTreeImplTest, SelectionBoundsForPartialOccludedLayers) { | 2146 TEST_F(LayerTreeImplTest, SelectionBoundsForPartialOccludedLayers) { |
| 2141 int root_layer_id = 12345; | 2147 int root_layer_id = 12345; |
| 2142 int clip_layer_id = 1234; | 2148 int clip_layer_id = 1234; |
| 2143 int clipped_layer_id = 123; | 2149 int clipped_layer_id = 123; |
| 2144 scoped_ptr<LayerImpl> root = | 2150 scoped_ptr<LayerImpl> root = |
| 2145 LayerImpl::Create(host_impl().active_tree(), root_layer_id); | 2151 LayerImpl::Create(host_impl().active_tree(), root_layer_id); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2191 | 2197 |
| 2192 host_impl().SetViewportSize(root->bounds()); | 2198 host_impl().SetViewportSize(root->bounds()); |
| 2193 host_impl().active_tree()->SetRootLayer(root.Pass()); | 2199 host_impl().active_tree()->SetRootLayer(root.Pass()); |
| 2194 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); | 2200 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); |
| 2195 | 2201 |
| 2196 // Sanity check the scenario we just created. | 2202 // Sanity check the scenario we just created. |
| 2197 ASSERT_EQ(1u, RenderSurfaceLayerList().size()); | 2203 ASSERT_EQ(1u, RenderSurfaceLayerList().size()); |
| 2198 | 2204 |
| 2199 LayerSelectionBound left_input; | 2205 LayerSelectionBound left_input; |
| 2200 left_input.type = SELECTION_BOUND_LEFT; | 2206 left_input.type = SELECTION_BOUND_LEFT; |
| 2201 left_input.layer_rect = gfx::RectF(25, 10, 5, 20); | 2207 left_input.edge_top = gfx::PointF(25, 10); |
| 2208 left_input.edge_bottom = gfx::PointF(25, 30); |
| 2202 left_input.layer_id = clipped_layer_id; | 2209 left_input.layer_id = clipped_layer_id; |
| 2203 | 2210 |
| 2204 LayerSelectionBound right_input; | 2211 LayerSelectionBound right_input; |
| 2205 right_input.type = SELECTION_BOUND_RIGHT; | 2212 right_input.type = SELECTION_BOUND_RIGHT; |
| 2206 right_input.layer_rect = gfx::RectF(75, 10, 5, 20); | 2213 right_input.edge_top = gfx::PointF(75, 10); |
| 2214 right_input.edge_bottom = gfx::PointF(75, 30); |
| 2207 right_input.layer_id = clipped_layer_id; | 2215 right_input.layer_id = clipped_layer_id; |
| 2208 host_impl().active_tree()->RegisterSelection(left_input, right_input); | 2216 host_impl().active_tree()->RegisterSelection(left_input, right_input); |
| 2209 | 2217 |
| 2210 // The left bound should be occluded by the clip layer. | 2218 // The left bound should be occluded by the clip layer. |
| 2211 ViewportSelectionBound left_output, right_output; | 2219 ViewportSelectionBound left_output, right_output; |
| 2212 host_impl().active_tree()->GetViewportSelection(&left_output, &right_output); | 2220 host_impl().active_tree()->GetViewportSelection(&left_output, &right_output); |
| 2213 EXPECT_EQ(left_input.type, left_output.type); | 2221 EXPECT_EQ(left_input.type, left_output.type); |
| 2214 gfx::RectF expected_left_output_rect = left_input.layer_rect; | 2222 gfx::PointF expected_left_output_top = left_input.edge_top; |
| 2215 expected_left_output_rect.Offset(clipping_offset); | 2223 gfx::PointF expected_left_output_bottom = left_input.edge_bottom; |
| 2216 EXPECT_EQ(expected_left_output_rect, left_output.viewport_rect); | 2224 expected_left_output_top.Offset(clipping_offset.x(), clipping_offset.y()); |
| 2225 expected_left_output_bottom.Offset(clipping_offset.x(), clipping_offset.y()); |
| 2226 EXPECT_EQ(expected_left_output_top, left_output.edge_top); |
| 2227 EXPECT_EQ(expected_left_output_bottom, left_output.edge_bottom); |
| 2217 EXPECT_TRUE(left_output.visible); | 2228 EXPECT_TRUE(left_output.visible); |
| 2218 EXPECT_EQ(right_input.type, right_output.type); | 2229 EXPECT_EQ(right_input.type, right_output.type); |
| 2219 gfx::RectF expected_right_output_rect = right_input.layer_rect; | 2230 gfx::PointF expected_right_output_top = right_input.edge_top; |
| 2220 expected_right_output_rect.Offset(clipping_offset); | 2231 gfx::PointF expected_right_output_bottom = right_input.edge_bottom; |
| 2221 EXPECT_EQ(expected_right_output_rect, right_output.viewport_rect); | 2232 expected_right_output_bottom.Offset(clipping_offset.x(), clipping_offset.y()); |
| 2233 expected_right_output_top.Offset(clipping_offset.x(), clipping_offset.y()); |
| 2234 EXPECT_EQ(expected_right_output_top, right_output.edge_top); |
| 2235 EXPECT_EQ(expected_right_output_bottom, right_output.edge_bottom); |
| 2222 EXPECT_FALSE(right_output.visible); | 2236 EXPECT_FALSE(right_output.visible); |
| 2223 | 2237 |
| 2224 // Handles outside the viewport bounds should be marked invisible. | 2238 // Handles outside the viewport bounds should be marked invisible. |
| 2225 left_input.layer_rect = gfx::RectF(-25, 0, 5, 20); | 2239 left_input.edge_top = gfx::PointF(-25, 0); |
| 2240 left_input.edge_bottom = gfx::PointF(-25, 20); |
| 2226 host_impl().active_tree()->RegisterSelection(left_input, right_input); | 2241 host_impl().active_tree()->RegisterSelection(left_input, right_input); |
| 2227 host_impl().active_tree()->GetViewportSelection(&left_output, &right_output); | 2242 host_impl().active_tree()->GetViewportSelection(&left_output, &right_output); |
| 2228 EXPECT_FALSE(left_output.visible); | 2243 EXPECT_FALSE(left_output.visible); |
| 2229 | 2244 |
| 2230 left_input.layer_rect = gfx::RectF(0, -25, 5, 20); | 2245 left_input.edge_top = gfx::PointF(0, -25); |
| 2246 left_input.edge_bottom = gfx::PointF(0, -5); |
| 2231 host_impl().active_tree()->RegisterSelection(left_input, right_input); | 2247 host_impl().active_tree()->RegisterSelection(left_input, right_input); |
| 2232 host_impl().active_tree()->GetViewportSelection(&left_output, &right_output); | 2248 host_impl().active_tree()->GetViewportSelection(&left_output, &right_output); |
| 2233 EXPECT_FALSE(left_output.visible); | 2249 EXPECT_FALSE(left_output.visible); |
| 2234 | 2250 |
| 2235 // If the handle bottom is partially visible, the handle is marked visible. | 2251 // If the handle bottom is partially visible, the handle is marked visible. |
| 2236 left_input.layer_rect = gfx::RectF(0, -20, 5, 21); | 2252 left_input.edge_top = gfx::PointF(0, -20); |
| 2253 left_input.edge_bottom = gfx::PointF(0, 1); |
| 2237 host_impl().active_tree()->RegisterSelection(left_input, right_input); | 2254 host_impl().active_tree()->RegisterSelection(left_input, right_input); |
| 2238 host_impl().active_tree()->GetViewportSelection(&left_output, &right_output); | 2255 host_impl().active_tree()->GetViewportSelection(&left_output, &right_output); |
| 2239 EXPECT_TRUE(left_output.visible); | 2256 EXPECT_TRUE(left_output.visible); |
| 2240 } | 2257 } |
| 2241 | 2258 |
| 2242 TEST_F(LayerTreeImplTest, SelectionBoundsForScaledLayers) { | 2259 TEST_F(LayerTreeImplTest, SelectionBoundsForScaledLayers) { |
| 2243 int root_layer_id = 1; | 2260 int root_layer_id = 1; |
| 2244 int sub_layer_id = 2; | 2261 int sub_layer_id = 2; |
| 2245 scoped_ptr<LayerImpl> root = | 2262 scoped_ptr<LayerImpl> root = |
| 2246 LayerImpl::Create(host_impl().active_tree(), root_layer_id); | 2263 LayerImpl::Create(host_impl().active_tree(), root_layer_id); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2286 page_scale_factor, page_scale_factor, page_scale_factor); | 2303 page_scale_factor, page_scale_factor, page_scale_factor); |
| 2287 host_impl().active_tree()->SetRootLayer(root.Pass()); | 2304 host_impl().active_tree()->SetRootLayer(root.Pass()); |
| 2288 host_impl().active_tree()->SetViewportLayersFromIds(1, 1, Layer::INVALID_ID); | 2305 host_impl().active_tree()->SetViewportLayersFromIds(1, 1, Layer::INVALID_ID); |
| 2289 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); | 2306 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); |
| 2290 | 2307 |
| 2291 // Sanity check the scenario we just created. | 2308 // Sanity check the scenario we just created. |
| 2292 ASSERT_EQ(1u, RenderSurfaceLayerList().size()); | 2309 ASSERT_EQ(1u, RenderSurfaceLayerList().size()); |
| 2293 | 2310 |
| 2294 LayerSelectionBound left_input; | 2311 LayerSelectionBound left_input; |
| 2295 left_input.type = SELECTION_BOUND_LEFT; | 2312 left_input.type = SELECTION_BOUND_LEFT; |
| 2296 left_input.layer_rect = gfx::RectF(10, 10, 5, 20); | 2313 left_input.edge_top = gfx::PointF(10, 10); |
| 2314 left_input.edge_bottom = gfx::PointF(10, 30); |
| 2297 left_input.layer_id = root_layer_id; | 2315 left_input.layer_id = root_layer_id; |
| 2298 | 2316 |
| 2299 LayerSelectionBound right_input; | 2317 LayerSelectionBound right_input; |
| 2300 right_input.type = SELECTION_BOUND_RIGHT; | 2318 right_input.type = SELECTION_BOUND_RIGHT; |
| 2301 right_input.layer_rect = gfx::RectF(0, 0, 5, 20); | 2319 right_input.edge_top = gfx::PointF(0, 0); |
| 2320 right_input.edge_bottom = gfx::PointF(0, 20); |
| 2302 right_input.layer_id = sub_layer_id; | 2321 right_input.layer_id = sub_layer_id; |
| 2303 host_impl().active_tree()->RegisterSelection(left_input, right_input); | 2322 host_impl().active_tree()->RegisterSelection(left_input, right_input); |
| 2304 | 2323 |
| 2305 // The viewport bounds should be properly scaled by the page scale, but should | 2324 // The viewport bounds should be properly scaled by the page scale, but should |
| 2306 // remain in DIP coordinates. | 2325 // remain in DIP coordinates. |
| 2307 ViewportSelectionBound left_output, right_output; | 2326 ViewportSelectionBound left_output, right_output; |
| 2308 host_impl().active_tree()->GetViewportSelection(&left_output, &right_output); | 2327 host_impl().active_tree()->GetViewportSelection(&left_output, &right_output); |
| 2309 EXPECT_EQ(left_input.type, left_output.type); | 2328 EXPECT_EQ(left_input.type, left_output.type); |
| 2310 gfx::RectF expected_left_output_rect = left_input.layer_rect; | 2329 gfx::PointF expected_left_output_top = left_input.edge_top; |
| 2311 expected_left_output_rect.Scale(page_scale_factor); | 2330 gfx::PointF expected_left_output_bottom = left_input.edge_bottom; |
| 2312 EXPECT_EQ(left_input.layer_rect, left_output.viewport_rect); | 2331 expected_left_output_top.Scale(page_scale_factor); |
| 2332 expected_left_output_bottom.Scale(page_scale_factor); |
| 2333 EXPECT_EQ(left_input.edge_top, left_output.edge_top); |
| 2334 EXPECT_EQ(left_input.edge_bottom, left_output.edge_bottom); |
| 2313 EXPECT_TRUE(left_output.visible); | 2335 EXPECT_TRUE(left_output.visible); |
| 2314 EXPECT_EQ(right_input.type, right_output.type); | 2336 EXPECT_EQ(right_input.type, right_output.type); |
| 2315 gfx::RectF expected_right_output_rect = right_input.layer_rect; | 2337 |
| 2316 expected_right_output_rect.Offset(sub_layer_offset); | 2338 gfx::PointF expected_right_output_top = right_input.edge_top; |
| 2317 expected_right_output_rect.Scale(page_scale_factor); | 2339 gfx::PointF expected_right_output_bottom = right_input.edge_bottom; |
| 2318 EXPECT_EQ(expected_right_output_rect, right_output.viewport_rect); | 2340 expected_right_output_top.Offset(sub_layer_offset.x(), sub_layer_offset.y()); |
| 2341 expected_right_output_bottom.Offset(sub_layer_offset.x(), |
| 2342 sub_layer_offset.y()); |
| 2343 expected_right_output_top.Scale(page_scale_factor); |
| 2344 expected_right_output_bottom.Scale(page_scale_factor); |
| 2345 EXPECT_EQ(expected_right_output_top, right_output.edge_top); |
| 2346 EXPECT_EQ(expected_right_output_bottom, right_output.edge_bottom); |
| 2319 EXPECT_TRUE(right_output.visible); | 2347 EXPECT_TRUE(right_output.visible); |
| 2320 } | 2348 } |
| 2321 | 2349 |
| 2322 TEST_F(LayerTreeImplTest, NumLayersTestOne) { | 2350 TEST_F(LayerTreeImplTest, NumLayersTestOne) { |
| 2323 EXPECT_EQ(0u, host_impl().active_tree()->NumLayers()); | 2351 EXPECT_EQ(0u, host_impl().active_tree()->NumLayers()); |
| 2324 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl().active_tree(), 1); | 2352 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl().active_tree(), 1); |
| 2325 EXPECT_EQ(1u, host_impl().active_tree()->NumLayers()); | 2353 EXPECT_EQ(1u, host_impl().active_tree()->NumLayers()); |
| 2326 } | 2354 } |
| 2327 | 2355 |
| 2328 TEST_F(LayerTreeImplTest, NumLayersSmallTree) { | 2356 TEST_F(LayerTreeImplTest, NumLayersSmallTree) { |
| 2329 EXPECT_EQ(0u, host_impl().active_tree()->NumLayers()); | 2357 EXPECT_EQ(0u, host_impl().active_tree()->NumLayers()); |
| 2330 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl().active_tree(), 1); | 2358 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl().active_tree(), 1); |
| 2331 root->AddChild(LayerImpl::Create(host_impl().active_tree(), 2)); | 2359 root->AddChild(LayerImpl::Create(host_impl().active_tree(), 2)); |
| 2332 root->AddChild(LayerImpl::Create(host_impl().active_tree(), 3)); | 2360 root->AddChild(LayerImpl::Create(host_impl().active_tree(), 3)); |
| 2333 root->child_at(1)->AddChild(LayerImpl::Create(host_impl().active_tree(), 4)); | 2361 root->child_at(1)->AddChild(LayerImpl::Create(host_impl().active_tree(), 4)); |
| 2334 EXPECT_EQ(4u, host_impl().active_tree()->NumLayers()); | 2362 EXPECT_EQ(4u, host_impl().active_tree()->NumLayers()); |
| 2335 } | 2363 } |
| 2336 | 2364 |
| 2337 } // namespace | 2365 } // namespace |
| 2338 } // namespace cc | 2366 } // namespace cc |
| OLD | NEW |