| Index: ui/gfx/transform.cc
|
| diff --git a/ui/gfx/transform.cc b/ui/gfx/transform.cc
|
| index 03e2873d27c5ca1e795c3d4c5049854bf87c0c42..86c4b1bdc78dc8d5a049c89c268c492261874030 100644
|
| --- a/ui/gfx/transform.cc
|
| +++ b/ui/gfx/transform.cc
|
| @@ -3,9 +3,6 @@
|
| // found in the LICENSE file.
|
|
|
| #include "ui/gfx/transform.h"
|
| -
|
| -#include <cmath>
|
| -
|
| #include "ui/gfx/point.h"
|
| #include "ui/gfx/rect.h"
|
| #include "ui/gfx/skia_util.h"
|
| @@ -19,93 +16,101 @@ Transform::Transform() {
|
| Transform::~Transform() {}
|
|
|
| void Transform::SetRotate(float degree) {
|
| - matrix_.setRotate(SkFloatToScalar(degree));
|
| + matrix_.setRotateDegreesAbout(0, 0, 1, SkFloatToScalar(degree));
|
| }
|
|
|
| void Transform::SetScaleX(float x) {
|
| - matrix_.setScaleX(SkFloatToScalar(x));
|
| + matrix_.setScale(
|
| + SkFloatToScalar(x),
|
| + matrix_.get(1,1),
|
| + matrix_.get(2,2));
|
| }
|
|
|
| void Transform::SetScaleY(float y) {
|
| - matrix_.setScaleY(SkFloatToScalar(y));
|
| + matrix_.setScale(
|
| + matrix_.get(0,0),
|
| + SkFloatToScalar(y),
|
| + matrix_.get(2,2));
|
| }
|
|
|
| void Transform::SetScale(float x, float y) {
|
| - matrix_.setScale(SkFloatToScalar(x), SkFloatToScalar(y));
|
| + matrix_.setScale(
|
| + SkFloatToScalar(x),
|
| + SkFloatToScalar(y),
|
| + matrix_.get(2, 2));
|
| }
|
|
|
| void Transform::SetTranslateX(float x) {
|
| - matrix_.setTranslateX(SkFloatToScalar(x));
|
| + matrix_.setTranslate(
|
| + SkFloatToScalar(x),
|
| + matrix_.get(1,3),
|
| + matrix_.get(2,3));
|
| }
|
|
|
| void Transform::SetTranslateY(float y) {
|
| - matrix_.setTranslateY(SkFloatToScalar(y));
|
| + matrix_.setTranslate(
|
| + matrix_.get(0,3),
|
| + SkFloatToScalar(y),
|
| + matrix_.get(2,3));
|
| }
|
|
|
| void Transform::SetTranslate(float x, float y) {
|
| - matrix_.setTranslate(SkFloatToScalar(x), SkFloatToScalar(y));
|
| + matrix_.setTranslate(
|
| + SkFloatToScalar(x),
|
| + SkFloatToScalar(y),
|
| + matrix_.get(2, 3));
|
| }
|
|
|
| void Transform::ConcatRotate(float degree) {
|
| - matrix_.postRotate(SkFloatToScalar(degree));
|
| + SkMatrix44 rot;
|
| + rot.setRotateDegreesAbout(0, 0, 1, SkFloatToScalar(degree));
|
| + matrix_.postConcat(rot);
|
| }
|
|
|
| void Transform::ConcatScale(float x, float y) {
|
| - matrix_.postScale(SkFloatToScalar(x), SkFloatToScalar(y));
|
| + SkMatrix44 scale;
|
| + scale.setScale(SkFloatToScalar(x), SkFloatToScalar(y), 1);
|
| + matrix_.postConcat(scale);
|
| }
|
|
|
| void Transform::ConcatTranslate(float x, float y) {
|
| - matrix_.postTranslate(SkFloatToScalar(x), SkFloatToScalar(y));
|
| + SkMatrix44 translate;
|
| + translate.setTranslate(SkFloatToScalar(x), SkFloatToScalar(y), 0);
|
| + matrix_.postConcat(translate);
|
| }
|
|
|
| -bool Transform::PreconcatTransform(const Transform& transform) {
|
| - return matrix_.setConcat(matrix_, transform.matrix_);
|
| +void Transform::PreconcatTransform(const Transform& transform) {
|
| + if (!transform.matrix_.isIdentity()) {
|
| + matrix_.preConcat(transform.matrix_);
|
| + }
|
| }
|
|
|
| -bool Transform::ConcatTransform(const Transform& transform) {
|
| - return matrix_.setConcat(transform.matrix_, matrix_);
|
| +void Transform::ConcatTransform(const Transform& transform) {
|
| + if (!transform.matrix_.isIdentity()) {
|
| + matrix_.postConcat(transform.matrix_);
|
| + }
|
| }
|
|
|
| bool Transform::HasChange() const {
|
| return !matrix_.isIdentity();
|
| }
|
|
|
| -bool Transform::TransformPoint(gfx::Point* point) {
|
| - SkPoint skp;
|
| - matrix_.mapXY(SkIntToScalar(point->x()), SkIntToScalar(point->y()), &skp);
|
| - point->SetPoint(static_cast<int>(std::floor(skp.fX)),
|
| - static_cast<int>(std::floor(skp.fY)));
|
| - return true;
|
| -}
|
| -
|
| -bool Transform::TransformPointReverse(gfx::Point* point) {
|
| - SkMatrix inverse;
|
| - // TODO(sad): Try to avoid trying to invert the matrix.
|
| - if (matrix_.invert(&inverse)) {
|
| - SkPoint skp;
|
| - inverse.mapXY(SkIntToScalar(point->x()), SkIntToScalar(point->y()), &skp);
|
| - point->SetPoint(static_cast<int>(std::floor(skp.fX)),
|
| - static_cast<int>(std::floor(skp.fY)));
|
| - return true;
|
| - }
|
| - return false;
|
| -}
|
| -
|
| -bool Transform::TransformRect(gfx::Rect* rect) {
|
| +bool Transform::TransformRect(gfx::Rect* rect) const {
|
| SkRect src = gfx::RectToSkRect(*rect);
|
| - if (!matrix_.mapRect(&src))
|
| + const SkMatrix& matrix = matrix_;
|
| + if (!matrix.mapRect(&src))
|
| return false;
|
| *rect = gfx::SkRectToRect(src);
|
| return true;
|
| }
|
|
|
| -bool Transform::TransformRectReverse(gfx::Rect* rect) {
|
| - SkMatrix inverse;
|
| +bool Transform::TransformRectReverse(gfx::Rect* rect) const {
|
| + SkMatrix44 inverse;
|
| if (!matrix_.invert(&inverse))
|
| return false;
|
| -
|
| + const SkMatrix& matrix = inverse;
|
| SkRect src = gfx::RectToSkRect(*rect);
|
| - if (!inverse.mapRect(&src))
|
| + if (!matrix.mapRect(&src))
|
| return false;
|
| *rect = gfx::SkRectToRect(src);
|
| return true;
|
|
|