| 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" |
| 11 #include "SkMatrix.h" | 11 #include "SkMatrix.h" |
| 12 #include "SkPaint.h" | 12 #include "SkPaint.h" |
| 13 #include "SkPoint.h" | 13 #include "SkPoint.h" |
| 14 #include "SkRect.h" | 14 #include "SkRect.h" |
| 15 #include "SkRefCnt.h" | 15 #include "SkRefCnt.h" |
| 16 #include "SkScalar.h" | 16 #include "SkScalar.h" |
| 17 #include "SkSize.h" | 17 #include "SkSize.h" |
| 18 #include "SkString.h" | 18 #include "SkString.h" |
| 19 | 19 |
| 20 #include "gm.h" | 20 #include "gm.h" |
| 21 | 21 |
| 22 static const SkColor gColors[] = { | 22 constexpr SkColor gColors[] = { |
| 23 SK_ColorRED, SK_ColorYELLOW | 23 SK_ColorRED, SK_ColorYELLOW |
| 24 }; | 24 }; |
| 25 | 25 |
| 26 // These annoying defines are necessary, because the only other alternative | 26 // These annoying defines are necessary, because the only other alternative |
| 27 // is to use SkIntToScalar(...) everywhere. | 27 // is to use SkIntToScalar(...) everywhere. |
| 28 static const SkScalar sZero = 0; | 28 constexpr SkScalar sZero = 0; |
| 29 static const SkScalar sHalf = SK_ScalarHalf; | 29 constexpr SkScalar sHalf = SK_ScalarHalf; |
| 30 static const SkScalar sOne = SK_Scalar1; | 30 constexpr SkScalar sOne = SK_Scalar1; |
| 31 | 31 |
| 32 // These arrays define the gradient stop points | 32 // These arrays define the gradient stop points |
| 33 // as x1, y1, x2, y2 per gradient to draw. | 33 // as x1, y1, x2, y2 per gradient to draw. |
| 34 static const SkPoint linearPts[][2] = { | 34 constexpr SkPoint linearPts[][2] = { |
| 35 {{sZero, sZero}, {sOne, sZero}}, | 35 {{sZero, sZero}, {sOne, sZero}}, |
| 36 {{sZero, sZero}, {sZero, sOne}}, | 36 {{sZero, sZero}, {sZero, sOne}}, |
| 37 {{sOne, sZero}, {sZero, sZero}}, | 37 {{sOne, sZero}, {sZero, sZero}}, |
| 38 {{sZero, sOne}, {sZero, sZero}}, | 38 {{sZero, sOne}, {sZero, sZero}}, |
| 39 | 39 |
| 40 {{sZero, sZero}, {sOne, sOne}}, | 40 {{sZero, sZero}, {sOne, sOne}}, |
| 41 {{sOne, sOne}, {sZero, sZero}}, | 41 {{sOne, sOne}, {sZero, sZero}}, |
| 42 {{sOne, sZero}, {sZero, sOne}}, | 42 {{sOne, sZero}, {sZero, sOne}}, |
| 43 {{sZero, sOne}, {sOne, sZero}} | 43 {{sZero, sOne}, {sOne, sZero}} |
| 44 }; | 44 }; |
| 45 | 45 |
| 46 static const SkPoint radialPts[][2] = { | 46 constexpr SkPoint radialPts[][2] = { |
| 47 {{sZero, sHalf}, {sOne, sHalf}}, | 47 {{sZero, sHalf}, {sOne, sHalf}}, |
| 48 {{sHalf, sZero}, {sHalf, sOne}}, | 48 {{sHalf, sZero}, {sHalf, sOne}}, |
| 49 {{sOne, sHalf}, {sZero, sHalf}}, | 49 {{sOne, sHalf}, {sZero, sHalf}}, |
| 50 {{sHalf, sOne}, {sHalf, sZero}}, | 50 {{sHalf, sOne}, {sHalf, sZero}}, |
| 51 | 51 |
| 52 {{sZero, sZero}, {sOne, sOne}}, | 52 {{sZero, sZero}, {sOne, sOne}}, |
| 53 {{sOne, sOne}, {sZero, sZero}}, | 53 {{sOne, sOne}, {sZero, sZero}}, |
| 54 {{sOne, sZero}, {sZero, sOne}}, | 54 {{sOne, sZero}, {sZero, sOne}}, |
| 55 {{sZero, sOne}, {sOne, sZero}} | 55 {{sZero, sOne}, {sOne, sZero}} |
| 56 }; | 56 }; |
| 57 | 57 |
| 58 // These define the pixels allocated to each gradient image. | 58 // These define the pixels allocated to each gradient image. |
| 59 static const SkScalar TESTGRID_X = SkIntToScalar(200); | 59 constexpr SkScalar TESTGRID_X = SkIntToScalar(200); |
| 60 static const SkScalar TESTGRID_Y = SkIntToScalar(200); | 60 constexpr SkScalar TESTGRID_Y = SkIntToScalar(200); |
| 61 | 61 |
| 62 static const int IMAGES_X = 4; // number of images per row | 62 constexpr int IMAGES_X = 4; // number of images per row |
| 63 | 63 |
| 64 static sk_sp<SkShader> make_linear_gradient(const SkPoint pts[2], const SkMatrix
& localMatrix) { | 64 static sk_sp<SkShader> make_linear_gradient(const SkPoint pts[2], const SkMatrix
& localMatrix) { |
| 65 return SkGradientShader::MakeLinear(pts, gColors, nullptr, SK_ARRAY_COUNT(gC
olors), | 65 return SkGradientShader::MakeLinear(pts, gColors, nullptr, SK_ARRAY_COUNT(gC
olors), |
| 66 SkShader::kClamp_TileMode, 0, &localMatr
ix); | 66 SkShader::kClamp_TileMode, 0, &localMatr
ix); |
| 67 } | 67 } |
| 68 | 68 |
| 69 static sk_sp<SkShader> make_radial_gradient(const SkPoint pts[2], const SkMatrix
& localMatrix) { | 69 static sk_sp<SkShader> make_radial_gradient(const SkPoint pts[2], const SkMatrix
& localMatrix) { |
| 70 SkPoint center; | 70 SkPoint center; |
| 71 center.set(SkScalarAve(pts[0].fX, pts[1].fX), | 71 center.set(SkScalarAve(pts[0].fX, pts[1].fX), |
| 72 SkScalarAve(pts[0].fY, pts[1].fY)); | 72 SkScalarAve(pts[0].fY, pts[1].fY)); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 DEF_SIMPLE_GM_BG(gradient_matrix, canvas, 800, 800, | 111 DEF_SIMPLE_GM_BG(gradient_matrix, canvas, 800, 800, |
| 112 sk_tool_utils::color_to_565(0xFFDDDDDD)) { | 112 sk_tool_utils::color_to_565(0xFFDDDDDD)) { |
| 113 draw_gradients(canvas, &make_linear_gradient, | 113 draw_gradients(canvas, &make_linear_gradient, |
| 114 linearPts, SK_ARRAY_COUNT(linearPts)); | 114 linearPts, SK_ARRAY_COUNT(linearPts)); |
| 115 | 115 |
| 116 canvas->translate(0, TESTGRID_Y); | 116 canvas->translate(0, TESTGRID_Y); |
| 117 | 117 |
| 118 draw_gradients(canvas, &make_radial_gradient, | 118 draw_gradients(canvas, &make_radial_gradient, |
| 119 radialPts, SK_ARRAY_COUNT(radialPts)); | 119 radialPts, SK_ARRAY_COUNT(radialPts)); |
| 120 } | 120 } |
| OLD | NEW |