| 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 ); |
| 154 SkPaint paint; | 158 SkPaint paint; |
| 155 paint.setShader(SkGradientShader::MakeRadial(SkPoint::Make(x, y), radius
, colors, nullptr, | 159 paint.setShader(shader); |
| 156 2, SkShader::kClamp_TileMod
e)); | |
| 157 canvas->drawCircle(x, y, radius, paint); | 160 canvas->drawCircle(x, y, radius, paint); |
| 158 | 161 |
| 159 return surface->newImageSnapshot(); | 162 return surface->newImageSnapshot(); |
| 160 } | 163 } |
| 161 | 164 |
| 162 static void Draw(SkCanvas* canvas, const SkBitmap& bitmap, const SkRect& rec
t, SkImageFilter* filter) { | 165 static void Draw(SkCanvas* canvas, const SkBitmap& bitmap, const SkRect& rec
t, SkImageFilter* filter) { |
| 163 SkPaint paint; | 166 SkPaint paint; |
| 164 paint.setImageFilter(filter)->unref(); | 167 paint.setImageFilter(filter)->unref(); |
| 165 canvas->saveLayer(&rect, &paint); | 168 canvas->saveLayer(&rect, &paint); |
| 166 canvas->drawBitmap(bitmap, 0, 0); | 169 canvas->drawBitmap(bitmap, 0, 0); |
| 167 canvas->restore(); | 170 canvas->restore(); |
| 168 | 171 |
| 169 SkPaint strokePaint; | 172 SkPaint strokePaint; |
| 170 strokePaint.setColor(0xFFFF0000); | 173 strokePaint.setColor(0xFFFF0000); |
| 171 strokePaint.setStyle(SkPaint::kStroke_Style); | 174 strokePaint.setStyle(SkPaint::kStroke_Style); |
| 172 canvas->drawRect(rect, strokePaint); | 175 canvas->drawRect(rect, strokePaint); |
| 173 | 176 |
| 174 canvas->translate(SkIntToScalar(80), 0); | 177 canvas->translate(SkIntToScalar(80), 0); |
| 175 } | 178 } |
| 176 | 179 |
| 177 typedef GM INHERITED; | 180 typedef GM INHERITED; |
| 178 }; | 181 }; |
| 179 | 182 |
| 180 /////////////////////////////////////////////////////////////////////////////// | 183 /////////////////////////////////////////////////////////////////////////////// |
| 181 | 184 |
| 182 DEF_GM( return new ImageFiltersCropExpandGM; ) | 185 DEF_GM( return new ImageFiltersCropExpandGM; ) |
| OLD | NEW |