Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / ui / gfx / transform_util.h
bloba77ded28f73c5021d75f97fd92708dc69d550ca4
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/transform.h"
11 namespace gfx {
13 class Point;
14 class Rect;
16 // Returns a scale transform at |anchor| point.
17 GFX_EXPORT Transform GetScaleTransform(const Point& anchor, float scale);
19 // Contains the components of a factored transform. These components may be
20 // blended and recomposed.
21 struct GFX_EXPORT DecomposedTransform {
22 // The default constructor initializes the components in such a way that
23 // if used with Compose below, will produce the identity transform.
24 DecomposedTransform();
26 SkMScalar translate[3];
27 SkMScalar scale[3];
28 SkMScalar skew[3];
29 SkMScalar perspective[4];
30 SkMScalar quaternion[4];
32 std::string ToString() const;
34 // Copy and assign are allowed.
37 // Interpolates the decomposed components |to| with |from| using the
38 // routines described in http://www.w3.org/TR/css3-3d-transform/.
39 // |progress| is in the range [0, 1] (0 leaves |out| unchanged, and 1
40 // assigns |from| to |out|).
41 GFX_EXPORT bool BlendDecomposedTransforms(DecomposedTransform* out,
42 const DecomposedTransform& to,
43 const DecomposedTransform& from,
44 double progress);
46 // Decomposes this transform into its translation, scale, skew, perspective,
47 // and rotation components following the routines detailed in this spec:
48 // http://www.w3.org/TR/css3-3d-transforms/.
49 GFX_EXPORT bool DecomposeTransform(DecomposedTransform* out,
50 const Transform& transform);
52 // Composes a transform from the given translation, scale, skew, prespective,
53 // and rotation components following the routines detailed in this spec:
54 // http://www.w3.org/TR/css3-3d-transforms/.
55 GFX_EXPORT Transform ComposeTransform(const DecomposedTransform& decomp);
57 GFX_EXPORT bool SnapTransform(Transform* out,
58 const Transform& transform,
59 const Rect& viewport);
61 } // namespace gfx
63 #endif // UI_GFX_TRANSFORM_UTIL_H_