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 | 9 |
10 #include "Resources.h" | 10 #include "Resources.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 path.setFillType(SkPath::kEvenOdd_FillType); | 39 path.setFillType(SkPath::kEvenOdd_FillType); |
40 | 40 |
41 path.addRect(SkRect::MakeWH(N/2, N)); | 41 path.addRect(SkRect::MakeWH(N/2, N)); |
42 path.addRect(SkRect::MakeWH(N, N/2)); | 42 path.addRect(SkRect::MakeWH(N, N/2)); |
43 path.moveTo(0, 0); path.lineTo(N, 0); path.lineTo(0, N); path.close(); | 43 path.moveTo(0, 0); path.lineTo(N, 0); path.lineTo(0, N); path.close(); |
44 | 44 |
45 canvas->drawPath(path, SkPaint()); | 45 canvas->drawPath(path, SkPaint()); |
46 return surface->newImageSnapshot(); | 46 return surface->newImageSnapshot(); |
47 } | 47 } |
48 | 48 |
49 static SkImage* zoom_up(SkImage* orig) { | 49 static SkImage* zoom_up(SkSurface* origSurf, SkImage* orig) { |
50 const SkScalar S = 8; // amount to scale up | 50 const SkScalar S = 8; // amount to scale up |
51 const int D = 2; // dimension scaling for the offscreen | 51 const int D = 2; // dimension scaling for the offscreen |
52 // since we only view the center, don't need to produce the entire thing | 52 // since we only view the center, don't need to produce the entire thing |
53 | 53 |
54 SkImageInfo info = SkImageInfo::MakeN32(orig->width() * D, orig->height() *
D, | 54 SkImageInfo info = SkImageInfo::MakeN32(orig->width() * D, orig->height() *
D, |
55 kOpaque_SkAlphaType); | 55 kOpaque_SkAlphaType); |
56 SkAutoTUnref<SkSurface> surface(orig->newSurface(info)); | 56 SkAutoTUnref<SkSurface> surface(origSurf->newSurface(info)); |
57 SkCanvas* canvas = surface->getCanvas(); | 57 SkCanvas* canvas = surface->getCanvas(); |
58 canvas->drawColor(SK_ColorWHITE); | 58 canvas->drawColor(SK_ColorWHITE); |
59 canvas->scale(S, S); | 59 canvas->scale(S, S); |
60 canvas->translate(-SkScalarHalf(orig->width()) * (S - D) / S, | 60 canvas->translate(-SkScalarHalf(orig->width()) * (S - D) / S, |
61 -SkScalarHalf(orig->height()) * (S - D) / S); | 61 -SkScalarHalf(orig->height()) * (S - D) / S); |
62 canvas->drawImage(orig, 0, 0, nullptr); | 62 canvas->drawImage(orig, 0, 0, nullptr); |
63 | 63 |
64 if (S > 3) { | 64 if (S > 3) { |
65 SkPaint paint; | 65 SkPaint paint; |
66 paint.setColor(SK_ColorWHITE); | 66 paint.setColor(SK_ColorWHITE); |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 canvas->drawColor(SK_ColorWHITE); | 214 canvas->drawColor(SK_ColorWHITE); |
215 size.set(info.width(), info.height()); | 215 size.set(info.width(), info.height()); |
216 } else { | 216 } else { |
217 canvas->translate(SkScalarHalf(fCell.width() - fImage->width()), | 217 canvas->translate(SkScalarHalf(fCell.width() - fImage->width()), |
218 SkScalarHalf(fCell.height() - fImage->height())); | 218 SkScalarHalf(fCell.height() - fImage->height())); |
219 } | 219 } |
220 this->drawTheImage(canvas, size, filter, dx, dy); | 220 this->drawTheImage(canvas, size, filter, dx, dy); |
221 | 221 |
222 if (surface) { | 222 if (surface) { |
223 SkAutoTUnref<SkImage> orig(surface->newImageSnapshot()); | 223 SkAutoTUnref<SkImage> orig(surface->newImageSnapshot()); |
224 SkAutoTUnref<SkImage> zoomed(zoom_up(orig)); | 224 SkAutoTUnref<SkImage> zoomed(zoom_up(surface, orig)); |
225 origCanvas->drawImage(zoomed, | 225 origCanvas->drawImage(zoomed, |
226 SkScalarHalf(fCell.width() - zoomed->width()), | 226 SkScalarHalf(fCell.width() - zoomed->width()), |
227 SkScalarHalf(fCell.height() - zoomed->height()
)); | 227 SkScalarHalf(fCell.height() - zoomed->height()
)); |
228 } | 228 } |
229 } | 229 } |
230 | 230 |
231 void drawBorders(SkCanvas* canvas) { | 231 void drawBorders(SkCanvas* canvas) { |
232 SkPaint p; | 232 SkPaint p; |
233 p.setStyle(SkPaint::kStroke_Style); | 233 p.setStyle(SkPaint::kStroke_Style); |
234 p.setColor(SK_ColorBLUE); | 234 p.setColor(SK_ColorBLUE); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 } | 288 } |
289 | 289 |
290 private: | 290 private: |
291 typedef SampleView INHERITED; | 291 typedef SampleView INHERITED; |
292 }; | 292 }; |
293 | 293 |
294 ////////////////////////////////////////////////////////////////////////////// | 294 ////////////////////////////////////////////////////////////////////////////// |
295 | 295 |
296 static SkView* MyFactory() { return new FilterQualityView; } | 296 static SkView* MyFactory() { return new FilterQualityView; } |
297 static SkViewRegister reg(MyFactory); | 297 static SkViewRegister reg(MyFactory); |
OLD | NEW |