OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "SkColorFilter.h" | 10 #include "SkColorFilter.h" |
11 #include "SkColorPriv.h" | 11 #include "SkColorPriv.h" |
12 #include "SkShader.h" | 12 #include "SkShader.h" |
13 | 13 |
14 #include "SkBitmapSource.h" | |
15 #include "SkBlurImageFilter.h" | 14 #include "SkBlurImageFilter.h" |
16 #include "SkColorMatrixFilter.h" | 15 #include "SkColorMatrixFilter.h" |
17 #include "SkDisplacementMapEffect.h" | 16 #include "SkDisplacementMapEffect.h" |
18 #include "SkDropShadowImageFilter.h" | 17 #include "SkDropShadowImageFilter.h" |
19 #include "SkGradientShader.h" | 18 #include "SkGradientShader.h" |
19 #include "SkImageSource.h" | |
20 #include "SkMorphologyImageFilter.h" | 20 #include "SkMorphologyImageFilter.h" |
21 #include "SkColorFilterImageFilter.h" | 21 #include "SkColorFilterImageFilter.h" |
22 #include "SkMergeImageFilter.h" | 22 #include "SkMergeImageFilter.h" |
23 #include "SkOffsetImageFilter.h" | 23 #include "SkOffsetImageFilter.h" |
24 #include "SkSurface.h" | |
24 | 25 |
25 /////////////////////////////////////////////////////////////////////////////// | 26 /////////////////////////////////////////////////////////////////////////////// |
26 | 27 |
27 class ImageFiltersCropExpandGM : public skiagm::GM { | 28 class ImageFiltersCropExpandGM : public skiagm::GM { |
28 public: | 29 public: |
29 ImageFiltersCropExpandGM () {} | 30 ImageFiltersCropExpandGM () {} |
30 | 31 |
31 protected: | 32 protected: |
32 | 33 |
33 virtual SkString onShortName() { | 34 virtual SkString onShortName() { |
(...skipping 15 matching lines...) Expand all Loading... | |
49 canvas.save(); | 50 canvas.save(); |
50 canvas.translate(SkIntToScalar(x), SkIntToScalar(y)); | 51 canvas.translate(SkIntToScalar(x), SkIntToScalar(y)); |
51 canvas.drawRect(SkRect::MakeXYWH(0, 0, 8, 8), darkPaint); | 52 canvas.drawRect(SkRect::MakeXYWH(0, 0, 8, 8), darkPaint); |
52 canvas.drawRect(SkRect::MakeXYWH(8, 0, 8, 8), lightPaint); | 53 canvas.drawRect(SkRect::MakeXYWH(8, 0, 8, 8), lightPaint); |
53 canvas.drawRect(SkRect::MakeXYWH(0, 8, 8, 8), lightPaint); | 54 canvas.drawRect(SkRect::MakeXYWH(0, 8, 8, 8), lightPaint); |
54 canvas.drawRect(SkRect::MakeXYWH(8, 8, 8, 8), darkPaint); | 55 canvas.drawRect(SkRect::MakeXYWH(8, 8, 8, 8), darkPaint); |
55 canvas.restore(); | 56 canvas.restore(); |
56 } | 57 } |
57 } | 58 } |
58 } | 59 } |
59 | 60 |
robertphillips
2015/09/15 17:43:52
static SkImage* MakeGradientCircle(int width, int
f(malita)
2015/09/15 18:12:53
Done.
| |
60 void make_gradient_circle(int width, int height, SkBitmap* bitmap) { | 61 SkImage* make_gradient_circle(int width, int height) { |
61 SkScalar x = SkIntToScalar(width / 2); | 62 SkScalar x = SkIntToScalar(width / 2); |
62 SkScalar y = SkIntToScalar(height / 2); | 63 SkScalar y = SkIntToScalar(height / 2); |
63 SkScalar radius = SkMinScalar(x, y) * 0.8f; | 64 SkScalar radius = SkMinScalar(x, y) * 0.8f; |
64 bitmap->allocN32Pixels(width, height); | 65 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(width, hei ght)); |
65 SkCanvas canvas(*bitmap); | 66 SkCanvas* canvas = surface->getCanvas(); |
66 canvas.clear(0x00000000); | 67 canvas->clear(0x00000000); |
67 SkColor colors[2]; | 68 SkColor colors[2]; |
68 colors[0] = SK_ColorWHITE; | 69 colors[0] = SK_ColorWHITE; |
69 colors[1] = SK_ColorBLACK; | 70 colors[1] = SK_ColorBLACK; |
70 SkAutoTUnref<SkShader> shader( | 71 SkAutoTUnref<SkShader> shader( |
71 SkGradientShader::CreateRadial(SkPoint::Make(x, y), radius, colors, nullptr, 2, | 72 SkGradientShader::CreateRadial(SkPoint::Make(x, y), radius, colors, nullptr, 2, |
72 SkShader::kClamp_TileMode) | 73 SkShader::kClamp_TileMode) |
73 ); | 74 ); |
74 SkPaint paint; | 75 SkPaint paint; |
75 paint.setShader(shader); | 76 paint.setShader(shader); |
76 canvas.drawCircle(x, y, radius, paint); | 77 canvas->drawCircle(x, y, radius, paint); |
78 | |
79 return surface->newImageSnapshot(); | |
77 } | 80 } |
78 | 81 |
79 static void draw(SkCanvas* canvas, const SkBitmap& bitmap, const SkRect& rec t, SkImageFilter* filter) { | 82 static void draw(SkCanvas* canvas, const SkBitmap& bitmap, const SkRect& rec t, SkImageFilter* filter) { |
80 SkPaint paint; | 83 SkPaint paint; |
81 paint.setImageFilter(filter)->unref(); | 84 paint.setImageFilter(filter)->unref(); |
82 canvas->saveLayer(&rect, &paint); | 85 canvas->saveLayer(&rect, &paint); |
83 canvas->drawBitmap(bitmap, 0, 0); | 86 canvas->drawBitmap(bitmap, 0, 0); |
84 canvas->restore(); | 87 canvas->restore(); |
85 | 88 |
86 SkPaint strokePaint; | 89 SkPaint strokePaint; |
87 strokePaint.setColor(0xFFFF0000); | 90 strokePaint.setColor(0xFFFF0000); |
88 strokePaint.setStyle(SkPaint::kStroke_Style); | 91 strokePaint.setStyle(SkPaint::kStroke_Style); |
89 canvas->drawRect(rect, strokePaint); | 92 canvas->drawRect(rect, strokePaint); |
90 | 93 |
91 canvas->translate(SkIntToScalar(80), 0); | 94 canvas->translate(SkIntToScalar(80), 0); |
92 } | 95 } |
93 | 96 |
robertphillips
2015/09/15 17:43:52
override ?
f(malita)
2015/09/15 18:12:53
Done.
| |
94 virtual void onDraw(SkCanvas* canvas) { | 97 virtual void onDraw(SkCanvas* canvas) { |
95 SkAutoTUnref<SkColorFilter> cf( | 98 SkAutoTUnref<SkColorFilter> cf( |
96 SkColorFilter::CreateModeFilter(SK_ColorBLUE, SkXfermode::kSrcIn_Mod e)); | 99 SkColorFilter::CreateModeFilter(SK_ColorBLUE, SkXfermode::kSrcIn_Mod e)); |
97 SkImageFilter::CropRect crop_rect( | 100 SkImageFilter::CropRect crop_rect( |
98 SkRect::Make(SkIRect::MakeXYWH(10, 10, 44, 44)), | 101 SkRect::Make(SkIRect::MakeXYWH(10, 10, 44, 44)), |
99 SkImageFilter::CropRect::kHasAll_CropEdge); | 102 SkImageFilter::CropRect::kHasAll_CropEdge); |
100 | 103 |
robertphillips
2015/09/15 17:43:52
gradientCircle ?
f(malita)
2015/09/15 18:12:53
Done.
| |
101 SkBitmap gradient_circle, checkerboard; | 104 SkAutoTUnref<SkImage> gradient_circle(make_gradient_circle(64, 64)); |
102 make_gradient_circle(64, 64, &gradient_circle); | 105 SkBitmap checkerboard; |
103 make_checkerboard(&checkerboard); | 106 make_checkerboard(&checkerboard); |
104 | 107 |
105 SkAutoTUnref<SkImageFilter> gradient_circle_source( | 108 SkAutoTUnref<SkImageFilter> gradient_circle_source( |
106 SkBitmapSource::Create(gradient_circle)); | 109 SkImageSource::Create(gradient_circle)); |
107 SkAutoTUnref<SkImageFilter> noop_cropped( | 110 SkAutoTUnref<SkImageFilter> noop_cropped( |
108 SkOffsetImageFilter::Create(0, 0, nullptr, &crop_rect)); | 111 SkOffsetImageFilter::Create(0, 0, nullptr, &crop_rect)); |
109 SkScalar sk255 = SkIntToScalar(255); | 112 SkScalar sk255 = SkIntToScalar(255); |
110 SkScalar matrix[20] = { 1, 0, 0, 0, 0, | 113 SkScalar matrix[20] = { 1, 0, 0, 0, 0, |
111 0, 1, 0, 0, sk255, | 114 0, 1, 0, 0, sk255, |
112 0, 0, 1, 0, 0, | 115 0, 0, 1, 0, 0, |
113 0, 0, 0, 0, sk255 }; | 116 0, 0, 0, 0, sk255 }; |
114 SkAutoTUnref<SkColorFilter> cf_alpha_trans(SkColorMatrixFilter::Create(m atrix)); | 117 SkAutoTUnref<SkColorFilter> cf_alpha_trans(SkColorMatrixFilter::Create(m atrix)); |
115 | 118 |
116 SkRect r = SkRect::MakeWH(SkIntToScalar(64), SkIntToScalar(64)); | 119 SkRect r = SkRect::MakeWH(SkIntToScalar(64), SkIntToScalar(64)); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
162 } | 165 } |
163 | 166 |
164 private: | 167 private: |
165 typedef GM INHERITED; | 168 typedef GM INHERITED; |
166 }; | 169 }; |
167 | 170 |
168 /////////////////////////////////////////////////////////////////////////////// | 171 /////////////////////////////////////////////////////////////////////////////// |
169 | 172 |
170 static skiagm::GM* MyFactory(void*) { return new ImageFiltersCropExpandGM; } | 173 static skiagm::GM* MyFactory(void*) { return new ImageFiltersCropExpandGM; } |
171 static skiagm::GMRegistry reg(MyFactory); | 174 static skiagm::GMRegistry reg(MyFactory); |
OLD | NEW |