| 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 |  | 
|---|
| 14 | /** | 
|---|
| 15 | *  A compressed form of a rotation+scale matrix. | 
|---|
| 16 | * | 
|---|
| 17 | *  [ fSCos     -fSSin    fTx ] | 
|---|
| 18 | *  [ fSSin      fSCos    fTy ] | 
|---|
| 19 | *  [     0          0      1 ] | 
|---|
| 20 | */ | 
|---|
| 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 | */ | 
|---|
| 33 | static SkRSXform MakeFromRadians(SkScalar scale, SkScalar radians, SkScalar tx, SkScalar ty, | 
|---|
| 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 |  | 
|---|
| 40 | SkScalar fSCos; | 
|---|
| 41 | SkScalar fSSin; | 
|---|
| 42 | SkScalar fTx; | 
|---|
| 43 | SkScalar fTy; | 
|---|
| 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 |  | 
|---|
| 70 |  | 
|---|