| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "SkColorMatrixFilter.h" | 10 #include "SkColorMatrixFilter.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 *array->append() = cf_make_brightness(0.5f); | 46 *array->append() = cf_make_brightness(0.5f); |
| 47 *array->append() = cf_make_grayscale(); | 47 *array->append() = cf_make_grayscale(); |
| 48 *array->append() = cf_make_colorize(SK_ColorBLUE); | 48 *array->append() = cf_make_colorize(SK_ColorBLUE); |
| 49 } | 49 } |
| 50 | 50 |
| 51 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 51 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 52 #include "SkGradientShader.h" | 52 #include "SkGradientShader.h" |
| 53 #include "SkImage.h" | 53 #include "SkImage.h" |
| 54 #include "Resources.h" | 54 #include "Resources.h" |
| 55 | 55 |
| 56 static SkShader* sh_make_lineargradient0() { | 56 static sk_sp<SkShader> sh_make_lineargradient0() { |
| 57 const SkPoint pts[] = { { 0, 0 }, { 100, 100 } }; | 57 const SkPoint pts[] = { { 0, 0 }, { 100, 100 } }; |
| 58 const SkColor colors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE }; | 58 const SkColor colors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE }; |
| 59 return SkGradientShader::CreateLinear(pts, colors, nullptr, 3, SkShader::kRe
peat_TileMode); | 59 return SkGradientShader::MakeLinear(pts, colors, nullptr, 3, SkShader::kRepe
at_TileMode); |
| 60 } | 60 } |
| 61 | 61 |
| 62 static SkShader* sh_make_lineargradient1() { | 62 static sk_sp<SkShader> sh_make_lineargradient1() { |
| 63 const SkPoint pts[] = { { 0, 0 }, { 100, 100 } }; | 63 const SkPoint pts[] = { { 0, 0 }, { 100, 100 } }; |
| 64 const SkColor colors[] = { SK_ColorRED, 0x0000FF00, SK_ColorBLUE }; | 64 const SkColor colors[] = { SK_ColorRED, 0x0000FF00, SK_ColorBLUE }; |
| 65 return SkGradientShader::CreateLinear(pts, colors, nullptr, 3, SkShader::kRe
peat_TileMode); | 65 return SkGradientShader::MakeLinear(pts, colors, nullptr, 3, SkShader::kRepe
at_TileMode); |
| 66 } | 66 } |
| 67 | 67 |
| 68 static SkShader* sh_make_image() { | 68 static sk_sp<SkShader> sh_make_image() { |
| 69 SkAutoTUnref<SkImage> image(GetResourceAsImage("mandrill_128.png")); | 69 SkAutoTUnref<SkImage> image(GetResourceAsImage("mandrill_128.png")); |
| 70 if (!image) { | 70 if (!image) { |
| 71 return nullptr; | 71 return nullptr; |
| 72 } | 72 } |
| 73 return image->newShader(SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMo
de); | 73 return sk_sp<SkShader>(image->newShader(SkShader::kRepeat_TileMode, |
| 74 SkShader::kRepeat_TileMode)); |
| 74 } | 75 } |
| 75 | 76 |
| 76 static void sk_gm_get_shaders(SkTDArray<SkShader*>* array) { | 77 static void sk_gm_get_shaders(SkTDArray<SkShader*>* array) { |
| 77 if (SkShader* shader = sh_make_lineargradient0()) { | 78 if (auto shader = sh_make_lineargradient0()) { |
| 78 *array->append() = shader; | 79 *array->append() = shader.release(); |
| 79 } | 80 } |
| 80 if (SkShader* shader = sh_make_lineargradient1()) { | 81 if (auto shader = sh_make_lineargradient1()) { |
| 81 *array->append() = shader; | 82 *array->append() = shader.release(); |
| 82 } | 83 } |
| 83 if (SkShader* shader = sh_make_image()) { | 84 if (auto shader = sh_make_image()) { |
| 84 *array->append() = shader; | 85 *array->append() = shader.release(); |
| 85 } | 86 } |
| 86 } | 87 } |
| 87 | 88 |
| 88 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 89 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 89 | 90 |
| 90 static SkImageFilter* make_blur(float amount, SkImageFilter* input = nullptr) { | 91 static SkImageFilter* make_blur(float amount, SkImageFilter* input = nullptr) { |
| 91 return SkBlurImageFilter::Create(amount, amount, input); | 92 return SkBlurImageFilter::Create(amount, amount, input); |
| 92 } | 93 } |
| 93 | 94 |
| 94 static SkImageFilter* make_brightness(float amount, SkImageFilter* input = nullp
tr) { | 95 static SkImageFilter* make_brightness(float amount, SkImageFilter* input = nullp
tr) { |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 SkColorFilter* filter = x >= 0 ? filters[x] : nullptr; | 214 SkColorFilter* filter = x >= 0 ? filters[x] : nullptr; |
| 214 | 215 |
| 215 paint.setShader(shader->newWithColorFilter(filter))->unref(); | 216 paint.setShader(shader->newWithColorFilter(filter))->unref(); |
| 216 canvas->drawRect(r, paint); | 217 canvas->drawRect(r, paint); |
| 217 canvas->translate(150, 0); | 218 canvas->translate(150, 0); |
| 218 } | 219 } |
| 219 canvas->restore(); | 220 canvas->restore(); |
| 220 canvas->translate(0, 150); | 221 canvas->translate(0, 150); |
| 221 } | 222 } |
| 222 } | 223 } |
| OLD | NEW |