Skia
2D Graphics Library
SkRSXform.h
Go to the documentation of this file.
1 /*
2  * Copyright 2015 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #ifndef SkRSXform_DEFINED
9 #define SkRSXform_DEFINED
10 
11 #include "include/core/SkPoint.h"
12 #include "include/core/SkSize.h"
13 
21 struct SkRSXform {
22  static SkRSXform Make(SkScalar scos, SkScalar ssin, SkScalar tx, SkScalar ty) {
23  SkRSXform xform = { scos, ssin, tx, ty };
24  return xform;
25  }
26 
27  /*
28  * Initialize a new xform based on the scale, rotation (in radians), final tx,ty location
29  * and anchor-point ax,ay within the src quad.
30  *
31  * Note: the anchor point is not normalized (e.g. 0...1) but is in pixels of the src image.
32  */
34  SkScalar ax, SkScalar ay) {
35  const SkScalar s = SkScalarSin(radians) * scale;
36  const SkScalar c = SkScalarCos(radians) * scale;
37  return Make(c, s, tx + -c * ax + s * ay, ty + -s * ax - c * ay);
38  }
39 
44 
45  bool rectStaysRect() const {
46  return 0 == fSCos || 0 == fSSin;
47  }
48 
49  void setIdentity() {
50  fSCos = 1;
51  fSSin = fTx = fTy = 0;
52  }
53 
54  void set(SkScalar scos, SkScalar ssin, SkScalar tx, SkScalar ty) {
55  fSCos = scos;
56  fSSin = ssin;
57  fTx = tx;
58  fTy = ty;
59  }
60 
61  void toQuad(SkScalar width, SkScalar height, SkPoint quad[4]) const;
62  void toQuad(const SkSize& size, SkPoint quad[4]) const {
63  this->toQuad(size.width(), size.height(), quad);
64  }
65  void toTriStrip(SkScalar width, SkScalar height, SkPoint strip[4]) const;
66 };
67 
68 #endif
69 
SkSize.h
SkRSXform
A compressed form of a rotation+scale matrix.
Definition: SkRSXform.h:21
SkRSXform::fTy
SkScalar fTy
Definition: SkRSXform.h:43
SkRSXform::toQuad
void toQuad(SkScalar width, SkScalar height, SkPoint quad[4]) const
SkRSXform::rectStaysRect
bool rectStaysRect() const
Definition: SkRSXform.h:45
SkRSXform::setIdentity
void setIdentity()
Definition: SkRSXform.h:49
SkRSXform::MakeFromRadians
static SkRSXform MakeFromRadians(SkScalar scale, SkScalar radians, SkScalar tx, SkScalar ty, SkScalar ax, SkScalar ay)
Definition: SkRSXform.h:33
SkPoint
Definition: SkPoint.h:160
SkRSXform::fSSin
SkScalar fSSin
Definition: SkRSXform.h:41
SkRSXform::toQuad
void toQuad(const SkSize &size, SkPoint quad[4]) const
Definition: SkRSXform.h:62
SkSize
Definition: SkSize.h:49
SkPoint.h
SkRSXform::set
void set(SkScalar scos, SkScalar ssin, SkScalar tx, SkScalar ty)
Definition: SkRSXform.h:54
SkScalar
float SkScalar
Definition: SkScalar.h:16
SkRSXform::fTx
SkScalar fTx
Definition: SkRSXform.h:42
SkRSXform::toTriStrip
void toTriStrip(SkScalar width, SkScalar height, SkPoint strip[4]) const
SkScalarCos
#define SkScalarCos(radians)
Definition: SkScalar.h:45
SkSize::width
SkScalar width() const
Definition: SkSize.h:73
SkRSXform::Make
static SkRSXform Make(SkScalar scos, SkScalar ssin, SkScalar tx, SkScalar ty)
Definition: SkRSXform.h:22
SkRSXform::fSCos
SkScalar fSCos
Definition: SkRSXform.h:40
SkScalarSin
#define SkScalarSin(radians)
Definition: SkScalar.h:44
SkSize::height
SkScalar height() const
Definition: SkSize.h:74