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

Side by Side Diff: gm/gradient_matrix.cpp

Issue 1793303002: Reland of "more shader-->sp conversions (patchset #5 id:80001 of https://codereview.chromium… (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: make pictureRef a value, so its clearer what's going on Created 4 years, 9 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 | « gm/gradientDirtyLaundry.cpp ('k') | gm/gradients.cpp » ('j') | 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 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 static const SkScalar TESTGRID_X = SkIntToScalar(200);
60 static const SkScalar TESTGRID_Y = SkIntToScalar(200); 60 static const SkScalar TESTGRID_Y = SkIntToScalar(200);
61 61
62 static const int IMAGES_X = 4; // number of images per row 62 static const int IMAGES_X = 4; // number of images per row
63 63
64 static SkShader* make_linear_gradient(const SkPoint pts[2], const SkMatrix& loca lMatrix) { 64 static sk_sp<SkShader> make_linear_gradient(const SkPoint pts[2], const SkMatrix & localMatrix) {
65 return SkGradientShader::CreateLinear(pts, gColors, nullptr, SK_ARRAY_COUNT( gColors), 65 return SkGradientShader::MakeLinear(pts, gColors, nullptr, SK_ARRAY_COUNT(gC olors),
66 SkShader::kClamp_TileMode, 0, &localMa trix); 66 SkShader::kClamp_TileMode, 0, &localMatr ix);
67 } 67 }
68 68
69 static SkShader* make_radial_gradient(const SkPoint pts[2], const SkMatrix& loca lMatrix) { 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));
73 float radius = (center - pts[0]).length(); 73 float radius = (center - pts[0]).length();
74 return SkGradientShader::CreateRadial(center, radius, gColors, nullptr, SK_A RRAY_COUNT(gColors), 74 return SkGradientShader::MakeRadial(center, radius, gColors, nullptr, SK_ARR AY_COUNT(gColors),
75 SkShader::kClamp_TileMode, 0, &localMa trix); 75 SkShader::kClamp_TileMode, 0, &localMatr ix);
76 } 76 }
77 77
78 static void draw_gradients(SkCanvas* canvas, 78 static void draw_gradients(SkCanvas* canvas,
79 SkShader* (*makeShader)(const SkPoint[2], const SkMat rix&), 79 sk_sp<SkShader> (*makeShader)(const SkPoint[2], const SkMatrix&),
80 const SkPoint ptsArray[][2], int numImages) { 80 const SkPoint ptsArray[][2], int numImages) {
81 // Use some nice prime numbers for the rectangle and matrix with 81 // Use some nice prime numbers for the rectangle and matrix with
82 // different scaling along the x and y axes (which is the bug this 82 // different scaling along the x and y axes (which is the bug this
83 // test addresses, where incorrect order of operations mixed up the axes) 83 // test addresses, where incorrect order of operations mixed up the axes)
84 SkRect rectGrad = { 84 SkRect rectGrad = {
85 SkIntToScalar(43), SkIntToScalar(61), 85 SkIntToScalar(43), SkIntToScalar(61),
86 SkIntToScalar(181), SkIntToScalar(167) }; 86 SkIntToScalar(181), SkIntToScalar(167) };
87 SkMatrix shaderMat; 87 SkMatrix shaderMat;
88 shaderMat.setScale(rectGrad.width(), rectGrad.height()); 88 shaderMat.setScale(rectGrad.width(), rectGrad.height());
89 shaderMat.postTranslate(rectGrad.left(), rectGrad.top()); 89 shaderMat.postTranslate(rectGrad.left(), rectGrad.top());
90 90
91 canvas->save(); 91 canvas->save();
92 for (int i = 0; i < numImages; i++) { 92 for (int i = 0; i < numImages; i++) {
93 // Advance line downwards if necessary. 93 // Advance line downwards if necessary.
94 if (i % IMAGES_X == 0 && i != 0) { 94 if (i % IMAGES_X == 0 && i != 0) {
95 canvas->restore(); 95 canvas->restore();
96 canvas->translate(0, TESTGRID_Y); 96 canvas->translate(0, TESTGRID_Y);
97 canvas->save(); 97 canvas->save();
98 } 98 }
99 99
100 // Setup shader and draw.
101 SkAutoTUnref<SkShader> shader(makeShader(*ptsArray, shaderMat));
102
103 SkPaint paint; 100 SkPaint paint;
104 paint.setShader(shader); 101 paint.setShader(makeShader(*ptsArray, shaderMat));
105 canvas->drawRect(rectGrad, paint); 102 canvas->drawRect(rectGrad, paint);
106 103
107 // Advance to next position. 104 // Advance to next position.
108 canvas->translate(TESTGRID_X, 0); 105 canvas->translate(TESTGRID_X, 0);
109 ptsArray++; 106 ptsArray++;
110 } 107 }
111 canvas->restore(); 108 canvas->restore();
112 } 109 }
113 110
114 DEF_SIMPLE_GM_BG(gradient_matrix, canvas, 800, 800, 111 DEF_SIMPLE_GM_BG(gradient_matrix, canvas, 800, 800,
115 sk_tool_utils::color_to_565(0xFFDDDDDD)) { 112 sk_tool_utils::color_to_565(0xFFDDDDDD)) {
116 draw_gradients(canvas, &make_linear_gradient, 113 draw_gradients(canvas, &make_linear_gradient,
117 linearPts, SK_ARRAY_COUNT(linearPts)); 114 linearPts, SK_ARRAY_COUNT(linearPts));
118 115
119 canvas->translate(0, TESTGRID_Y); 116 canvas->translate(0, TESTGRID_Y);
120 117
121 draw_gradients(canvas, &make_radial_gradient, 118 draw_gradients(canvas, &make_radial_gradient,
122 radialPts, SK_ARRAY_COUNT(radialPts)); 119 radialPts, SK_ARRAY_COUNT(radialPts));
123 } 120 }
OLDNEW
« no previous file with comments | « gm/gradientDirtyLaundry.cpp ('k') | gm/gradients.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698