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 "SkImage.h" | 9 #include "SkImage.h" |
10 #include "SkImageSource.h" | 10 #include "SkImageSource.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 canvas->clear(SK_ColorBLACK); | 46 canvas->clear(SK_ColorBLACK); |
47 SkPaint paint; | 47 SkPaint paint; |
48 | 48 |
49 for (int i = 0; i < 4; i++) { | 49 for (int i = 0; i < 4; i++) { |
50 SkImage* image = (i & 0x01) ? fCheckerboard.get() : fBitmap.get(); | 50 SkImage* image = (i & 0x01) ? fCheckerboard.get() : fBitmap.get(); |
51 SkIRect cropRect = SkIRect::MakeXYWH(i * 12, | 51 SkIRect cropRect = SkIRect::MakeXYWH(i * 12, |
52 i * 8, | 52 i * 8, |
53 image->width() - i * 8, | 53 image->width() - i * 8, |
54 image->height() - i * 12); | 54 image->height() - i * 12); |
55 SkImageFilter::CropRect rect(SkRect::Make(cropRect)); | 55 SkImageFilter::CropRect rect(SkRect::Make(cropRect)); |
56 SkAutoTUnref<SkImageFilter> tileInput(SkImageSource::Create(image)); | 56 sk_sp<SkImageFilter> tileInput(SkImageSource::Create(image)); |
57 SkScalar dx = SkIntToScalar(i*5); | 57 SkScalar dx = SkIntToScalar(i*5); |
58 SkScalar dy = SkIntToScalar(i*10); | 58 SkScalar dy = SkIntToScalar(i*10); |
59 SkAutoTUnref<SkImageFilter> filter(SkOffsetImageFilter::Create(dx, d
y, tileInput, | 59 paint.setImageFilter(SkOffsetImageFilter::Make(dx, dy, std::move(til
eInput), &rect)); |
60 &rect
)); | |
61 paint.setImageFilter(filter); | |
62 DrawClippedImage(canvas, image, paint, 1, cropRect); | 60 DrawClippedImage(canvas, image, paint, 1, cropRect); |
63 canvas->translate(SkIntToScalar(image->width() + MARGIN), 0); | 61 canvas->translate(SkIntToScalar(image->width() + MARGIN), 0); |
64 } | 62 } |
65 | 63 |
66 SkIRect cropRect = SkIRect::MakeXYWH(0, 0, 100, 100); | 64 SkIRect cropRect = SkIRect::MakeXYWH(0, 0, 100, 100); |
67 SkImageFilter::CropRect rect(SkRect::Make(cropRect)); | 65 SkImageFilter::CropRect rect(SkRect::Make(cropRect)); |
68 SkAutoTUnref<SkImageFilter> filter(SkOffsetImageFilter::Create(-5, -10,
nullptr, &rect)); | 66 paint.setImageFilter(SkOffsetImageFilter::Make(-5, -10, nullptr, &rect))
; |
69 paint.setImageFilter(filter); | |
70 DrawClippedImage(canvas, fBitmap.get(), paint, 2, cropRect); | 67 DrawClippedImage(canvas, fBitmap.get(), paint, 2, cropRect); |
71 } | 68 } |
72 private: | 69 private: |
73 static void DrawClippedImage(SkCanvas* canvas, const SkImage* image, const S
kPaint& paint, | 70 static void DrawClippedImage(SkCanvas* canvas, const SkImage* image, const S
kPaint& paint, |
74 SkScalar scale, const SkIRect& cropRect) { | 71 SkScalar scale, const SkIRect& cropRect) { |
75 SkRect clipRect = SkRect::MakeIWH(image->width(), image->height()); | 72 SkRect clipRect = SkRect::MakeIWH(image->width(), image->height()); |
76 | 73 |
77 canvas->save(); | 74 canvas->save(); |
78 canvas->clipRect(clipRect); | 75 canvas->clipRect(clipRect); |
79 canvas->scale(scale, scale); | 76 canvas->scale(scale, scale); |
(...skipping 24 matching lines...) Expand all Loading... |
104 public: | 101 public: |
105 SimpleOffsetImageFilterGM() {} | 102 SimpleOffsetImageFilterGM() {} |
106 | 103 |
107 protected: | 104 protected: |
108 SkString onShortName() override { | 105 SkString onShortName() override { |
109 return SkString("simple-offsetimagefilter"); | 106 return SkString("simple-offsetimagefilter"); |
110 } | 107 } |
111 | 108 |
112 SkISize onISize() override { return SkISize::Make(640, 200); } | 109 SkISize onISize() override { return SkISize::Make(640, 200); } |
113 | 110 |
114 void doDraw(SkCanvas* canvas, const SkRect& r, SkImageFilter* imgf, | 111 void doDraw(SkCanvas* canvas, const SkRect& r, sk_sp<SkImageFilter> imgf, |
115 const SkRect* clipR = nullptr) { | 112 const SkRect* clipR = nullptr) { |
116 SkPaint p; | 113 SkPaint p; |
117 | 114 |
118 if (clipR) { | 115 if (clipR) { |
119 p.setColor(0xFF00FF00); | 116 p.setColor(0xFF00FF00); |
120 p.setStyle(SkPaint::kStroke_Style); | 117 p.setStyle(SkPaint::kStroke_Style); |
121 canvas->drawRect(clipR->makeInset(SK_ScalarHalf, SK_ScalarHalf), p); | 118 canvas->drawRect(clipR->makeInset(SK_ScalarHalf, SK_ScalarHalf), p); |
122 p.setStyle(SkPaint::kFill_Style); | 119 p.setStyle(SkPaint::kFill_Style); |
123 } | 120 } |
124 | 121 |
125 if (imgf && imgf->cropRectIsSet()) { | 122 if (imgf && imgf->cropRectIsSet()) { |
126 SkImageFilter::CropRect cr = imgf->getCropRect(); | 123 SkImageFilter::CropRect cr = imgf->getCropRect(); |
127 | 124 |
128 p.setColor(0x66FF00FF); | 125 p.setColor(0x66FF00FF); |
129 p.setStyle(SkPaint::kStroke_Style); | 126 p.setStyle(SkPaint::kStroke_Style); |
130 canvas->drawRect(cr.rect().makeInset(SK_ScalarHalf, SK_ScalarHalf),
p); | 127 canvas->drawRect(cr.rect().makeInset(SK_ScalarHalf, SK_ScalarHalf),
p); |
131 p.setStyle(SkPaint::kFill_Style); | 128 p.setStyle(SkPaint::kFill_Style); |
132 } | 129 } |
133 | 130 |
134 p.setColor(0x660000FF); | 131 p.setColor(0x660000FF); |
135 canvas->drawRect(r, p); | 132 canvas->drawRect(r, p); |
136 | 133 |
137 if (clipR) { | 134 if (clipR) { |
138 canvas->save(); | 135 canvas->save(); |
139 canvas->clipRect(*clipR); | 136 canvas->clipRect(*clipR); |
140 } | 137 } |
141 if (imgf) { | 138 if (imgf) { |
142 p.setImageFilter(imgf)->unref(); | 139 p.setImageFilter(std::move(imgf)); |
143 } | 140 } |
144 p.setColor(0x66FF0000); | 141 p.setColor(0x66FF0000); |
145 canvas->drawRect(r, p); | 142 canvas->drawRect(r, p); |
146 | 143 |
147 if (clipR) { | 144 if (clipR) { |
148 canvas->restore(); | 145 canvas->restore(); |
149 } | 146 } |
150 } | 147 } |
151 | 148 |
152 void onDraw(SkCanvas* canvas) override { | 149 void onDraw(SkCanvas* canvas) override { |
153 const SkRect r = SkRect::MakeWH(40, 40); | 150 const SkRect r = SkRect::MakeWH(40, 40); |
154 SkImageFilter::CropRect cr0(r); | 151 SkImageFilter::CropRect cr0(r); |
155 SkImageFilter::CropRect cr1(SkRect::MakeWH(20, 20)); | 152 SkImageFilter::CropRect cr1(SkRect::MakeWH(20, 20)); |
156 const SkRect r2 = SkRect::MakeXYWH(40, 0, 40, 40); | 153 const SkRect r2 = SkRect::MakeXYWH(40, 0, 40, 40); |
157 SkImageFilter::CropRect cr2(r2); | 154 SkImageFilter::CropRect cr2(r2); |
158 | 155 |
159 canvas->translate(40, 40); | 156 canvas->translate(40, 40); |
160 | 157 |
161 canvas->save(); | 158 canvas->save(); |
162 this->doDraw(canvas, r, nullptr); | 159 this->doDraw(canvas, r, nullptr); |
163 | 160 |
164 canvas->translate(100, 0); | 161 canvas->translate(100, 0); |
165 this->doDraw(canvas, r, SkOffsetImageFilter::Create(20, 20)); | 162 this->doDraw(canvas, r, SkOffsetImageFilter::Make(20, 20, nullptr)); |
166 | 163 |
167 canvas->translate(100, 0); | 164 canvas->translate(100, 0); |
168 this->doDraw(canvas, r, SkOffsetImageFilter::Create(20, 20, nullptr, &cr
0)); | 165 this->doDraw(canvas, r, SkOffsetImageFilter::Make(20, 20, nullptr, &cr0)
); |
169 | 166 |
170 canvas->translate(100, 0); | 167 canvas->translate(100, 0); |
171 this->doDraw(canvas, r, SkOffsetImageFilter::Create(20, 20), &r); | 168 this->doDraw(canvas, r, SkOffsetImageFilter::Make(20, 20, nullptr), &r); |
172 | 169 |
173 canvas->translate(100, 0); | 170 canvas->translate(100, 0); |
174 this->doDraw(canvas, r, SkOffsetImageFilter::Create(20, 20, nullptr, &cr
1)); | 171 this->doDraw(canvas, r, SkOffsetImageFilter::Make(20, 20, nullptr, &cr1)
); |
175 | 172 |
176 SkRect clipR = SkRect::MakeXYWH(40, 40, 40, 40); | 173 SkRect clipR = SkRect::MakeXYWH(40, 40, 40, 40); |
177 canvas->translate(100, 0); | 174 canvas->translate(100, 0); |
178 this->doDraw(canvas, r, SkOffsetImageFilter::Create(20, 20, nullptr, nul
lptr), &clipR); | 175 this->doDraw(canvas, r, SkOffsetImageFilter::Make(20, 20, nullptr, nullp
tr), &clipR); |
179 canvas->restore(); | 176 canvas->restore(); |
180 | 177 |
181 // 2nd row | 178 // 2nd row |
182 canvas->translate(0, 80); | 179 canvas->translate(0, 80); |
183 | 180 |
184 /* | 181 /* |
185 * combos of clip and crop rects that align with src and dst | 182 * combos of clip and crop rects that align with src and dst |
186 */ | 183 */ |
187 | 184 |
188 // crop==clip==src | 185 // crop==clip==src |
189 this->doDraw(canvas, r, SkOffsetImageFilter::Create(40, 0, nullptr, &cr0
), &r); | 186 this->doDraw(canvas, r, SkOffsetImageFilter::Make(40, 0, nullptr, &cr0),
&r); |
190 | 187 |
191 // crop==src, clip==dst | 188 // crop==src, clip==dst |
192 canvas->translate(100, 0); | 189 canvas->translate(100, 0); |
193 this->doDraw(canvas, r, SkOffsetImageFilter::Create(40, 0, nullptr, &cr0
), &r2); | 190 this->doDraw(canvas, r, SkOffsetImageFilter::Make(40, 0, nullptr, &cr0),
&r2); |
194 | 191 |
195 // crop==dst, clip==src | 192 // crop==dst, clip==src |
196 canvas->translate(100, 0); | 193 canvas->translate(100, 0); |
197 this->doDraw(canvas, r, SkOffsetImageFilter::Create(40, 0, nullptr, &cr2
), &r); | 194 this->doDraw(canvas, r, SkOffsetImageFilter::Make(40, 0, nullptr, &cr2),
&r); |
198 | 195 |
199 // crop==clip==dst | 196 // crop==clip==dst |
200 canvas->translate(100, 0); | 197 canvas->translate(100, 0); |
201 this->doDraw(canvas, r, SkOffsetImageFilter::Create(40, 0, nullptr, &cr2
), &r2); | 198 this->doDraw(canvas, r, SkOffsetImageFilter::Make(40, 0, nullptr, &cr2),
&r2); |
202 } | 199 } |
203 | 200 |
204 private: | 201 private: |
205 typedef skiagm::GM INHERITED; | 202 typedef skiagm::GM INHERITED; |
206 }; | 203 }; |
207 DEF_GM( return new SimpleOffsetImageFilterGM; ) | 204 DEF_GM( return new SimpleOffsetImageFilterGM; ) |
OLD | NEW |