• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifndef UI_GFX_TRANSFORM_UTIL_H_
6 #define UI_GFX_TRANSFORM_UTIL_H_
7 
8 #include "ui/gfx/gfx_export.h"
9 #include "ui/gfx/transform.h"
10 
11 namespace gfx {
12 
13 class Point;
14 class Rect;
15 
16 // Returns a scale transform at |anchor| point.
17 GFX_EXPORT Transform GetScaleTransform(const Point& anchor, float scale);
18 
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();
25 
26   SkMScalar translate[3];
27   SkMScalar scale[3];
28   SkMScalar skew[3];
29   SkMScalar perspective[4];
30   SkMScalar quaternion[4];
31 
32   std::string ToString() const;
33 
34   // Copy and assign are allowed.
35 };
36 
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);
45 
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);
51 
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);
56 
57 GFX_EXPORT bool SnapTransform(Transform* out,
58                               const Transform& transform,
59                               const Rect& viewport);
60 
61 }  // namespace gfx
62 
63 #endif  // UI_GFX_TRANSFORM_UTIL_H_
64