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 "SkColor.h" | 9 #include "SkColor.h" |
10 #include "SkBitmapSource.h" | 10 #include "SkBitmapSource.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 protected: | 26 protected: |
27 virtual SkString onShortName() { | 27 virtual SkString onShortName() { |
28 return SkString("imagefiltersscaled"); | 28 return SkString("imagefiltersscaled"); |
29 } | 29 } |
30 | 30 |
31 virtual SkISize onISize() { | 31 virtual SkISize onISize() { |
32 return make_isize(860, 500); | 32 return make_isize(860, 500); |
33 } | 33 } |
34 | 34 |
35 void make_checkerboard() { | 35 void make_checkerboard() { |
36 fCheckerboard.setConfig(SkBitmap::kARGB_8888_Config, 64, 64); | 36 fCheckerboard.allocN32Pixels(64, 64); |
37 fCheckerboard.allocPixels(); | |
38 SkBitmapDevice device(fCheckerboard); | 37 SkBitmapDevice device(fCheckerboard); |
39 SkCanvas canvas(&device); | 38 SkCanvas canvas(&device); |
40 canvas.clear(0x00000000); | 39 canvas.clear(0x00000000); |
41 SkPaint darkPaint; | 40 SkPaint darkPaint; |
42 darkPaint.setColor(0xFF404040); | 41 darkPaint.setColor(0xFF404040); |
43 SkPaint lightPaint; | 42 SkPaint lightPaint; |
44 lightPaint.setColor(0xFFA0A0A0); | 43 lightPaint.setColor(0xFFA0A0A0); |
45 for (int y = 0; y < 64; y += 16) { | 44 for (int y = 0; y < 64; y += 16) { |
46 for (int x = 0; x < 64; x += 16) { | 45 for (int x = 0; x < 64; x += 16) { |
47 canvas.save(); | 46 canvas.save(); |
48 canvas.translate(SkIntToScalar(x), SkIntToScalar(y)); | 47 canvas.translate(SkIntToScalar(x), SkIntToScalar(y)); |
49 canvas.drawRect(SkRect::MakeXYWH(0, 0, 8, 8), darkPaint); | 48 canvas.drawRect(SkRect::MakeXYWH(0, 0, 8, 8), darkPaint); |
50 canvas.drawRect(SkRect::MakeXYWH(8, 0, 8, 8), lightPaint); | 49 canvas.drawRect(SkRect::MakeXYWH(8, 0, 8, 8), lightPaint); |
51 canvas.drawRect(SkRect::MakeXYWH(0, 8, 8, 8), lightPaint); | 50 canvas.drawRect(SkRect::MakeXYWH(0, 8, 8, 8), lightPaint); |
52 canvas.drawRect(SkRect::MakeXYWH(8, 8, 8, 8), darkPaint); | 51 canvas.drawRect(SkRect::MakeXYWH(8, 8, 8, 8), darkPaint); |
53 canvas.restore(); | 52 canvas.restore(); |
54 } | 53 } |
55 } | 54 } |
56 } | 55 } |
57 | 56 |
58 void make_gradient_circle(int width, int height) { | 57 void make_gradient_circle(int width, int height) { |
59 SkScalar x = SkIntToScalar(width / 2); | 58 SkScalar x = SkIntToScalar(width / 2); |
60 SkScalar y = SkIntToScalar(height / 2); | 59 SkScalar y = SkIntToScalar(height / 2); |
61 SkScalar radius = SkScalarMul(SkMinScalar(x, y), SkIntToScalar(4) / SkIn
tToScalar(5)); | 60 SkScalar radius = SkScalarMul(SkMinScalar(x, y), SkIntToScalar(4) / SkIn
tToScalar(5)); |
62 fGradientCircle.setConfig(SkBitmap::kARGB_8888_Config, width, height); | 61 fGradientCircle.allocN32Pixels(width, height); |
63 fGradientCircle.allocPixels(); | |
64 SkBitmapDevice device(fGradientCircle); | 62 SkBitmapDevice device(fGradientCircle); |
65 SkCanvas canvas(&device); | 63 SkCanvas canvas(&device); |
66 canvas.clear(0x00000000); | 64 canvas.clear(0x00000000); |
67 SkColor colors[2]; | 65 SkColor colors[2]; |
68 colors[0] = SK_ColorWHITE; | 66 colors[0] = SK_ColorWHITE; |
69 colors[1] = SK_ColorBLACK; | 67 colors[1] = SK_ColorBLACK; |
70 SkAutoTUnref<SkShader> shader( | 68 SkAutoTUnref<SkShader> shader( |
71 SkGradientShader::CreateRadial(SkPoint::Make(x, y), radius, colors,
NULL, 2, | 69 SkGradientShader::CreateRadial(SkPoint::Make(x, y), radius, colors,
NULL, 2, |
72 SkShader::kClamp_TileMode) | 70 SkShader::kClamp_TileMode) |
73 ); | 71 ); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 SkBitmap fGradientCircle; | 141 SkBitmap fGradientCircle; |
144 typedef GM INHERITED; | 142 typedef GM INHERITED; |
145 }; | 143 }; |
146 | 144 |
147 ////////////////////////////////////////////////////////////////////////////// | 145 ////////////////////////////////////////////////////////////////////////////// |
148 | 146 |
149 static GM* MyFactory(void*) { return new ImageFiltersScaledGM; } | 147 static GM* MyFactory(void*) { return new ImageFiltersScaledGM; } |
150 static GMRegistry reg(MyFactory); | 148 static GMRegistry reg(MyFactory); |
151 | 149 |
152 } | 150 } |
OLD | NEW |