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" |
(...skipping 11 matching lines...) Expand all Loading... |
22 auto surface(caller->makeSurface(info)); | 22 auto surface(caller->makeSurface(info)); |
23 if (nullptr == surface) { | 23 if (nullptr == surface) { |
24 surface = SkSurface::MakeRaster(info); | 24 surface = SkSurface::MakeRaster(info); |
25 } | 25 } |
26 SkCanvas* canvas = surface->getCanvas(); | 26 SkCanvas* canvas = surface->getCanvas(); |
27 | 27 |
28 SkPaint paint; | 28 SkPaint paint; |
29 paint.setXfermode(SkXfermode::Create(SkXfermode::kSrc_Mode)); | 29 paint.setXfermode(SkXfermode::Create(SkXfermode::kSrc_Mode)); |
30 | 30 |
31 paint.setColor(SK_ColorWHITE); | 31 paint.setColor(SK_ColorWHITE); |
32 SkRect r = SkRect::MakeXYWH(0, 0, | 32 SkRect r = SkRect::MakeXYWH(0, 0, |
33 SkIntToScalar(kBlockSize), SkIntToScalar(kBlockS
ize)); | 33 SkIntToScalar(kBlockSize), SkIntToScalar(kBlockS
ize)); |
34 canvas->drawRect(r, paint); | 34 canvas->drawRect(r, paint); |
35 | 35 |
36 paint.setColor(SK_ColorRED); | 36 paint.setColor(SK_ColorRED); |
37 r = SkRect::MakeXYWH(SkIntToScalar(kBlockSize), 0, | 37 r = SkRect::MakeXYWH(SkIntToScalar(kBlockSize), 0, |
38 SkIntToScalar(kBlockSize), SkIntToScalar(kBlockSize)); | 38 SkIntToScalar(kBlockSize), SkIntToScalar(kBlockSize)); |
39 canvas->drawRect(r, paint); | 39 canvas->drawRect(r, paint); |
40 | 40 |
41 paint.setColor(SK_ColorGREEN); | 41 paint.setColor(SK_ColorGREEN); |
42 r = SkRect::MakeXYWH(0, SkIntToScalar(kBlockSize), | 42 r = SkRect::MakeXYWH(0, SkIntToScalar(kBlockSize), |
43 SkIntToScalar(kBlockSize), SkIntToScalar(kBlockSize)); | 43 SkIntToScalar(kBlockSize), SkIntToScalar(kBlockSize)); |
44 canvas->drawRect(r, paint); | 44 canvas->drawRect(r, paint); |
45 | 45 |
46 paint.setColor(SK_ColorTRANSPARENT); | 46 paint.setColor(SK_ColorTRANSPARENT); |
47 r = SkRect::MakeXYWH(SkIntToScalar(kBlockSize), SkIntToScalar(kBlockSize), | 47 r = SkRect::MakeXYWH(SkIntToScalar(kBlockSize), SkIntToScalar(kBlockSize), |
48 SkIntToScalar(kBlockSize), SkIntToScalar(kBlockSize)); | 48 SkIntToScalar(kBlockSize), SkIntToScalar(kBlockSize)); |
49 canvas->drawRect(r, paint); | 49 canvas->drawRect(r, paint); |
50 | 50 |
51 return surface->makeImageSnapshot(); | 51 return surface->makeImageSnapshot(); |
52 } | 52 } |
53 | 53 |
54 // This GM tests the drawAtlas API with colors, different xfer modes | 54 // This GM tests the drawAtlas API with colors, different xfer modes |
55 // and transparency in the atlas image | 55 // and transparency in the atlas image |
56 class DrawAtlasColorsGM : public skiagm::GM { | 56 class DrawAtlasColorsGM : public skiagm::GM { |
57 public: | 57 public: |
58 DrawAtlasColorsGM() { | 58 DrawAtlasColorsGM() { |
59 this->setBGColor(sk_tool_utils::color_to_565(0xFFCCCCCC)); | 59 this->setBGColor(sk_tool_utils::color_to_565(0xFFCCCCCC)); |
60 } | 60 } |
61 | 61 |
62 protected: | 62 protected: |
63 SkString onShortName() override { | 63 SkString onShortName() override { |
64 return SkString("draw-atlas-colors"); | 64 return SkString("draw-atlas-colors"); |
65 } | 65 } |
66 | 66 |
67 SkISize onISize() override { | 67 SkISize onISize() override { |
68 return SkISize::Make(kNumXferModes * (kAtlasSize + kPad) + kPad, | 68 return SkISize::Make(kNumXferModes * (kAtlasSize + kPad) + kPad, |
69 2 * kNumColors * (kAtlasSize + kPad) + kTextPad + k
Pad); | 69 2 * kNumColors * (kAtlasSize + kPad) + kTextPad + k
Pad); |
70 } | 70 } |
71 | 71 |
72 void onDraw(SkCanvas* canvas) override { | 72 void onDraw(SkCanvas* canvas) override { |
73 const SkRect target = SkRect::MakeWH(SkIntToScalar(kAtlasSize), SkIntToS
calar(kAtlasSize)); | 73 const SkRect target = SkRect::MakeWH(SkIntToScalar(kAtlasSize), SkIntToS
calar(kAtlasSize)); |
74 | 74 |
75 if (nullptr == fAtlas) { | 75 if (nullptr == fAtlas) { |
76 fAtlas = make_atlas(canvas, kAtlasSize); | 76 fAtlas = make_atlas(canvas, kAtlasSize); |
77 } | 77 } |
78 | 78 |
79 const struct { | 79 const struct { |
80 SkXfermode::Mode fMode; | 80 SkXfermode::Mode fMode; |
81 const char* fLabel; | 81 const char* fLabel; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 textP.setAntiAlias(true); | 140 textP.setAntiAlias(true); |
141 sk_tool_utils::set_portable_typeface(&textP, nullptr); | 141 sk_tool_utils::set_portable_typeface(&textP, nullptr); |
142 | 142 |
143 for (int i = 0; i < numModes; ++i) { | 143 for (int i = 0; i < numModes; ++i) { |
144 canvas->drawText(gModes[i].fLabel, strlen(gModes[i].fLabel), | 144 canvas->drawText(gModes[i].fLabel, strlen(gModes[i].fLabel), |
145 i*(target.width()+kPad)+kPad, SkIntToScalar(kTextPa
d), | 145 i*(target.width()+kPad)+kPad, SkIntToScalar(kTextPa
d), |
146 textP); | 146 textP); |
147 } | 147 } |
148 | 148 |
149 for (int i = 0; i < numModes; ++i) { | 149 for (int i = 0; i < numModes; ++i) { |
150 canvas->save(); | 150 canvas->save(); |
151 canvas->translate(SkIntToScalar(i*(target.height()+kPad)), | 151 canvas->translate(SkIntToScalar(i*(target.height()+kPad)), |
152 SkIntToScalar(kTextPad+kPad)); | 152 SkIntToScalar(kTextPad+kPad)); |
153 // w/o a paint | 153 // w/o a paint |
154 canvas->drawAtlas(fAtlas.get(), xforms, rects, quadColors, numColors
, | 154 canvas->drawAtlas(fAtlas.get(), xforms, rects, quadColors, numColors
, |
155 gModes[i].fMode, nullptr, nullptr); | 155 gModes[i].fMode, nullptr, nullptr); |
156 canvas->translate(0.0f, numColors*(target.height()+kPad)); | 156 canvas->translate(0.0f, numColors*(target.height()+kPad)); |
157 // w a paint | 157 // w a paint |
158 canvas->drawAtlas(fAtlas.get(), xforms, rects, quadColors, numColors
, | 158 canvas->drawAtlas(fAtlas.get(), xforms, rects, quadColors, numColors
, |
159 gModes[i].fMode, nullptr, &paint); | 159 gModes[i].fMode, nullptr, &paint); |
160 canvas->restore(); | 160 canvas->restore(); |
161 } | 161 } |
162 } | 162 } |
163 | 163 |
164 private: | 164 private: |
165 static const int kNumXferModes = 29; | 165 static const int kNumXferModes = 29; |
166 static const int kNumColors = 4; | 166 static const int kNumColors = 4; |
167 static const int kAtlasSize = 30; | 167 static const int kAtlasSize = 30; |
168 static const int kPad = 2; | 168 static const int kPad = 2; |
169 static const int kTextPad = 8; | 169 static const int kTextPad = 8; |
170 | 170 |
171 | 171 |
172 sk_sp<SkImage> fAtlas; | 172 sk_sp<SkImage> fAtlas; |
173 | 173 |
174 typedef GM INHERITED; | 174 typedef GM INHERITED; |
175 }; | 175 }; |
176 DEF_GM( return new DrawAtlasColorsGM; ) | 176 DEF_GM( return new DrawAtlasColorsGM; ) |
177 | |
OLD | NEW |