1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef UI_GFX_TRANSFORM_UTIL_H_
6 #define UI_GFX_TRANSFORM_UTIL_H_
8 #include "ui/gfx/gfx_export.h"
9 #include "ui/gfx/point.h"
10 #include "ui/gfx/transform.h"
17 // Returns a scale transform at |anchor| point.
18 GFX_EXPORT Transform
GetScaleTransform(const Point
& anchor
, float scale
);
20 // Contains the components of a factored transform. These components may be
21 // blended and recomposed.
22 struct GFX_EXPORT DecomposedTransform
{
23 // The default constructor initializes the components in such a way that
24 // if used with Compose below, will produce the identity transform.
25 DecomposedTransform();
27 SkMScalar translate
[3];
30 SkMScalar perspective
[4];
31 SkMScalar quaternion
[4];
33 std::string
ToString() const;
35 // Copy and assign are allowed.
38 // Interpolates the decomposed components |to| with |from| using the
39 // routines described in http://www.w3.org/TR/css3-3d-transform/.
40 // |progress| is in the range [0, 1] (0 leaves |out| unchanged, and 1
41 // assigns |from| to |out|).
42 GFX_EXPORT
bool BlendDecomposedTransforms(DecomposedTransform
* out
,
43 const DecomposedTransform
& to
,
44 const DecomposedTransform
& from
,
47 // Decomposes this transform into its translation, scale, skew, perspective,
48 // and rotation components following the routines detailed in this spec:
49 // http://www.w3.org/TR/css3-3d-transforms/.
50 GFX_EXPORT
bool DecomposeTransform(DecomposedTransform
* out
,
51 const Transform
& transform
);
53 // Composes a transform from the given translation, scale, skew, prespective,
54 // and rotation components following the routines detailed in this spec:
55 // http://www.w3.org/TR/css3-3d-transforms/.
56 GFX_EXPORT Transform
ComposeTransform(const DecomposedTransform
& decomp
);
58 GFX_EXPORT
bool SnapTransform(Transform
* out
,
59 const Transform
& transform
,
60 const Rect
& viewport
);
62 // Calculates a transform with a transformed origin. The resulting tranform is
63 // created by composing P * T * P^-1 where P is a constant transform to the new
65 GFX_EXPORT Transform
TransformAboutPivot(const gfx::Point
& pivot
,
66 const gfx::Transform
& transform
);
70 #endif // UI_GFX_TRANSFORM_UTIL_H_