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

Side by Side Diff: samplecode/SampleAtlas.cpp

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 | « include/core/SkRSXform.h ('k') | no next file » | 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 #include "SampleCode.h" 8 #include "SampleCode.h"
9 #include "SkAnimTimer.h" 9 #include "SkAnimTimer.h"
10 #include "SkView.h" 10 #include "SkView.h"
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 if (fAlpha > 1) { 89 if (fAlpha > 1) {
90 fAlpha = 1; 90 fAlpha = 1;
91 fDAlpha = -fDAlpha; 91 fDAlpha = -fDAlpha;
92 } else if (fAlpha < 0) { 92 } else if (fAlpha < 0) {
93 fAlpha = 0; 93 fAlpha = 0;
94 fDAlpha = -fDAlpha; 94 fDAlpha = -fDAlpha;
95 } 95 }
96 } 96 }
97 97
98 SkRSXform asRSXform() const { 98 SkRSXform asRSXform() const {
99 SkMatrix m; 99 return SkRSXform::MakeFromRadians(fScale, fRadian, fCenter.x(), fCen ter.y(),
100 m.setTranslate(-8, -8); 100 SkScalarHalf(kCellSize), SkScalarH alf(kCellSize));
101 m.postScale(fScale, fScale);
102 m.postRotate(SkRadiansToDegrees(fRadian));
103 m.postTranslate(fCenter.fX, fCenter.fY);
104
105 SkRSXform x;
106 x.fSCos = m.getScaleX();
107 x.fSSin = m.getSkewY();
108 x.fTx = m.getTranslateX();
109 x.fTy = m.getTranslateY();
110 return x;
111 } 101 }
112 }; 102 };
113 103
114 enum { 104 enum {
115 N = 256, 105 N = 256,
116 }; 106 };
117 107
118 SkAutoTUnref<SkImage> fAtlas; 108 SkAutoTUnref<SkImage> fAtlas;
119 Rec fRec[N]; 109 Rec fRec[N];
120 SkRect fTex[N]; 110 SkRect fTex[N];
(...skipping 10 matching lines...) Expand all
131 for (int y = 0; y < kAtlasSize; y += kCellSize) { 121 for (int y = 0; y < kAtlasSize; y += kCellSize) {
132 for (int x = 0; x < kAtlasSize; x += kCellSize) { 122 for (int x = 0; x < kAtlasSize; x += kCellSize) {
133 const SkScalar sx = SkIntToScalar(x); 123 const SkScalar sx = SkIntToScalar(x);
134 const SkScalar sy = SkIntToScalar(y); 124 const SkScalar sy = SkIntToScalar(y);
135 fTex[i].setXYWH(sx, sy, cell, cell); 125 fTex[i].setXYWH(sx, sy, cell, cell);
136 126
137 fRec[i].fCenter.set(sx + cell/2, sy + 3*cell/4); 127 fRec[i].fCenter.set(sx + cell/2, sy + 3*cell/4);
138 fRec[i].fVelocity.fX = rand.nextSScalar1() * kMaxSpeed; 128 fRec[i].fVelocity.fX = rand.nextSScalar1() * kMaxSpeed;
139 fRec[i].fVelocity.fY = rand.nextSScalar1() * kMaxSpeed; 129 fRec[i].fVelocity.fY = rand.nextSScalar1() * kMaxSpeed;
140 fRec[i].fScale = 1; 130 fRec[i].fScale = 1;
141 fRec[i].fDScale = rand.nextSScalar1() / 4; 131 fRec[i].fDScale = rand.nextSScalar1() / 16;
142 fRec[i].fRadian = 0; 132 fRec[i].fRadian = 0;
143 fRec[i].fDRadian = rand.nextSScalar1() / 8; 133 fRec[i].fDRadian = rand.nextSScalar1() / 8;
144 fRec[i].fAlpha = rand.nextUScalar1(); 134 fRec[i].fAlpha = rand.nextUScalar1();
145 fRec[i].fDAlpha = rand.nextSScalar1() / 10; 135 fRec[i].fDAlpha = rand.nextSScalar1() / 10;
146 i += 1; 136 i += 1;
147 } 137 }
148 } 138 }
149 } 139 }
150 140
151 void toggleUseColors() { 141 void toggleUseColors() {
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 #endif 217 #endif
228 218
229 private: 219 private:
230 typedef SampleView INHERITED; 220 typedef SampleView INHERITED;
231 }; 221 };
232 222
233 ////////////////////////////////////////////////////////////////////////////// 223 //////////////////////////////////////////////////////////////////////////////
234 224
235 static SkView* MyFactory() { return new DrawAtlasView; } 225 static SkView* MyFactory() { return new DrawAtlasView; }
236 static SkViewRegister reg(MyFactory); 226 static SkViewRegister reg(MyFactory);
OLDNEW
« no previous file with comments | « include/core/SkRSXform.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698