Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(417)

Side by Side Diff: gm/hardstop_gradients.cpp

Issue 2204873005: Update hardstop_gradients GM to include more special cases (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Add more comments Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2016 Google Inc. 2 * Copyright 2016 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 /* 8 /*
9 * This GM presents a variety of different gradients with different 9 * This GM presents a variety of different gradients with different
10 * tile modes. Each entry in the table is a rectangle with a linear 10 * tile modes. Each entry in the table is a rectangle with a linear
11 * gradient that spans from its left edge to its right edge. The rows 11 * gradient that spans from its left edge to its right edge. The rows
12 * in the table represent different color/position configurations, 12 * in the table represent different color/position configurations,
13 * while the columns in the table represent different tile modes. In 13 * while the columns in the table represent different tile modes. In
14 * order to highlight the differences between tile modes, the gradient 14 * order to highlight the differences between tile modes, the gradient
15 * starts and ends at 30 pixel inset from either side of the rectangle. 15 * starts and ends at 30 pixel inset from either side of the rectangle.
16 * 16 *
17 * | Clamp Repeat Mirror 17 * | Clamp Repeat Mirror
18 * _____________________|___________________________________________ 18 * ___________________________|___________________________________________
19 * 2-color | rect00 rect01 rect02 19 * 2-color | rect00 rect01 rect02
20 * 3-color | rect10 rect11 rect12 20 * 3-color even | rect10 rect11 rect12
21 * 5-color hard stop | rect20 rect21 rect22 21 * 3-color texture | rect20 rect21 rect22
22 * 5-color edge case 1 | rect30 rect31 rect32 22 * 5-color hard stop | rect30 rect31 rect32
23 * 5-color edge case 2 | rect40 rect41 rect42 23 * 4-color hard stop centered | rect40 rect41 rect42
24 * 3-color hard stop 001 | rect50 rect51 rect52
25 * 3-color hard stop 011 | rect60 rect61 rect62
24 * 26 *
25 * The LAST two t-values in edge case 1 are the same, while the FIRST 27 * The first three rows are cases covered by pre-hard-stop code; simple
26 * two t-values in edge case 2 are the same. 28 * 2-color gradients, 3-color gradients with the middle color centered,
29 * and general gradients that are rendered from a texture atlas.
30 *
31 * The next four rows all deal with hard stop gradients. The fourth row
32 * is a generic hard stop gradient, while the three subsequent rows deal
33 * with special cases of hard stop gradients; centered hard stop gradients
34 * (with t-values 0, 0.5, 0.5, 1), and two edge cases (with t-values
35 * 0, 0, 1 and 0, 1, 1).
27 */ 36 */
28 37
29 #include "gm.h" 38 #include "gm.h"
30 39
31 #include "SkGradientShader.h" 40 #include "SkGradientShader.h"
32 41
33 const int WIDTH = 500; 42 const int WIDTH = 500;
34 const int HEIGHT = 500; 43 const int HEIGHT = 500;
35 44
36 const int NUM_ROWS = 5; 45 const int NUM_ROWS = 7;
37 const int NUM_COLS = 3; 46 const int NUM_COLS = 3;
38 47
39 const int CELL_WIDTH = WIDTH / NUM_COLS; 48 const int CELL_WIDTH = WIDTH / NUM_COLS;
40 const int CELL_HEIGHT = HEIGHT / NUM_ROWS; 49 const int CELL_HEIGHT = HEIGHT / NUM_ROWS;
41 50
42 const int PAD_WIDTH = 3; 51 const int PAD_WIDTH = 3;
43 const int PAD_HEIGHT = 3; 52 const int PAD_HEIGHT = 3;
44 53
45 const int RECT_WIDTH = CELL_WIDTH - (2 * PAD_WIDTH); 54 const int RECT_WIDTH = CELL_WIDTH - (2 * PAD_WIDTH);
46 const int RECT_HEIGHT = CELL_HEIGHT - (2 * PAD_HEIGHT); 55 const int RECT_HEIGHT = CELL_HEIGHT - (2 * PAD_HEIGHT);
47 56
48 static void shade_rect(SkCanvas* canvas, sk_sp<SkShader> shader, int cellRow, in t cellCol) { 57 static void shade_rect(SkCanvas* canvas, sk_sp<SkShader> shader, int cellRow, in t cellCol) {
49 SkPaint paint; 58 SkPaint paint;
50 paint.setShader(shader); 59 paint.setShader(shader);
51 60
52 SkRect rect = SkRect::MakeXYWH(SkIntToScalar(cellCol * CELL_WIDTH + PAD_WID TH), 61 SkRect rect = SkRect::MakeXYWH(SkIntToScalar(cellCol * CELL_WIDTH + PAD_WID TH),
53 SkIntToScalar(cellRow * CELL_HEIGHT + PAD_HEI GHT), 62 SkIntToScalar(cellRow * CELL_HEIGHT + PAD_HEI GHT),
54 SkIntToScalar(RECT_WIDTH), 63 SkIntToScalar(RECT_WIDTH),
55 SkIntToScalar(RECT_HEIGHT)); 64 SkIntToScalar(RECT_HEIGHT));
56 65
57 canvas->drawRect(rect, paint); 66 canvas->drawRect(rect, paint);
58 } 67 }
59 68
60 static void create_gradient_points(int cellRow, int cellCol, SkPoint points[2]) { 69 static void create_gradient_points(int cellRow, int cellCol, SkPoint points[2]) {
61 const int X_OFFSET = 30; 70 const int X_OFFSET = 30;
62 71
63 auto x0 = SkIntToScalar(cellCol * CELL_WIDTH + PAD_WIDTH + X_OFFSET); 72 auto x0 = SkIntToScalar(cellCol * CELL_WIDTH + PAD_WIDTH + X_OFFSET);
64 auto x1 = SkIntToScalar((cellCol+1) * CELL_WIDTH - PAD_WIDTH - X_OFFSET); 73 auto x1 = SkIntToScalar((cellCol+1) * CELL_WIDTH - PAD_WIDTH - X_OFFSET);
65 auto y = SkIntToScalar(cellRow * CELL_HEIGHT + PAD_HEIGHT + RECT_HEIGHT/2); 74 auto y = SkIntToScalar(cellRow * CELL_HEIGHT + PAD_HEIGHT + RECT_HEIGHT /2);
66 75
67 points[0] = SkPoint::Make(x0, y); 76 points[0] = SkPoint::Make(x0, y);
68 points[1] = SkPoint::Make(x1, y); 77 points[1] = SkPoint::Make(x1, y);
69 } 78 }
70 79
71 class HardstopGradientShaderGM : public skiagm::GM { 80 class HardstopGradientShaderGM : public skiagm::GM {
72 public: 81 public:
73 HardstopGradientShaderGM() { 82 HardstopGradientShaderGM() {
74 83
75 } 84 }
(...skipping 11 matching lines...) Expand all
87 SkPoint points[2]; 96 SkPoint points[2];
88 97
89 SkColor colors[] = { 98 SkColor colors[] = {
90 SK_ColorRED, 99 SK_ColorRED,
91 SK_ColorGREEN, 100 SK_ColorGREEN,
92 SK_ColorBLUE, 101 SK_ColorBLUE,
93 SK_ColorYELLOW, 102 SK_ColorYELLOW,
94 SK_ColorMAGENTA, 103 SK_ColorMAGENTA,
95 }; 104 };
96 105
97 SkScalar row3[] = {0.00f, 0.25f, 0.50f, 0.50f, 1.00f}; 106 SkScalar row3[] = {0.00f, 0.25f, 1.00f};
98 SkScalar row4[] = {0.00f, 0.25f, 0.50f, 1.00f, 1.00f}; 107 SkScalar row4[] = {0.00f, 0.25f, 0.50f, 0.50f, 1.00f};
99 SkScalar row5[] = {0.00f, 0.00f, 0.50f, 0.50f, 1.00f}; 108 SkScalar row5[] = {0.00f, 0.50f, 0.50f, 1.00f};
109 SkScalar row6[] = {0.00f, 0.00f, 1.00f};
110 SkScalar row7[] = {0.00f, 1.00f, 1.00f};
100 111
101 SkScalar* positions[] = { 112 SkScalar* positions[NUM_ROWS] = {
102 nullptr, 113 nullptr,
103 nullptr, 114 nullptr,
104 row3, 115 row3,
105 row4, 116 row4,
106 row5, 117 row5,
118 row6,
119 row7,
107 }; 120 };
108 121
109 int numGradientColors[] = { 122 int numGradientColors[NUM_ROWS] = {
110 2, 123 2,
111 3, 124 3,
125 3,
112 5, 126 5,
113 5, 127 4,
114 5, 128 3,
129 3,
115 }; 130 };
116 131
117 SkShader::TileMode tilemodes[] = { 132 SkShader::TileMode tilemodes[NUM_COLS] = {
118 SkShader::kClamp_TileMode, 133 SkShader::kClamp_TileMode,
119 SkShader::kRepeat_TileMode, 134 SkShader::kRepeat_TileMode,
120 SkShader::kMirror_TileMode, 135 SkShader::kMirror_TileMode,
121 }; 136 };
122 137
123 for (int cellRow = 0; cellRow < NUM_ROWS; cellRow++) { 138 for (int cellRow = 0; cellRow < NUM_ROWS; cellRow++) {
124 for (int cellCol = 0; cellCol < NUM_COLS; cellCol++) { 139 for (int cellCol = 0; cellCol < NUM_COLS; cellCol++) {
125 create_gradient_points(cellRow, cellCol, points); 140 create_gradient_points(cellRow, cellCol, points);
126 141
127 auto shader = SkGradientShader::MakeLinear( 142 auto shader = SkGradientShader::MakeLinear(
128 points, 143 points,
129 colors, 144 colors,
130 positions[cellRow], 145 positions[cellRow],
131 numGradientColors[cellRow], 146 numGradientColors[cellRow],
132 tilemodes[cellCol], 147 tilemodes[cellCol],
133 0, 148 0,
134 nullptr); 149 nullptr);
135 150
136 shade_rect(canvas, shader, cellRow, cellCol); 151 shade_rect(canvas, shader, cellRow, cellCol);
137 } 152 }
138 } 153 }
139 } 154 }
140 155
141 private: 156 private:
142 typedef skiagm::GM INHERITED; 157 typedef skiagm::GM INHERITED;
143 }; 158 };
144 159
145 DEF_GM(return new HardstopGradientShaderGM;) 160 DEF_GM(return new HardstopGradientShaderGM;)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698