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

Side by Side Diff: gm/gradient_matrix.cpp

Issue 16094020: Fixed a bug with linear gradient PDF matrices and added test cases (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | gyp/gmslides.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2013 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7 #include "gm.h"
8 #include "SkGradientShader.h"
9
10 static const SkColor gColors[] = {
11 SK_ColorRED, SK_ColorYELLOW
12 };
13 static const SkScalar gPosAll[] = {
14 0, SK_Scalar1
15 };
16
17 static SkShader* SimpleGradient(const SkPoint pts[2]) {
vandebo (ex-Chrome) 2013/06/11 05:15:10 static helper functions are named in hacker case:
ducky 2013/06/11 21:35:32 Done.
18 return SkGradientShader::CreateLinear(pts, gColors, gPosAll,
19 2, SkShader::kClamp_TileMode, NULL);
vandebo (ex-Chrome) 2013/06/11 05:15:10 nit: put "2" on the previous line.
ducky 2013/06/11 21:35:32 Done.
20 }
21
22 namespace skiagm {
23
24 class GradientMatrixGM : public GM {
25 public:
26 GradientMatrixGM() {
27 this->setBGColor(0xFFDDDDDD);
28 }
29
30 protected:
31 SkString onShortName() {
32 return SkString("gradient_matrix");
33 }
34
35 virtual SkISize onISize() { return make_isize(800, 400); }
vandebo (ex-Chrome) 2013/06/11 05:15:10 line wrap.
ducky 2013/06/11 21:35:32 Done.
36
37 virtual void onDraw(SkCanvas* canvas) {
38 const int TESTGRID_X = 200;
vandebo (ex-Chrome) 2013/06/11 05:15:10 Should be SkScalar instead of int (applies in mult
ducky 2013/06/11 21:35:32 Done.
39 const int TESTGRID_Y = 200;
40
41 canvas->save();
42
43 testGrad(canvas, 0, 0, 1, 0);
44 canvas->translate(TESTGRID_X, 0);
45 testGrad(canvas, 0, 0, 0, 1);
46 canvas->translate(TESTGRID_X, 0);
47 testGrad(canvas, 1, 0, 0, 0);
48 canvas->translate(TESTGRID_X, 0);
49 testGrad(canvas, 0, 1, 0, 0);
50
51 canvas->restore();
52 canvas->translate(0, TESTGRID_Y);
53 canvas->save();
54
55 testGrad(canvas, 0, 0, 1, 1);
56 canvas->translate(TESTGRID_X, 0);
57 testGrad(canvas, 1, 1, 0, 0);
58 canvas->translate(TESTGRID_X, 0);
59 testGrad(canvas, 1, 0, 0, 1);
60 canvas->translate(TESTGRID_X, 0);
61 testGrad(canvas, 0, 1, 1, 0);
62 }
63
64 virtual void simpleGrad(SkCanvas* canvas) {
vandebo (ex-Chrome) 2013/06/11 05:15:10 This method is unused, remove.
ducky 2013/06/11 21:35:32 Done.
65 SkPoint pts[2] = {
66 { 100, 0 },
67 { 0, 0 }
68 };
69 SkMatrix shaderMat = SkMatrix();
70 shaderMat.setAll(1, 0, 0,
71 0, 1, 0,
72 0, 0, 1);
73 SkRect rectGrad = { 0, 0, 100, 100 }; // very simple numbers
74
75 SkShader* shader = SimpleGradient(pts);
76 shader->setLocalMatrix(shaderMat);
77 SkPaint paint;
78 paint.setAntiAlias(true);
79 paint.setShader(shader);
80 canvas->drawRect(rectGrad, paint);
81 shader->unref();
82 }
83
84 virtual void testGrad(SkCanvas* canvas, int x1, int y1, int x2, int y2) {
vandebo (ex-Chrome) 2013/06/11 05:15:10 not virtual. In fact, it can be a static helper f
ducky 2013/06/11 21:35:32 Done.
85 SkPoint pts[2] = {
vandebo (ex-Chrome) 2013/06/11 05:15:10 why not just pass SkPoints[2] ?
ducky 2013/06/11 21:35:32 Done.
86 { x1, y1 },
87 { x2, y2 }
88 };
89 SkMatrix shaderMat = SkMatrix();
90 shaderMat.setAll(138, 0, 43,
91 0, 106, 61,
92 0, 0, 1);
93 SkRect rectGrad = { 43, 61, 181, 167 }; // some nice prime numbers
94
95 SkShader* shader = SimpleGradient(pts);
96 shader->setLocalMatrix(shaderMat);
97 SkPaint paint;
98 paint.setAntiAlias(true);
vandebo (ex-Chrome) 2013/06/11 05:15:10 remove - not needed for this test.
ducky 2013/06/11 21:35:32 Done.
99 paint.setShader(shader);
100 canvas->drawRect(rectGrad, paint);
101 shader->unref();
102 }
103
104 private:
105 typedef GM INHERITED;
106 };
107
108 static GM* MyFactory(void*) { return new GradientMatrixGM; }
109 static GMRegistry reg(MyFactory);
110
111 }
OLDNEW
« no previous file with comments | « no previous file | gyp/gmslides.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698