| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "SkColorFilterImageFilter.h" | 10 #include "SkColorFilterImageFilter.h" |
| 11 #include "SkGradientShader.h" | 11 #include "SkGradientShader.h" |
| 12 #include "SkTableColorFilter.h" | 12 #include "SkTableColorFilter.h" |
| 13 | 13 |
| 14 static SkShader* make_shader0(int w, int h) { | 14 static sk_sp<SkShader> make_shader0(int w, int h) { |
| 15 SkPoint pts[] = { {0, 0}, {SkIntToScalar(w), SkIntToScalar(h)} }; | 15 SkPoint pts[] = { {0, 0}, {SkIntToScalar(w), SkIntToScalar(h)} }; |
| 16 SkColor colors[] = { | 16 SkColor colors[] = { |
| 17 SK_ColorBLACK, SK_ColorGREEN, SK_ColorCYAN, | 17 SK_ColorBLACK, SK_ColorGREEN, SK_ColorCYAN, |
| 18 SK_ColorRED, 0, SK_ColorBLUE, SK_ColorWHITE | 18 SK_ColorRED, 0, SK_ColorBLUE, SK_ColorWHITE |
| 19 }; | 19 }; |
| 20 return SkGradientShader::CreateLinear(pts, colors, nullptr, SK_ARRAY_COUNT(c
olors), | 20 return SkGradientShader::MakeLinear(pts, colors, nullptr, SK_ARRAY_COUNT(col
ors), |
| 21 SkShader::kClamp_TileMode); | 21 SkShader::kClamp_TileMode); |
| 22 } | 22 } |
| 23 static void make_bm0(SkBitmap* bm) { | 23 static void make_bm0(SkBitmap* bm) { |
| 24 int W = 120; | 24 int W = 120; |
| 25 int H = 120; | 25 int H = 120; |
| 26 bm->allocN32Pixels(W, H); | 26 bm->allocN32Pixels(W, H); |
| 27 bm->eraseColor(SK_ColorTRANSPARENT); | 27 bm->eraseColor(SK_ColorTRANSPARENT); |
| 28 | 28 |
| 29 SkCanvas canvas(*bm); | 29 SkCanvas canvas(*bm); |
| 30 SkPaint paint; | 30 SkPaint paint; |
| 31 paint.setShader(make_shader0(W, H))->unref(); | 31 paint.setShader(make_shader0(W, H)); |
| 32 canvas.drawPaint(paint); | 32 canvas.drawPaint(paint); |
| 33 } | 33 } |
| 34 static SkShader* make_shader1(int w, int h) { | 34 static sk_sp<SkShader> make_shader1(int w, int h) { |
| 35 SkScalar cx = SkIntToScalar(w)/2; | 35 SkScalar cx = SkIntToScalar(w)/2; |
| 36 SkScalar cy = SkIntToScalar(h)/2; | 36 SkScalar cy = SkIntToScalar(h)/2; |
| 37 SkColor colors[] = { | 37 SkColor colors[] = { |
| 38 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, | 38 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, |
| 39 }; | 39 }; |
| 40 return SkGradientShader::CreateRadial(SkPoint::Make(cx, cy), cx, colors, nul
lptr, | 40 return SkGradientShader::MakeRadial(SkPoint::Make(cx, cy), cx, colors, nullp
tr, |
| 41 SK_ARRAY_COUNT(colors), SkShader::kCla
mp_TileMode); | 41 SK_ARRAY_COUNT(colors), SkShader::kClamp
_TileMode); |
| 42 } | 42 } |
| 43 static void make_bm1(SkBitmap* bm) { | 43 static void make_bm1(SkBitmap* bm) { |
| 44 int W = 120; | 44 int W = 120; |
| 45 int H = 120; | 45 int H = 120; |
| 46 SkScalar cx = SkIntToScalar(W)/2; | 46 SkScalar cx = SkIntToScalar(W)/2; |
| 47 SkScalar cy = SkIntToScalar(H)/2; | 47 SkScalar cy = SkIntToScalar(H)/2; |
| 48 bm->allocN32Pixels(W, H); | 48 bm->allocN32Pixels(W, H); |
| 49 bm->eraseColor(SK_ColorTRANSPARENT); | 49 bm->eraseColor(SK_ColorTRANSPARENT); |
| 50 | 50 |
| 51 SkCanvas canvas(*bm); | 51 SkCanvas canvas(*bm); |
| 52 SkPaint paint; | 52 SkPaint paint; |
| 53 paint.setShader(make_shader1(W, H))->unref(); | 53 paint.setShader(make_shader1(W, H)); |
| 54 paint.setAntiAlias(true); | 54 paint.setAntiAlias(true); |
| 55 canvas.drawCircle(cx, cy, cx, paint); | 55 canvas.drawCircle(cx, cy, cx, paint); |
| 56 } | 56 } |
| 57 | 57 |
| 58 static void make_table0(uint8_t table[]) { | 58 static void make_table0(uint8_t table[]) { |
| 59 for (int i = 0; i < 256; ++i) { | 59 for (int i = 0; i < 256; ++i) { |
| 60 int n = i >> 5; | 60 int n = i >> 5; |
| 61 table[i] = (n << 5) | (n << 2) | (n >> 1); | 61 table[i] = (n << 5) | (n << 2) | (n >> 1); |
| 62 } | 62 } |
| 63 } | 63 } |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 const int MODES = MODE_COUNT * COLOR_COUNT; | 227 const int MODES = MODE_COUNT * COLOR_COUNT; |
| 228 SkAutoTUnref<SkColorFilter> filters[MODES]; | 228 SkAutoTUnref<SkColorFilter> filters[MODES]; |
| 229 int index = 0; | 229 int index = 0; |
| 230 for (int i = 0; i < MODE_COUNT; ++i) { | 230 for (int i = 0; i < MODE_COUNT; ++i) { |
| 231 for (int j = 0; j < COLOR_COUNT; ++j) { | 231 for (int j = 0; j < COLOR_COUNT; ++j) { |
| 232 filters[index++].reset(SkColorFilter::CreateModeFilter(fColors[j
], fModes[i])); | 232 filters[index++].reset(SkColorFilter::CreateModeFilter(fColors[j
], fModes[i])); |
| 233 } | 233 } |
| 234 } | 234 } |
| 235 | 235 |
| 236 SkPaint paint; | 236 SkPaint paint; |
| 237 paint.setShader(make_shader1(50, 50))->unref(); | 237 paint.setShader(make_shader1(50, 50)); |
| 238 SkRect r = SkRect::MakeWH(50, 50); | 238 SkRect r = SkRect::MakeWH(50, 50); |
| 239 const SkScalar spacer = 10; | 239 const SkScalar spacer = 10; |
| 240 | 240 |
| 241 canvas->translate(spacer, spacer); | 241 canvas->translate(spacer, spacer); |
| 242 | 242 |
| 243 canvas->drawRect(r, paint); // orig | 243 canvas->drawRect(r, paint); // orig |
| 244 | 244 |
| 245 for (int i = 0; i < MODES; ++i) { | 245 for (int i = 0; i < MODES; ++i) { |
| 246 paint.setColorFilter(filters[i]); | 246 paint.setColorFilter(filters[i]); |
| 247 | 247 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 DEF_GM( return new ComposeColorFilterGM(gColors0, gModes0, "wacky"); ) | 286 DEF_GM( return new ComposeColorFilterGM(gColors0, gModes0, "wacky"); ) |
| 287 | 287 |
| 288 const SkColor gColors1[] = { 0x80FF0000, 0x8000FF00, 0x800000FF }; | 288 const SkColor gColors1[] = { 0x80FF0000, 0x8000FF00, 0x800000FF }; |
| 289 const SkXfermode::Mode gModes1[] = { | 289 const SkXfermode::Mode gModes1[] = { |
| 290 SkXfermode::kSrcOver_Mode, | 290 SkXfermode::kSrcOver_Mode, |
| 291 SkXfermode::kXor_Mode, | 291 SkXfermode::kXor_Mode, |
| 292 SkXfermode::kDstOut_Mode, | 292 SkXfermode::kDstOut_Mode, |
| 293 SkXfermode::kSrcATop_Mode, | 293 SkXfermode::kSrcATop_Mode, |
| 294 }; | 294 }; |
| 295 DEF_GM( return new ComposeColorFilterGM(gColors1, gModes1, "alpha"); ) | 295 DEF_GM( return new ComposeColorFilterGM(gColors1, gModes1, "alpha"); ) |
| OLD | NEW |