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 SK_API 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 
#define SkScalarSin(radians)
Definition: SkScalar.h:43
#define SkScalarCos(radians)
Definition: SkScalar.h:44
float SkScalar
Definition: SkScalar.h:14
sk_sp< SkDrawLooper > SK_API Make(SkColor4f color, SkColorSpace *cs, SkScalar sigma, SkScalar dx, SkScalar dy)
A compressed form of a rotation+scale matrix.
Definition: SkRSXform.h:21
void setIdentity()
Definition: SkRSXform.h:49
SkScalar fTy
Definition: SkRSXform.h:43
SkScalar fSCos
Definition: SkRSXform.h:40
void toQuad(SkScalar width, SkScalar height, SkPoint quad[4]) const
void set(SkScalar scos, SkScalar ssin, SkScalar tx, SkScalar ty)
Definition: SkRSXform.h:54
void toTriStrip(SkScalar width, SkScalar height, SkPoint strip[4]) const
static SkRSXform Make(SkScalar scos, SkScalar ssin, SkScalar tx, SkScalar ty)
Definition: SkRSXform.h:22
bool rectStaysRect() const
Definition: SkRSXform.h:45
static SkRSXform MakeFromRadians(SkScalar scale, SkScalar radians, SkScalar tx, SkScalar ty, SkScalar ax, SkScalar ay)
Definition: SkRSXform.h:33
void toQuad(const SkSize &size, SkPoint quad[4]) const
Definition: SkRSXform.h:62
SkScalar fTx
Definition: SkRSXform.h:42
SkScalar fSSin
Definition: SkRSXform.h:41
Definition: SkSize.h:51
SkScalar width() const
Definition: SkSize.h:75
SkScalar height() const
Definition: SkSize.h:76