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

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: Address review comments Created 7 years, 10 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 b73419a2992adbb9d1ffed37fa47e3b26b48aba6..f2499ae42437789a244ab1bafd571bc84ad2f9b5 100644
--- a/ui/compositor/layer.cc
+++ b/ui/compositor/layer.cc
@@ -200,7 +200,7 @@ gfx::Transform Layer::GetTargetTransform() const {
LayerAnimationElement::TRANSFORM)) {
return animator_->GetTargetTransform();
}
- return transform_;
+ return transform();
}
void Layer::SetBounds(const gfx::Rect& bounds) {
@@ -410,6 +410,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;
@@ -449,6 +462,7 @@ void Layer::SetExternalTexture(Texture* texture) {
}
cc_layer_->removeLayerAnimationEventObserver(this);
new_layer->setOpacity(cc_layer_->opacity());
+ new_layer->setTransform(cc_layer_->transform());
cc_layer_= new_layer;
cc_layer_->addLayerAnimationEventObserver(this);
cc_layer_is_accelerated_ = layer_updated_externally_;
@@ -460,7 +474,6 @@ void Layer::SetExternalTexture(Texture* texture) {
cc_layer_->setContentsOpaque(fills_bounds_opaquely_);
cc_layer_->setForceRenderSurface(force_render_surface_);
cc_layer_->setIsDrawable(IsDrawn());
- RecomputeTransform();
}
RecomputeDrawsContentAndUVRect();
}
@@ -519,8 +532,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_)
@@ -641,9 +657,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();
@@ -660,9 +677,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) {
@@ -731,7 +746,7 @@ const gfx::Rect& Layer::GetBoundsForAnimation() const {
return bounds();
}
-const gfx::Transform& Layer::GetTransformForAnimation() const {
+gfx::Transform Layer::GetTransformForAnimation() const {
return transform();
}
@@ -759,6 +774,10 @@ SkColor Layer::GetColorForAnimation() const {
solid_color_layer_->backgroundColor() : SK_ColorBLACK;
}
+float Layer::GetDeviceScaleFactor() const {
+ return device_scale_factor_;
+}
+
void Layer::AddThreadedAnimation(scoped_ptr<cc::Animation> animation) {
DCHECK(cc_layer_);
cc_layer_->addAnimation(animation.Pass());
@@ -784,22 +803,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());
danakj 2013/02/19 16:19:31 This ordering is different from the inverse case.
+ 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