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

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: Rebased 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
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 2250 matching lines...) Expand 10 before | Expand all | Expand 10 after
2261 if (delta > tolerance) 2261 if (delta > tolerance)
2262 return false; 2262 return false;
2263 } 2263 }
2264 } 2264 }
2265 2265
2266 return true; 2266 return true;
2267 } 2267 }
2268 2268
2269 void VerifyPropertyTreeValuesForSurface(RenderSurfaceImpl* render_surface, 2269 void VerifyPropertyTreeValuesForSurface(RenderSurfaceImpl* render_surface,
2270 PropertyTrees* property_trees) { 2270 PropertyTrees* property_trees) {
2271 const bool render_surface_draw_transforms_match = 2271 SurfaceDrawProperties draw_properties;
2272 ApproximatelyEqual(render_surface->draw_transform(), 2272 ComputeSurfaceDrawPropertiesUsingPropertyTrees(render_surface, property_trees,
2273 DrawTransformOfRenderSurfaceFromPropertyTrees( 2273 &draw_properties);
2274 render_surface, property_trees->transform_tree)); 2274
2275 const bool render_surface_draw_transforms_match = ApproximatelyEqual(
2276 render_surface->draw_transform(), draw_properties.draw_transform);
2275 CHECK(render_surface_draw_transforms_match) 2277 CHECK(render_surface_draw_transforms_match)
2276 << "expected: " << render_surface->draw_transform().ToString() 2278 << "expected: " << render_surface->draw_transform().ToString()
2277 << " actual: " 2279 << " actual: " << draw_properties.draw_transform.ToString();
2278 << DrawTransformOfRenderSurfaceFromPropertyTrees(
2279 render_surface, property_trees->transform_tree)
2280 .ToString();
2281 2280
2282 const bool render_surface_screen_space_transform_match = 2281 const bool render_surface_screen_space_transform_match =
2283 ApproximatelyEqual(render_surface->screen_space_transform(), 2282 ApproximatelyEqual(render_surface->screen_space_transform(),
2284 ScreenSpaceTransformOfRenderSurfaceFromPropertyTrees( 2283 draw_properties.screen_space_transform);
2285 render_surface, property_trees->transform_tree));
2286 CHECK(render_surface_screen_space_transform_match) 2284 CHECK(render_surface_screen_space_transform_match)
2287 << "expected: " << render_surface->screen_space_transform().ToString() 2285 << "expected: " << render_surface->screen_space_transform().ToString()
2288 << " actual: " 2286 << " actual: " << draw_properties.screen_space_transform.ToString();
2289 << ScreenSpaceTransformOfRenderSurfaceFromPropertyTrees(
2290 render_surface, property_trees->transform_tree)
2291 .ToString();
2292 2287
2293 const bool render_surface_replica_draw_transforms_match = 2288 const bool render_surface_replica_draw_transforms_match =
2294 ApproximatelyEqual(render_surface->replica_draw_transform(), 2289 ApproximatelyEqual(render_surface->replica_draw_transform(),
2295 DrawTransformOfRenderSurfaceReplicaFromPropertyTrees( 2290 draw_properties.replica_draw_transform);
2296 render_surface, property_trees->transform_tree));
2297 CHECK(render_surface_replica_draw_transforms_match) 2291 CHECK(render_surface_replica_draw_transforms_match)
2298 << "expected: " << render_surface->replica_draw_transform().ToString() 2292 << "expected: " << render_surface->replica_draw_transform().ToString()
2299 << " actual: " 2293 << " actual: " << draw_properties.replica_draw_transform.ToString();
2300 << DrawTransformOfRenderSurfaceReplicaFromPropertyTrees(
2301 render_surface, property_trees->transform_tree)
2302 .ToString();
2303 2294
2304 const bool render_surface_replica_screen_space_transforms_match = 2295 const bool render_surface_replica_screen_space_transforms_match =
2305 ApproximatelyEqual( 2296 ApproximatelyEqual(render_surface->replica_screen_space_transform(),
2306 render_surface->replica_screen_space_transform(), 2297 draw_properties.replica_screen_space_transform);
2307 ScreenSpaceTransformOfRenderSurfaceReplicaFromPropertyTrees(
2308 render_surface, property_trees->transform_tree));
2309 CHECK(render_surface_replica_screen_space_transforms_match) 2298 CHECK(render_surface_replica_screen_space_transforms_match)
2310 << "expected: " 2299 << "expected: "
2311 << render_surface->replica_screen_space_transform().ToString() 2300 << render_surface->replica_screen_space_transform().ToString()
2312 << " actual: " 2301 << " actual: "
2313 << ScreenSpaceTransformOfRenderSurfaceReplicaFromPropertyTrees( 2302 << draw_properties.replica_screen_space_transform.ToString();
2314 render_surface, property_trees->transform_tree)
2315 .ToString();
2316 2303
2317 CHECK_EQ(render_surface->is_clipped(), 2304 CHECK_EQ(render_surface->is_clipped(), draw_properties.is_clipped);
2318 RenderSurfaceIsClippedFromPropertyTrees(render_surface,
2319 property_trees->clip_tree));
2320 2305
2321 const bool render_surface_clip_rects_match = 2306 const bool render_surface_clip_rects_match = ApproximatelyEqual(
2322 ApproximatelyEqual(render_surface->clip_rect(), 2307 render_surface->clip_rect(), draw_properties.clip_rect);
2323 ClipRectOfRenderSurfaceFromPropertyTrees(
2324 render_surface, property_trees->clip_tree));
2325 CHECK(render_surface_clip_rects_match) 2308 CHECK(render_surface_clip_rects_match)
2326 << "expected: " << render_surface->clip_rect().ToString() << " actual: " 2309 << "expected: " << render_surface->clip_rect().ToString()
2327 << ClipRectOfRenderSurfaceFromPropertyTrees(render_surface, 2310 << " actual: " << draw_properties.clip_rect.ToString();
2328 property_trees->clip_tree)
2329 .ToString();
2330 2311
2312 CHECK_EQ(render_surface->draw_opacity(), draw_properties.draw_opacity);
2313
2314 // content_rect has to be computed recursively, so is computed separately from
enne (OOO) 2015/09/02 21:51:35 It may need to be computed differently, but it doe
ajuma 2015/09/03 15:06:49 Added content_rect to RenderSurfaceDrawProperties.
2315 // other draw properties.
2331 const bool render_surface_content_rects_match = 2316 const bool render_surface_content_rects_match =
2332 ApproximatelyEqual(render_surface->content_rect(), 2317 ApproximatelyEqual(render_surface->content_rect(),
2333 render_surface->content_rect_from_property_trees()); 2318 render_surface->content_rect_from_property_trees());
2334 CHECK(render_surface_content_rects_match) 2319 CHECK(render_surface_content_rects_match)
2335 << "expected: " << render_surface->content_rect().ToString() 2320 << "expected: " << render_surface->content_rect().ToString()
2336 << " actual: " 2321 << " actual: "
2337 << render_surface->content_rect_from_property_trees().ToString(); 2322 << render_surface->content_rect_from_property_trees().ToString();
2338
2339 CHECK_EQ(render_surface->draw_opacity(),
2340 DrawOpacityOfRenderSurfaceFromPropertyTrees(
2341 render_surface, property_trees->effect_tree));
2342 } 2323 }
2343 2324
2344 void VerifyPropertyTreeValuesForLayer(LayerImpl* current_layer, 2325 void VerifyPropertyTreeValuesForLayer(LayerImpl* current_layer,
2345 PropertyTrees* property_trees, 2326 PropertyTrees* property_trees,
2346 bool layers_always_allowed_lcd_text, 2327 bool layers_always_allowed_lcd_text,
2347 bool can_use_lcd_text) { 2328 bool can_use_lcd_text) {
2348 const bool visible_rects_match = 2329 DrawProperties draw_properties;
2349 ApproximatelyEqual(current_layer->visible_layer_rect(), 2330 ComputeLayerDrawPropertiesUsingPropertyTrees(
2350 current_layer->visible_rect_from_property_trees()); 2331 current_layer, property_trees, layers_always_allowed_lcd_text,
2332 can_use_lcd_text, &draw_properties);
2333
2334 const bool visible_rects_match = ApproximatelyEqual(
2335 current_layer->visible_layer_rect(), draw_properties.visible_layer_rect);
2351 CHECK(visible_rects_match) 2336 CHECK(visible_rects_match)
2352 << "expected: " << current_layer->visible_layer_rect().ToString() 2337 << "expected: " << current_layer->visible_layer_rect().ToString()
2353 << " actual: " 2338 << " actual: " << draw_properties.visible_layer_rect.ToString();
2354 << current_layer->visible_rect_from_property_trees().ToString();
2355 2339
2356 const bool draw_transforms_match = 2340 const bool draw_transforms_match = ApproximatelyEqual(
2357 ApproximatelyEqual(current_layer->draw_transform(), 2341 current_layer->draw_transform(), draw_properties.target_space_transform);
2358 DrawTransformFromPropertyTrees(
2359 current_layer, property_trees->transform_tree));
2360 CHECK(draw_transforms_match) 2342 CHECK(draw_transforms_match)
2361 << "expected: " << current_layer->draw_transform().ToString() 2343 << "expected: " << current_layer->draw_transform().ToString()
2362 << " actual: " 2344 << " actual: " << draw_properties.target_space_transform.ToString();
2363 << DrawTransformFromPropertyTrees(
2364 current_layer, property_trees->transform_tree).ToString();
2365 2345
2366 const bool draw_opacities_match = 2346 CHECK_EQ(current_layer->draw_opacity(), draw_properties.opacity);
2367 current_layer->draw_opacity() == 2347 CHECK_EQ(current_layer->can_use_lcd_text(), draw_properties.can_use_lcd_text);
2368 DrawOpacityFromPropertyTrees(current_layer, property_trees->effect_tree);
2369 CHECK(draw_opacities_match)
2370 << "expected: " << current_layer->draw_opacity()
2371 << " actual: " << DrawOpacityFromPropertyTrees(
2372 current_layer, property_trees->effect_tree);
2373
2374 const bool can_use_lcd_text_match =
2375 CanUseLcdTextFromPropertyTrees(
2376 current_layer, layers_always_allowed_lcd_text, can_use_lcd_text,
2377 property_trees) == current_layer->can_use_lcd_text();
2378 CHECK(can_use_lcd_text_match);
2379
2380 CHECK_EQ(current_layer->screen_space_transform_is_animating(), 2348 CHECK_EQ(current_layer->screen_space_transform_is_animating(),
2381 ScreenSpaceTransformIsAnimatingFromPropertyTrees( 2349 draw_properties.screen_space_transform_is_animating);
2382 current_layer, property_trees->transform_tree));
2383 2350
2384 const bool drawable_content_rects_match = 2351 const bool drawable_content_rects_match =
2385 ApproximatelyEqual(current_layer->drawable_content_rect(), 2352 ApproximatelyEqual(current_layer->drawable_content_rect(),
2386 DrawableContentRectFromPropertyTrees( 2353 draw_properties.drawable_content_rect);
2387 current_layer, property_trees->transform_tree));
2388 CHECK(drawable_content_rects_match) 2354 CHECK(drawable_content_rects_match)
2389 << "expected: " << current_layer->drawable_content_rect().ToString() 2355 << "expected: " << current_layer->drawable_content_rect().ToString()
2390 << " actual: " 2356 << " actual: " << draw_properties.drawable_content_rect.ToString();
2391 << DrawableContentRectFromPropertyTrees(current_layer,
2392 property_trees->transform_tree)
2393 .ToString();
2394 2357
2395 const bool clip_rects_match = ApproximatelyEqual( 2358 const bool clip_rects_match =
2396 current_layer->clip_rect(), 2359 ApproximatelyEqual(current_layer->clip_rect(), draw_properties.clip_rect);
2397 ClipRectFromPropertyTrees(current_layer, property_trees->transform_tree));
2398 CHECK(clip_rects_match) << "expected: " 2360 CHECK(clip_rects_match) << "expected: "
2399 << current_layer->clip_rect().ToString() 2361 << current_layer->clip_rect().ToString()
2400 << " actual: " 2362 << " actual: "
2401 << ClipRectFromPropertyTrees( 2363 << draw_properties.clip_rect.ToString();
2402 current_layer, property_trees->transform_tree)
2403 .ToString();
2404 2364
2405 CHECK_EQ(current_layer->draw_properties().maximum_animation_contents_scale, 2365 CHECK_EQ(current_layer->draw_properties().maximum_animation_contents_scale,
2406 MaximumAnimationTargetScaleFromPropertyTrees( 2366 draw_properties.maximum_animation_contents_scale);
2407 current_layer, property_trees->transform_tree));
2408 CHECK_EQ(current_layer->draw_properties().starting_animation_contents_scale, 2367 CHECK_EQ(current_layer->draw_properties().starting_animation_contents_scale,
2409 StartingAnimationScaleFromPropertyTrees( 2368 draw_properties.starting_animation_contents_scale);
2410 current_layer, property_trees->transform_tree));
2411 } 2369 }
2412 2370
2413 void VerifyPropertyTreeValues( 2371 void VerifyPropertyTreeValues(
2414 LayerTreeHostCommon::CalcDrawPropsImplInputs* inputs) { 2372 LayerTreeHostCommon::CalcDrawPropsImplInputs* inputs) {
2415 LayerIterator it, end; 2373 LayerIterator it, end;
2416 for (it = LayerIterator::Begin(inputs->render_surface_layer_list), 2374 for (it = LayerIterator::Begin(inputs->render_surface_layer_list),
2417 end = LayerIterator::End(inputs->render_surface_layer_list); 2375 end = LayerIterator::End(inputs->render_surface_layer_list);
2418 it != end; ++it) { 2376 it != end; ++it) {
2419 LayerImpl* current_layer = *it; 2377 LayerImpl* current_layer = *it;
2420 if (it.represents_target_render_surface()) 2378 if (it.represents_target_render_surface())
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
2575 if (render_to_separate_surface) { 2533 if (render_to_separate_surface) {
2576 if (IsRootLayer(layer)) { 2534 if (IsRootLayer(layer)) {
2577 // The root layer's surface content rect is always the entire viewport. 2535 // The root layer's surface content rect is always the entire viewport.
2578 gfx::Rect viewport = 2536 gfx::Rect viewport =
2579 gfx::ToEnclosingRect(property_trees->clip_tree.ViewportClip()); 2537 gfx::ToEnclosingRect(property_trees->clip_tree.ViewportClip());
2580 layer->render_surface()->SetAccumulatedContentRect(viewport); 2538 layer->render_surface()->SetAccumulatedContentRect(viewport);
2581 } else { 2539 } else {
2582 // If the owning layer of a render surface draws content, the content 2540 // If the owning layer of a render surface draws content, the content
2583 // rect of the render surface is initialized to the drawable content 2541 // rect of the render surface is initialized to the drawable content
2584 // rect of the layer. 2542 // rect of the layer.
2585 gfx::Rect content_rect = 2543 gfx::Rect content_rect = layer->DrawsContent()
2586 layer->DrawsContent() ? DrawableContentRectFromPropertyTrees( 2544 ? layer->drawable_content_rect()
2587 layer, property_trees->transform_tree) 2545 : gfx::Rect();
2588 : gfx::Rect();
2589 layer->render_surface()->SetAccumulatedContentRect(content_rect); 2546 layer->render_surface()->SetAccumulatedContentRect(content_rect);
2590 } 2547 }
2591 } else if (!layer_should_be_skipped && 2548 } else if (!layer_should_be_skipped &&
2592 !IsRootLayer(layer->render_target())) { 2549 !IsRootLayer(layer->render_target())) {
2593 // In this case, the layer's drawable content rect can expand the 2550 // In this case, the layer's drawable content rect can expand the
2594 // content rect of the render surface it is drawing into. 2551 // content rect of the render surface it is drawing into.
2595 gfx::Rect surface_content_rect = 2552 gfx::Rect surface_content_rect =
2596 layer->render_target()->render_surface()->accumulated_content_rect(); 2553 layer->render_target()->render_surface()->accumulated_content_rect();
2597 surface_content_rect.Union(DrawableContentRectFromPropertyTrees( 2554 surface_content_rect.Union(layer->drawable_content_rect());
2598 layer, property_trees->transform_tree));
2599 layer->render_target()->render_surface()->SetAccumulatedContentRect( 2555 layer->render_target()->render_surface()->SetAccumulatedContentRect(
2600 surface_content_rect); 2556 surface_content_rect);
2601 } 2557 }
2602 } 2558 }
2603 2559
2604 for (auto& child_layer : layer->children()) { 2560 for (auto& child_layer : layer->children()) {
2605 CalculateRenderSurfaceLayerListInternal( 2561 CalculateRenderSurfaceLayerListInternal(
2606 child_layer, property_trees, render_surface_layer_list, descendants, 2562 child_layer, property_trees, render_surface_layer_list, descendants,
2607 nearest_occlusion_immune_ancestor, layer_is_drawn, 2563 nearest_occlusion_immune_ancestor, layer_is_drawn,
2608 can_render_to_separate_surface, current_render_surface_layer_list_id, 2564 can_render_to_separate_surface, current_render_surface_layer_list_id,
(...skipping 18 matching lines...) Expand all
2627 } 2583 }
2628 2584
2629 if (render_to_separate_surface && !IsRootLayer(layer) && 2585 if (render_to_separate_surface && !IsRootLayer(layer) &&
2630 layer->render_surface()->layer_list().empty()) { 2586 layer->render_surface()->layer_list().empty()) {
2631 RemoveSurfaceForEarlyExit(layer, render_surface_layer_list); 2587 RemoveSurfaceForEarlyExit(layer, render_surface_layer_list);
2632 return; 2588 return;
2633 } 2589 }
2634 2590
2635 if (verify_property_trees && render_to_separate_surface && 2591 if (verify_property_trees && render_to_separate_surface &&
2636 !IsRootLayer(layer)) { 2592 !IsRootLayer(layer)) {
2637 if (!layer->replica_layer() && 2593 if (!layer->replica_layer() && layer->render_surface()->is_clipped()) {
2638 RenderSurfaceIsClippedFromPropertyTrees(layer->render_surface(),
2639 property_trees->clip_tree)) {
2640 // Here, we clip the render surface's content rect with its clip rect. 2594 // Here, we clip the render surface's content rect with its clip rect.
2641 // As the clip rect of render surface is in the surface's target space, 2595 // As the clip rect of render surface is in the surface's target space,
2642 // we first map the content rect into the target space, intersect it with 2596 // we first map the content rect into the target space, intersect it with
2643 // clip rect and project back the result to the surface space. 2597 // clip rect and project back the result to the surface space.
2644 gfx::Rect surface_content_rect = 2598 gfx::Rect surface_content_rect =
2645 layer->render_surface()->accumulated_content_rect(); 2599 layer->render_surface()->accumulated_content_rect();
2646 2600
2647 if (!surface_content_rect.IsEmpty()) { 2601 if (!surface_content_rect.IsEmpty()) {
2648 gfx::Rect surface_clip_rect = LayerTreeHostCommon::CalculateVisibleRect( 2602 gfx::Rect surface_clip_rect = LayerTreeHostCommon::CalculateVisibleRect(
2649 ClipRectOfRenderSurfaceFromPropertyTrees(layer->render_surface(), 2603 layer->render_surface()->clip_rect(), surface_content_rect,
2650 property_trees->clip_tree), 2604 layer->render_surface()->draw_transform());
2651 surface_content_rect,
2652 DrawTransformOfRenderSurfaceFromPropertyTrees(
2653 layer->render_surface(), property_trees->transform_tree));
2654 surface_content_rect.Intersect(surface_clip_rect); 2605 surface_content_rect.Intersect(surface_clip_rect);
2655 layer->render_surface()->SetAccumulatedContentRect( 2606 layer->render_surface()->SetAccumulatedContentRect(
2656 surface_content_rect); 2607 surface_content_rect);
2657 } 2608 }
2658 } 2609 }
2659 layer->render_surface()->SetContentRectFromPropertyTrees( 2610 layer->render_surface()->SetContentRectFromPropertyTrees(
2660 layer->render_surface()->accumulated_content_rect()); 2611 layer->render_surface()->accumulated_content_rect());
2661 if (!IsRootLayer(layer->parent()->render_target())) { 2612 if (!IsRootLayer(layer->parent()->render_target())) {
2662 // The surface's drawable content rect may expand the content rect 2613 // The surface's drawable content rect may expand the content rect
2663 // of its target's surface(surface's target's surface). 2614 // of its target's surface(surface's target's surface).
2664 gfx::Rect surface_target_rect = layer->parent() 2615 gfx::Rect surface_target_rect = layer->parent()
2665 ->render_target() 2616 ->render_target()
2666 ->render_surface() 2617 ->render_surface()
2667 ->accumulated_content_rect(); 2618 ->accumulated_content_rect();
2668 surface_target_rect.Union(DrawableContentRectOfSurfaceFromPropertyTrees( 2619 surface_target_rect.Union(
2669 layer->render_surface(), property_trees->transform_tree)); 2620 gfx::ToEnclosedRect(layer->render_surface()->DrawableContentRect()));
2670 layer->parent() 2621 layer->parent()
2671 ->render_target() 2622 ->render_target()
2672 ->render_surface() 2623 ->render_surface()
2673 ->SetAccumulatedContentRect(surface_target_rect); 2624 ->SetAccumulatedContentRect(surface_target_rect);
2674 } 2625 }
2675 } 2626 }
2676 2627
2677 if (verify_property_trees && IsRootLayer(layer)) 2628 if (verify_property_trees && IsRootLayer(layer))
2678 layer->render_surface()->SetContentRectFromPropertyTrees( 2629 layer->render_surface()->SetContentRectFromPropertyTrees(
2679 layer->render_surface()->accumulated_content_rect()); 2630 layer->render_surface()->accumulated_content_rect());
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
2824 2775
2825 PropertyTrees* GetPropertyTrees(Layer* layer) { 2776 PropertyTrees* GetPropertyTrees(Layer* layer) {
2826 return layer->layer_tree_host()->property_trees(); 2777 return layer->layer_tree_host()->property_trees();
2827 } 2778 }
2828 2779
2829 PropertyTrees* GetPropertyTrees(LayerImpl* layer) { 2780 PropertyTrees* GetPropertyTrees(LayerImpl* layer) {
2830 return layer->layer_tree_impl()->property_trees(); 2781 return layer->layer_tree_impl()->property_trees();
2831 } 2782 }
2832 2783
2833 } // namespace cc 2784 } // namespace cc
OLDNEW
« cc/trees/draw_property_utils.cc ('K') | « cc/trees/draw_property_utils.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698