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" |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 static SkImage* MakeGradientCircle(int width, int height) { | 144 static SkImage* MakeGradientCircle(int width, int height) { |
145 SkScalar x = SkIntToScalar(width / 2); | 145 SkScalar x = SkIntToScalar(width / 2); |
146 SkScalar y = SkIntToScalar(height / 2); | 146 SkScalar y = SkIntToScalar(height / 2); |
147 SkScalar radius = SkMinScalar(x, y) * 0.8f; | 147 SkScalar radius = SkMinScalar(x, y) * 0.8f; |
148 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(width, hei
ght)); | 148 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(width, hei
ght)); |
149 SkCanvas* canvas = surface->getCanvas(); | 149 SkCanvas* canvas = surface->getCanvas(); |
150 canvas->clear(0x00000000); | 150 canvas->clear(0x00000000); |
151 SkColor colors[2]; | 151 SkColor colors[2]; |
152 colors[0] = SK_ColorWHITE; | 152 colors[0] = SK_ColorWHITE; |
153 colors[1] = SK_ColorBLACK; | 153 colors[1] = SK_ColorBLACK; |
154 SkAutoTUnref<SkShader> shader( | |
155 SkGradientShader::CreateRadial(SkPoint::Make(x, y), radius, colors,
nullptr, 2, | |
156 SkShader::kClamp_TileMode) | |
157 ); | |
158 SkPaint paint; | 154 SkPaint paint; |
159 paint.setShader(shader); | 155 paint.setShader(SkGradientShader::MakeRadial(SkPoint::Make(x, y), radius
, colors, nullptr, |
| 156 2, SkShader::kClamp_TileMod
e)); |
160 canvas->drawCircle(x, y, radius, paint); | 157 canvas->drawCircle(x, y, radius, paint); |
161 | 158 |
162 return surface->newImageSnapshot(); | 159 return surface->newImageSnapshot(); |
163 } | 160 } |
164 | 161 |
165 static void Draw(SkCanvas* canvas, const SkBitmap& bitmap, const SkRect& rec
t, SkImageFilter* filter) { | 162 static void Draw(SkCanvas* canvas, const SkBitmap& bitmap, const SkRect& rec
t, SkImageFilter* filter) { |
166 SkPaint paint; | 163 SkPaint paint; |
167 paint.setImageFilter(filter)->unref(); | 164 paint.setImageFilter(filter)->unref(); |
168 canvas->saveLayer(&rect, &paint); | 165 canvas->saveLayer(&rect, &paint); |
169 canvas->drawBitmap(bitmap, 0, 0); | 166 canvas->drawBitmap(bitmap, 0, 0); |
170 canvas->restore(); | 167 canvas->restore(); |
171 | 168 |
172 SkPaint strokePaint; | 169 SkPaint strokePaint; |
173 strokePaint.setColor(0xFFFF0000); | 170 strokePaint.setColor(0xFFFF0000); |
174 strokePaint.setStyle(SkPaint::kStroke_Style); | 171 strokePaint.setStyle(SkPaint::kStroke_Style); |
175 canvas->drawRect(rect, strokePaint); | 172 canvas->drawRect(rect, strokePaint); |
176 | 173 |
177 canvas->translate(SkIntToScalar(80), 0); | 174 canvas->translate(SkIntToScalar(80), 0); |
178 } | 175 } |
179 | 176 |
180 typedef GM INHERITED; | 177 typedef GM INHERITED; |
181 }; | 178 }; |
182 | 179 |
183 /////////////////////////////////////////////////////////////////////////////// | 180 /////////////////////////////////////////////////////////////////////////////// |
184 | 181 |
185 DEF_GM( return new ImageFiltersCropExpandGM; ) | 182 DEF_GM( return new ImageFiltersCropExpandGM; ) |
OLD | NEW |