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

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

Issue 2067783002: cc: Calculate visible rect inside non root copy request (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@rectF
Patch Set: rebase Created 4 years, 6 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 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/draw_property_utils.h" 5 #include "cc/trees/draw_property_utils.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <vector> 9 #include <vector>
10 10
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 target_node_id, &clip_to_target)) { 85 target_node_id, &clip_to_target)) {
86 *clip_rect_in_target_space = MathUtil::ProjectClippedRect( 86 *clip_rect_in_target_space = MathUtil::ProjectClippedRect(
87 clip_to_target, clip_node->data.clip_in_target_space); 87 clip_to_target, clip_node->data.clip_in_target_space);
88 } else { 88 } else {
89 return false; 89 return false;
90 } 90 }
91 } 91 }
92 return true; 92 return true;
93 } 93 }
94 94
95 struct ClipRect {
96 bool is_clipped;
97 gfx::RectF clip_rect;
98 };
99
100 static ClipRect ComputeRectInTargetSpace(gfx::RectF rect,
101 const TransformTree& transform_tree,
102 int current_transform_id,
103 int target_transform_id) {
104 gfx::Transform current_to_target;
105 if (!transform_tree.ComputeTransformWithDestinationSublayerScale(
106 current_transform_id, target_transform_id, &current_to_target))
107 return ClipRect{false, gfx::RectF()};
ajuma 2016/06/14 15:09:53 To make the bools here and below more readable (th
weiliangc 2016/06/15 12:27:57 Renamed ClipRect to ConditionalClip, and add comme
108 if (current_transform_id > target_transform_id)
109 return ClipRect{true, MathUtil::MapClippedRect(current_to_target, rect)};
110 else
ajuma 2016/06/14 15:09:53 Nit: no need for 'else' after return
weiliangc 2016/06/15 12:27:57 Done.
111 return ClipRect{true,
112 MathUtil::ProjectClippedRect(current_to_target, rect)};
113 }
114
115 static ClipRect ComputeCurrentClip(const ClipNode* clip_node,
116 const TransformTree& transform_tree,
117 int target_transform_id) {
118 if (clip_node->data.transform_id != target_transform_id) {
119 return ComputeRectInTargetSpace(clip_node->data.clip, transform_tree,
120 clip_node->data.transform_id,
121 target_transform_id);
122 } else {
ajuma 2016/06/14 15:09:53 Here too, no need to use 'else' here since there's
weiliangc 2016/06/15 12:27:57 Done.
123 gfx::RectF current_clip = clip_node->data.clip;
124 gfx::Vector2dF sublayer_scale =
125 transform_tree.Node(target_transform_id)->data.sublayer_scale;
126 if (sublayer_scale.x() > 0 && sublayer_scale.y() > 0) {
127 current_clip.Scale(sublayer_scale.x(), sublayer_scale.y());
128 }
129 return ClipRect{true, current_clip};
130 }
131 }
132
133 static ClipRect ComputeAccumulatedClip(const ClipTree& clip_tree,
134 int local_clip_id,
135 const EffectTree& effect_tree,
136 int target_id,
137 const TransformTree& transform_tree) {
138 const ClipNode* clip_node = clip_tree.Node(local_clip_id);
139 const EffectNode* target_node = effect_tree.Node(target_id);
140 int target_transform_id = target_node->data.transform_id;
141 bool is_clipped = false;
142
143 // Collect all the clips that need to be accumulated.
144 std::stack<const ClipNode*> parent_chain;
145
146 // If target is not direct ancestor of clip, this will find least common
147 // ancestor between the target and the clip.
148 while (target_node->id >= 0 && clip_node->id >= 0) {
149 while (target_node->data.clip_id > clip_node->id ||
150 target_node->data.has_unclipped_descendants) {
151 target_node = effect_tree.Node(target_node->data.target_id);
152 }
153 if (target_node->data.clip_id == clip_node->id)
154 break;
155 while (target_node->data.clip_id < clip_node->id) {
156 parent_chain.push(clip_node);
157 clip_node = clip_tree.parent(clip_node);
158 }
159 if (target_node->data.clip_id == clip_node->id) {
160 clip_node = parent_chain.top();
161 parent_chain.pop();
162 break;
163 }
164 }
165
166 // TODO(weiliangc): If we don't create clip for render surface, we don't need
167 // to check applies_local_clip.
168 while (!clip_node->data.applies_local_clip && parent_chain.size() > 0) {
169 clip_node = parent_chain.top();
170 parent_chain.pop();
171 }
172
173 if (!clip_node->data.applies_local_clip)
174 return ClipRect{false, gfx::RectF()};
175
176 ClipRect current_clip =
177 ComputeCurrentClip(clip_node, transform_tree, target_transform_id);
178 is_clipped = current_clip.is_clipped;
179 gfx::RectF accumulated_clip = current_clip.clip_rect;
180
181 while (parent_chain.size() > 0) {
182 clip_node = parent_chain.top();
183 parent_chain.pop();
184 if (!clip_node->data.applies_local_clip) {
185 continue;
186 }
187 ClipRect current_clip =
188 ComputeCurrentClip(clip_node, transform_tree, target_transform_id);
189
190 if (!current_clip.is_clipped)
191 return ClipRect{false, gfx::RectF()};
192
193 is_clipped |= current_clip.is_clipped;
194 accumulated_clip =
195 gfx::IntersectRects(accumulated_clip, current_clip.clip_rect);
196 }
197
198 return ClipRect{is_clipped,
199 accumulated_clip.IsEmpty() ? gfx::RectF() : accumulated_clip};
200 }
201
95 template <typename LayerType> 202 template <typename LayerType>
96 void CalculateClipRects( 203 void CalculateClipRects(
97 const typename LayerType::LayerListType& visible_layer_list, 204 const typename LayerType::LayerListType& visible_layer_list,
98 const ClipTree& clip_tree, 205 const ClipTree& clip_tree,
99 const TransformTree& transform_tree, 206 const TransformTree& transform_tree,
100 const EffectTree& effect_tree, 207 const EffectTree& effect_tree,
101 bool non_root_surfaces_enabled) { 208 bool non_root_surfaces_enabled) {
102 for (auto& layer : visible_layer_list) { 209 for (auto& layer : visible_layer_list) {
103 const ClipNode* clip_node = clip_tree.Node(layer->clip_tree_index()); 210 const ClipNode* clip_node = clip_tree.Node(layer->clip_tree_index());
104 // The entire layer is visible if it has copy requests. 211 // The entire layer is visible if it has copy requests.
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 template <typename LayerType> 284 template <typename LayerType>
178 void CalculateVisibleRects( 285 void CalculateVisibleRects(
179 const typename LayerType::LayerListType& visible_layer_list, 286 const typename LayerType::LayerListType& visible_layer_list,
180 const ClipTree& clip_tree, 287 const ClipTree& clip_tree,
181 const TransformTree& transform_tree, 288 const TransformTree& transform_tree,
182 const EffectTree& effect_tree, 289 const EffectTree& effect_tree,
183 bool non_root_surfaces_enabled) { 290 bool non_root_surfaces_enabled) {
184 for (auto& layer : visible_layer_list) { 291 for (auto& layer : visible_layer_list) {
185 gfx::Size layer_bounds = layer->bounds(); 292 gfx::Size layer_bounds = layer->bounds();
186 293
187 const EffectNode* effect_node = 294 int effect_ancestor_with_copy_request =
188 effect_tree.Node(layer->effect_tree_index()); 295 effect_tree.ClosestAncestorWithCopyRequest(layer->effect_tree_index());
189 if (effect_node->data.has_copy_request && 296 if (effect_ancestor_with_copy_request > 1) {
190 effect_node->owner_id == layer->id()) { 297 // Non root copy request.
191 layer->set_visible_layer_rect(gfx::Rect(layer_bounds)); 298 ClipRect accumulated_clip_rect = ComputeAccumulatedClip(
299 clip_tree, layer->clip_tree_index(), effect_tree,
300 effect_ancestor_with_copy_request, transform_tree);
301 if (!accumulated_clip_rect.is_clipped) {
302 layer->set_visible_layer_rect(gfx::Rect(layer_bounds));
303 continue;
304 }
305
306 gfx::RectF accumulated_clip_in_copy_request_space =
307 accumulated_clip_rect.clip_rect;
308 const EffectNode* copy_request_effect_node =
309 effect_tree.Node(effect_ancestor_with_copy_request);
310 ClipRect clip_in_layer_space = ComputeRectInTargetSpace(
311 accumulated_clip_in_copy_request_space, transform_tree,
312 copy_request_effect_node->data.transform_id,
313 layer->transform_tree_index());
314 if (clip_in_layer_space.is_clipped) {
ajuma 2016/06/14 15:09:53 Since accumulated_clip_rect.is_clipped is true her
weiliangc 2016/06/15 12:27:57 Yes I think so.
315 gfx::RectF clip_rect = clip_in_layer_space.clip_rect;
316 clip_rect.Offset(-layer->offset_to_transform_parent());
317 gfx::Rect visible_rect = gfx::ToEnclosingRect(clip_rect);
318 visible_rect.Intersect(gfx::Rect(layer_bounds));
319 layer->set_visible_layer_rect(visible_rect);
320 } else {
321 layer->set_visible_layer_rect(gfx::Rect(layer_bounds));
322 }
192 continue; 323 continue;
193 } 324 }
194 325
195 const ClipNode* clip_node = clip_tree.Node(layer->clip_tree_index()); 326 const ClipNode* clip_node = clip_tree.Node(layer->clip_tree_index());
196 const TransformNode* transform_node = 327 const TransformNode* transform_node =
197 transform_tree.Node(layer->transform_tree_index()); 328 transform_tree.Node(layer->transform_tree_index());
198 if (!non_root_surfaces_enabled) { 329 if (!non_root_surfaces_enabled) {
199 // When we only have a root surface, the clip node and the layer must 330 // When we only have a root surface, the clip node and the layer must
200 // necessarily have the same target (the root). 331 // necessarily have the same target (the root).
201 if (transform_node->data.ancestors_are_invertible) { 332 if (transform_node->data.ancestors_are_invertible) {
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 } 802 }
672 803
673 void ComputeEffects(EffectTree* effect_tree) { 804 void ComputeEffects(EffectTree* effect_tree) {
674 if (!effect_tree->needs_update()) 805 if (!effect_tree->needs_update())
675 return; 806 return;
676 for (int i = 1; i < static_cast<int>(effect_tree->size()); ++i) 807 for (int i = 1; i < static_cast<int>(effect_tree->size()); ++i)
677 effect_tree->UpdateEffects(i); 808 effect_tree->UpdateEffects(i);
678 effect_tree->set_needs_update(false); 809 effect_tree->set_needs_update(false);
679 } 810 }
680 811
681 static gfx::RectF ComputeCurrentClip(const ClipNode* clip_node,
682 const TransformTree& transform_tree,
683 int target_transform_id) {
684 if (clip_node->data.transform_id != target_transform_id) {
685 gfx::Transform current_to_target;
686 if (!transform_tree.ComputeTransformWithDestinationSublayerScale(
687 clip_node->data.transform_id, target_transform_id,
688 &current_to_target))
689 return gfx::RectF();
690 if (clip_node->data.transform_id > target_transform_id)
691 return MathUtil::MapClippedRect(current_to_target, clip_node->data.clip);
692 else
693 return MathUtil::ProjectClippedRect(current_to_target,
694 clip_node->data.clip);
695 } else {
696 gfx::RectF current_clip = clip_node->data.clip;
697 gfx::Vector2dF sublayer_scale =
698 transform_tree.Node(target_transform_id)->data.sublayer_scale;
699 if (sublayer_scale.x() > 0 && sublayer_scale.y() > 0) {
700 current_clip.Scale(sublayer_scale.x(), sublayer_scale.y());
701 }
702 return current_clip;
703 }
704 }
705
706 static gfx::RectF ComputeAccumulatedClip(const ClipTree& clip_tree,
707 int local_clip_id,
708 const EffectTree& effect_tree,
709 int target_id,
710 const TransformTree& transform_tree) {
711 const ClipNode* clip_node = clip_tree.Node(local_clip_id);
712 const EffectNode* target_node = effect_tree.Node(target_id);
713 int target_transform_id = target_node->data.transform_id;
714
715 // Collect all the clips that need to be accumulated.
716 std::stack<const ClipNode*> parent_chain;
717
718 // If target is not direct ancestor of clip, this will find least common
719 // ancestor between the target and the clip.
720 while (target_node->id >= 0 && clip_node->id >= 0) {
721 while (target_node->data.clip_id > clip_node->id ||
722 target_node->data.has_unclipped_descendants) {
723 target_node = effect_tree.Node(target_node->data.target_id);
724 }
725 if (target_node->data.clip_id == clip_node->id)
726 break;
727 while (target_node->data.clip_id < clip_node->id) {
728 parent_chain.push(clip_node);
729 clip_node = clip_tree.parent(clip_node);
730 }
731 if (target_node->data.clip_id == clip_node->id) {
732 clip_node = parent_chain.top();
733 parent_chain.pop();
734 break;
735 }
736 }
737
738 // TODO(weiliangc): If we don't create clip for render surface, we don't need
739 // to check applies_local_clip.
740 while (!clip_node->data.applies_local_clip && parent_chain.size() > 0) {
741 clip_node = parent_chain.top();
742 parent_chain.pop();
743 }
744
745 if (!clip_node->data.applies_local_clip)
746 return gfx::RectF();
747
748 gfx::RectF accumulated_clip =
749 ComputeCurrentClip(clip_node, transform_tree, target_transform_id);
750
751 while (parent_chain.size() > 0) {
752 clip_node = parent_chain.top();
753 parent_chain.pop();
754 if (!clip_node->data.applies_local_clip) {
755 continue;
756 }
757 gfx::RectF current_clip =
758 ComputeCurrentClip(clip_node, transform_tree, target_transform_id);
759
760 if (current_clip.IsEmpty())
761 return gfx::RectF();
762
763 accumulated_clip = gfx::IntersectRects(accumulated_clip, current_clip);
764 }
765
766 return accumulated_clip.IsEmpty() ? gfx::RectF() : accumulated_clip;
767 }
768
769 static void ComputeClipsWithEffectTree(PropertyTrees* property_trees) { 812 static void ComputeClipsWithEffectTree(PropertyTrees* property_trees) {
770 EffectTree* effect_tree = &property_trees->effect_tree; 813 EffectTree* effect_tree = &property_trees->effect_tree;
771 const ClipTree* clip_tree = &property_trees->clip_tree; 814 const ClipTree* clip_tree = &property_trees->clip_tree;
772 const TransformTree* transform_tree = &property_trees->transform_tree; 815 const TransformTree* transform_tree = &property_trees->transform_tree;
773 EffectNode* root_effect_node = effect_tree->Node(1); 816 EffectNode* root_effect_node = effect_tree->Node(1);
774 const RenderSurfaceImpl* root_render_surface = 817 const RenderSurfaceImpl* root_render_surface =
775 root_effect_node->data.render_surface; 818 root_effect_node->data.render_surface;
776 gfx::Rect root_clip = gfx::ToEnclosingRect( 819 gfx::Rect root_clip = gfx::ToEnclosingRect(
777 clip_tree->Node(root_effect_node->data.clip_id)->data.clip); 820 clip_tree->Node(root_effect_node->data.clip_id)->data.clip);
778 if (root_render_surface->is_clipped()) 821 if (root_render_surface->is_clipped())
779 DCHECK(root_clip == root_render_surface->clip_rect()) 822 DCHECK(root_clip == root_render_surface->clip_rect())
780 << "clip on root render surface: " 823 << "clip on root render surface: "
781 << root_render_surface->clip_rect().ToString() 824 << root_render_surface->clip_rect().ToString()
782 << " v.s. root effect node's clip: " << root_clip.ToString(); 825 << " v.s. root effect node's clip: " << root_clip.ToString();
783 for (int i = 2; i < static_cast<int>(effect_tree->size()); ++i) { 826 for (int i = 2; i < static_cast<int>(effect_tree->size()); ++i) {
784 EffectNode* effect_node = effect_tree->Node(i); 827 EffectNode* effect_node = effect_tree->Node(i);
785 const EffectNode* target_node = 828 const EffectNode* target_node =
786 effect_tree->Node(effect_node->data.target_id); 829 effect_tree->Node(effect_node->data.target_id);
787 gfx::RectF accumulated_clip = 830 ClipRect accumulated_clip_rect =
788 ComputeAccumulatedClip(*clip_tree, effect_node->data.clip_id, 831 ComputeAccumulatedClip(*clip_tree, effect_node->data.clip_id,
789 *effect_tree, target_node->id, *transform_tree); 832 *effect_tree, target_node->id, *transform_tree);
833 gfx::RectF accumulated_clip = accumulated_clip_rect.clip_rect;
790 const RenderSurfaceImpl* render_surface = effect_node->data.render_surface; 834 const RenderSurfaceImpl* render_surface = effect_node->data.render_surface;
791 if (render_surface && render_surface->is_clipped()) { 835 if (render_surface && render_surface->is_clipped()) {
792 DCHECK(gfx::ToEnclosingRect(accumulated_clip) == 836 DCHECK(gfx::ToEnclosingRect(accumulated_clip) ==
793 render_surface->clip_rect()) 837 render_surface->clip_rect())
794 << " render surface's clip rect: " 838 << " render surface's clip rect: "
795 << render_surface->clip_rect().ToString() 839 << render_surface->clip_rect().ToString()
796 << " v.s. accumulated clip: " 840 << " v.s. accumulated clip: "
797 << gfx::ToEnclosingRect(accumulated_clip).ToString(); 841 << gfx::ToEnclosingRect(accumulated_clip).ToString();
798 } 842 }
799 } 843 }
800 } 844 }
801 845
802 static void ComputeLayerClipRect(const PropertyTrees* property_trees, 846 static void ComputeLayerClipRect(const PropertyTrees* property_trees,
803 const LayerImpl* layer) { 847 const LayerImpl* layer) {
804 const EffectTree* effect_tree = &property_trees->effect_tree; 848 const EffectTree* effect_tree = &property_trees->effect_tree;
805 const ClipTree* clip_tree = &property_trees->clip_tree; 849 const ClipTree* clip_tree = &property_trees->clip_tree;
806 const TransformTree* transform_tree = &property_trees->transform_tree; 850 const TransformTree* transform_tree = &property_trees->transform_tree;
807 const EffectNode* effect_node = effect_tree->Node(layer->effect_tree_index()); 851 const EffectNode* effect_node = effect_tree->Node(layer->effect_tree_index());
808 const EffectNode* target_node = 852 const EffectNode* target_node =
809 effect_node->data.has_render_surface 853 effect_node->data.has_render_surface
810 ? effect_node 854 ? effect_node
811 : effect_tree->Node(effect_node->data.target_id); 855 : effect_tree->Node(effect_node->data.target_id);
812 // TODO(weiliangc): When effect node has up to date render surface info on 856 // TODO(weiliangc): When effect node has up to date render surface info on
813 // compositor thread, no need to check for resourceless draw mode 857 // compositor thread, no need to check for resourceless draw mode
814 if (!property_trees->non_root_surfaces_enabled) { 858 if (!property_trees->non_root_surfaces_enabled) {
815 target_node = effect_tree->Node(1); 859 target_node = effect_tree->Node(1);
816 } 860 }
817 861
818 gfx::RectF accumulated_clip = 862 ClipRect accumulated_clip_rect =
819 ComputeAccumulatedClip(*clip_tree, layer->clip_tree_index(), *effect_tree, 863 ComputeAccumulatedClip(*clip_tree, layer->clip_tree_index(), *effect_tree,
820 target_node->id, *transform_tree); 864 target_node->id, *transform_tree);
821 865
866 gfx::RectF accumulated_clip = accumulated_clip_rect.clip_rect;
867
822 if ((!property_trees->non_root_surfaces_enabled && 868 if ((!property_trees->non_root_surfaces_enabled &&
823 clip_tree->Node(layer->clip_tree_index()) 869 clip_tree->Node(layer->clip_tree_index())
824 ->data.layers_are_clipped_when_surfaces_disabled) || 870 ->data.layers_are_clipped_when_surfaces_disabled) ||
825 clip_tree->Node(layer->clip_tree_index())->data.layers_are_clipped) { 871 clip_tree->Node(layer->clip_tree_index())->data.layers_are_clipped) {
826 DCHECK(layer->clip_rect() == gfx::ToEnclosingRect(accumulated_clip)) 872 DCHECK(layer->clip_rect() == gfx::ToEnclosingRect(accumulated_clip))
827 << " layer: " << layer->id() << " clip id: " << layer->clip_tree_index() 873 << " layer: " << layer->id() << " clip id: " << layer->clip_tree_index()
828 << " layer clip: " << layer->clip_rect().ToString() << " v.s. " 874 << " layer clip: " << layer->clip_rect().ToString() << " v.s. "
829 << gfx::ToEnclosingRect(accumulated_clip).ToString() 875 << gfx::ToEnclosingRect(accumulated_clip).ToString()
830 << " and clip node clip: " 876 << " and clip node clip: "
831 << gfx::ToEnclosingRect(clip_tree->Node(layer->clip_tree_index()) 877 << gfx::ToEnclosingRect(clip_tree->Node(layer->clip_tree_index())
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after
1318 void UpdateElasticOverscroll(PropertyTrees* property_trees, 1364 void UpdateElasticOverscroll(PropertyTrees* property_trees,
1319 const Layer* overscroll_elasticity_layer, 1365 const Layer* overscroll_elasticity_layer,
1320 const gfx::Vector2dF& elastic_overscroll) { 1366 const gfx::Vector2dF& elastic_overscroll) {
1321 UpdateElasticOverscrollInternal(property_trees, overscroll_elasticity_layer, 1367 UpdateElasticOverscrollInternal(property_trees, overscroll_elasticity_layer,
1322 elastic_overscroll); 1368 elastic_overscroll);
1323 } 1369 }
1324 1370
1325 } // namespace draw_property_utils 1371 } // namespace draw_property_utils
1326 1372
1327 } // namespace cc 1373 } // namespace cc
OLDNEW
« no previous file with comments | « no previous file | cc/trees/layer_tree_host_common_unittest.cc » ('j') | cc/trees/layer_tree_host_common_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698