summaryrefslogtreecommitdiffstats
path: root/ui/gfx/compositor
diff options
context:
space:
mode:
Diffstat (limited to 'ui/gfx/compositor')
-rw-r--r--ui/gfx/compositor/compositor_gl.cc25
-rw-r--r--ui/gfx/compositor/compositor_win.cc25
-rw-r--r--ui/gfx/compositor/layer_animator.cc50
-rw-r--r--ui/gfx/compositor/layer_animator.h5
4 files changed, 46 insertions, 59 deletions
diff --git a/ui/gfx/compositor/compositor_gl.cc b/ui/gfx/compositor/compositor_gl.cc
index f8d9efb..d59d85f 100644
--- a/ui/gfx/compositor/compositor_gl.cc
+++ b/ui/gfx/compositor/compositor_gl.cc
@@ -279,30 +279,7 @@ void TextureGL::DrawInternal(const ui::TextureProgramGL& program,
t.ConcatScale(2.0f/window_size.width(), 2.0f/window_size.height());
GLfloat m[16];
- const SkMatrix& matrix = t.matrix();
-
- // Convert 3x3 view transform matrix (row major) into 4x4 GL matrix (column
- // major). Assume 2-D rotations/translations restricted to XY plane.
-
- m[ 0] = matrix[0];
- m[ 1] = matrix[3];
- m[ 2] = 0;
- m[ 3] = matrix[6];
-
- m[ 4] = matrix[1];
- m[ 5] = matrix[4];
- m[ 6] = 0;
- m[ 7] = matrix[7];
-
- m[ 8] = 0;
- m[ 9] = 0;
- m[10] = 1;
- m[11] = 0;
-
- m[12] = matrix[2];
- m[13] = matrix[5];
- m[14] = 0;
- m[15] = matrix[8];
+ t.matrix().asColMajorf(m);
static const GLfloat vertices[] = { -1., -1., +0., +0., +1.,
+1., -1., +0., +1., +1.,
diff --git a/ui/gfx/compositor/compositor_win.cc b/ui/gfx/compositor/compositor_win.cc
index 19b91b5..7518108 100644
--- a/ui/gfx/compositor/compositor_win.cc
+++ b/ui/gfx/compositor/compositor_win.cc
@@ -339,21 +339,15 @@ void CompositorWin::Init() {
void CompositorWin::UpdatePerspective(const ui::Transform& transform,
const gfx::Size& view_size) {
- // Apply transform from view.
- const SkMatrix& sk_matrix(transform.matrix());
- // Use -1 * kMTransY for y-translation as origin for views is upper left.
- D3DXMATRIX transform_matrix(
- // row 1
- sk_matrix[SkMatrix::kMScaleX], sk_matrix[SkMatrix::kMSkewX], 0.0f,
- sk_matrix[SkMatrix::kMPersp0],
- // row 2
- sk_matrix[SkMatrix::kMSkewY], sk_matrix[SkMatrix::kMScaleY], 0.0f,
- sk_matrix[SkMatrix::kMPersp1],
- // row 3
- 0.0f, 0.0f, 1.0f, sk_matrix[SkMatrix::kMPersp2],
- // row 4.
- sk_matrix[SkMatrix::kMTransX], -sk_matrix[SkMatrix::kMTransY], 0.0f,
- 1.0f);
+ float transform_data_buffer[16];
+ transform.matrix().asColMajorf(transform_data_buffer);
+ D3DXMATRIX transform_matrix(&transform_data_buffer[0]);
+ std::swap(transform_matrix._12, transform_matrix._21);
+ std::swap(transform_matrix._13, transform_matrix._31);
+ std::swap(transform_matrix._23, transform_matrix._32);
+
+ // Different coordinate system; flip the y.
+ transform_matrix._42 *= -1;
// Scale so x and y are from 0-2.
D3DXMATRIX scale_matrix;
@@ -380,6 +374,7 @@ void CompositorWin::UpdatePerspective(const ui::Transform& transform,
D3DXMATRIX wvp = transform_matrix * scale_matrix * translate_matrix * view *
projection_matrix;
+
fx_->GetVariableByName("gWVP")->AsMatrix()->SetMatrix(wvp);
}
diff --git a/ui/gfx/compositor/layer_animator.cc b/ui/gfx/compositor/layer_animator.cc
index 9122975..49b4440 100644
--- a/ui/gfx/compositor/layer_animator.cc
+++ b/ui/gfx/compositor/layer_animator.cc
@@ -13,6 +13,22 @@
#include "ui/gfx/transform.h"
#include "ui/gfx/rect.h"
+namespace {
+
+void SetMatrixElement(SkMatrix44& matrix, int index, SkMScalar value) {
+ int row = index / 4;
+ int col = index % 4;
+ matrix.set(row, col, value);
+}
+
+SkMScalar GetMatrixElement(const SkMatrix44& matrix, int index) {
+ int row = index / 4;
+ int col = index % 4;
+ return matrix.get(row, col);
+}
+
+} // anonymous namespace
+
namespace ui {
LayerAnimator::LayerAnimator(Layer* layer)
@@ -51,21 +67,15 @@ void LayerAnimator::AnimateToPoint(const gfx::Point& target) {
void LayerAnimator::AnimateTransform(const Transform& transform) {
StopAnimating(TRANSFORM);
const Transform& layer_transform = layer_->transform();
- bool all_equal = true;
- // TODO: replace with == when we Transform supports ==.
- for (int i = 0; i < 9; ++i) {
- if (transform.matrix()[i] != layer_transform.matrix()[i]) {
- all_equal = false;
- break;
- }
- }
- if (all_equal)
+ if (transform == layer_transform)
return; // Already there.
Element& element = elements_[TRANSFORM];
- for (int i = 0; i < 9; ++i) {
- element.params.transform.start[i] = layer_transform.matrix()[i];
- element.params.transform.target[i] = transform.matrix()[i];
+ for (int i = 0; i < 16; ++i) {
+ element.params.transform.start[i] =
+ GetMatrixElement(layer_transform.matrix(), i);
+ element.params.transform.target[i] =
+ GetMatrixElement(transform.matrix(), i);
}
element.animation = CreateAndStartAnimation();
}
@@ -90,10 +100,11 @@ void LayerAnimator::AnimationProgressed(const ui::Animation* animation) {
case TRANSFORM: {
Transform transform;
- for (int i = 0; i < 9; ++i) {
- transform.matrix()[i] = e->second.animation->CurrentValueBetween(
- e->second.params.transform.start[i],
- e->second.params.transform.target[i]);
+ for (int i = 0; i < 16; ++i) {
+ SkMScalar value = e->second.animation->CurrentValueBetween(
+ e->second.params.transform.start[i],
+ e->second.params.transform.target[i]);
+ SetMatrixElement(transform.matrix(), i, value);
}
layer_->set_transform(transform);
break;
@@ -121,8 +132,11 @@ void LayerAnimator::AnimationEnded(const ui::Animation* animation) {
case TRANSFORM: {
Transform transform;
- for (int i = 0; i < 9; ++i)
- transform.matrix()[i] = e->second.params.transform.target[i];
+ for (int i = 0; i < 16; ++i) {
+ SetMatrixElement(transform.matrix(),
+ i,
+ e->second.params.transform.target[i]);
+ }
layer_->set_transform(transform);
break;
}
diff --git a/ui/gfx/compositor/layer_animator.h b/ui/gfx/compositor/layer_animator.h
index da86766..c30ba87 100644
--- a/ui/gfx/compositor/layer_animator.h
+++ b/ui/gfx/compositor/layer_animator.h
@@ -11,6 +11,7 @@
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "third_party/skia/include/core/SkScalar.h"
+#include "third_party/skia/include/utils/SkMatrix44.h"
#include "ui/base/animation/animation_delegate.h"
#include "ui/base/animation/tween.h"
#include "ui/gfx/point.h"
@@ -68,8 +69,8 @@ class LayerAnimator : public ui::AnimationDelegate {
// Parameters used whe animating the transform.
struct TransformParams {
// TODO: make 4x4 whe Transform is updated.
- SkScalar start[9];
- SkScalar target[9];
+ SkMScalar start[16];
+ SkMScalar target[16];
};
union Params {