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

Unified Diff: samplecode/SampleShip.cpp

Issue 1395533002: Add DrawShipSim sample. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: samplecode/SampleShip.cpp
diff --git a/samplecode/SampleShip.cpp b/samplecode/SampleShip.cpp
index 6553266a14dcba908212d8794d254ffec3b7a1c5..caaad046d91824eaf4c129dff115316558fd22c4 100644
--- a/samplecode/SampleShip.cpp
+++ b/samplecode/SampleShip.cpp
@@ -20,11 +20,34 @@ static const int kGrid = 100;
static const int kWidth = 960;
static const int kHeight = 640;
-class DrawShipView : public SampleView {
- const char* fName;
+typedef void (*DrawAtlasProc)(SkCanvas*, SkImage*, const SkRSXform[], const SkRect[],
robertphillips 2015/10/07 18:07:00 tab over ?
+const SkColor[], int, const SkRect*, const SkPaint*);
+
+static void draw_atlas(SkCanvas* canvas, SkImage* atlas, const SkRSXform xform[],
+ const SkRect tex[], const SkColor colors[], int count, const SkRect* cull,
+ const SkPaint* paint) {
+ canvas->drawAtlas(atlas, xform, tex, colors, count, SkXfermode::kModulate_Mode, cull, paint);
+}
+
+static void draw_atlas_sim(SkCanvas* canvas, SkImage* atlas, const SkRSXform xform[],
robertphillips 2015/10/07 18:07:00 \n ?
+ const SkRect tex[], const SkColor colors[], int count, const SkRect* cull,
+ const SkPaint* paint) {
+ for (int i = 0; i < count; ++i) {
+ SkMatrix matrix;
+ matrix.setRSXform(xform[i]);
+
+ canvas->save();
+ canvas->concat(matrix);
+ canvas->drawImageRect(atlas, tex[i], tex[i].makeOffset(-tex[i].x(), -tex[i].y()), paint,
+ SkCanvas::kFast_SrcRectConstraint);
+ canvas->restore();
+ }
+}
+
+class DrawShipView : public SampleView {
public:
- DrawShipView(const char name[]) : fName(name) {
+ DrawShipView(const char name[], DrawAtlasProc proc) : fName(name), fProc(proc) {
fAtlas.reset(GetResourceAsImage("ship.png"));
if (!fAtlas) {
SkDebugf("\nCould not decode file ship.png. Falling back to penguin mode.\n");
@@ -123,8 +146,7 @@ protected:
fXform[i].fTy += dy;
}
- canvas->drawAtlas(fAtlas, fXform, fTex, nullptr, kGrid*kGrid+1, SkXfermode::kSrcOver_Mode,
- nullptr, &paint);
+ fProc(canvas, fAtlas, fXform, fTex, nullptr, kGrid*kGrid+1, nullptr, &paint);
canvas->drawText(outString.c_str(), outString.size(), 100.f, 100.f, paint);
this->inval(nullptr);
@@ -140,6 +162,9 @@ protected:
#endif
private:
+ const char* fName;
+ DrawAtlasProc fProc;
+
SkAutoTUnref<SkImage> fAtlas;
SkRSXform fXform[kGrid*kGrid+1];
SkRect fTex[kGrid*kGrid+1];
@@ -153,4 +178,5 @@ private:
//////////////////////////////////////////////////////////////////////////////
-DEF_SAMPLE( return new DrawShipView("DrawShip"); )
+DEF_SAMPLE( return new DrawShipView("DrawShip", draw_atlas); )
+DEF_SAMPLE( return new DrawShipView("DrawShipSim", draw_atlas_sim); )
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698