Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(62)

Side by Side Diff: cc/trees/layer_tree_impl_unittest.cc

Issue 300323005: Route selection bounds updates through the compositor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix tests Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/trees/layer_tree_impl.cc ('k') | content/common/cc_messages.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 2052 matching lines...) Expand 10 before | Expand all | Expand 10 after
2063 ASSERT_TRUE(result_layer); 2063 ASSERT_TRUE(result_layer);
2064 EXPECT_EQ(123, result_layer->id()); 2064 EXPECT_EQ(123, result_layer->id());
2065 2065
2066 test_point = gfx::Point(35, 65); 2066 test_point = gfx::Point(35, 65);
2067 result_layer = 2067 result_layer =
2068 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion( 2068 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion(
2069 test_point); 2069 test_point);
2070 EXPECT_FALSE(result_layer); 2070 EXPECT_FALSE(result_layer);
2071 } 2071 }
2072 2072
2073 TEST_F(LayerTreeImplTest, SelectionBoundsForSingleLayer) {
2074 int root_layer_id = 12345;
2075 scoped_ptr<LayerImpl> root =
2076 LayerImpl::Create(host_impl().active_tree(), root_layer_id);
2077
2078 gfx::Transform identity_matrix;
2079 gfx::Point3F transform_origin;
2080 gfx::PointF position;
2081 gfx::Size bounds(100, 100);
2082 SetLayerPropertiesForTesting(root.get(),
2083 identity_matrix,
2084 transform_origin,
2085 position,
2086 bounds,
2087 true,
2088 false);
2089 root->SetDrawsContent(true);
2090
2091 host_impl().SetViewportSize(root->bounds());
2092 host_impl().active_tree()->SetRootLayer(root.Pass());
2093 host_impl().active_tree()->UpdateDrawProperties();
2094
2095 // Sanity check the scenario we just created.
2096 ASSERT_EQ(1u, RenderSurfaceLayerList().size());
2097 ASSERT_EQ(1u, root_layer()->render_surface()->layer_list().size());
2098
2099 LayerSelectionBound left_input;
2100 left_input.type = SELECTION_BOUND_LEFT;
2101 left_input.layer_rect = gfx::RectF(10, 10, 5, 20);
2102 left_input.layer_id = root_layer_id;
2103
2104 LayerSelectionBound right_input;
2105 right_input.type = SELECTION_BOUND_RIGHT;
2106 right_input.layer_rect = gfx::RectF(50, 10, 5, 20);
2107 right_input.layer_id = root_layer_id;
2108
2109 ViewportSelectionBound left_output, right_output;
2110
2111 // Empty input bounds should produce empty output bounds.
2112 host_impl().active_tree()->GetViewportSelection(&left_output, &right_output);
2113 EXPECT_EQ(ViewportSelectionBound(), left_output);
2114 EXPECT_EQ(ViewportSelectionBound(), right_output);
2115
2116 // Selection bounds should produce distinct left and right bounds.
2117 host_impl().active_tree()->RegisterSelection(left_input, right_input);
2118 host_impl().active_tree()->GetViewportSelection(&left_output, &right_output);
2119 EXPECT_EQ(left_input.type, left_output.type);
2120 EXPECT_EQ(left_input.layer_rect, left_output.viewport_rect);
2121 EXPECT_TRUE(left_output.visible);
2122 EXPECT_EQ(right_input.type, right_output.type);
2123 EXPECT_EQ(right_input.layer_rect, right_output.viewport_rect);
2124 EXPECT_TRUE(right_output.visible);
2125
2126 // Insertion bounds should produce identical left and right bounds.
2127 LayerSelectionBound insertion_input;
2128 insertion_input.type = SELECTION_BOUND_CENTER;
2129 insertion_input.layer_rect = gfx::RectF(10, 10, 5, 20);
2130 insertion_input.layer_id = root_layer_id;
2131 host_impl().active_tree()->RegisterSelection(insertion_input,
2132 LayerSelectionBound());
2133 host_impl().active_tree()->GetViewportSelection(&left_output, &right_output);
2134 EXPECT_EQ(insertion_input.type, left_output.type);
2135 EXPECT_EQ(insertion_input.layer_rect, left_output.viewport_rect);
2136 EXPECT_TRUE(left_output.visible);
2137 EXPECT_EQ(left_output, right_output);
2138 }
2139
2140 TEST_F(LayerTreeImplTest, SelectionBoundsForPartialOccludedLayers) {
2141 int root_layer_id = 12345;
2142 int clip_layer_id = 1234;
2143 int clipped_layer_id = 123;
2144 scoped_ptr<LayerImpl> root =
2145 LayerImpl::Create(host_impl().active_tree(), root_layer_id);
2146 root->SetDrawsContent(true);
2147
2148 gfx::Transform identity_matrix;
2149 gfx::Point3F transform_origin;
2150 gfx::PointF position;
2151 gfx::Size bounds(100, 100);
2152 SetLayerPropertiesForTesting(root.get(),
2153 identity_matrix,
2154 transform_origin,
2155 position,
2156 bounds,
2157 true,
2158 false);
2159
2160 gfx::Vector2dF clipping_offset(10, 10);
2161 {
2162 scoped_ptr<LayerImpl> clipping_layer =
2163 LayerImpl::Create(host_impl().active_tree(), clip_layer_id);
2164 // The clipping layer should occlude the right selection bound.
2165 gfx::PointF position = gfx::PointF() + clipping_offset;
2166 gfx::Size bounds(50, 50);
2167 SetLayerPropertiesForTesting(clipping_layer.get(),
2168 identity_matrix,
2169 transform_origin,
2170 position,
2171 bounds,
2172 true,
2173 false);
2174 clipping_layer->SetMasksToBounds(true);
2175
2176 scoped_ptr<LayerImpl> clipped_layer =
2177 LayerImpl::Create(host_impl().active_tree(), clipped_layer_id);
2178 position = gfx::PointF();
2179 bounds = gfx::Size(100, 100);
2180 SetLayerPropertiesForTesting(clipped_layer.get(),
2181 identity_matrix,
2182 transform_origin,
2183 position,
2184 bounds,
2185 true,
2186 false);
2187 clipped_layer->SetDrawsContent(true);
2188 clipping_layer->AddChild(clipped_layer.Pass());
2189 root->AddChild(clipping_layer.Pass());
2190 }
2191
2192 host_impl().SetViewportSize(root->bounds());
2193 host_impl().active_tree()->SetRootLayer(root.Pass());
2194 host_impl().active_tree()->UpdateDrawProperties();
2195
2196 // Sanity check the scenario we just created.
2197 ASSERT_EQ(1u, RenderSurfaceLayerList().size());
2198
2199 LayerSelectionBound left_input;
2200 left_input.type = SELECTION_BOUND_LEFT;
2201 left_input.layer_rect = gfx::RectF(25, 10, 5, 20);
2202 left_input.layer_id = clipped_layer_id;
2203
2204 LayerSelectionBound right_input;
2205 right_input.type = SELECTION_BOUND_RIGHT;
2206 right_input.layer_rect = gfx::RectF(75, 10, 5, 20);
2207 right_input.layer_id = clipped_layer_id;
2208 host_impl().active_tree()->RegisterSelection(left_input, right_input);
2209
2210 // The left bound should be occluded by the clip layer.
2211 ViewportSelectionBound left_output, right_output;
2212 host_impl().active_tree()->GetViewportSelection(&left_output, &right_output);
2213 EXPECT_EQ(left_input.type, left_output.type);
2214 gfx::RectF expected_left_output_rect = left_input.layer_rect;
2215 expected_left_output_rect.Offset(clipping_offset);
2216 EXPECT_EQ(expected_left_output_rect, left_output.viewport_rect);
2217 EXPECT_TRUE(left_output.visible);
2218 EXPECT_EQ(right_input.type, right_output.type);
2219 gfx::RectF expected_right_output_rect = right_input.layer_rect;
2220 expected_right_output_rect.Offset(clipping_offset);
2221 EXPECT_EQ(expected_right_output_rect, right_output.viewport_rect);
2222 EXPECT_FALSE(right_output.visible);
2223
2224 // Handles outside the viewport bounds should be marked invisible.
2225 left_input.layer_rect = gfx::RectF(-25, 0, 5, 20);
2226 host_impl().active_tree()->RegisterSelection(left_input, right_input);
2227 host_impl().active_tree()->GetViewportSelection(&left_output, &right_output);
2228 EXPECT_FALSE(left_output.visible);
2229
2230 left_input.layer_rect = gfx::RectF(0, -25, 5, 20);
2231 host_impl().active_tree()->RegisterSelection(left_input, right_input);
2232 host_impl().active_tree()->GetViewportSelection(&left_output, &right_output);
2233 EXPECT_FALSE(left_output.visible);
2234
2235 // If the handle bottom is partially visible, the handle is marked visible.
2236 left_input.layer_rect = gfx::RectF(0, -20, 5, 21);
2237 host_impl().active_tree()->RegisterSelection(left_input, right_input);
2238 host_impl().active_tree()->GetViewportSelection(&left_output, &right_output);
2239 EXPECT_TRUE(left_output.visible);
2240 }
2241
2242 TEST_F(LayerTreeImplTest, SelectionBoundsForScaledLayers) {
2243 int root_layer_id = 1;
2244 int sub_layer_id = 2;
2245 scoped_ptr<LayerImpl> root =
2246 LayerImpl::Create(host_impl().active_tree(), root_layer_id);
2247 root->SetDrawsContent(true);
2248
2249 gfx::Transform identity_matrix;
2250 gfx::Point3F transform_origin;
2251 gfx::PointF position;
2252 gfx::Size bounds(100, 100);
2253 SetLayerPropertiesForTesting(root.get(),
2254 identity_matrix,
2255 transform_origin,
2256 position,
2257 bounds,
2258 true,
2259 false);
2260
2261 gfx::Vector2dF sub_layer_offset(10, 0);
2262 {
2263 scoped_ptr<LayerImpl> sub_layer =
2264 LayerImpl::Create(host_impl().active_tree(), sub_layer_id);
2265 gfx::PointF position = gfx::PointF() + sub_layer_offset;
2266 gfx::Size bounds(50, 50);
2267 SetLayerPropertiesForTesting(sub_layer.get(),
2268 identity_matrix,
2269 transform_origin,
2270 position,
2271 bounds,
2272 true,
2273 false);
2274 sub_layer->SetDrawsContent(true);
2275 root->AddChild(sub_layer.Pass());
2276 }
2277
2278 float device_scale_factor = 3.f;
2279 float page_scale_factor = 5.f;
2280 gfx::Size scaled_bounds_for_root = gfx::ToCeiledSize(
2281 gfx::ScaleSize(root->bounds(), device_scale_factor * page_scale_factor));
2282 host_impl().SetViewportSize(scaled_bounds_for_root);
2283
2284 host_impl().SetDeviceScaleFactor(device_scale_factor);
2285 host_impl().active_tree()->SetPageScaleFactorAndLimits(
2286 page_scale_factor, page_scale_factor, page_scale_factor);
2287 host_impl().active_tree()->SetRootLayer(root.Pass());
2288 host_impl().active_tree()->SetViewportLayersFromIds(1, 1, Layer::INVALID_ID);
2289 host_impl().active_tree()->UpdateDrawProperties();
2290
2291 // Sanity check the scenario we just created.
2292 ASSERT_EQ(1u, RenderSurfaceLayerList().size());
2293
2294 LayerSelectionBound left_input;
2295 left_input.type = SELECTION_BOUND_LEFT;
2296 left_input.layer_rect = gfx::RectF(10, 10, 5, 20);
2297 left_input.layer_id = root_layer_id;
2298
2299 LayerSelectionBound right_input;
2300 right_input.type = SELECTION_BOUND_RIGHT;
2301 right_input.layer_rect = gfx::RectF(0, 0, 5, 20);
2302 right_input.layer_id = sub_layer_id;
2303 host_impl().active_tree()->RegisterSelection(left_input, right_input);
2304
2305 // The viewport bounds should be properly scaled by the page scale, but should
2306 // remain in DIP coordinates.
2307 ViewportSelectionBound left_output, right_output;
2308 host_impl().active_tree()->GetViewportSelection(&left_output, &right_output);
2309 EXPECT_EQ(left_input.type, left_output.type);
2310 gfx::RectF expected_left_output_rect = left_input.layer_rect;
2311 expected_left_output_rect.Scale(page_scale_factor);
2312 EXPECT_EQ(left_input.layer_rect, left_output.viewport_rect);
2313 EXPECT_TRUE(left_output.visible);
2314 EXPECT_EQ(right_input.type, right_output.type);
2315 gfx::RectF expected_right_output_rect = right_input.layer_rect;
2316 expected_right_output_rect.Offset(sub_layer_offset);
2317 expected_right_output_rect.Scale(page_scale_factor);
2318 EXPECT_EQ(expected_right_output_rect, right_output.viewport_rect);
2319 EXPECT_TRUE(right_output.visible);
2320 }
2321
2073 } // namespace 2322 } // namespace
2074 } // namespace cc 2323 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_impl.cc ('k') | content/common/cc_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698