Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(285)

Side by Side Diff: include/core/SkRSXform.h

Issue 1269563006: add helper to create RSXform w/ anchorPt (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: don't post-translate by anchor Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | samplecode/SampleAtlas.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef SkRSXform_DEFINED 8 #ifndef SkRSXform_DEFINED
9 #define SkRSXform_DEFINED 9 #define SkRSXform_DEFINED
10 10
11 #include "SkScalar.h" 11 #include "SkScalar.h"
12 12
13 /** 13 /**
14 * A compressed form of a rotation+scale matrix. 14 * A compressed form of a rotation+scale matrix.
15 * 15 *
16 * [ fSCos -fSSin fTx ] 16 * [ fSCos -fSSin fTx ]
17 * [ fSSin fSCos fTy ] 17 * [ fSSin fSCos fTy ]
18 * [ 0 0 1 ] 18 * [ 0 0 1 ]
19 */ 19 */
20 struct SkRSXform { 20 struct SkRSXform {
21 SkScalar fSCos; 21 static SkRSXform Make(SkScalar scos, SkScalar ssin, SkScalar tx, SkScalar ty ) {
22 SkScalar fSSin; 22 SkRSXform xform = { scos, ssin, tx, ty };
23 SkScalar fTx; 23 return xform;
24 SkScalar fTy; 24 }
25
26 /*
27 * Initialize a new xform based on the scale, rotation (in radians), final tx,ty location
28 * and anchor-point ax,ay within the src quad.
29 *
30 * Note: the anchor point is not normalized (e.g. 0...1) but is in pixels o f the src image.
31 */
32 static SkRSXform MakeFromRadians(SkScalar scale, SkScalar radians, SkScalar tx, SkScalar ty,
33 SkScalar ax, SkScalar ay) {
34 const SkScalar s = SkScalarSin(radians) * scale;
35 const SkScalar c = SkScalarCos(radians) * scale;
36 return Make(c, s, tx + -c * ax + s * ay, ty + -s * ax - c * ay);
37 }
38
39 SkScalar fSCos;
40 SkScalar fSSin;
41 SkScalar fTx;
42 SkScalar fTy;
25 43
26 bool rectStaysRect() const { 44 bool rectStaysRect() const {
27 return 0 == fSCos || 0 == fSSin; 45 return 0 == fSCos || 0 == fSSin;
28 } 46 }
29 47
30 void setIdentity() { 48 void setIdentity() {
31 fSCos = 1; 49 fSCos = 1;
32 fSSin = fTx = fTy = 0; 50 fSSin = fTx = fTy = 0;
33 } 51 }
34 52
35 void set(SkScalar scos, SkScalar ssin, SkScalar tx, SkScalar ty) { 53 void set(SkScalar scos, SkScalar ssin, SkScalar tx, SkScalar ty) {
36 fSCos = scos; 54 fSCos = scos;
37 fSSin = ssin; 55 fSSin = ssin;
38 fTx = tx; 56 fTx = tx;
39 fTy = ty; 57 fTy = ty;
40 } 58 }
41 59
42 void toQuad(SkScalar width, SkScalar height, SkPoint quad[4]) const; 60 void toQuad(SkScalar width, SkScalar height, SkPoint quad[4]) const;
43 void toQuad(const SkSize& size, SkPoint quad[4]) const { 61 void toQuad(const SkSize& size, SkPoint quad[4]) const {
44 this->toQuad(size.width(), size.height(), quad); 62 this->toQuad(size.width(), size.height(), quad);
45 } 63 }
46 }; 64 };
47 65
48 #endif 66 #endif
49 67
OLDNEW
« no previous file with comments | « no previous file | samplecode/SampleAtlas.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698