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

Unified Diff: ui/compositor/layer.cc

Issue 12226080: Thread ui transform animations (Closed) Base URL: http://git.chromium.org/chromium/src.git@DefineThreadedLayerAnimationElements
Patch Set: Speed up animations in WebContentsViewAuraTest.QuickOverscrollDirectionChange Created 7 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/compositor/layer.h ('k') | ui/compositor/layer_animation_delegate.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/compositor/layer.cc
diff --git a/ui/compositor/layer.cc b/ui/compositor/layer.cc
index 2ace412653bb46e840399748d357830b02651fea..cc4b70423e7b3ef12a1cdcadafd23a50bda6f050 100644
--- a/ui/compositor/layer.cc
+++ b/ui/compositor/layer.cc
@@ -208,7 +208,7 @@ gfx::Transform Layer::GetTargetTransform() const {
LayerAnimationElement::TRANSFORM)) {
return animator_->GetTargetTransform();
}
- return transform_;
+ return transform();
}
void Layer::SetBounds(const gfx::Rect& bounds) {
@@ -418,6 +418,19 @@ void Layer::ConvertPointToLayer(const Layer* source,
target->ConvertPointFromAncestor(root_layer, point);
}
+// static
+gfx::Transform Layer::ConvertTransformToCCTransform(
+ const gfx::Transform& transform,
+ const gfx::Rect& bounds,
+ float device_scale_factor) {
+ gfx::Transform cc_transform;
+ cc_transform.Scale(device_scale_factor, device_scale_factor);
+ cc_transform.Translate(bounds.x(), bounds.y());
+ cc_transform.PreconcatTransform(transform);
+ cc_transform.Scale(1.0f / device_scale_factor, 1.0f / device_scale_factor);
+ return cc_transform;
+}
+
void Layer::SetFillsBoundsOpaquely(bool fills_bounds_opaquely) {
if (fills_bounds_opaquely_ == fills_bounds_opaquely)
return;
@@ -439,6 +452,7 @@ void Layer::SwitchToLayer(scoped_refptr<cc::Layer> new_layer) {
}
cc_layer_->RemoveLayerAnimationEventObserver(this);
new_layer->SetOpacity(cc_layer_->opacity());
+ new_layer->SetTransform(cc_layer_->transform());
cc_layer_= new_layer;
content_layer_ = NULL;
@@ -477,7 +491,6 @@ void Layer::SetExternalTexture(Texture* texture) {
SwitchToLayer(new_layer);
content_layer_ = new_layer;
}
- RecomputeTransform();
}
RecomputeDrawsContentAndUVRect();
}
@@ -500,7 +513,6 @@ void Layer::SetDelegatedFrame(scoped_ptr<cc::DelegatedFrameData> frame,
SwitchToLayer(new_layer);
content_layer_ = new_layer;
}
- RecomputeTransform();
}
if (has_frame)
delegated_renderer_layer_->SetFrameData(frame.Pass());
@@ -567,8 +579,11 @@ void Layer::SuppressPaint() {
void Layer::OnDeviceScaleFactorChanged(float device_scale_factor) {
if (device_scale_factor_ == device_scale_factor)
return;
+ if (animator_)
+ animator_->StopAnimatingProperty(LayerAnimationElement::TRANSFORM);
+ gfx::Transform transform = this->transform();
device_scale_factor_ = device_scale_factor;
- RecomputeTransform();
+ RecomputeCCTransformFromTransform(transform);
RecomputeDrawsContentAndUVRect();
SchedulePaint(gfx::Rect(bounds_.size()));
if (delegate_)
@@ -689,9 +704,10 @@ void Layer::SetBoundsImmediately(const gfx::Rect& bounds) {
if (delegate_)
closure = delegate_->PrepareForLayerBoundsChange();
bool was_move = bounds_.size() == bounds.size();
+ gfx::Transform transform = this->transform();
bounds_ = bounds;
- RecomputeTransform();
+ RecomputeCCTransformFromTransform(transform);
RecomputeDrawsContentAndUVRect();
if (!closure.is_null())
closure.Run();
@@ -708,9 +724,7 @@ void Layer::SetBoundsImmediately(const gfx::Rect& bounds) {
}
void Layer::SetTransformImmediately(const gfx::Transform& transform) {
- transform_ = transform;
-
- RecomputeTransform();
+ RecomputeCCTransformFromTransform(transform);
}
void Layer::SetOpacityImmediately(float opacity) {
@@ -779,7 +793,7 @@ const gfx::Rect& Layer::GetBoundsForAnimation() const {
return bounds();
}
-const gfx::Transform& Layer::GetTransformForAnimation() const {
+gfx::Transform Layer::GetTransformForAnimation() const {
return transform();
}
@@ -807,6 +821,10 @@ SkColor Layer::GetColorForAnimation() const {
solid_color_layer_->background_color() : SK_ColorBLACK;
}
+float Layer::GetDeviceScaleFactor() const {
+ return device_scale_factor_;
+}
+
void Layer::AddThreadedAnimation(scoped_ptr<cc::Animation> animation) {
DCHECK(cc_layer_);
// Until this layer has a compositor (and hence cc_layer_ has a
@@ -875,22 +893,19 @@ void Layer::CreateWebLayer() {
cc_layer_->AddLayerAnimationEventObserver(this);
}
-void Layer::RecomputeTransform() {
- gfx::Transform scale_translate;
- scale_translate.matrix().set3x3(device_scale_factor_, 0, 0,
- 0, device_scale_factor_, 0,
- 0, 0, 1);
- // Start with the inverse matrix of above.
+void Layer::RecomputeCCTransformFromTransform(const gfx::Transform& transform) {
+ cc_layer_->SetTransform(ConvertTransformToCCTransform(transform,
+ bounds_,
+ device_scale_factor_));
+}
+
+gfx::Transform Layer::transform() const {
gfx::Transform transform;
- transform.matrix().set3x3(1.0f / device_scale_factor_, 0, 0,
- 0, 1.0f / device_scale_factor_, 0,
- 0, 0, 1);
- transform.ConcatTransform(transform_);
- gfx::Transform translate;
- translate.Translate(bounds_.x(), bounds_.y());
- transform.ConcatTransform(translate);
- transform.ConcatTransform(scale_translate);
- cc_layer_->SetTransform(transform);
+ transform.Translate(-bounds_.x(), -bounds_.y());
+ transform.Scale(1.0f / device_scale_factor_, 1.0f / device_scale_factor_);
+ transform.PreconcatTransform(cc_layer_->transform());
+ transform.Scale(device_scale_factor_, device_scale_factor_);
+ return transform;
}
void Layer::RecomputeDrawsContentAndUVRect() {
« no previous file with comments | « ui/compositor/layer.h ('k') | ui/compositor/layer_animation_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698