OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright 2015 Google Inc. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license that can be | |
5 * found in the LICENSE file. | |
6 */ | |
7 | |
8 #include "SkBitmapSource.h" | |
9 #include "SkTileImageFilter.h" | |
10 #include "gm.h" | |
11 | |
12 namespace skiagm { | |
13 | |
14 class BigTileImageFilterGM : public GM { | |
15 public: | |
16 BigTileImageFilterGM() { | |
17 this->setBGColor(0xFF000000); | |
18 } | |
19 | |
20 protected: | |
21 | |
22 SkString onShortName() override { | |
23 return SkString("bigtileimagefilter"); | |
24 } | |
25 | |
26 SkISize onISize() override{ | |
27 return SkISize::Make(kWidth, kHeight); | |
28 } | |
29 | |
30 void onOnceBeforeDraw() override { | |
31 fBitmap.allocN32Pixels(kBitmapSize, kBitmapSize); | |
32 | |
33 SkCanvas canvas(fBitmap); | |
34 canvas.clear(0xFF000000); | |
35 | |
36 SkPaint paint; | |
37 paint.setColor(SK_ColorRED); | |
38 paint.setStrokeWidth(3); | |
39 paint.setStyle(SkPaint::kStroke_Style); | |
40 | |
41 canvas.drawCircle(SkScalarHalf(kBitmapSize), SkScalarHalf(kBitmapSize), | |
42 SkScalarHalf(kBitmapSize), paint); | |
43 } | |
44 | |
45 void onDraw(SkCanvas* canvas) override { | |
46 canvas->clear(SK_ColorBLACK); | |
47 | |
48 SkPaint p; | |
49 | |
50 SkAutoTUnref<SkBitmapSource> bms(SkBitmapSource::Create(fBitmap)); | |
51 SkAutoTUnref<SkTileImageFilter> tif(SkTileImageFilter::Create( | |
52 SkRect::MakeWH(SkIntToScalar(kBitmapSize), SkIntToSc
alar(kBitmapSize)), | |
53 SkRect::MakeWH(SkIntToScalar(kWidth), SkIntToScalar(
kHeight)), | |
54 bms)); | |
55 p.setImageFilter(tif); | |
56 | |
57 SkRect bound = SkRect::MakeWH(SkIntToScalar(kWidth), SkIntToScalar(kHeig
ht)); | |
58 canvas->saveLayer(&bound, &p); | |
59 canvas->restore(); | |
60 } | |
61 | |
62 private: | |
63 static const int kWidth = 512; | |
64 static const int kHeight = 512; | |
65 static const int kBitmapSize = 64; | |
66 | |
67 SkBitmap fBitmap; | |
68 | |
69 typedef GM INHERITED; | |
70 }; | |
71 | |
72 ////////////////////////////////////////////////////////////////////////////// | |
73 | |
74 DEF_GM( return SkNEW(BigTileImageFilterGM); ) | |
75 | |
76 } | |
OLD | NEW |