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 // Create a square atlas of: | 13 // Create a square atlas of: |
14 // opaque white | opaque red | 14 // opaque white | opaque red |
15 // ------------------------------------ | 15 // ------------------------------------ |
16 // opaque green | transparent black | 16 // opaque green | transparent black |
17 // | 17 // |
18 static sk_sp<SkImage> make_atlas(SkCanvas* caller, int atlasSize) { | 18 static sk_sp<SkImage> make_atlas(SkCanvas* caller, int atlasSize) { |
19 const int kBlockSize = atlasSize/2; | 19 const int kBlockSize = atlasSize/2; |
20 | 20 |
21 SkImageInfo info = SkImageInfo::MakeN32Premul(atlasSize, atlasSize); | 21 SkImageInfo info = SkImageInfo::MakeN32Premul(atlasSize, atlasSize); |
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::Make(SkXfermode::kSrc_Mode)); | 29 paint.setBlendMode(SkBlendMode::kSrc); |
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); |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 private: | 162 private: |
163 static constexpr int kNumXferModes = 29; | 163 static constexpr int kNumXferModes = 29; |
164 static constexpr int kNumColors = 4; | 164 static constexpr int kNumColors = 4; |
165 static constexpr int kAtlasSize = 30; | 165 static constexpr int kAtlasSize = 30; |
166 static constexpr int kPad = 2; | 166 static constexpr int kPad = 2; |
167 static constexpr int kTextPad = 8; | 167 static constexpr int kTextPad = 8; |
168 | 168 |
169 typedef GM INHERITED; | 169 typedef GM INHERITED; |
170 }; | 170 }; |
171 DEF_GM( return new DrawAtlasColorsGM; ) | 171 DEF_GM( return new DrawAtlasColorsGM; ) |
OLD | NEW |