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

Side by Side Diff: cc/layers/layer_utils.cc

Issue 295193002: Get rid of graphics layer anchor points, and replace with transform origin. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix nit. Created 6 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 | Annotate | Revision Log
« no previous file with comments | « cc/layers/layer_unittest.cc ('k') | cc/layers/layer_utils_unittest.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 "cc/layers/layer_utils.h" 5 #include "cc/layers/layer_utils.h"
6 6
7 #include "cc/layers/layer_impl.h" 7 #include "cc/layers/layer_impl.h"
8 #include "cc/trees/layer_tree_host_common.h" 8 #include "cc/trees/layer_tree_host_common.h"
9 #include "ui/gfx/box_f.h" 9 #include "ui/gfx/box_f.h"
10 10
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 68
69 // We want to inflate/transform the box as few times as possible. Each time 69 // We want to inflate/transform the box as few times as possible. Each time
70 // we do this, we have to make the box axis aligned again, so if we make many 70 // we do this, we have to make the box axis aligned again, so if we make many
71 // small adjustments to the box by transforming it repeatedly rather than 71 // small adjustments to the box by transforming it repeatedly rather than
72 // once by the product of all these matrices, we will accumulate a bunch of 72 // once by the product of all these matrices, we will accumulate a bunch of
73 // unnecessary inflation because of the the many axis-alignment fixes. This 73 // unnecessary inflation because of the the many axis-alignment fixes. This
74 // matrix stores said product. 74 // matrix stores said product.
75 gfx::Transform coalesced_transform; 75 gfx::Transform coalesced_transform;
76 76
77 for (const LayerImpl* layer = &layer_in; layer; layer = layer->parent()) { 77 for (const LayerImpl* layer = &layer_in; layer; layer = layer->parent()) {
78 int anchor_x = layer->anchor_point().x() * layer->bounds().width(); 78 int transform_origin_x = layer->transform_origin().x();
79 int anchor_y = layer->anchor_point().y() * layer->bounds().height(); 79 int transform_origin_y = layer->transform_origin().y();
80 int transform_origin_z = layer->transform_origin().z();
81
80 gfx::PointF position = layer->position(); 82 gfx::PointF position = layer->position();
81 if (layer->parent() && !HasAnimationThatInflatesBounds(*layer)) { 83 if (layer->parent() && !HasAnimationThatInflatesBounds(*layer)) {
82 // |composite_layer_transform| contains 1 - 4 mentioned above. We compute 84 // |composite_layer_transform| contains 1 - 4 mentioned above. We compute
83 // it separately and apply afterwards because it's a bit more efficient 85 // it separately and apply afterwards because it's a bit more efficient
84 // because post-multiplication appears a bit more expensive, so we want 86 // because post-multiplication appears a bit more expensive, so we want
85 // to do it only once. 87 // to do it only once.
86 gfx::Transform composite_layer_transform; 88 gfx::Transform composite_layer_transform;
87 89
88 composite_layer_transform.Translate3d(anchor_x + position.x(), 90 composite_layer_transform.Translate3d(transform_origin_x + position.x(),
89 anchor_y + position.y(), 91 transform_origin_y + position.y(),
90 layer->anchor_point_z()); 92 transform_origin_z);
91 composite_layer_transform.PreconcatTransform(layer->transform()); 93 composite_layer_transform.PreconcatTransform(layer->transform());
92 composite_layer_transform.Translate3d( 94 composite_layer_transform.Translate3d(
93 -anchor_x, -anchor_y, -layer->anchor_point_z()); 95 -transform_origin_x, -transform_origin_y, -transform_origin_z);
94 96
95 // Add this layer's contributions to the |coalesced_transform|. 97 // Add this layer's contributions to the |coalesced_transform|.
96 coalesced_transform.ConcatTransform(composite_layer_transform); 98 coalesced_transform.ConcatTransform(composite_layer_transform);
97 continue; 99 continue;
98 } 100 }
99 101
100 // First, apply coalesced transform we've been building and reset it. 102 // First, apply coalesced transform we've been building and reset it.
101 coalesced_transform.TransformBox(&box); 103 coalesced_transform.TransformBox(&box);
102 coalesced_transform.MakeIdentity(); 104 coalesced_transform.MakeIdentity();
103 105
104 // We need to apply the inflation about the layer's anchor point. Rather 106 // We need to apply the inflation about the layer's anchor point. Rather
105 // than doing this via transforms, we'll just shift the box directly. 107 // than doing this via transforms, we'll just shift the box directly.
106 box.set_origin(box.origin() + gfx::Vector3dF(-anchor_x, 108 box.set_origin(box.origin() + gfx::Vector3dF(-transform_origin_x,
107 -anchor_y, 109 -transform_origin_y,
108 -layer->anchor_point_z())); 110 -transform_origin_z));
109 111
110 // Perform the inflation 112 // Perform the inflation
111 if (HasFilterAnimationThatInflatesBounds(*layer)) { 113 if (HasFilterAnimationThatInflatesBounds(*layer)) {
112 gfx::BoxF inflated; 114 gfx::BoxF inflated;
113 if (!layer->layer_animation_controller()->FilterAnimationBoundsForBox( 115 if (!layer->layer_animation_controller()->FilterAnimationBoundsForBox(
114 box, &inflated)) 116 box, &inflated))
115 return false; 117 return false;
116 box = inflated; 118 box = inflated;
117 } 119 }
118 120
119 if (HasTransformAnimationThatInflatesBounds(*layer)) { 121 if (HasTransformAnimationThatInflatesBounds(*layer)) {
120 gfx::BoxF inflated; 122 gfx::BoxF inflated;
121 if (!layer->layer_animation_controller()->TransformAnimationBoundsForBox( 123 if (!layer->layer_animation_controller()->TransformAnimationBoundsForBox(
122 box, &inflated)) 124 box, &inflated))
123 return false; 125 return false;
124 box = inflated; 126 box = inflated;
125 } 127 }
126 128
127 // Apply step 3) mentioned above. 129 // Apply step 3) mentioned above.
128 box.set_origin(box.origin() + gfx::Vector3dF(anchor_x + position.x(), 130 box.set_origin(box.origin() +
129 anchor_y + position.y(), 131 gfx::Vector3dF(transform_origin_x + position.x(),
130 layer->anchor_point_z())); 132 transform_origin_y + position.y(),
133 transform_origin_z));
131 } 134 }
132 135
133 // If we've got an unapplied coalesced transform at this point, it must still 136 // If we've got an unapplied coalesced transform at this point, it must still
134 // be applied. 137 // be applied.
135 if (!coalesced_transform.IsIdentity()) 138 if (!coalesced_transform.IsIdentity())
136 coalesced_transform.TransformBox(&box); 139 coalesced_transform.TransformBox(&box);
137 140
138 *out = box; 141 *out = box;
139 142
140 return true; 143 return true;
141 } 144 }
142 145
143 } // namespace cc 146 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/layer_unittest.cc ('k') | cc/layers/layer_utils_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698