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

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

Issue 2148383005: cc: Use sublayer scale from effect tree (2) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments Created 4 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/property_tree.h ('k') | cc/trees/property_tree_builder.cc » ('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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include <set> 7 #include <set>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 if (source_id == dest_id) 150 if (source_id == dest_id)
151 return true; 151 return true;
152 152
153 if (source_id > dest_id) { 153 if (source_id > dest_id) {
154 return CombineTransformsBetween(source_id, dest_id, transform); 154 return CombineTransformsBetween(source_id, dest_id, transform);
155 } 155 }
156 156
157 return CombineInversesBetween(source_id, dest_id, transform); 157 return CombineInversesBetween(source_id, dest_id, transform);
158 } 158 }
159 159
160 bool TransformTree::ComputeTransformWithDestinationSublayerScale( 160 bool TransformTree::ComputeTransformWithDestinationSurfaceContentsScale(
161 int source_id, 161 int source_id,
162 int dest_id, 162 int dest_id,
163 gfx::Transform* transform) const { 163 gfx::Transform* transform) const {
164 bool success = ComputeTransform(source_id, dest_id, transform); 164 bool success = ComputeTransform(source_id, dest_id, transform);
165 165
166 const TransformNode* dest_node = Node(dest_id); 166 const TransformNode* dest_node = Node(dest_id);
167 if (!dest_node->needs_sublayer_scale) 167 if (!dest_node->needs_surface_contents_scale)
168 return success; 168 return success;
169 169
170 transform->matrix().postScale(dest_node->sublayer_scale.x(), 170 transform->matrix().postScale(dest_node->surface_contents_scale.x(),
171 dest_node->sublayer_scale.y(), 1.f); 171 dest_node->surface_contents_scale.y(), 1.f);
172 return success; 172 return success;
173 } 173 }
174 174
175 bool TransformTree::ComputeTransformWithSourceSublayerScale(
176 int source_id,
177 int dest_id,
178 gfx::Transform* transform) const {
179 bool success = ComputeTransform(source_id, dest_id, transform);
180
181 const TransformNode* source_node = Node(source_id);
182 if (!source_node->needs_sublayer_scale)
183 return success;
184
185 if (source_node->sublayer_scale.x() == 0 ||
186 source_node->sublayer_scale.y() == 0)
187 return false;
188
189 transform->Scale(1.f / source_node->sublayer_scale.x(),
190 1.f / source_node->sublayer_scale.y());
191 return success;
192 }
193
194 bool TransformTree::Are2DAxisAligned(int source_id, int dest_id) const { 175 bool TransformTree::Are2DAxisAligned(int source_id, int dest_id) const {
195 gfx::Transform transform; 176 gfx::Transform transform;
196 return ComputeTransform(source_id, dest_id, &transform) && 177 return ComputeTransform(source_id, dest_id, &transform) &&
197 transform.Preserves2dAxisAlignment(); 178 transform.Preserves2dAxisAlignment();
198 } 179 }
199 180
200 bool TransformTree::NeedsSourceToParentUpdate(TransformNode* node) { 181 bool TransformTree::NeedsSourceToParentUpdate(TransformNode* node) {
201 return (source_to_parent_updates_allowed() && 182 return (source_to_parent_updates_allowed() &&
202 node->parent_id != node->source_node_id); 183 node->parent_id != node->source_node_id);
203 } 184 }
204 185
205 void TransformTree::ResetChangeTracking() { 186 void TransformTree::ResetChangeTracking() {
206 for (int id = 1; id < static_cast<int>(size()); ++id) { 187 for (int id = 1; id < static_cast<int>(size()); ++id) {
207 TransformNode* node = Node(id); 188 TransformNode* node = Node(id);
208 node->transform_changed = false; 189 node->transform_changed = false;
209 } 190 }
210 } 191 }
211 192
212 void TransformTree::UpdateTransforms(int id) { 193 void TransformTree::UpdateTransforms(int id) {
213 TransformNode* node = Node(id); 194 TransformNode* node = Node(id);
214 TransformNode* parent_node = parent(node); 195 TransformNode* parent_node = parent(node);
215 TransformNode* target_node = Node(TargetId(id)); 196 TransformNode* target_node = Node(TargetId(id));
216 TransformNode* source_node = Node(node->source_node_id); 197 TransformNode* source_node = Node(node->source_node_id);
217 property_trees()->UpdateCachedNumber(); 198 property_trees()->UpdateCachedNumber();
218 if (node->needs_local_transform_update || NeedsSourceToParentUpdate(node)) 199 if (node->needs_local_transform_update || NeedsSourceToParentUpdate(node))
219 UpdateLocalTransform(node); 200 UpdateLocalTransform(node);
220 else 201 else
221 UndoSnapping(node); 202 UndoSnapping(node);
222 UpdateScreenSpaceTransform(node, parent_node, target_node); 203 UpdateScreenSpaceTransform(node, parent_node, target_node);
223 UpdateSublayerScale(node); 204 UpdateSurfaceContentsScale(node);
224 UpdateAnimationProperties(node, parent_node); 205 UpdateAnimationProperties(node, parent_node);
225 UpdateSnapping(node); 206 UpdateSnapping(node);
226 UpdateTargetSpaceTransform(node, target_node); 207 UpdateTargetSpaceTransform(node, target_node);
227 UpdateNodeAndAncestorsHaveIntegerTranslations(node, parent_node); 208 UpdateNodeAndAncestorsHaveIntegerTranslations(node, parent_node);
228 UpdateTransformChanged(node, parent_node, source_node); 209 UpdateTransformChanged(node, parent_node, source_node);
229 UpdateNodeAndAncestorsAreAnimatedOrInvertible(node, parent_node); 210 UpdateNodeAndAncestorsAreAnimatedOrInvertible(node, parent_node);
230 } 211 }
231 212
232 bool TransformTree::IsDescendant(int desc_id, int source_id) const { 213 bool TransformTree::IsDescendant(int desc_id, int source_id) const {
233 while (desc_id != source_id) { 214 while (desc_id != source_id) {
(...skipping 28 matching lines...) Expand all
262 return true; 243 return true;
263 } 244 }
264 245
265 // Flattening is defined in a way that requires it to be applied while 246 // Flattening is defined in a way that requires it to be applied while
266 // traversing downward in the tree. We first identify nodes that are on the 247 // traversing downward in the tree. We first identify nodes that are on the
267 // path from the source to the destination (this is traversing upward), and 248 // path from the source to the destination (this is traversing upward), and
268 // then we visit these nodes in reverse order, flattening as needed. We 249 // then we visit these nodes in reverse order, flattening as needed. We
269 // early-out if we get to a node whose target node is the destination, since 250 // early-out if we get to a node whose target node is the destination, since
270 // we can then re-use the target space transform stored at that node. However, 251 // we can then re-use the target space transform stored at that node. However,
271 // we cannot re-use a stored target space transform if the destination has a 252 // we cannot re-use a stored target space transform if the destination has a
272 // zero sublayer scale, since stored target space transforms have sublayer 253 // zero surface contents scale, since stored target space transforms have
273 // scale baked in, but we need to compute an unscaled transform. 254 // surface contents scale baked in, but we need to compute an unscaled
255 // transform.
274 std::vector<int> source_to_destination; 256 std::vector<int> source_to_destination;
275 source_to_destination.push_back(current->id); 257 source_to_destination.push_back(current->id);
276 current = parent(current); 258 current = parent(current);
277 bool destination_has_non_zero_sublayer_scale = 259 bool destination_has_non_zero_surface_contents_scale =
278 dest->sublayer_scale.x() != 0.f && dest->sublayer_scale.y() != 0.f; 260 dest->surface_contents_scale.x() != 0.f &&
279 DCHECK(destination_has_non_zero_sublayer_scale || 261 dest->surface_contents_scale.y() != 0.f;
262 DCHECK(destination_has_non_zero_surface_contents_scale ||
280 !dest->ancestors_are_invertible); 263 !dest->ancestors_are_invertible);
281 for (; current && current->id > dest_id; current = parent(current)) { 264 for (; current && current->id > dest_id; current = parent(current)) {
282 if (destination_has_non_zero_sublayer_scale && 265 if (destination_has_non_zero_surface_contents_scale &&
283 TargetId(current->id) == dest_id && 266 TargetId(current->id) == dest_id &&
284 ContentTargetId(current->id) == dest_id) 267 ContentTargetId(current->id) == dest_id)
285 break; 268 break;
286 source_to_destination.push_back(current->id); 269 source_to_destination.push_back(current->id);
287 } 270 }
288 271
289 gfx::Transform combined_transform; 272 gfx::Transform combined_transform;
290 if (current->id > dest_id) { 273 if (current->id > dest_id) {
291 combined_transform = ToTarget(current->id); 274 combined_transform = ToTarget(current->id);
292 // The stored target space transform has sublayer scale baked in, but we 275 // The stored target space transform has surface contents scale baked in,
293 // need the unscaled transform. 276 // but we need the unscaled transform.
294 combined_transform.matrix().postScale( 277 combined_transform.matrix().postScale(
295 1.0f / dest->sublayer_scale.x(), 1.0f / dest->sublayer_scale.y(), 1.0f); 278 1.0f / dest->surface_contents_scale.x(),
279 1.0f / dest->surface_contents_scale.y(), 1.0f);
296 } else if (current->id < dest_id) { 280 } else if (current->id < dest_id) {
297 // We have reached the lowest common ancestor of the source and destination 281 // We have reached the lowest common ancestor of the source and destination
298 // nodes. This case can occur when we are transforming between a node 282 // nodes. This case can occur when we are transforming between a node
299 // corresponding to a fixed-position layer (or its descendant) and the node 283 // corresponding to a fixed-position layer (or its descendant) and the node
300 // corresponding to the layer's render target. For example, consider the 284 // corresponding to the layer's render target. For example, consider the
301 // layer tree R->T->S->F where F is fixed-position, S owns a render surface, 285 // layer tree R->T->S->F where F is fixed-position, S owns a render surface,
302 // and T has a significant transform. This will yield the following 286 // and T has a significant transform. This will yield the following
303 // transform tree: 287 // transform tree:
304 // R 288 // R
305 // | 289 // |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 parent_node->node_and_ancestors_are_flat && node->to_parent.IsFlat(); 395 parent_node->node_and_ancestors_are_flat && node->to_parent.IsFlat();
412 SetToScreen(node->id, to_screen_space_transform); 396 SetToScreen(node->id, to_screen_space_transform);
413 } 397 }
414 398
415 gfx::Transform from_screen; 399 gfx::Transform from_screen;
416 if (!ToScreen(node->id).GetInverse(&from_screen)) 400 if (!ToScreen(node->id).GetInverse(&from_screen))
417 node->ancestors_are_invertible = false; 401 node->ancestors_are_invertible = false;
418 SetFromScreen(node->id, from_screen); 402 SetFromScreen(node->id, from_screen);
419 } 403 }
420 404
421 void TransformTree::UpdateSublayerScale(TransformNode* node) { 405 void TransformTree::UpdateSurfaceContentsScale(TransformNode* node) {
422 // The sublayer scale depends on the screen space transform, so update it too. 406 // The surface contents scale depends on the screen space transform, so update
423 if (!node->needs_sublayer_scale) { 407 // it too.
424 node->sublayer_scale = gfx::Vector2dF(1.0f, 1.0f); 408 if (!node->needs_surface_contents_scale) {
409 node->surface_contents_scale = gfx::Vector2dF(1.0f, 1.0f);
425 return; 410 return;
426 } 411 }
427 412
428 float layer_scale_factor = 413 float layer_scale_factor =
429 device_scale_factor_ * device_transform_scale_factor_; 414 device_scale_factor_ * device_transform_scale_factor_;
430 if (node->in_subtree_of_page_scale_layer) 415 if (node->in_subtree_of_page_scale_layer)
431 layer_scale_factor *= page_scale_factor_; 416 layer_scale_factor *= page_scale_factor_;
432 node->sublayer_scale = MathUtil::ComputeTransform2dScaleComponents( 417 node->surface_contents_scale = MathUtil::ComputeTransform2dScaleComponents(
433 ToScreen(node->id), layer_scale_factor); 418 ToScreen(node->id), layer_scale_factor);
434 } 419 }
435 420
436 void TransformTree::UpdateTargetSpaceTransform(TransformNode* node, 421 void TransformTree::UpdateTargetSpaceTransform(TransformNode* node,
437 TransformNode* target_node) { 422 TransformNode* target_node) {
438 gfx::Transform target_space_transform; 423 gfx::Transform target_space_transform;
439 if (node->needs_sublayer_scale) { 424 if (node->needs_surface_contents_scale) {
440 target_space_transform.MakeIdentity(); 425 target_space_transform.MakeIdentity();
441 target_space_transform.Scale(node->sublayer_scale.x(), 426 target_space_transform.Scale(node->surface_contents_scale.x(),
442 node->sublayer_scale.y()); 427 node->surface_contents_scale.y());
443 } else { 428 } else {
444 // In order to include the root transform for the root surface, we walk up 429 // In order to include the root transform for the root surface, we walk up
445 // to the root of the transform tree in ComputeTransform. 430 // to the root of the transform tree in ComputeTransform.
446 int target_id = target_node->id; 431 int target_id = target_node->id;
447 ComputeTransformWithDestinationSublayerScale(node->id, target_id, 432 ComputeTransformWithDestinationSurfaceContentsScale(
448 &target_space_transform); 433 node->id, target_id, &target_space_transform);
449 } 434 }
450 435
451 gfx::Transform from_target; 436 gfx::Transform from_target;
452 if (!target_space_transform.GetInverse(&from_target)) 437 if (!target_space_transform.GetInverse(&from_target))
453 node->ancestors_are_invertible = false; 438 node->ancestors_are_invertible = false;
454 SetToTarget(node->id, target_space_transform); 439 SetToTarget(node->id, target_space_transform);
455 SetFromTarget(node->id, from_target); 440 SetFromTarget(node->id, from_target);
456 } 441 }
457 442
458 void TransformTree::UpdateAnimationProperties(TransformNode* node, 443 void TransformTree::UpdateAnimationProperties(TransformNode* node,
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 int TransformTree::ContentTargetId(int node_id) const { 639 int TransformTree::ContentTargetId(int node_id) const {
655 DCHECK(static_cast<int>(cached_data_.size()) > node_id); 640 DCHECK(static_cast<int>(cached_data_.size()) > node_id);
656 return cached_data_[node_id].content_target_id; 641 return cached_data_[node_id].content_target_id;
657 } 642 }
658 643
659 void TransformTree::SetContentTargetId(int node_id, int content_target_id) { 644 void TransformTree::SetContentTargetId(int node_id, int content_target_id) {
660 DCHECK(static_cast<int>(cached_data_.size()) > node_id); 645 DCHECK(static_cast<int>(cached_data_.size()) > node_id);
661 cached_data_[node_id].content_target_id = content_target_id; 646 cached_data_[node_id].content_target_id = content_target_id;
662 } 647 }
663 648
664 gfx::Transform TransformTree::ToScreenSpaceTransformWithoutSublayerScale( 649 gfx::Transform TransformTree::ToScreenSpaceTransformWithoutSurfaceContentsScale(
665 int id) const { 650 int id) const {
666 DCHECK_GT(id, 0); 651 DCHECK_GT(id, 0);
667 if (id == 1) { 652 if (id == 1) {
668 return gfx::Transform(); 653 return gfx::Transform();
669 } 654 }
670 const TransformNode* node = Node(id); 655 const TransformNode* node = Node(id);
671 gfx::Transform screen_space_transform = ToScreen(id); 656 gfx::Transform screen_space_transform = ToScreen(id);
672 if (node->sublayer_scale.x() != 0.0 && node->sublayer_scale.y() != 0.0) 657 if (node->surface_contents_scale.x() != 0.0 &&
673 screen_space_transform.Scale(1.0 / node->sublayer_scale.x(), 658 node->surface_contents_scale.y() != 0.0)
674 1.0 / node->sublayer_scale.y()); 659 screen_space_transform.Scale(1.0 / node->surface_contents_scale.x(),
660 1.0 / node->surface_contents_scale.y());
675 return screen_space_transform; 661 return screen_space_transform;
676 } 662 }
677 663
678 bool TransformTree::operator==(const TransformTree& other) const { 664 bool TransformTree::operator==(const TransformTree& other) const {
679 return PropertyTree::operator==(other) && 665 return PropertyTree::operator==(other) &&
680 source_to_parent_updates_allowed_ == 666 source_to_parent_updates_allowed_ ==
681 other.source_to_parent_updates_allowed() && 667 other.source_to_parent_updates_allowed() &&
682 page_scale_factor_ == other.page_scale_factor() && 668 page_scale_factor_ == other.page_scale_factor() &&
683 device_scale_factor_ == other.device_scale_factor() && 669 device_scale_factor_ == other.device_scale_factor() &&
684 device_transform_scale_factor_ == 670 device_transform_scale_factor_ ==
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
828 node->hidden_by_backface_visibility = 814 node->hidden_by_backface_visibility =
829 transform_node->local.IsBackFaceVisible(); 815 transform_node->local.IsBackFaceVisible();
830 } 816 }
831 return; 817 return;
832 } 818 }
833 } 819 }
834 } 820 }
835 node->hidden_by_backface_visibility = false; 821 node->hidden_by_backface_visibility = false;
836 } 822 }
837 823
838 void EffectTree::UpdateSublayerScale(EffectNode* effect_node) { 824 void EffectTree::UpdateSurfaceContentsScale(EffectNode* effect_node) {
839 if (!effect_node->has_render_surface || effect_node->transform_id == 0) { 825 if (!effect_node->has_render_surface || effect_node->transform_id == 0) {
840 effect_node->sublayer_scale = gfx::Vector2dF(1.0f, 1.0f); 826 effect_node->surface_contents_scale = gfx::Vector2dF(1.0f, 1.0f);
841 return; 827 return;
842 } 828 }
843 829
844 TransformTree& transform_tree = property_trees()->transform_tree; 830 TransformTree& transform_tree = property_trees()->transform_tree;
845 float layer_scale_factor = transform_tree.device_scale_factor() * 831 float layer_scale_factor = transform_tree.device_scale_factor() *
846 transform_tree.device_transform_scale_factor(); 832 transform_tree.device_transform_scale_factor();
847 TransformNode* transform_node = 833 TransformNode* transform_node =
848 transform_tree.Node(effect_node->transform_id); 834 transform_tree.Node(effect_node->transform_id);
849 if (transform_node->in_subtree_of_page_scale_layer) 835 if (transform_node->in_subtree_of_page_scale_layer)
850 layer_scale_factor *= transform_tree.page_scale_factor(); 836 layer_scale_factor *= transform_tree.page_scale_factor();
851 effect_node->sublayer_scale = MathUtil::ComputeTransform2dScaleComponents( 837 effect_node->surface_contents_scale =
852 transform_tree.ToScreen(transform_node->id), layer_scale_factor); 838 MathUtil::ComputeTransform2dScaleComponents(
839 transform_tree.ToScreen(transform_node->id), layer_scale_factor);
853 } 840 }
854 841
855 void EffectTree::UpdateEffects(int id) { 842 void EffectTree::UpdateEffects(int id) {
856 EffectNode* node = Node(id); 843 EffectNode* node = Node(id);
857 EffectNode* parent_node = parent(node); 844 EffectNode* parent_node = parent(node);
858 845
859 UpdateOpacities(node, parent_node); 846 UpdateOpacities(node, parent_node);
860 UpdateIsDrawn(node, parent_node); 847 UpdateIsDrawn(node, parent_node);
861 UpdateEffectChanged(node, parent_node); 848 UpdateEffectChanged(node, parent_node);
862 UpdateBackfaceVisibility(node, parent_node); 849 UpdateBackfaceVisibility(node, parent_node);
863 UpdateSublayerScale(node); 850 UpdateSurfaceContentsScale(node);
864 } 851 }
865 852
866 void EffectTree::AddCopyRequest(int node_id, 853 void EffectTree::AddCopyRequest(int node_id,
867 std::unique_ptr<CopyOutputRequest> request) { 854 std::unique_ptr<CopyOutputRequest> request) {
868 copy_requests_.insert(std::make_pair(node_id, std::move(request))); 855 copy_requests_.insert(std::make_pair(node_id, std::move(request)));
869 } 856 }
870 857
871 void EffectTree::PushCopyRequestsTo(EffectTree* other_tree) { 858 void EffectTree::PushCopyRequestsTo(EffectTree* other_tree) {
872 // If other_tree still has copy requests, this means there was a commit 859 // If other_tree still has copy requests, this means there was a commit
873 // without a draw. This only happens in some edge cases during lost context or 860 // without a draw. This only happens in some edge cases during lost context or
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
919 source_id = destination_id; 906 source_id = destination_id;
920 } else { 907 } else {
921 // The root surface doesn't have the notion of sub-layer scale, but 908 // The root surface doesn't have the notion of sub-layer scale, but
922 // instead has a similar notion of transforming from the space of the root 909 // instead has a similar notion of transforming from the space of the root
923 // layer to the space of the screen. 910 // layer to the space of the screen.
924 DCHECK_EQ(0, destination_id); 911 DCHECK_EQ(0, destination_id);
925 source_id = 1; 912 source_id = 1;
926 } 913 }
927 gfx::Transform transform; 914 gfx::Transform transform;
928 property_trees() 915 property_trees()
929 ->transform_tree.ComputeTransformWithDestinationSublayerScale( 916 ->transform_tree.ComputeTransformWithDestinationSurfaceContentsScale(
930 source_id, destination_id, &transform); 917 source_id, destination_id, &transform);
931 it->set_area(MathUtil::MapEnclosingClippedRect(transform, it->area())); 918 it->set_area(MathUtil::MapEnclosingClippedRect(transform, it->area()));
932 } 919 }
933 } 920 }
934 921
935 bool EffectTree::HasCopyRequests() const { 922 bool EffectTree::HasCopyRequests() const {
936 return !copy_requests_.empty(); 923 return !copy_requests_.empty();
937 } 924 }
938 925
939 void EffectTree::ClearCopyRequests() { 926 void EffectTree::ClearCopyRequests() {
(...skipping 944 matching lines...) Expand 10 before | Expand all | Expand 10 after
1884 cached_data_.property_tree_update_number = 0; 1871 cached_data_.property_tree_update_number = 0;
1885 cached_data_.animation_scales = std::vector<AnimationScaleData>( 1872 cached_data_.animation_scales = std::vector<AnimationScaleData>(
1886 transform_tree.nodes().size(), AnimationScaleData()); 1873 transform_tree.nodes().size(), AnimationScaleData());
1887 } 1874 }
1888 1875
1889 void PropertyTrees::UpdateCachedNumber() { 1876 void PropertyTrees::UpdateCachedNumber() {
1890 cached_data_.property_tree_update_number++; 1877 cached_data_.property_tree_update_number++;
1891 } 1878 }
1892 1879
1893 } // namespace cc 1880 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/property_tree.h ('k') | cc/trees/property_tree_builder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698