| Index: cc/output/overlay_candidate.cc
|
| diff --git a/cc/output/overlay_candidate.cc b/cc/output/overlay_candidate.cc
|
| index 0cbd3deefa8de361f4b9273c8d705a8743d9445e..2261ae0b8b0cb0bcca5cb39293d51533e7ddccd2 100644
|
| --- a/cc/output/overlay_candidate.cc
|
| +++ b/cc/output/overlay_candidate.cc
|
| @@ -6,10 +6,33 @@
|
|
|
| #include <algorithm>
|
| #include "base/logging.h"
|
| +#include "cc/base/math_util.h"
|
| #include "ui/gfx/geometry/rect_conversions.h"
|
| +#include "ui/gfx/geometry/vector3d_f.h"
|
|
|
| namespace cc {
|
|
|
| +namespace {
|
| +// Tolerance for considering axis vector elements to be zero.
|
| +const SkMScalar kEpsilon = 1e-8f;
|
| +
|
| +enum Axis { NONE, AXIS_POS_X, AXIS_NEG_X, AXIS_POS_Y, AXIS_NEG_Y };
|
| +
|
| +Axis VectorToAxis(const gfx::Vector3dF& vec) {
|
| + if (std::abs(vec.z()) > kEpsilon)
|
| + return NONE;
|
| + const bool x_zero = (std::abs(vec.x()) <= kEpsilon);
|
| + const bool y_zero = (std::abs(vec.y()) <= kEpsilon);
|
| + if (x_zero && !y_zero)
|
| + return (vec.y() > 0) ? AXIS_POS_Y : AXIS_NEG_Y;
|
| + else if (y_zero && !x_zero)
|
| + return (vec.x() > 0) ? AXIS_POS_X : AXIS_NEG_X;
|
| + else
|
| + return NONE;
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| OverlayCandidate::OverlayCandidate()
|
| : transform(gfx::OVERLAY_TRANSFORM_NONE),
|
| format(RGBA_8888),
|
| @@ -23,12 +46,34 @@ OverlayCandidate::~OverlayCandidate() {}
|
| // static
|
| gfx::OverlayTransform OverlayCandidate::GetOverlayTransform(
|
| const gfx::Transform& quad_transform,
|
| - bool flipped) {
|
| - if (!quad_transform.IsPositiveScaleOrTranslation())
|
| + bool y_flipped) {
|
| + if (!quad_transform.Preserves2dAxisAlignment()) {
|
| return gfx::OVERLAY_TRANSFORM_INVALID;
|
| + }
|
| +
|
| + gfx::Vector3dF x_axis = MathUtil::GetXAxis(quad_transform);
|
| + gfx::Vector3dF y_axis = MathUtil::GetYAxis(quad_transform);
|
| + if (y_flipped) {
|
| + y_axis.Scale(-1);
|
| + }
|
|
|
| - return flipped ? gfx::OVERLAY_TRANSFORM_FLIP_VERTICAL
|
| - : gfx::OVERLAY_TRANSFORM_NONE;
|
| + Axis x_to = VectorToAxis(x_axis);
|
| + Axis y_to = VectorToAxis(y_axis);
|
| +
|
| + if (x_to == AXIS_POS_X && y_to == AXIS_POS_Y)
|
| + return gfx::OVERLAY_TRANSFORM_NONE;
|
| + else if (x_to == AXIS_NEG_X && y_to == AXIS_POS_Y)
|
| + return gfx::OVERLAY_TRANSFORM_FLIP_HORIZONTAL;
|
| + else if (x_to == AXIS_POS_X && y_to == AXIS_NEG_Y)
|
| + return gfx::OVERLAY_TRANSFORM_FLIP_VERTICAL;
|
| + else if (x_to == AXIS_NEG_Y && y_to == AXIS_POS_X)
|
| + return gfx::OVERLAY_TRANSFORM_ROTATE_270;
|
| + else if (x_to == AXIS_NEG_X && y_to == AXIS_NEG_Y)
|
| + return gfx::OVERLAY_TRANSFORM_ROTATE_180;
|
| + else if (x_to == AXIS_POS_Y && y_to == AXIS_NEG_X)
|
| + return gfx::OVERLAY_TRANSFORM_ROTATE_90;
|
| + else
|
| + return gfx::OVERLAY_TRANSFORM_INVALID;
|
| }
|
|
|
| // static
|
| @@ -131,7 +176,7 @@ gfx::OverlayTransform OverlayCandidate::ModifyTransform(
|
| gfx::RectF OverlayCandidate::GetOverlayRect(
|
| const gfx::Transform& quad_transform,
|
| const gfx::Rect& rect) {
|
| - DCHECK(quad_transform.IsPositiveScaleOrTranslation());
|
| + DCHECK(quad_transform.Preserves2dAxisAlignment());
|
|
|
| gfx::RectF float_rect(rect);
|
| quad_transform.TransformRect(&float_rect);
|
|
|