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 "SkColorMatrixFilter.h" | 9 #include "SkColorMatrixFilter.h" |
10 #include "SkGradientShader.h" | 10 #include "SkGradientShader.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 protected: | 30 protected: |
31 SkString onShortName() override { | 31 SkString onShortName() override { |
32 return SkString("colormatrix"); | 32 return SkString("colormatrix"); |
33 } | 33 } |
34 | 34 |
35 SkISize onISize() override { | 35 SkISize onISize() override { |
36 return SkISize::Make(WIDTH, HEIGHT); | 36 return SkISize::Make(WIDTH, HEIGHT); |
37 } | 37 } |
38 | 38 |
39 void onOnceBeforeDraw() override { | 39 void onOnceBeforeDraw() override { |
40 fSolidImg.reset(CreateSolidBitmap(64, 64)); | 40 fSolidImg = CreateSolidBitmap(64, 64); |
41 fTransparentImg.reset(CreateTransparentBitmap(64, 64)); | 41 fTransparentImg = CreateTransparentBitmap(64, 64); |
42 } | 42 } |
43 | 43 |
44 static SkImage* CreateSolidBitmap(int width, int height) { | 44 static sk_sp<SkImage> CreateSolidBitmap(int width, int height) { |
45 SkBitmap bm; | 45 SkBitmap bm; |
46 bm.allocN32Pixels(width, height); | 46 bm.allocN32Pixels(width, height); |
47 SkCanvas canvas(bm); | 47 SkCanvas canvas(bm); |
48 canvas.clear(0x0); | 48 canvas.clear(0x0); |
49 for (int y = 0; y < height; ++y) { | 49 for (int y = 0; y < height; ++y) { |
50 for (int x = 0; x < width; ++x) { | 50 for (int x = 0; x < width; ++x) { |
51 SkPaint paint; | 51 SkPaint paint; |
52 paint.setColor(SkColorSetARGB(255, x * 255 / width, y * 255 / he
ight, 0)); | 52 paint.setColor(SkColorSetARGB(255, x * 255 / width, y * 255 / he
ight, 0)); |
53 canvas.drawRect(SkRect::MakeXYWH(SkIntToScalar(x), | 53 canvas.drawRect(SkRect::MakeXYWH(SkIntToScalar(x), |
54 SkIntToScalar(y), SK_Scalar1, SK_Scalar1), paint); | 54 SkIntToScalar(y), SK_Scalar1, SK_Scalar1), paint); |
55 } | 55 } |
56 } | 56 } |
57 return SkImage::NewFromBitmap(bm); | 57 return SkImage::MakeFromBitmap(bm); |
58 } | 58 } |
59 | 59 |
60 // creates a bitmap with shades of transparent gray. | 60 // creates a bitmap with shades of transparent gray. |
61 static SkImage* CreateTransparentBitmap(int width, int height) { | 61 static sk_sp<SkImage> CreateTransparentBitmap(int width, int height) { |
62 SkBitmap bm; | 62 SkBitmap bm; |
63 bm.allocN32Pixels(width, height); | 63 bm.allocN32Pixels(width, height); |
64 SkCanvas canvas(bm); | 64 SkCanvas canvas(bm); |
65 canvas.clear(0x0); | 65 canvas.clear(0x0); |
66 | 66 |
67 SkPoint pts[] = {{0, 0}, {SkIntToScalar(width), SkIntToScalar(height)}}; | 67 SkPoint pts[] = {{0, 0}, {SkIntToScalar(width), SkIntToScalar(height)}}; |
68 SkColor colors[] = {0x00000000, 0xFFFFFFFF}; | 68 SkColor colors[] = {0x00000000, 0xFFFFFFFF}; |
69 SkPaint paint; | 69 SkPaint paint; |
70 paint.setShader(SkGradientShader::MakeLinear(pts, colors, nullptr, 2, | 70 paint.setShader(SkGradientShader::MakeLinear(pts, colors, nullptr, 2, |
71 SkShader::kClamp_TileMode))
; | 71 SkShader::kClamp_TileMode))
; |
72 canvas.drawRect(SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(heigh
t)), paint); | 72 canvas.drawRect(SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(heigh
t)), paint); |
73 return SkImage::NewFromBitmap(bm); | 73 return SkImage::MakeFromBitmap(bm); |
74 } | 74 } |
75 | 75 |
76 void onDraw(SkCanvas* canvas) override { | 76 void onDraw(SkCanvas* canvas) override { |
77 SkPaint paint; | 77 SkPaint paint; |
78 SkColorMatrix matrix; | 78 SkColorMatrix matrix; |
79 | 79 |
80 paint.setXfermodeMode(SkXfermode::kSrc_Mode); | 80 paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
81 const SkImage* bmps[] = { fSolidImg, fTransparentImg }; | 81 const SkImage* bmps[] = { fSolidImg.get(), fTransparentImg.get() }; |
82 | 82 |
83 for (size_t i = 0; i < SK_ARRAY_COUNT(bmps); ++i) { | 83 for (size_t i = 0; i < SK_ARRAY_COUNT(bmps); ++i) { |
84 matrix.setIdentity(); | 84 matrix.setIdentity(); |
85 set_color_matrix(&paint, matrix); | 85 set_color_matrix(&paint, matrix); |
86 canvas->drawImage(bmps[i], 0, 0, &paint); | 86 canvas->drawImage(bmps[i], 0, 0, &paint); |
87 | 87 |
88 matrix.setRotate(SkColorMatrix::kR_Axis, 90); | 88 matrix.setRotate(SkColorMatrix::kR_Axis, 90); |
89 set_color_matrix(&paint, matrix); | 89 set_color_matrix(&paint, matrix); |
90 canvas->drawImage(bmps[i], 80, 0, &paint); | 90 canvas->drawImage(bmps[i], 80, 0, &paint); |
91 | 91 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 }; | 132 }; |
133 | 133 |
134 set_array(&paint, data); | 134 set_array(&paint, data); |
135 canvas->drawImage(bmps[i], 160, 160, &paint); | 135 canvas->drawImage(bmps[i], 160, 160, &paint); |
136 /////////////////////////////////////////////// | 136 /////////////////////////////////////////////// |
137 canvas->translate(0, 240); | 137 canvas->translate(0, 240); |
138 } | 138 } |
139 } | 139 } |
140 | 140 |
141 private: | 141 private: |
142 SkAutoTUnref<SkImage> fSolidImg; | 142 sk_sp<SkImage> fSolidImg; |
143 SkAutoTUnref<SkImage> fTransparentImg; | 143 sk_sp<SkImage> fTransparentImg; |
144 | 144 |
145 typedef skiagm::GM INHERITED; | 145 typedef skiagm::GM INHERITED; |
146 }; | 146 }; |
147 DEF_GM( return new ColorMatrixGM; ) | 147 DEF_GM( return new ColorMatrixGM; ) |
148 | 148 |
OLD | NEW |