Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 |
|
tomhudson
2016/08/03 14:14:36
I can intuit meanings of most of these names if I
| |
| 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 * | 24 * 3-color hard stop 001 | rect50 rect51 rect52 |
| 25 * The LAST two t-values in edge case 1 are the same, while the FIRST | 25 * 3-color hard stop 011 | rect60 rect61 rect62 |
| 26 * two t-values in edge case 2 are the same. | |
| 27 */ | 26 */ |
| 28 | 27 |
| 29 #include "gm.h" | 28 #include "gm.h" |
| 30 | 29 |
| 31 #include "SkGradientShader.h" | 30 #include "SkGradientShader.h" |
| 32 | 31 |
| 33 const int WIDTH = 500; | 32 const int WIDTH = 500; |
| 34 const int HEIGHT = 500; | 33 const int HEIGHT = 500; |
| 35 | 34 |
| 36 const int NUM_ROWS = 5; | 35 const int NUM_ROWS = 7; |
| 37 const int NUM_COLS = 3; | 36 const int NUM_COLS = 3; |
| 38 | 37 |
| 39 const int CELL_WIDTH = WIDTH / NUM_COLS; | 38 const int CELL_WIDTH = WIDTH / NUM_COLS; |
| 40 const int CELL_HEIGHT = HEIGHT / NUM_ROWS; | 39 const int CELL_HEIGHT = HEIGHT / NUM_ROWS; |
| 41 | 40 |
| 42 const int PAD_WIDTH = 3; | 41 const int PAD_WIDTH = 3; |
| 43 const int PAD_HEIGHT = 3; | 42 const int PAD_HEIGHT = 3; |
| 44 | 43 |
| 45 const int RECT_WIDTH = CELL_WIDTH - (2 * PAD_WIDTH); | 44 const int RECT_WIDTH = CELL_WIDTH - (2 * PAD_WIDTH); |
| 46 const int RECT_HEIGHT = CELL_HEIGHT - (2 * PAD_HEIGHT); | 45 const int RECT_HEIGHT = CELL_HEIGHT - (2 * PAD_HEIGHT); |
| 47 | 46 |
| 48 static void shade_rect(SkCanvas* canvas, sk_sp<SkShader> shader, int cellRow, in t cellCol) { | 47 static void shade_rect(SkCanvas* canvas, sk_sp<SkShader> shader, int cellRow, in t cellCol) { |
| 49 SkPaint paint; | 48 SkPaint paint; |
| 50 paint.setShader(shader); | 49 paint.setShader(shader); |
| 51 | 50 |
| 52 SkRect rect = SkRect::MakeXYWH(SkIntToScalar(cellCol * CELL_WIDTH + PAD_WID TH), | 51 SkRect rect = SkRect::MakeXYWH(SkIntToScalar(cellCol * CELL_WIDTH + PAD_WID TH), |
| 53 SkIntToScalar(cellRow * CELL_HEIGHT + PAD_HEI GHT), | 52 SkIntToScalar(cellRow * CELL_HEIGHT + PAD_HEI GHT), |
| 54 SkIntToScalar(RECT_WIDTH), | 53 SkIntToScalar(RECT_WIDTH), |
| 55 SkIntToScalar(RECT_HEIGHT)); | 54 SkIntToScalar(RECT_HEIGHT)); |
| 56 | 55 |
| 57 canvas->drawRect(rect, paint); | 56 canvas->drawRect(rect, paint); |
| 58 } | 57 } |
| 59 | 58 |
| 60 static void create_gradient_points(int cellRow, int cellCol, SkPoint points[2]) { | 59 static void create_gradient_points(int cellRow, int cellCol, SkPoint points[2]) { |
| 61 const int X_OFFSET = 30; | 60 const int X_OFFSET = 30; |
| 62 | 61 |
| 63 auto x0 = SkIntToScalar(cellCol * CELL_WIDTH + PAD_WIDTH + X_OFFSET); | 62 auto x0 = SkIntToScalar(cellCol * CELL_WIDTH + PAD_WIDTH + X_OFFSET); |
| 64 auto x1 = SkIntToScalar((cellCol+1) * CELL_WIDTH - PAD_WIDTH - X_OFFSET); | 63 auto x1 = SkIntToScalar((cellCol+1) * CELL_WIDTH - PAD_WIDTH - X_OFFSET); |
| 65 auto y = SkIntToScalar(cellRow * CELL_HEIGHT + PAD_HEIGHT + RECT_HEIGHT/2); | 64 auto y = SkIntToScalar(cellRow * CELL_HEIGHT + PAD_HEIGHT + RECT_HEIGHT /2); |
| 66 | 65 |
| 67 points[0] = SkPoint::Make(x0, y); | 66 points[0] = SkPoint::Make(x0, y); |
| 68 points[1] = SkPoint::Make(x1, y); | 67 points[1] = SkPoint::Make(x1, y); |
| 69 } | 68 } |
| 70 | 69 |
| 71 class HardstopGradientShaderGM : public skiagm::GM { | 70 class HardstopGradientShaderGM : public skiagm::GM { |
| 72 public: | 71 public: |
| 73 HardstopGradientShaderGM() { | 72 HardstopGradientShaderGM() { |
| 74 | 73 |
| 75 } | 74 } |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 87 SkPoint points[2]; | 86 SkPoint points[2]; |
| 88 | 87 |
| 89 SkColor colors[] = { | 88 SkColor colors[] = { |
| 90 SK_ColorRED, | 89 SK_ColorRED, |
| 91 SK_ColorGREEN, | 90 SK_ColorGREEN, |
| 92 SK_ColorBLUE, | 91 SK_ColorBLUE, |
| 93 SK_ColorYELLOW, | 92 SK_ColorYELLOW, |
| 94 SK_ColorMAGENTA, | 93 SK_ColorMAGENTA, |
| 95 }; | 94 }; |
| 96 | 95 |
| 97 SkScalar row3[] = {0.00f, 0.25f, 0.50f, 0.50f, 1.00f}; | 96 SkScalar row3[] = {0.00f, 0.25f, 1.00f}; |
| 98 SkScalar row4[] = {0.00f, 0.25f, 0.50f, 1.00f, 1.00f}; | 97 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}; | 98 SkScalar row5[] = {0.00f, 0.50f, 0.50f, 1.00f}; |
| 99 SkScalar row6[] = {0.00f, 0.00f, 1.00f}; | |
| 100 SkScalar row7[] = {0.00f, 1.00f, 1.00f}; | |
| 100 | 101 |
| 101 SkScalar* positions[] = { | 102 SkScalar* positions[NUM_ROWS] = { |
| 102 nullptr, | 103 nullptr, |
| 103 nullptr, | 104 nullptr, |
| 104 row3, | 105 row3, |
| 105 row4, | 106 row4, |
| 106 row5, | 107 row5, |
| 108 row6, | |
| 109 row7, | |
| 107 }; | 110 }; |
| 108 | 111 |
| 109 int numGradientColors[] = { | 112 int numGradientColors[NUM_ROWS] = { |
| 110 2, | 113 2, |
| 111 3, | 114 3, |
| 115 3, | |
| 112 5, | 116 5, |
| 113 5, | 117 4, |
| 114 5, | 118 3, |
| 119 3, | |
| 115 }; | 120 }; |
| 116 | 121 |
| 117 SkShader::TileMode tilemodes[] = { | 122 SkShader::TileMode tilemodes[NUM_COLS] = { |
| 118 SkShader::kClamp_TileMode, | 123 SkShader::kClamp_TileMode, |
| 119 SkShader::kRepeat_TileMode, | 124 SkShader::kRepeat_TileMode, |
| 120 SkShader::kMirror_TileMode, | 125 SkShader::kMirror_TileMode, |
| 121 }; | 126 }; |
| 122 | 127 |
| 123 for (int cellRow = 0; cellRow < NUM_ROWS; cellRow++) { | 128 for (int cellRow = 0; cellRow < NUM_ROWS; cellRow++) { |
| 124 for (int cellCol = 0; cellCol < NUM_COLS; cellCol++) { | 129 for (int cellCol = 0; cellCol < NUM_COLS; cellCol++) { |
| 125 create_gradient_points(cellRow, cellCol, points); | 130 create_gradient_points(cellRow, cellCol, points); |
| 126 | 131 |
| 127 auto shader = SkGradientShader::MakeLinear( | 132 auto shader = SkGradientShader::MakeLinear( |
| 128 points, | 133 points, |
| 129 colors, | 134 colors, |
| 130 positions[cellRow], | 135 positions[cellRow], |
| 131 numGradientColors[cellRow], | 136 numGradientColors[cellRow], |
| 132 tilemodes[cellCol], | 137 tilemodes[cellCol], |
| 133 0, | 138 0, |
| 134 nullptr); | 139 nullptr); |
| 135 | 140 |
| 136 shade_rect(canvas, shader, cellRow, cellCol); | 141 shade_rect(canvas, shader, cellRow, cellCol); |
| 137 } | 142 } |
| 138 } | 143 } |
| 139 } | 144 } |
| 140 | 145 |
| 141 private: | 146 private: |
| 142 typedef skiagm::GM INHERITED; | 147 typedef skiagm::GM INHERITED; |
| 143 }; | 148 }; |
| 144 | 149 |
| 145 DEF_GM(return new HardstopGradientShaderGM;) | 150 DEF_GM(return new HardstopGradientShaderGM;) |
| OLD | NEW |