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 #include "gm.h" | 8 #include "gm.h" |
9 | 9 |
10 #include "SkSurface.h" | 10 #include "SkSurface.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 const char* label() override { | 51 const char* label() override { |
52 return fLabel.c_str(); | 52 return fLabel.c_str(); |
53 } | 53 } |
54 protected: | 54 protected: |
55 SkFilterQuality fQuality; | 55 SkFilterQuality fQuality; |
56 SkBitmap fBitmap; | 56 SkBitmap fBitmap; |
57 SkString fLabel; | 57 SkString fLabel; |
58 }; | 58 }; |
59 | 59 |
60 struct GradientCellRenderer : public CellRenderer { | 60 struct GradientCellRenderer : public CellRenderer { |
61 GradientCellRenderer(SkColor colorOne, SkColor colorTwo) { | 61 GradientCellRenderer(SkColor colorOne, SkColor colorTwo, bool manyStops) { |
62 fColors[0] = colorOne; | 62 fColors[0] = colorOne; |
63 fColors[1] = colorTwo; | 63 fColors[1] = colorTwo; |
| 64 fManyStops = manyStops; |
64 } | 65 } |
65 void draw(SkCanvas* canvas) override { | 66 void draw(SkCanvas* canvas) override { |
66 SkPoint points[2] = { | 67 SkPoint points[2] = { |
67 SkPoint::Make(0, 0), | 68 SkPoint::Make(0, 0), |
68 SkPoint::Make(0, gScalarSize) | 69 SkPoint::Make(0, gScalarSize) |
69 }; | 70 }; |
70 SkPaint paint; | 71 SkPaint paint; |
71 paint.setShader(SkGradientShader::MakeLinear(points, fColors, nullptr, 2
, | 72 if (fManyStops) { |
72 SkShader::kClamp_TileMode))
; | 73 SkColor colors[4] ={ |
| 74 fColors[0], fColors[0], fColors[1], fColors[1] |
| 75 }; |
| 76 paint.setShader(SkGradientShader::MakeLinear(points, colors, nullptr
, 4, |
| 77 SkShader::kClamp_TileMo
de)); |
| 78 } else { |
| 79 paint.setShader(SkGradientShader::MakeLinear(points, fColors, nullpt
r, 2, |
| 80 SkShader::kClamp_TileMo
de)); |
| 81 } |
73 canvas->drawPaint(paint); | 82 canvas->drawPaint(paint); |
74 } | 83 } |
75 const char* label() override { | 84 const char* label() override { |
76 return "Linear Gradient"; | 85 return "Linear Gradient"; |
77 } | 86 } |
78 protected: | 87 protected: |
79 SkColor fColors[2]; | 88 SkColor fColors[2]; |
| 89 bool fManyStops; |
80 }; | 90 }; |
81 | 91 |
82 struct VerticesCellRenderer : public CellRenderer { | 92 struct VerticesCellRenderer : public CellRenderer { |
83 VerticesCellRenderer(SkColor colorOne, SkColor colorTwo) { | 93 VerticesCellRenderer(SkColor colorOne, SkColor colorTwo) { |
84 fColors[0] = fColors[1] = colorOne; | 94 fColors[0] = fColors[1] = colorOne; |
85 fColors[2] = fColors[3] = colorTwo; | 95 fColors[2] = fColors[3] = colorTwo; |
86 } | 96 } |
87 void draw(SkCanvas* canvas) override { | 97 void draw(SkCanvas* canvas) override { |
88 SkPaint paint; | 98 SkPaint paint; |
89 SkPoint vertices[4] = { | 99 SkPoint vertices[4] = { |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 | 201 |
192 // sRGB primaries, rendered as bitmaps | 202 // sRGB primaries, rendered as bitmaps |
193 renderers.push_back(new BitmapCellRenderer(SK_ColorRED, kNone_SkFilterQualit
y)); | 203 renderers.push_back(new BitmapCellRenderer(SK_ColorRED, kNone_SkFilterQualit
y)); |
194 renderers.push_back(new BitmapCellRenderer(SK_ColorGREEN, kLow_SkFilterQuali
ty)); | 204 renderers.push_back(new BitmapCellRenderer(SK_ColorGREEN, kLow_SkFilterQuali
ty)); |
195 // Larger bitmap to trigger mipmaps | 205 // Larger bitmap to trigger mipmaps |
196 renderers.push_back(new BitmapCellRenderer(SK_ColorRED, kMedium_SkFilterQual
ity, 2.0f)); | 206 renderers.push_back(new BitmapCellRenderer(SK_ColorRED, kMedium_SkFilterQual
ity, 2.0f)); |
197 // Smaller bitmap to trigger bicubic | 207 // Smaller bitmap to trigger bicubic |
198 renderers.push_back(new BitmapCellRenderer(SK_ColorGREEN, kHigh_SkFilterQual
ity, 0.5f)); | 208 renderers.push_back(new BitmapCellRenderer(SK_ColorGREEN, kHigh_SkFilterQual
ity, 0.5f)); |
199 | 209 |
200 // Various gradients involving sRGB primaries and white/black | 210 // Various gradients involving sRGB primaries and white/black |
201 renderers.push_back(new GradientCellRenderer(SK_ColorRED, SK_ColorGREEN)); | 211 |
202 renderers.push_back(new GradientCellRenderer(SK_ColorGREEN, SK_ColorBLACK)); | 212 // First with just two stops (implemented with uniforms on GPU) |
203 renderers.push_back(new GradientCellRenderer(SK_ColorGREEN, SK_ColorWHITE)); | 213 renderers.push_back(new GradientCellRenderer(SK_ColorRED, SK_ColorGREEN, fal
se)); |
| 214 renderers.push_back(new GradientCellRenderer(SK_ColorGREEN, SK_ColorBLACK, f
alse)); |
| 215 renderers.push_back(new GradientCellRenderer(SK_ColorGREEN, SK_ColorWHITE, f
alse)); |
| 216 |
| 217 // ... and then with four stops (implemented with textures on GPU) |
| 218 renderers.push_back(new GradientCellRenderer(SK_ColorRED, SK_ColorGREEN, tru
e)); |
| 219 renderers.push_back(new GradientCellRenderer(SK_ColorGREEN, SK_ColorBLACK, t
rue)); |
| 220 renderers.push_back(new GradientCellRenderer(SK_ColorGREEN, SK_ColorWHITE, t
rue)); |
204 | 221 |
205 // Vertex colors | 222 // Vertex colors |
206 renderers.push_back(new VerticesCellRenderer(SK_ColorRED, SK_ColorRED)); | 223 renderers.push_back(new VerticesCellRenderer(SK_ColorRED, SK_ColorRED)); |
207 renderers.push_back(new VerticesCellRenderer(SK_ColorRED, SK_ColorGREEN)); | 224 renderers.push_back(new VerticesCellRenderer(SK_ColorRED, SK_ColorGREEN)); |
208 | 225 |
209 draw_gamut_grid(canvas, renderers); | 226 draw_gamut_grid(canvas, renderers); |
210 } | 227 } |
OLD | NEW |