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

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

Issue 1310283002: cc: Avoid duplicate work when computing draw properties using property trees (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 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/draw_property_utils.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 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_host_common.h" 5 #include "cc/trees/layer_tree_host_common.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/trace_event/trace_event.h" 9 #include "base/trace_event/trace_event.h"
10 #include "cc/base/math_util.h" 10 #include "cc/base/math_util.h"
(...skipping 2256 matching lines...) Expand 10 before | Expand all | Expand 10 after
2267 if (delta > tolerance) 2267 if (delta > tolerance)
2268 return false; 2268 return false;
2269 } 2269 }
2270 } 2270 }
2271 2271
2272 return true; 2272 return true;
2273 } 2273 }
2274 2274
2275 void VerifyPropertyTreeValuesForSurface(RenderSurfaceImpl* render_surface, 2275 void VerifyPropertyTreeValuesForSurface(RenderSurfaceImpl* render_surface,
2276 PropertyTrees* property_trees) { 2276 PropertyTrees* property_trees) {
2277 const bool render_surface_draw_transforms_match = 2277 SurfaceDrawProperties draw_properties;
2278 ApproximatelyEqual(render_surface->draw_transform(), 2278 ComputeSurfaceDrawPropertiesUsingPropertyTrees(render_surface, property_trees,
2279 DrawTransformOfRenderSurfaceFromPropertyTrees( 2279 &draw_properties);
2280 render_surface, property_trees->transform_tree)); 2280
2281 const bool render_surface_draw_transforms_match = ApproximatelyEqual(
2282 render_surface->draw_transform(), draw_properties.draw_transform);
2281 CHECK(render_surface_draw_transforms_match) 2283 CHECK(render_surface_draw_transforms_match)
2282 << "expected: " << render_surface->draw_transform().ToString() 2284 << "expected: " << render_surface->draw_transform().ToString()
2283 << " actual: " 2285 << " actual: " << draw_properties.draw_transform.ToString();
2284 << DrawTransformOfRenderSurfaceFromPropertyTrees(
2285 render_surface, property_trees->transform_tree)
2286 .ToString();
2287 2286
2288 const bool render_surface_screen_space_transform_match = 2287 const bool render_surface_screen_space_transform_match =
2289 ApproximatelyEqual(render_surface->screen_space_transform(), 2288 ApproximatelyEqual(render_surface->screen_space_transform(),
2290 ScreenSpaceTransformOfRenderSurfaceFromPropertyTrees( 2289 draw_properties.screen_space_transform);
2291 render_surface, property_trees->transform_tree));
2292 CHECK(render_surface_screen_space_transform_match) 2290 CHECK(render_surface_screen_space_transform_match)
2293 << "expected: " << render_surface->screen_space_transform().ToString() 2291 << "expected: " << render_surface->screen_space_transform().ToString()
2294 << " actual: " 2292 << " actual: " << draw_properties.screen_space_transform.ToString();
2295 << ScreenSpaceTransformOfRenderSurfaceFromPropertyTrees(
2296 render_surface, property_trees->transform_tree)
2297 .ToString();
2298 2293
2299 const bool render_surface_replica_draw_transforms_match = 2294 const bool render_surface_replica_draw_transforms_match =
2300 ApproximatelyEqual(render_surface->replica_draw_transform(), 2295 ApproximatelyEqual(render_surface->replica_draw_transform(),
2301 DrawTransformOfRenderSurfaceReplicaFromPropertyTrees( 2296 draw_properties.replica_draw_transform);
2302 render_surface, property_trees->transform_tree));
2303 CHECK(render_surface_replica_draw_transforms_match) 2297 CHECK(render_surface_replica_draw_transforms_match)
2304 << "expected: " << render_surface->replica_draw_transform().ToString() 2298 << "expected: " << render_surface->replica_draw_transform().ToString()
2305 << " actual: " 2299 << " actual: " << draw_properties.replica_draw_transform.ToString();
2306 << DrawTransformOfRenderSurfaceReplicaFromPropertyTrees(
2307 render_surface, property_trees->transform_tree)
2308 .ToString();
2309 2300
2310 const bool render_surface_replica_screen_space_transforms_match = 2301 const bool render_surface_replica_screen_space_transforms_match =
2311 ApproximatelyEqual( 2302 ApproximatelyEqual(render_surface->replica_screen_space_transform(),
2312 render_surface->replica_screen_space_transform(), 2303 draw_properties.replica_screen_space_transform);
2313 ScreenSpaceTransformOfRenderSurfaceReplicaFromPropertyTrees(
2314 render_surface, property_trees->transform_tree));
2315 CHECK(render_surface_replica_screen_space_transforms_match) 2304 CHECK(render_surface_replica_screen_space_transforms_match)
2316 << "expected: " 2305 << "expected: "
2317 << render_surface->replica_screen_space_transform().ToString() 2306 << render_surface->replica_screen_space_transform().ToString()
2318 << " actual: " 2307 << " actual: "
2319 << ScreenSpaceTransformOfRenderSurfaceReplicaFromPropertyTrees( 2308 << draw_properties.replica_screen_space_transform.ToString();
2320 render_surface, property_trees->transform_tree)
2321 .ToString();
2322 2309
2323 CHECK_EQ(render_surface->is_clipped(), 2310 CHECK_EQ(render_surface->is_clipped(), draw_properties.is_clipped);
2324 RenderSurfaceIsClippedFromPropertyTrees(render_surface,
2325 property_trees->clip_tree));
2326 2311
2327 const bool render_surface_clip_rects_match = 2312 const bool render_surface_clip_rects_match = ApproximatelyEqual(
2328 ApproximatelyEqual(render_surface->clip_rect(), 2313 render_surface->clip_rect(), draw_properties.clip_rect);
2329 ClipRectOfRenderSurfaceFromPropertyTrees(
2330 render_surface, property_trees->clip_tree));
2331 CHECK(render_surface_clip_rects_match) 2314 CHECK(render_surface_clip_rects_match)
2332 << "expected: " << render_surface->clip_rect().ToString() << " actual: " 2315 << "expected: " << render_surface->clip_rect().ToString()
2333 << ClipRectOfRenderSurfaceFromPropertyTrees(render_surface, 2316 << " actual: " << draw_properties.clip_rect.ToString();
2334 property_trees->clip_tree)
2335 .ToString();
2336 2317
2318 CHECK_EQ(render_surface->draw_opacity(), draw_properties.draw_opacity);
2319
2320 // content_rect has to be computed recursively, so is computed separately from
2321 // other draw properties.
2337 const bool render_surface_content_rects_match = 2322 const bool render_surface_content_rects_match =
2338 ApproximatelyEqual(render_surface->content_rect(), 2323 ApproximatelyEqual(render_surface->content_rect(),
2339 render_surface->content_rect_from_property_trees()); 2324 render_surface->content_rect_from_property_trees());
2340 CHECK(render_surface_content_rects_match) 2325 CHECK(render_surface_content_rects_match)
2341 << "expected: " << render_surface->content_rect().ToString() 2326 << "expected: " << render_surface->content_rect().ToString()
2342 << " actual: " 2327 << " actual: "
2343 << render_surface->content_rect_from_property_trees().ToString(); 2328 << render_surface->content_rect_from_property_trees().ToString();
2344
2345 CHECK_EQ(render_surface->draw_opacity(),
2346 DrawOpacityOfRenderSurfaceFromPropertyTrees(
2347 render_surface, property_trees->effect_tree));
2348 } 2329 }
2349 2330
2350 void VerifyPropertyTreeValuesForLayer(LayerImpl* current_layer, 2331 void VerifyPropertyTreeValuesForLayer(LayerImpl* current_layer,
2351 PropertyTrees* property_trees, 2332 PropertyTrees* property_trees,
2352 bool layers_always_allowed_lcd_text, 2333 bool layers_always_allowed_lcd_text,
2353 bool can_use_lcd_text) { 2334 bool can_use_lcd_text) {
2354 const bool visible_rects_match = 2335 DrawProperties<LayerImpl> draw_properties;
2355 ApproximatelyEqual(current_layer->visible_layer_rect(), 2336 ComputeLayerDrawPropertiesUsingPropertyTrees(
2356 current_layer->visible_rect_from_property_trees()); 2337 current_layer, property_trees, layers_always_allowed_lcd_text,
2338 can_use_lcd_text, &draw_properties);
2339
2340 const bool visible_rects_match = ApproximatelyEqual(
2341 current_layer->visible_layer_rect(), draw_properties.visible_layer_rect);
2357 CHECK(visible_rects_match) 2342 CHECK(visible_rects_match)
2358 << "expected: " << current_layer->visible_layer_rect().ToString() 2343 << "expected: " << current_layer->visible_layer_rect().ToString()
2359 << " actual: " 2344 << " actual: " << draw_properties.visible_layer_rect.ToString();
2360 << current_layer->visible_rect_from_property_trees().ToString();
2361 2345
2362 const bool draw_transforms_match = 2346 const bool draw_transforms_match = ApproximatelyEqual(
2363 ApproximatelyEqual(current_layer->draw_transform(), 2347 current_layer->draw_transform(), draw_properties.target_space_transform);
2364 DrawTransformFromPropertyTrees(
2365 current_layer, property_trees->transform_tree));
2366 CHECK(draw_transforms_match) 2348 CHECK(draw_transforms_match)
2367 << "expected: " << current_layer->draw_transform().ToString() 2349 << "expected: " << current_layer->draw_transform().ToString()
2368 << " actual: " 2350 << " actual: " << draw_properties.target_space_transform.ToString();
2369 << DrawTransformFromPropertyTrees(
2370 current_layer, property_trees->transform_tree).ToString();
2371 2351
2372 const bool draw_opacities_match = 2352 CHECK_EQ(current_layer->draw_opacity(), draw_properties.opacity);
2373 current_layer->draw_opacity() == 2353 CHECK_EQ(current_layer->can_use_lcd_text(), draw_properties.can_use_lcd_text);
2374 DrawOpacityFromPropertyTrees(current_layer, property_trees->effect_tree);
2375 CHECK(draw_opacities_match)
2376 << "expected: " << current_layer->draw_opacity()
2377 << " actual: " << DrawOpacityFromPropertyTrees(
2378 current_layer, property_trees->effect_tree);
2379
2380 const bool can_use_lcd_text_match =
2381 CanUseLcdTextFromPropertyTrees(
2382 current_layer, layers_always_allowed_lcd_text, can_use_lcd_text,
2383 property_trees) == current_layer->can_use_lcd_text();
2384 CHECK(can_use_lcd_text_match);
2385
2386 CHECK_EQ(current_layer->screen_space_transform_is_animating(), 2354 CHECK_EQ(current_layer->screen_space_transform_is_animating(),
2387 ScreenSpaceTransformIsAnimatingFromPropertyTrees( 2355 draw_properties.screen_space_transform_is_animating);
2388 current_layer, property_trees->transform_tree));
2389 2356
2390 const bool drawable_content_rects_match = 2357 const bool drawable_content_rects_match =
2391 ApproximatelyEqual(current_layer->drawable_content_rect(), 2358 ApproximatelyEqual(current_layer->drawable_content_rect(),
2392 DrawableContentRectFromPropertyTrees( 2359 draw_properties.drawable_content_rect);
2393 current_layer, property_trees->transform_tree));
2394 CHECK(drawable_content_rects_match) 2360 CHECK(drawable_content_rects_match)
2395 << "expected: " << current_layer->drawable_content_rect().ToString() 2361 << "expected: " << current_layer->drawable_content_rect().ToString()
2396 << " actual: " 2362 << " actual: " << draw_properties.drawable_content_rect.ToString();
2397 << DrawableContentRectFromPropertyTrees(current_layer,
2398 property_trees->transform_tree)
2399 .ToString();
2400 2363
2401 const bool clip_rects_match = ApproximatelyEqual( 2364 const bool clip_rects_match =
2402 current_layer->clip_rect(), 2365 ApproximatelyEqual(current_layer->clip_rect(), draw_properties.clip_rect);
2403 ClipRectFromPropertyTrees(current_layer, property_trees->transform_tree));
2404 CHECK(clip_rects_match) << "expected: " 2366 CHECK(clip_rects_match) << "expected: "
2405 << current_layer->clip_rect().ToString() 2367 << current_layer->clip_rect().ToString()
2406 << " actual: " 2368 << " actual: "
2407 << ClipRectFromPropertyTrees( 2369 << draw_properties.clip_rect.ToString();
2408 current_layer, property_trees->transform_tree)
2409 .ToString();
2410 2370
2411 CHECK_EQ(current_layer->draw_properties().maximum_animation_contents_scale, 2371 CHECK_EQ(current_layer->draw_properties().maximum_animation_contents_scale,
2412 MaximumAnimationTargetScaleFromPropertyTrees( 2372 draw_properties.maximum_animation_contents_scale);
2413 current_layer, property_trees->transform_tree));
2414 CHECK_EQ(current_layer->draw_properties().starting_animation_contents_scale, 2373 CHECK_EQ(current_layer->draw_properties().starting_animation_contents_scale,
2415 StartingAnimationScaleFromPropertyTrees( 2374 draw_properties.starting_animation_contents_scale);
2416 current_layer, property_trees->transform_tree));
2417 } 2375 }
2418 2376
2419 void VerifyPropertyTreeValues( 2377 void VerifyPropertyTreeValues(
2420 LayerTreeHostCommon::CalcDrawPropsImplInputs* inputs) { 2378 LayerTreeHostCommon::CalcDrawPropsImplInputs* inputs) {
2421 LayerIterator it, end; 2379 LayerIterator it, end;
2422 for (it = LayerIterator::Begin(inputs->render_surface_layer_list), 2380 for (it = LayerIterator::Begin(inputs->render_surface_layer_list),
2423 end = LayerIterator::End(inputs->render_surface_layer_list); 2381 end = LayerIterator::End(inputs->render_surface_layer_list);
2424 it != end; ++it) { 2382 it != end; ++it) {
2425 LayerImpl* current_layer = *it; 2383 LayerImpl* current_layer = *it;
2426 if (it.represents_target_render_surface()) 2384 if (it.represents_target_render_surface())
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
2581 if (render_to_separate_surface) { 2539 if (render_to_separate_surface) {
2582 if (IsRootLayer(layer)) { 2540 if (IsRootLayer(layer)) {
2583 // The root layer's surface content rect is always the entire viewport. 2541 // The root layer's surface content rect is always the entire viewport.
2584 gfx::Rect viewport = 2542 gfx::Rect viewport =
2585 ViewportRectFromPropertyTrees(property_trees->clip_tree); 2543 ViewportRectFromPropertyTrees(property_trees->clip_tree);
2586 layer->render_surface()->SetAccumulatedContentRect(viewport); 2544 layer->render_surface()->SetAccumulatedContentRect(viewport);
2587 } else { 2545 } else {
2588 // If the owning layer of a render surface draws content, the content 2546 // If the owning layer of a render surface draws content, the content
2589 // rect of the render surface is initialized to the drawable content 2547 // rect of the render surface is initialized to the drawable content
2590 // rect of the layer. 2548 // rect of the layer.
2591 gfx::Rect content_rect = 2549 gfx::Rect content_rect = layer->DrawsContent()
2592 layer->DrawsContent() ? DrawableContentRectFromPropertyTrees( 2550 ? layer->drawable_content_rect()
jaydasika 2015/08/26 15:16:44 All the draw properties here are the ones calculat
ajuma 2015/08/26 15:21:32 No, I changed this so that once we switch from CDP
jaydasika 2015/08/26 15:27:42 This is inside CalculateRenderSurfaceLayerList whi
ajuma 2015/08/26 15:31:38 Right, when we switch, the property trees work wil
jaydasika 2015/08/26 15:54:03 Okay.
2593 layer, property_trees->transform_tree) 2551 : gfx::Rect();
2594 : gfx::Rect();
2595 layer->render_surface()->SetAccumulatedContentRect(content_rect); 2552 layer->render_surface()->SetAccumulatedContentRect(content_rect);
2596 } 2553 }
2597 } else if (!layer_should_be_skipped && 2554 } else if (!layer_should_be_skipped &&
2598 !IsRootLayer(layer->render_target())) { 2555 !IsRootLayer(layer->render_target())) {
2599 // In this case, the layer's drawable content rect can expand the 2556 // In this case, the layer's drawable content rect can expand the
2600 // content rect of the render surface it is drawing into. 2557 // content rect of the render surface it is drawing into.
2601 gfx::Rect surface_content_rect = 2558 gfx::Rect surface_content_rect =
2602 layer->render_target()->render_surface()->accumulated_content_rect(); 2559 layer->render_target()->render_surface()->accumulated_content_rect();
2603 surface_content_rect.Union(DrawableContentRectFromPropertyTrees( 2560 surface_content_rect.Union(layer->drawable_content_rect());
2604 layer, property_trees->transform_tree));
2605 layer->render_target()->render_surface()->SetAccumulatedContentRect( 2561 layer->render_target()->render_surface()->SetAccumulatedContentRect(
2606 surface_content_rect); 2562 surface_content_rect);
2607 } 2563 }
2608 } 2564 }
2609 2565
2610 for (auto& child_layer : layer->children()) { 2566 for (auto& child_layer : layer->children()) {
2611 CalculateRenderSurfaceLayerListInternal( 2567 CalculateRenderSurfaceLayerListInternal(
2612 child_layer, property_trees, render_surface_layer_list, descendants, 2568 child_layer, property_trees, render_surface_layer_list, descendants,
2613 nearest_occlusion_immune_ancestor, layer_is_drawn, 2569 nearest_occlusion_immune_ancestor, layer_is_drawn,
2614 can_render_to_separate_surface, current_render_surface_layer_list_id, 2570 can_render_to_separate_surface, current_render_surface_layer_list_id,
(...skipping 18 matching lines...) Expand all
2633 } 2589 }
2634 2590
2635 if (render_to_separate_surface && !IsRootLayer(layer) && 2591 if (render_to_separate_surface && !IsRootLayer(layer) &&
2636 layer->render_surface()->layer_list().empty()) { 2592 layer->render_surface()->layer_list().empty()) {
2637 RemoveSurfaceForEarlyExit(layer, render_surface_layer_list); 2593 RemoveSurfaceForEarlyExit(layer, render_surface_layer_list);
2638 return; 2594 return;
2639 } 2595 }
2640 2596
2641 if (verify_property_trees && render_to_separate_surface && 2597 if (verify_property_trees && render_to_separate_surface &&
2642 !IsRootLayer(layer)) { 2598 !IsRootLayer(layer)) {
2643 if (!layer->replica_layer() && 2599 if (!layer->replica_layer() && layer->render_surface()->is_clipped()) {
2644 RenderSurfaceIsClippedFromPropertyTrees(layer->render_surface(),
2645 property_trees->clip_tree)) {
2646 // Here, we clip the render surface's content rect with its clip rect. 2600 // Here, we clip the render surface's content rect with its clip rect.
2647 // As the clip rect of render surface is in the surface's target space, 2601 // As the clip rect of render surface is in the surface's target space,
2648 // we first map the content rect into the target space, intersect it with 2602 // we first map the content rect into the target space, intersect it with
2649 // clip rect and project back the result to the surface space. 2603 // clip rect and project back the result to the surface space.
2650 gfx::Rect surface_content_rect = 2604 gfx::Rect surface_content_rect =
2651 layer->render_surface()->accumulated_content_rect(); 2605 layer->render_surface()->accumulated_content_rect();
2652 2606
2653 if (!surface_content_rect.IsEmpty()) { 2607 if (!surface_content_rect.IsEmpty()) {
2654 gfx::Rect surface_clip_rect = LayerTreeHostCommon::CalculateVisibleRect( 2608 gfx::Rect surface_clip_rect = LayerTreeHostCommon::CalculateVisibleRect(
2655 ClipRectOfRenderSurfaceFromPropertyTrees(layer->render_surface(), 2609 layer->render_surface()->clip_rect(), surface_content_rect,
2656 property_trees->clip_tree), 2610 layer->render_surface()->draw_transform());
2657 surface_content_rect,
2658 DrawTransformOfRenderSurfaceFromPropertyTrees(
2659 layer->render_surface(), property_trees->transform_tree));
2660 surface_content_rect.Intersect(surface_clip_rect); 2611 surface_content_rect.Intersect(surface_clip_rect);
2661 layer->render_surface()->SetAccumulatedContentRect( 2612 layer->render_surface()->SetAccumulatedContentRect(
2662 surface_content_rect); 2613 surface_content_rect);
2663 } 2614 }
2664 } 2615 }
2665 layer->render_surface()->SetContentRectFromPropertyTrees( 2616 layer->render_surface()->SetContentRectFromPropertyTrees(
2666 layer->render_surface()->accumulated_content_rect()); 2617 layer->render_surface()->accumulated_content_rect());
2667 if (!IsRootLayer(layer->parent()->render_target())) { 2618 if (!IsRootLayer(layer->parent()->render_target())) {
2668 // The surface's drawable content rect may expand the content rect 2619 // The surface's drawable content rect may expand the content rect
2669 // of its target's surface(surface's target's surface). 2620 // of its target's surface(surface's target's surface).
2670 gfx::Rect surface_target_rect = layer->parent() 2621 gfx::Rect surface_target_rect = layer->parent()
2671 ->render_target() 2622 ->render_target()
2672 ->render_surface() 2623 ->render_surface()
2673 ->accumulated_content_rect(); 2624 ->accumulated_content_rect();
2674 surface_target_rect.Union(DrawableContentRectOfSurfaceFromPropertyTrees( 2625 surface_target_rect.Union(
2675 layer->render_surface(), property_trees->transform_tree)); 2626 DrawableContentRectOfSurface(layer->render_surface()));
jaydasika 2015/08/26 15:54:03 We already have a RenderSurfaceImpl::DrawableConte
ajuma 2015/08/26 17:06:43 Thanks, good catch. Removed the function from draw
2676 layer->parent() 2627 layer->parent()
2677 ->render_target() 2628 ->render_target()
2678 ->render_surface() 2629 ->render_surface()
2679 ->SetAccumulatedContentRect(surface_target_rect); 2630 ->SetAccumulatedContentRect(surface_target_rect);
2680 } 2631 }
2681 } 2632 }
2682 2633
2683 if (verify_property_trees && IsRootLayer(layer)) 2634 if (verify_property_trees && IsRootLayer(layer))
2684 layer->render_surface()->SetContentRectFromPropertyTrees( 2635 layer->render_surface()->SetContentRectFromPropertyTrees(
2685 layer->render_surface()->accumulated_content_rect()); 2636 layer->render_surface()->accumulated_content_rect());
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
2830 2781
2831 PropertyTrees* GetPropertyTrees(Layer* layer) { 2782 PropertyTrees* GetPropertyTrees(Layer* layer) {
2832 return layer->layer_tree_host()->property_trees(); 2783 return layer->layer_tree_host()->property_trees();
2833 } 2784 }
2834 2785
2835 PropertyTrees* GetPropertyTrees(LayerImpl* layer) { 2786 PropertyTrees* GetPropertyTrees(LayerImpl* layer) {
2836 return layer->layer_tree_impl()->property_trees(); 2787 return layer->layer_tree_impl()->property_trees();
2837 } 2788 }
2838 2789
2839 } // namespace cc 2790 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/draw_property_utils.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698