OLD | NEW |
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 "gm.h" | 8 #include "gm.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkRSXform.h" | 10 #include "SkRSXform.h" |
11 #include "SkSurface.h" | 11 #include "SkSurface.h" |
12 | 12 |
13 class DrawAtlasGM : public skiagm::GM { | 13 class DrawAtlasGM : public skiagm::GM { |
14 static SkImage* MakeAtlas(SkCanvas* caller, const SkRect& target) { | 14 static SkImage* MakeAtlas(SkCanvas* caller, const SkRect& target) { |
15 SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100); | 15 SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100); |
16 SkAutoTUnref<SkSurface> surface(caller->newSurface(info)); | 16 SkAutoTUnref<SkSurface> surface(caller->newSurface(info)); |
17 if (NULL == surface) { | 17 if (nullptr == surface) { |
18 surface.reset(SkSurface::NewRaster(info)); | 18 surface.reset(SkSurface::NewRaster(info)); |
19 } | 19 } |
20 SkCanvas* canvas = surface->getCanvas(); | 20 SkCanvas* canvas = surface->getCanvas(); |
21 // draw red everywhere, but we don't expect to see it in the draw, testi
ng the notion | 21 // draw red everywhere, but we don't expect to see it in the draw, testi
ng the notion |
22 // that drawAtlas draws a subset-region of the atlas. | 22 // that drawAtlas draws a subset-region of the atlas. |
23 canvas->clear(SK_ColorRED); | 23 canvas->clear(SK_ColorRED); |
24 | 24 |
25 SkPaint paint; | 25 SkPaint paint; |
26 paint.setXfermodeMode(SkXfermode::kClear_Mode); | 26 paint.setXfermodeMode(SkXfermode::kClear_Mode); |
27 SkRect r(target); | 27 SkRect r(target); |
28 r.inset(-1, -1); | 28 r.inset(-1, -1); |
29 // zero out a place (with a 1-pixel border) to land our drawing. | 29 // zero out a place (with a 1-pixel border) to land our drawing. |
30 canvas->drawRect(r, paint); | 30 canvas->drawRect(r, paint); |
31 paint.setXfermode(NULL); | 31 paint.setXfermode(nullptr); |
32 paint.setColor(SK_ColorBLUE); | 32 paint.setColor(SK_ColorBLUE); |
33 paint.setAntiAlias(true); | 33 paint.setAntiAlias(true); |
34 canvas->drawOval(target, paint); | 34 canvas->drawOval(target, paint); |
35 return surface->newImageSnapshot(); | 35 return surface->newImageSnapshot(); |
36 } | 36 } |
37 | 37 |
38 SkAutoTUnref<SkImage> fAtlas; | 38 SkAutoTUnref<SkImage> fAtlas; |
39 | 39 |
40 public: | 40 public: |
41 DrawAtlasGM() {} | 41 DrawAtlasGM() {} |
42 | 42 |
43 protected: | 43 protected: |
44 | 44 |
45 SkString onShortName() override { | 45 SkString onShortName() override { |
46 return SkString("draw-atlas"); | 46 return SkString("draw-atlas"); |
47 } | 47 } |
48 | 48 |
49 SkISize onISize() override { | 49 SkISize onISize() override { |
50 return SkISize::Make(640, 480); | 50 return SkISize::Make(640, 480); |
51 } | 51 } |
52 | 52 |
53 void onDraw(SkCanvas* canvas) override { | 53 void onDraw(SkCanvas* canvas) override { |
54 const SkRect target = { 50, 50, 80, 90 }; | 54 const SkRect target = { 50, 50, 80, 90 }; |
55 if (NULL == fAtlas) { | 55 if (nullptr == fAtlas) { |
56 fAtlas.reset(MakeAtlas(canvas, target)); | 56 fAtlas.reset(MakeAtlas(canvas, target)); |
57 } | 57 } |
58 | 58 |
59 const struct { | 59 const struct { |
60 SkScalar fScale; | 60 SkScalar fScale; |
61 SkScalar fDegrees; | 61 SkScalar fDegrees; |
62 SkScalar fTx; | 62 SkScalar fTx; |
63 SkScalar fTy; | 63 SkScalar fTy; |
64 | 64 |
65 void apply(SkRSXform* xform) const { | 65 void apply(SkRSXform* xform) const { |
(...skipping 18 matching lines...) Expand all Loading... |
84 for (int i = 0; i < N; ++i) { | 84 for (int i = 0; i < N; ++i) { |
85 rec[i].apply(&xform[i]); | 85 rec[i].apply(&xform[i]); |
86 tex[i] = target; | 86 tex[i] = target; |
87 colors[i] = 0x80FF0000 + (i * 40 * 256); | 87 colors[i] = 0x80FF0000 + (i * 40 * 256); |
88 } | 88 } |
89 | 89 |
90 SkPaint paint; | 90 SkPaint paint; |
91 paint.setFilterQuality(kLow_SkFilterQuality); | 91 paint.setFilterQuality(kLow_SkFilterQuality); |
92 paint.setAntiAlias(true); | 92 paint.setAntiAlias(true); |
93 | 93 |
94 canvas->drawAtlas(fAtlas, xform, tex, N, NULL, &paint); | 94 canvas->drawAtlas(fAtlas, xform, tex, N, nullptr, &paint); |
95 canvas->translate(0, 100); | 95 canvas->translate(0, 100); |
96 canvas->drawAtlas(fAtlas, xform, tex, colors, N, SkXfermode::kSrcIn_Mode
, NULL, &paint); | 96 canvas->drawAtlas(fAtlas, xform, tex, colors, N, SkXfermode::kSrcIn_Mode
, nullptr, &paint); |
97 } | 97 } |
98 | 98 |
99 private: | 99 private: |
100 typedef GM INHERITED; | 100 typedef GM INHERITED; |
101 }; | 101 }; |
102 DEF_GM( return new DrawAtlasGM; ) | 102 DEF_GM( return new DrawAtlasGM; ) |
103 | 103 |
OLD | NEW |