OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "SkCanvas.h" | 8 #include "SkCanvas.h" |
9 #include "SkColor.h" | 9 #include "SkColor.h" |
10 #include "SkGradientShader.h" | 10 #include "SkGradientShader.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 {{0, 0}, {0, 1}}, | 30 {{0, 0}, {0, 1}}, |
31 {{1, 0}, {0, 0}}, | 31 {{1, 0}, {0, 0}}, |
32 {{0, 1}, {0, 0}}, | 32 {{0, 1}, {0, 0}}, |
33 | 33 |
34 {{0, 0}, {1, 1}}, | 34 {{0, 0}, {1, 1}}, |
35 {{1, 1}, {0, 0}}, | 35 {{1, 1}, {0, 0}}, |
36 {{1, 0}, {0, 1}}, | 36 {{1, 0}, {0, 1}}, |
37 {{0, 1}, {1, 0}} | 37 {{0, 1}, {1, 0}} |
38 }; | 38 }; |
39 | 39 |
| 40 static const SkPoint radialPts[][2] = { |
| 41 {{0, 0.5}, {1, 0.5}}, |
| 42 {{0.5, 0 }, {0.5, 1 }}, |
| 43 {{1, 0.5}, {0, 0.5}}, |
| 44 {{0.5, 1 }, {0.5, 0 }}, |
| 45 |
| 46 {{0, 0}, {1, 1}}, |
| 47 {{1, 1}, {0, 0}}, |
| 48 {{1, 0}, {0, 1}}, |
| 49 {{0, 1}, {1, 0}} |
| 50 }; |
| 51 |
| 52 |
40 static const SkScalar TESTGRID_X = 200; // pixels allocated to each image in
x dimension | 53 static const SkScalar TESTGRID_X = 200; // pixels allocated to each image in
x dimension |
41 static const SkScalar TESTGRID_Y = 200; // pixels allocated to each image in
y dimension | 54 static const SkScalar TESTGRID_Y = 200; // pixels allocated to each image in
y dimension |
42 | 55 |
43 static const int IMAGES_X = 4; // number of images per row | 56 static const int IMAGES_X = 4; // number of images per row |
44 | 57 |
45 static SkShader* make_linear_gradient(const SkPoint pts[2]) { | 58 static SkShader* make_linear_gradient(const SkPoint pts[2]) { |
46 return SkGradientShader::CreateLinear(pts, gColors, NULL, SK_ARRAY_COUNT(gCo
lors), | 59 return SkGradientShader::CreateLinear(pts, gColors, NULL, SK_ARRAY_COUNT(gCo
lors), |
47 SkShader::kClamp_TileMode, NULL); | 60 SkShader::kClamp_TileMode, NULL); |
48 } | 61 } |
49 | 62 |
| 63 static SkShader* make_radial_gradient(const SkPoint pts[2]) { |
| 64 SkPoint center; |
| 65 center.set(SkScalarAve(pts[0].fX, pts[1].fX), |
| 66 SkScalarAve(pts[0].fY, pts[1].fY)); |
| 67 float radius = (center - pts[0]).length(); |
| 68 return SkGradientShader::CreateRadial(center, radius, gColors, NULL, SK_ARRA
Y_COUNT(gColors), |
| 69 SkShader::kClamp_TileMode, NULL); |
| 70 } |
| 71 |
50 static void draw_gradients(SkCanvas* canvas, SkShader* (*makeShader)(const SkPoi
nt[2]), | 72 static void draw_gradients(SkCanvas* canvas, SkShader* (*makeShader)(const SkPoi
nt[2]), |
51 const SkPoint ptsArray[][2], int numImages) { | 73 const SkPoint ptsArray[][2], int numImages) { |
52 // Use some nice prime numbers for the rectangle and matrix with | 74 // Use some nice prime numbers for the rectangle and matrix with |
53 // different scaling along the x and y axes (which is the bug this | 75 // different scaling along the x and y axes (which is the bug this |
54 // test addresses, where incorrect order of operations mixed up the axes) | 76 // test addresses, where incorrect order of operations mixed up the axes) |
55 SkRect rectGrad = { 43, 61, 181, 167 }; | 77 SkRect rectGrad = { 43, 61, 181, 167 }; |
56 SkMatrix shaderMat; | 78 SkMatrix shaderMat; |
57 shaderMat.setScale(rectGrad.width(), rectGrad.height()); | 79 shaderMat.setScale(rectGrad.width(), rectGrad.height()); |
58 shaderMat.postTranslate(rectGrad.left(), rectGrad.top()); | 80 shaderMat.postTranslate(rectGrad.left(), rectGrad.top()); |
59 | 81 |
60 canvas->save(); | 82 canvas->save(); |
61 for (int i = 0; i < numImages; i++) { | 83 for (int i = 0; i < numImages; i++) { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 return SkString("gradient_matrix"); | 116 return SkString("gradient_matrix"); |
95 } | 117 } |
96 | 118 |
97 virtual SkISize onISize() SK_OVERRIDE { | 119 virtual SkISize onISize() SK_OVERRIDE { |
98 return SkISize::Make(800, 800); | 120 return SkISize::Make(800, 800); |
99 } | 121 } |
100 | 122 |
101 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 123 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
102 draw_gradients(canvas, &make_linear_gradient, | 124 draw_gradients(canvas, &make_linear_gradient, |
103 linearPts, SK_ARRAY_COUNT(linearPts)); | 125 linearPts, SK_ARRAY_COUNT(linearPts)); |
| 126 |
| 127 canvas->translate(0, TESTGRID_Y); |
| 128 |
| 129 draw_gradients(canvas, &make_radial_gradient, |
| 130 radialPts, SK_ARRAY_COUNT(radialPts)); |
104 } | 131 } |
105 | 132 |
106 private: | 133 private: |
107 typedef GM INHERITED; | 134 typedef GM INHERITED; |
108 }; | 135 }; |
109 | 136 |
110 DEF_GM( return new GradientMatrixGM; ) | 137 DEF_GM( return new GradientMatrixGM; ) |
111 } | 138 } |
OLD | NEW |