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

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: 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..118d578a987800de66048cf51a00b6e66302e5b2 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,28 @@ 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 scale_translate;
+ scale_translate.matrix().set3x3(device_scale_factor, 0, 0,
danakj 2013/02/16 04:49:51 Why do you use temporary gfx::Transforms for scali
ajuma 2013/02/19 16:12:19 Fixed now.
+ 0, device_scale_factor, 0,
+ 0, 0, 1);
+ // Start with the inverse matrix of above.
+ gfx::Transform cc_transform;
+ cc_transform.matrix().set3x3(1.0f / device_scale_factor, 0, 0,
+ 0, 1.0f / device_scale_factor, 0,
+ 0, 0, 1);
+ cc_transform.ConcatTransform(transform);
+ gfx::Transform translate;
+ translate.Translate(bounds.x(), bounds.y());
+ cc_transform.ConcatTransform(translate);
+ cc_transform.ConcatTransform(scale_translate);
+ return cc_transform;
+}
+
void Layer::SetFillsBoundsOpaquely(bool fills_bounds_opaquely) {
if (fills_bounds_opaquely_ == fills_bounds_opaquely)
return;
@@ -449,6 +471,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 +483,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 +541,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 +666,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 +686,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 +755,7 @@ const gfx::Rect& Layer::GetBoundsForAnimation() const {
return bounds();
}
-const gfx::Transform& Layer::GetTransformForAnimation() const {
+gfx::Transform Layer::GetTransformForAnimation() const {
return transform();
}
@@ -759,6 +783,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 +812,28 @@ 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);
+void Layer::RecomputeCCTransformFromTransform(const gfx::Transform& transform) {
+ cc_layer_->setTransform(ConvertTransformToCCTransform(transform,
+ bounds_,
+ device_scale_factor_));
+}
+
+gfx::Transform Layer::transform() const {
+ gfx::Transform inverse_scale;
+ inverse_scale.matrix().set3x3(1.0f / device_scale_factor_, 0, 0,
danakj 2013/02/16 04:49:51 Here you can use Scale() and Translate() as well i
ajuma 2013/02/19 16:12:19 Done.
+ 0, 1.0f / device_scale_factor_, 0,
+ 0, 0, 1);
// Start with the inverse matrix of above.
gfx::Transform transform;
- transform.matrix().set3x3(1.0f / device_scale_factor_, 0, 0,
- 0, 1.0f / device_scale_factor_, 0,
+ transform.matrix().set3x3(device_scale_factor_, 0, 0,
+ 0, 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.ConcatTransform(cc_layer_->transform());
+ transform.ConcatTransform(inverse_scale);
+ gfx::Transform inverse_translate;
+ inverse_translate.Translate(-bounds_.x(), -bounds_.y());
+ transform.ConcatTransform(inverse_translate);
+ 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