| 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 virtual SkString onShortName() { | 56 virtual SkString onShortName() { |
| 57 return SkString("colormatrix"); | 57 return SkString("colormatrix"); |
| 58 } | 58 } |
| 59 | 59 |
| 60 virtual SkISize onISize() { | 60 virtual SkISize onISize() { |
| 61 return make_isize(WIDTH, HEIGHT); | 61 return make_isize(WIDTH, HEIGHT); |
| 62 } | 62 } |
| 63 | 63 |
| 64 SkBitmap createSolidBitmap(int width, int height) { | 64 SkBitmap createSolidBitmap(int width, int height) { |
| 65 SkBitmap bm; | 65 SkBitmap bm; |
| 66 bm.setConfig(SkBitmap::kARGB_8888_Config, width, height); | 66 bm.allocN32Pixels(width, height); |
| 67 bm.allocPixels(); | |
| 68 SkCanvas canvas(bm); | 67 SkCanvas canvas(bm); |
| 69 canvas.clear(0x0); | 68 canvas.clear(0x0); |
| 70 for (int y = 0; y < height; ++y) { | 69 for (int y = 0; y < height; ++y) { |
| 71 for (int x = 0; x < width; ++x) { | 70 for (int x = 0; x < width; ++x) { |
| 72 SkPaint paint; | 71 SkPaint paint; |
| 73 paint.setColor(SkColorSetARGB(255, x * 255 / width, y * 255 / he
ight, 0)); | 72 paint.setColor(SkColorSetARGB(255, x * 255 / width, y * 255 / he
ight, 0)); |
| 74 canvas.drawRect(SkRect::MakeXYWH(SkIntToScalar(x), | 73 canvas.drawRect(SkRect::MakeXYWH(SkIntToScalar(x), |
| 75 SkIntToScalar(y), SK_Scalar1, SK_Scalar1), paint); | 74 SkIntToScalar(y), SK_Scalar1, SK_Scalar1), paint); |
| 76 } | 75 } |
| 77 } | 76 } |
| 78 return bm; | 77 return bm; |
| 79 } | 78 } |
| 80 | 79 |
| 81 // creates a bitmap with shades of transparent gray. | 80 // creates a bitmap with shades of transparent gray. |
| 82 SkBitmap createTransparentBitmap(int width, int height) { | 81 SkBitmap createTransparentBitmap(int width, int height) { |
| 83 SkBitmap bm; | 82 SkBitmap bm; |
| 84 bm.setConfig(SkBitmap::kARGB_8888_Config, width, height); | 83 bm.allocN32Pixels(width, height); |
| 85 bm.allocPixels(); | |
| 86 SkCanvas canvas(bm); | 84 SkCanvas canvas(bm); |
| 87 canvas.clear(0x0); | 85 canvas.clear(0x0); |
| 88 | 86 |
| 89 SkPoint pts[] = {{0, 0}, {SkIntToScalar(width), SkIntToScalar(height)}}; | 87 SkPoint pts[] = {{0, 0}, {SkIntToScalar(width), SkIntToScalar(height)}}; |
| 90 SkColor colors[] = {0x00000000, 0xFFFFFFFF}; | 88 SkColor colors[] = {0x00000000, 0xFFFFFFFF}; |
| 91 SkPaint paint; | 89 SkPaint paint; |
| 92 paint.setShader(SkGradientShader::CreateLinear(pts, colors, NULL, 2, | 90 paint.setShader(SkGradientShader::CreateLinear(pts, colors, NULL, 2, |
| 93 SkShader::kClamp_TileMode
))->unref(); | 91 SkShader::kClamp_TileMode
))->unref(); |
| 94 canvas.drawRect(SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(heigh
t)), paint); | 92 canvas.drawRect(SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(heigh
t)), paint); |
| 95 return bm; | 93 return bm; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 SkBitmap fTransparentBitmap; | 166 SkBitmap fTransparentBitmap; |
| 169 typedef GM INHERITED; | 167 typedef GM INHERITED; |
| 170 }; | 168 }; |
| 171 | 169 |
| 172 ////////////////////////////////////////////////////////////////////////////// | 170 ////////////////////////////////////////////////////////////////////////////// |
| 173 | 171 |
| 174 static GM* MyFactory(void*) { return new ColorMatrixGM; } | 172 static GM* MyFactory(void*) { return new ColorMatrixGM; } |
| 175 static GMRegistry reg(MyFactory); | 173 static GMRegistry reg(MyFactory); |
| 176 | 174 |
| 177 } | 175 } |
| OLD | NEW |