OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "sk_tool_utils.h" | 8 #include "sk_tool_utils.h" |
9 #include "SkColorFilterImageFilter.h" | 9 #include "SkColorFilterImageFilter.h" |
10 #include "SkColorMatrixFilter.h" | 10 #include "SkColorMatrixFilter.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 canvas->clear(SK_ColorBLACK); | 49 canvas->clear(SK_ColorBLACK); |
50 SkPaint red; | 50 SkPaint red; |
51 red.setColor(SK_ColorRED); | 51 red.setColor(SK_ColorRED); |
52 red.setStyle(SkPaint::kStroke_Style); | 52 red.setStyle(SkPaint::kStroke_Style); |
53 SkPaint blue; | 53 SkPaint blue; |
54 blue.setColor(SK_ColorBLUE); | 54 blue.setColor(SK_ColorBLUE); |
55 blue.setStyle(SkPaint::kStroke_Style); | 55 blue.setStyle(SkPaint::kStroke_Style); |
56 | 56 |
57 int x = 0, y = 0; | 57 int x = 0, y = 0; |
58 for (size_t i = 0; i < 4; i++) { | 58 for (size_t i = 0; i < 4; i++) { |
59 SkImage* image = (i & 0x01) ? fCheckerboard.get() : fBitmap.get(); | 59 sk_sp<SkImage> image = (i & 0x01) ? fCheckerboard : fBitmap; |
60 SkRect srcRect = SkRect::MakeXYWH(SkIntToScalar(image->width()/4), | 60 SkRect srcRect = SkRect::MakeXYWH(SkIntToScalar(image->width()/4), |
61 SkIntToScalar(image->height()/4), | 61 SkIntToScalar(image->height()/4), |
62 SkIntToScalar(image->width()/(i+1)
), | 62 SkIntToScalar(image->width()/(i+1)
), |
63 SkIntToScalar(image->height()/(i+1
))); | 63 SkIntToScalar(image->height()/(i+1
))); |
64 SkRect dstRect = SkRect::MakeXYWH(SkIntToScalar(i * 8), | 64 SkRect dstRect = SkRect::MakeXYWH(SkIntToScalar(i * 8), |
65 SkIntToScalar(i * 4), | 65 SkIntToScalar(i * 4), |
66 SkIntToScalar(image->width() - i *
12), | 66 SkIntToScalar(image->width() - i *
12), |
67 SkIntToScalar(image->height()) - i
* 12); | 67 SkIntToScalar(image->height()) - i
* 12); |
68 SkAutoTUnref<SkImageFilter> tileInput(SkImageSource::Create(image)); | 68 sk_sp<SkImageFilter> tileInput(SkImageSource::Make(image)); |
69 SkAutoTUnref<SkImageFilter> filter( | 69 sk_sp<SkImageFilter> filter(SkTileImageFilter::Create(srcRect, dstRe
ct, tileInput.get())); |
70 SkTileImageFilter::Create(srcRect, dstRect, tileInput)); | |
71 canvas->save(); | 70 canvas->save(); |
72 canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); | 71 canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); |
73 SkPaint paint; | 72 SkPaint paint; |
74 paint.setImageFilter(filter); | 73 paint.setImageFilter(std::move(filter)); |
75 canvas->drawImage(fBitmap.get(), 0, 0, &paint); | 74 canvas->drawImage(fBitmap.get(), 0, 0, &paint); |
76 canvas->drawRect(srcRect, red); | 75 canvas->drawRect(srcRect, red); |
77 canvas->drawRect(dstRect, blue); | 76 canvas->drawRect(dstRect, blue); |
78 canvas->restore(); | 77 canvas->restore(); |
79 x += image->width() + MARGIN; | 78 x += image->width() + MARGIN; |
80 if (x + image->width() > WIDTH) { | 79 if (x + image->width() > WIDTH) { |
81 x = 0; | 80 x = 0; |
82 y += image->height() + MARGIN; | 81 y += image->height() + MARGIN; |
83 } | 82 } |
84 } | 83 } |
(...skipping 26 matching lines...) Expand all Loading... |
111 private: | 110 private: |
112 sk_sp<SkImage> fBitmap, fCheckerboard; | 111 sk_sp<SkImage> fBitmap, fCheckerboard; |
113 | 112 |
114 typedef GM INHERITED; | 113 typedef GM INHERITED; |
115 }; | 114 }; |
116 | 115 |
117 ////////////////////////////////////////////////////////////////////////////// | 116 ////////////////////////////////////////////////////////////////////////////// |
118 | 117 |
119 DEF_GM(return new TileImageFilterGM;) | 118 DEF_GM(return new TileImageFilterGM;) |
120 } | 119 } |
OLD | NEW |