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

Side by Side Diff: samplecode/SampleShip.cpp

Issue 1810813003: update callsites for Make image factories (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: start to take advantage of sk_sp drawImage Created 4 years, 9 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 | « samplecode/SampleLayers.cpp ('k') | samplecode/SampleTextureDomain.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 #include "SampleCode.h" 8 #include "SampleCode.h"
9 #include "Resources.h" 9 #include "Resources.h"
10 #include "SkAnimTimer.h" 10 #include "SkAnimTimer.h"
(...skipping 30 matching lines...) Expand all
41 canvas->drawImageRect(atlas, tex[i], tex[i].makeOffset(-tex[i].x(), -tex [i].y()), paint, 41 canvas->drawImageRect(atlas, tex[i], tex[i].makeOffset(-tex[i].x(), -tex [i].y()), paint,
42 SkCanvas::kFast_SrcRectConstraint); 42 SkCanvas::kFast_SrcRectConstraint);
43 canvas->restore(); 43 canvas->restore();
44 } 44 }
45 } 45 }
46 46
47 47
48 class DrawShipView : public SampleView { 48 class DrawShipView : public SampleView {
49 public: 49 public:
50 DrawShipView(const char name[], DrawAtlasProc proc) : fName(name), fProc(pro c) { 50 DrawShipView(const char name[], DrawAtlasProc proc) : fName(name), fProc(pro c) {
51 fAtlas.reset(GetResourceAsImage("ship.png")); 51 fAtlas = GetResourceAsImage("ship.png");
52 if (!fAtlas) { 52 if (!fAtlas) {
53 SkDebugf("\nCould not decode file ship.png. Falling back to penguin mode.\n"); 53 SkDebugf("\nCould not decode file ship.png. Falling back to penguin mode.\n");
54 fAtlas.reset(GetResourceAsImage("baby_tux.png")); 54 fAtlas = GetResourceAsImage("baby_tux.png");
55 if (!fAtlas) { 55 if (!fAtlas) {
56 SkDebugf("\nCould not decode file baby_tux.png. Did you forget" 56 SkDebugf("\nCould not decode file baby_tux.png. Did you forget"
57 " to set the resourcePath?\n"); 57 " to set the resourcePath?\n");
58 return; 58 return;
59 } 59 }
60 } 60 }
61 61
62 SkScalar anchorX = fAtlas->width()*0.5f; 62 SkScalar anchorX = fAtlas->width()*0.5f;
63 SkScalar anchorY = fAtlas->height()*0.5f; 63 SkScalar anchorY = fAtlas->height()*0.5f;
64 int currIndex = 0; 64 int currIndex = 0;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 139
140 fXform[i].fSCos = kCosDiff*c - kSinDiff*s; 140 fXform[i].fSCos = kCosDiff*c - kSinDiff*s;
141 fXform[i].fSSin = kSinDiff*c + kCosDiff*s; 141 fXform[i].fSSin = kSinDiff*c + kCosDiff*s;
142 142
143 dx -= fXform[i].fSCos*anchorX - fXform[i].fSSin*anchorY; 143 dx -= fXform[i].fSCos*anchorX - fXform[i].fSSin*anchorY;
144 dy -= fXform[i].fSSin*anchorX + fXform[i].fSCos*anchorY; 144 dy -= fXform[i].fSSin*anchorX + fXform[i].fSCos*anchorY;
145 fXform[i].fTx += dx; 145 fXform[i].fTx += dx;
146 fXform[i].fTy += dy; 146 fXform[i].fTy += dy;
147 } 147 }
148 148
149 fProc(canvas, fAtlas, fXform, fTex, nullptr, kGrid*kGrid+1, nullptr, &pa int); 149 fProc(canvas, fAtlas.get(), fXform, fTex, nullptr, kGrid*kGrid+1, nullpt r, &paint);
150 paint.setColor(SK_ColorBLACK); 150 paint.setColor(SK_ColorBLACK);
151 canvas->drawRect(SkRect::MakeXYWH(0, 0, 200, 24), paint); 151 canvas->drawRect(SkRect::MakeXYWH(0, 0, 200, 24), paint);
152 paint.setColor(SK_ColorWHITE); 152 paint.setColor(SK_ColorWHITE);
153 canvas->drawText(outString.c_str(), outString.size(), 5, 15, paint); 153 canvas->drawText(outString.c_str(), outString.size(), 5, 15, paint);
154 154
155 this->inval(nullptr); 155 this->inval(nullptr);
156 } 156 }
157 157
158 #if 0 158 #if 0
159 // TODO: switch over to use this for our animation 159 // TODO: switch over to use this for our animation
160 bool onAnimate(const SkAnimTimer& timer) override { 160 bool onAnimate(const SkAnimTimer& timer) override {
161 SkScalar angle = SkDoubleToScalar(fmod(timer.secs() * 360 / 24, 360)); 161 SkScalar angle = SkDoubleToScalar(fmod(timer.secs() * 360 / 24, 360));
162 fAnimatingDrawable->setSweep(angle); 162 fAnimatingDrawable->setSweep(angle);
163 return true; 163 return true;
164 } 164 }
165 #endif 165 #endif
166 166
167 private: 167 private:
168 const char* fName; 168 const char* fName;
169 DrawAtlasProc fProc; 169 DrawAtlasProc fProc;
170 170
171 SkAutoTUnref<SkImage> fAtlas; 171 sk_sp<SkImage> fAtlas;
172 SkRSXform fXform[kGrid*kGrid+1]; 172 SkRSXform fXform[kGrid*kGrid+1];
173 SkRect fTex[kGrid*kGrid+1]; 173 SkRect fTex[kGrid*kGrid+1];
174 WallTimer fTimer; 174 WallTimer fTimer;
175 float fTimes[32]; 175 float fTimes[32];
176 int fCurrentTime; 176 int fCurrentTime;
177 177
178 178
179 typedef SampleView INHERITED; 179 typedef SampleView INHERITED;
180 }; 180 };
181 181
182 ////////////////////////////////////////////////////////////////////////////// 182 //////////////////////////////////////////////////////////////////////////////
183 183
184 DEF_SAMPLE( return new DrawShipView("DrawShip", draw_atlas); ) 184 DEF_SAMPLE( return new DrawShipView("DrawShip", draw_atlas); )
185 DEF_SAMPLE( return new DrawShipView("DrawShipSim", draw_atlas_sim); ) 185 DEF_SAMPLE( return new DrawShipView("DrawShipSim", draw_atlas_sim); )
OLDNEW
« no previous file with comments | « samplecode/SampleLayers.cpp ('k') | samplecode/SampleTextureDomain.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698