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

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

Issue 2543723003: cc : Seperate adding clip node and setting render surface is_clipped (Closed)
Patch Set: . Created 4 years 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 | « no previous file | 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 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/property_tree_builder.h" 5 #include "cc/trees/property_tree_builder.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <map> 9 #include <map>
10 #include <set> 10 #include <set>
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 const LayerType* inner_viewport_scroll_layer; 46 const LayerType* inner_viewport_scroll_layer;
47 const LayerType* outer_viewport_scroll_layer; 47 const LayerType* outer_viewport_scroll_layer;
48 const LayerType* overscroll_elasticity_layer; 48 const LayerType* overscroll_elasticity_layer;
49 gfx::Vector2dF elastic_overscroll; 49 gfx::Vector2dF elastic_overscroll;
50 float page_scale_factor; 50 float page_scale_factor;
51 bool in_subtree_of_page_scale_layer; 51 bool in_subtree_of_page_scale_layer;
52 bool affected_by_inner_viewport_bounds_delta; 52 bool affected_by_inner_viewport_bounds_delta;
53 bool affected_by_outer_viewport_bounds_delta; 53 bool affected_by_outer_viewport_bounds_delta;
54 bool should_flatten; 54 bool should_flatten;
55 bool is_hidden; 55 bool is_hidden;
56 bool apply_ancestor_clip;
56 uint32_t main_thread_scrolling_reasons; 57 uint32_t main_thread_scrolling_reasons;
57 bool scroll_tree_parent_created_by_uninheritable_criteria; 58 bool scroll_tree_parent_created_by_uninheritable_criteria;
58 const gfx::Transform* device_transform; 59 const gfx::Transform* device_transform;
59 gfx::Transform compound_transform_since_render_target; 60 gfx::Transform compound_transform_since_render_target;
60 bool axis_align_since_render_target; 61 bool axis_align_since_render_target;
61 SkColor safe_opaque_background_color; 62 SkColor safe_opaque_background_color;
62 }; 63 };
63 64
64 template <typename LayerType> 65 template <typename LayerType>
65 struct DataForRecursionFromChild { 66 struct DataForRecursionFromChild {
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 332
332 static Layer* Parent(Layer* layer) { 333 static Layer* Parent(Layer* layer) {
333 return layer->parent(); 334 return layer->parent();
334 } 335 }
335 336
336 static LayerImpl* Parent(LayerImpl* layer) { 337 static LayerImpl* Parent(LayerImpl* layer) {
337 return layer->test_properties()->parent; 338 return layer->test_properties()->parent;
338 } 339 }
339 340
340 template <typename LayerType> 341 template <typename LayerType>
342 static void SetSurfaceIsClipped(DataForRecursion<LayerType>* data_for_children,
343 bool apply_ancestor_clip,
344 LayerType* layer) {
345 // A surface with unclipped descendants cannot be clipped by its ancestor
346 // clip at draw time since the unclipped descendants aren't affected by the
347 // ancestor clip.
348 EffectNode* effect_node = data_for_children->property_trees->effect_tree.Node(
349 data_for_children->render_target);
350 DCHECK_EQ(effect_node->owner_id, layer->id());
351 effect_node->surface_is_clipped =
352 apply_ancestor_clip && !NumUnclippedDescendants(layer);
353 // The ancestor clip should propagate to children only if the surface doesn't
354 // apply the clip.
355 data_for_children->apply_ancestor_clip =
356 apply_ancestor_clip && !effect_node->surface_is_clipped;
357 }
358
359 template <typename LayerType>
341 void AddClipNodeIfNeeded(const DataForRecursion<LayerType>& data_from_ancestor, 360 void AddClipNodeIfNeeded(const DataForRecursion<LayerType>& data_from_ancestor,
342 LayerType* layer, 361 LayerType* layer,
343 bool created_render_surface, 362 bool created_render_surface,
344 bool created_transform_node, 363 bool created_transform_node,
345 DataForRecursion<LayerType>* data_for_children) { 364 DataForRecursion<LayerType>* data_for_children) {
346 ClipNode* parent = GetClipParent(data_from_ancestor, layer); 365 ClipNode* parent = GetClipParent(data_from_ancestor, layer);
weiliangc 2016/12/01 20:09:26 Since GetClipParent() also has two code path depen
jaydasika 2016/12/02 05:20:56 Done.
347 int parent_id = parent->id; 366 int parent_id = parent->id;
348 367
349 bool is_root = !Parent(layer); 368 bool inherits_clip = !ClipParent(layer);
350 369
351 // Whether we have an ancestor clip that we might need to apply. 370 bool apply_ancestor_clip = inherits_clip
352 bool ancestor_clips_subtree = is_root || parent->layers_are_clipped; 371 ? data_from_ancestor.apply_ancestor_clip
372 : parent->layers_are_clipped;
jaydasika 2016/12/01 09:12:54 apply_ancestor_clip here still depends on having a
weiliangc 2016/12/01 20:09:26 Could you clarify when apply_ancestor_clip would b
jaydasika 2016/12/02 05:20:56 Its the same. Its just computed differently now. T
353 373
354 bool layers_are_clipped = false; 374 bool layers_are_clipped = false;
355 bool has_unclipped_surface = false; 375 bool has_unclipped_surface = false;
356 376
357 if (created_render_surface) { 377 if (created_render_surface) {
378 SetSurfaceIsClipped(data_for_children, apply_ancestor_clip, layer);
358 // Clips can usually be applied to a surface's descendants simply by 379 // Clips can usually be applied to a surface's descendants simply by
359 // clipping the surface (or applied implicitly by the surface's bounds). 380 // clipping the surface (or applied implicitly by the surface's bounds).
360 // However, if the surface has unclipped descendants (layers that aren't 381 // However, if the surface has unclipped descendants (layers that aren't
361 // affected by the ancestor clip), we cannot clip the surface itself, and 382 // affected by the ancestor clip), we cannot clip the surface itself, and
362 // must instead apply clips to the clipped descendants. 383 // must instead apply clips to the clipped descendants.
363 if (ancestor_clips_subtree && NumUnclippedDescendants(layer) > 0) { 384 if (apply_ancestor_clip && NumUnclippedDescendants(layer) > 0) {
364 layers_are_clipped = true; 385 layers_are_clipped = true;
365 } else if (!ancestor_clips_subtree) { 386 } else if (!apply_ancestor_clip) {
366 // When there are no ancestor clips that need to be applied to a render 387 // When there are no ancestor clips that need to be applied to a render
367 // surface, we reset clipping state. The surface might contribute a clip 388 // surface, we reset clipping state. The surface might contribute a clip
368 // of its own, but clips from ancestor nodes don't need to be considered 389 // of its own, but clips from ancestor nodes don't need to be considered
369 // when computing clip rects or visibility. 390 // when computing clip rects or visibility.
370 has_unclipped_surface = true; 391 has_unclipped_surface = true;
371 DCHECK_NE(parent->clip_type, ClipNode::ClipType::APPLIES_LOCAL_CLIP); 392 DCHECK_NE(parent->clip_type, ClipNode::ClipType::APPLIES_LOCAL_CLIP);
372 } 393 }
373 // A surface with unclipped descendants cannot be clipped by its ancestor
374 // clip at draw time since the unclipped descendants aren't affected by the
375 // ancestor clip.
376 EffectNode* effect_node =
377 data_for_children->property_trees->effect_tree.Node(
378 data_for_children->render_target);
379 DCHECK(effect_node->owner_id == layer->id());
380 effect_node->surface_is_clipped =
381 ancestor_clips_subtree && !NumUnclippedDescendants(layer);
382 } else { 394 } else {
383 // Without a new render surface, layer clipping state from ancestors needs 395 // Without a new render surface, layer clipping state from ancestors needs
384 // to continue to propagate. 396 // to continue to propagate.
385 layers_are_clipped = ancestor_clips_subtree; 397 layers_are_clipped = apply_ancestor_clip;
386 } 398 }
387 399
388 bool layer_clips_subtree = LayerClipsSubtree(layer); 400 bool layer_clips_subtree = LayerClipsSubtree(layer);
389 if (layer_clips_subtree) 401 if (layer_clips_subtree) {
390 layers_are_clipped = true; 402 layers_are_clipped = true;
403 data_for_children->apply_ancestor_clip = true;
404 }
391 405
392 // Without surfaces, all non-viewport clips have to be applied using layer 406 // Without surfaces, all non-viewport clips have to be applied using layer
393 // clipping. 407 // clipping.
394 bool layers_are_clipped_when_surfaces_disabled = 408 bool layers_are_clipped_when_surfaces_disabled =
395 layer_clips_subtree || parent->layers_are_clipped_when_surfaces_disabled; 409 layer_clips_subtree || parent->layers_are_clipped_when_surfaces_disabled;
396 410
397 // Render surface's clip is needed during hit testing. So, we need to create 411 // Render surface's clip is needed during hit testing. So, we need to create
398 // a clip node for every render surface. 412 // a clip node for every render surface.
399 bool requires_node = layer_clips_subtree || created_render_surface; 413 bool requires_node = layer_clips_subtree || created_render_surface;
400 414
(...skipping 11 matching lines...) Expand all
412 ClipNode node; 426 ClipNode node;
413 node.clip = gfx::RectF(gfx::PointF() + layer->offset_to_transform_parent(), 427 node.clip = gfx::RectF(gfx::PointF() + layer->offset_to_transform_parent(),
414 gfx::SizeF(layer->bounds())); 428 gfx::SizeF(layer->bounds()));
415 node.transform_id = transform_parent->transform_tree_index(); 429 node.transform_id = transform_parent->transform_tree_index();
416 node.target_effect_id = data_for_children->render_target; 430 node.target_effect_id = data_for_children->render_target;
417 node.target_transform_id = data_for_children->property_trees->effect_tree 431 node.target_transform_id = data_for_children->property_trees->effect_tree
418 .Node(data_for_children->render_target) 432 .Node(data_for_children->render_target)
419 ->transform_id; 433 ->transform_id;
420 node.owner_id = layer->id(); 434 node.owner_id = layer->id();
421 435
422 if (ancestor_clips_subtree || layer_clips_subtree) { 436 if (apply_ancestor_clip || layer_clips_subtree) {
423 // Surfaces reset the rect used for layer clipping. At other nodes, layer 437 // Surfaces reset the rect used for layer clipping. At other nodes, layer
424 // clipping state from ancestors must continue to get propagated. 438 // clipping state from ancestors must continue to get propagated.
425 node.layer_clipping_uses_only_local_clip = 439 node.layer_clipping_uses_only_local_clip =
426 (created_render_surface && NumUnclippedDescendants(layer) == 0) || 440 (created_render_surface && NumUnclippedDescendants(layer) == 0) ||
427 !ancestor_clips_subtree; 441 !apply_ancestor_clip;
428 } else { 442 } else {
429 // Otherwise, we're either unclipped, or exist only in order to apply our 443 // Otherwise, we're either unclipped, or exist only in order to apply our
430 // parent's clips in our space. 444 // parent's clips in our space.
431 node.layer_clipping_uses_only_local_clip = false; 445 node.layer_clipping_uses_only_local_clip = false;
432 } 446 }
433 447
434 if (layer_clips_subtree) 448 if (layer_clips_subtree)
435 node.clip_type = ClipNode::ClipType::APPLIES_LOCAL_CLIP; 449 node.clip_type = ClipNode::ClipType::APPLIES_LOCAL_CLIP;
436 else 450 else
437 node.clip_type = ClipNode::ClipType::NONE; 451 node.clip_type = ClipNode::ClipType::NONE;
(...skipping 946 matching lines...) Expand 10 before | Expand all | Expand 10 after
1384 data_for_recursion.inner_viewport_scroll_layer = inner_viewport_scroll_layer; 1398 data_for_recursion.inner_viewport_scroll_layer = inner_viewport_scroll_layer;
1385 data_for_recursion.outer_viewport_scroll_layer = outer_viewport_scroll_layer; 1399 data_for_recursion.outer_viewport_scroll_layer = outer_viewport_scroll_layer;
1386 data_for_recursion.overscroll_elasticity_layer = overscroll_elasticity_layer; 1400 data_for_recursion.overscroll_elasticity_layer = overscroll_elasticity_layer;
1387 data_for_recursion.elastic_overscroll = elastic_overscroll; 1401 data_for_recursion.elastic_overscroll = elastic_overscroll;
1388 data_for_recursion.page_scale_factor = page_scale_factor; 1402 data_for_recursion.page_scale_factor = page_scale_factor;
1389 data_for_recursion.in_subtree_of_page_scale_layer = false; 1403 data_for_recursion.in_subtree_of_page_scale_layer = false;
1390 data_for_recursion.affected_by_inner_viewport_bounds_delta = false; 1404 data_for_recursion.affected_by_inner_viewport_bounds_delta = false;
1391 data_for_recursion.affected_by_outer_viewport_bounds_delta = false; 1405 data_for_recursion.affected_by_outer_viewport_bounds_delta = false;
1392 data_for_recursion.should_flatten = false; 1406 data_for_recursion.should_flatten = false;
1393 data_for_recursion.is_hidden = false; 1407 data_for_recursion.is_hidden = false;
1408 // The root clip is always applied.
1409 data_for_recursion.apply_ancestor_clip = true;
1394 data_for_recursion.main_thread_scrolling_reasons = 1410 data_for_recursion.main_thread_scrolling_reasons =
1395 MainThreadScrollingReason::kNotScrollingOnMain; 1411 MainThreadScrollingReason::kNotScrollingOnMain;
1396 data_for_recursion.scroll_tree_parent_created_by_uninheritable_criteria = 1412 data_for_recursion.scroll_tree_parent_created_by_uninheritable_criteria =
1397 true; 1413 true;
1398 data_for_recursion.device_transform = &device_transform; 1414 data_for_recursion.device_transform = &device_transform;
1399 1415
1400 data_for_recursion.property_trees->clear(); 1416 data_for_recursion.property_trees->clear();
1401 data_for_recursion.compound_transform_since_render_target = gfx::Transform(); 1417 data_for_recursion.compound_transform_since_render_target = gfx::Transform();
1402 data_for_recursion.axis_align_since_render_target = true; 1418 data_for_recursion.axis_align_since_render_target = true;
1403 data_for_recursion.property_trees->transform_tree.set_device_scale_factor( 1419 data_for_recursion.property_trees->transform_tree.set_device_scale_factor(
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
1496 color = SkColorSetA(color, 255); 1512 color = SkColorSetA(color, 255);
1497 BuildPropertyTreesTopLevelInternal( 1513 BuildPropertyTreesTopLevelInternal(
1498 root_layer, page_scale_layer, inner_viewport_scroll_layer, 1514 root_layer, page_scale_layer, inner_viewport_scroll_layer,
1499 outer_viewport_scroll_layer, overscroll_elasticity_layer, 1515 outer_viewport_scroll_layer, overscroll_elasticity_layer,
1500 elastic_overscroll, page_scale_factor, device_scale_factor, viewport, 1516 elastic_overscroll, page_scale_factor, device_scale_factor, viewport,
1501 device_transform, property_trees, color); 1517 device_transform, property_trees, color);
1502 property_trees->ResetCachedData(); 1518 property_trees->ResetCachedData();
1503 } 1519 }
1504 1520
1505 } // namespace cc 1521 } // namespace cc
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698