blob: 2f72cbf4a4a01b630d58e0ffd032915df34b04cd [file] [log] [blame]
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/quaternion.h"
#include "ui/gfx/geometry_skia_export.h"
#include "ui/gfx/transform.h"
namespace gfx {
class Point;
class Rect;
// Returns a scale transform at |anchor| point.
GEOMETRY_SKIA_EXPORT Transform GetScaleTransform(const Point& anchor,
float scale);
// Contains the components of a factored transform. These components may be
// blended and recomposed.
struct GEOMETRY_SKIA_EXPORT DecomposedTransform {
// The default constructor initializes the components in such a way that
// if used with Compose below, will produce the identity transform.
SkMScalar translate[3];
SkMScalar scale[3];
SkMScalar skew[3];
SkMScalar perspective[4];
Quaternion quaternion;
std::string ToString() const;
// Copy and assign are allowed.
// Interpolates the decomposed components |to| with |from| using the
// routines described in
// |progress| is in the range [0, 1]. If 0 we will return |from|, if 1, we will
// return |to|.
GEOMETRY_SKIA_EXPORT DecomposedTransform
BlendDecomposedTransforms(const DecomposedTransform& to,
const DecomposedTransform& from,
double progress);
// Decomposes this transform into its translation, scale, skew, perspective,
// and rotation components following the routines detailed in this spec:
GEOMETRY_SKIA_EXPORT bool DecomposeTransform(DecomposedTransform* out,
const Transform& transform);
// Composes a transform from the given translation, scale, skew, prespective,
// and rotation components following the routines detailed in this spec:
ComposeTransform(const DecomposedTransform& decomp);
GEOMETRY_SKIA_EXPORT bool SnapTransform(Transform* out,
const Transform& transform,
const Rect& viewport);
// Calculates a transform with a transformed origin. The resulting tranform is
// created by composing P * T * P^-1 where P is a constant transform to the new
// origin.
TransformAboutPivot(const gfx::Point& pivot, const gfx::Transform& transform);
} // namespace gfx