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 17 matching lines...) Expand all Loading... |
28 virtual SkString onShortName() { | 28 virtual SkString onShortName() { |
29 return SkString("imagefiltersscaled"); | 29 return SkString("imagefiltersscaled"); |
30 } | 30 } |
31 | 31 |
32 virtual SkISize onISize() { | 32 virtual SkISize onISize() { |
33 return make_isize(860, 500); | 33 return make_isize(860, 500); |
34 } | 34 } |
35 | 35 |
36 void make_checkerboard() { | 36 void make_checkerboard() { |
37 fCheckerboard.allocN32Pixels(64, 64); | 37 fCheckerboard.allocN32Pixels(64, 64); |
38 SkBitmapDevice device(fCheckerboard); | 38 SkCanvas canvas(fCheckerboard); |
39 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.allocN32Pixels(width, height); | 61 fGradientCircle.allocN32Pixels(width, height); |
63 SkBitmapDevice device(fGradientCircle); | 62 SkCanvas canvas(fGradientCircle); |
64 SkCanvas canvas(&device); | |
65 canvas.clear(0x00000000); | 63 canvas.clear(0x00000000); |
66 SkColor colors[2]; | 64 SkColor colors[2]; |
67 colors[0] = SK_ColorWHITE; | 65 colors[0] = SK_ColorWHITE; |
68 colors[1] = SK_ColorBLACK; | 66 colors[1] = SK_ColorBLACK; |
69 SkAutoTUnref<SkShader> shader( | 67 SkAutoTUnref<SkShader> shader( |
70 SkGradientShader::CreateRadial(SkPoint::Make(x, y), radius, colors,
NULL, 2, | 68 SkGradientShader::CreateRadial(SkPoint::Make(x, y), radius, colors,
NULL, 2, |
71 SkShader::kClamp_TileMode) | 69 SkShader::kClamp_TileMode) |
72 ); | 70 ); |
73 SkPaint paint; | 71 SkPaint paint; |
74 paint.setShader(shader); | 72 paint.setShader(shader); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 SkBitmap fGradientCircle; | 143 SkBitmap fGradientCircle; |
146 typedef GM INHERITED; | 144 typedef GM INHERITED; |
147 }; | 145 }; |
148 | 146 |
149 ////////////////////////////////////////////////////////////////////////////// | 147 ////////////////////////////////////////////////////////////////////////////// |
150 | 148 |
151 static GM* MyFactory(void*) { return new ImageFiltersScaledGM; } | 149 static GM* MyFactory(void*) { return new ImageFiltersScaledGM; } |
152 static GMRegistry reg(MyFactory); | 150 static GMRegistry reg(MyFactory); |
153 | 151 |
154 } | 152 } |
OLD | NEW |