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 #include "SkBlurImageFilter.h" | 9 #include "SkBlurImageFilter.h" |
10 #include "SkColorMatrixFilter.h" | 10 #include "SkColorMatrixFilter.h" |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 canvas->save(); | 97 canvas->save(); |
98 canvas->clipRect(r.makeOutset(outset, outset)); | 98 canvas->clipRect(r.makeOutset(outset, outset)); |
99 canvas->drawImage(image, 0, 0, &paint); | 99 canvas->drawImage(image, 0, 0, &paint); |
100 canvas->restore(); | 100 canvas->restore(); |
101 canvas->translate(0, r.height() + 20); | 101 canvas->translate(0, r.height() + 20); |
102 } | 102 } |
103 canvas->restore(); | 103 canvas->restore(); |
104 canvas->translate(r.width() + 20, 0); | 104 canvas->translate(r.width() + 20, 0); |
105 } | 105 } |
106 } | 106 } |
107 | |
108 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | |
109 #include "Resources.h" | |
110 #include "SkBlurImageFilter.h" | |
111 #include "SkMatrixConvolutionImageFilter.h" | |
112 #include "SkMorphologyImageFilter.h" | |
113 #include "SkColorMatrixFilter.h" | |
114 #include "SkColorFilterImageFilter.h" | |
115 #include "SkRRect.h" | |
116 | |
117 static void draw_set(SkCanvas* canvas, SkImageFilter* filters[], int count) { | |
118 const SkRect r = SkRect::MakeXYWH(30, 30, 200, 200); | |
119 const SkScalar offset = 250; | |
120 SkScalar dx = 0, dy = 0; | |
121 | |
122 for (int i = 0; i < count; ++i) { | |
123 canvas->save(); | |
124 SkRRect rr = SkRRect::MakeRectXY(r.makeOffset(dx, dy), 20, 20); | |
125 canvas->clipRRect(rr, SkRegion::kIntersect_Op, true); | |
126 canvas->saveLayer({ &rr.getBounds(), nullptr, filters[i], 0 }); | |
127 canvas->drawColor(0x40FFFFFF); | |
128 canvas->restore(); | |
129 canvas->restore(); | |
130 | |
131 if (0 == dx) { | |
132 dx = offset; | |
133 } else { | |
134 dx = 0; | |
135 dy = offset; | |
136 } | |
137 } | |
138 } | |
139 | |
140 DEF_SIMPLE_GM(savelayer_with_backdrop, canvas, 830, 550) { | |
141 SkColorMatrix cm; | |
142 cm.setSaturation(10); | |
143 SkAutoTUnref<SkColorFilter> cf(SkColorMatrixFilter::Create(cm)); | |
144 const SkScalar kernel[] = { 4, 0, 4, 0, -15, 0, 4, 0, 4 }; | |
145 SkImageFilter* filters[] = { | |
146 SkBlurImageFilter::Create(10, 10), | |
147 SkDilateImageFilter::Create(8, 8), | |
148 SkMatrixConvolutionImageFilter::Create({ 3, 3 }, kernel, 1, 0, { 0, 0 }, | |
149 SkMatrixConvolutionImageFilter::kClam
pToBlack_TileMode, | |
150 true), | |
151 SkColorFilterImageFilter::Create(cf), | |
152 }; | |
153 | |
154 const struct { | |
155 SkScalar fSx, fSy, fTx, fTy; | |
156 } xforms[] = { | |
157 { 1, 1, 0, 0 }, | |
158 { 0.5f, 0.5f, 530, 0 }, | |
159 { 0.25f, 0.25f, 530, 275 }, | |
160 { 0.125f, 0.125f, 530, 420 }, | |
161 }; | |
162 | |
163 SkPaint paint; | |
164 paint.setFilterQuality(kMedium_SkFilterQuality); | |
165 SkAutoTUnref<SkImage> image(GetResourceAsImage("mandrill_512.png")); | |
166 | |
167 canvas->translate(20, 20); | |
168 for (const auto& xform : xforms) { | |
169 canvas->save(); | |
170 canvas->translate(xform.fTx, xform.fTy); | |
171 canvas->scale(xform.fSx, xform.fSy); | |
172 canvas->drawImage(image, 0, 0, &paint); | |
173 draw_set(canvas, filters, SK_ARRAY_COUNT(filters)); | |
174 canvas->restore(); | |
175 } | |
176 | |
177 for (auto& filter : filters) { | |
178 filter->unref(); | |
179 } | |
180 } | |
OLD | NEW |