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

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: More style nits. 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
8 #include "SkCanvas.h"
9 #include "SkColor.h"
10 #include "SkGradientShader.h"
11 #include "SkMatrix.h"
12 #include "SkPaint.h"
13 #include "SkPoint.h"
14 #include "SkRect.h"
15 #include "SkRefCnt.h"
16 #include "SkScalar.h"
17 #include "SkSize.h"
18 #include "SkString.h"
19
20 #include "gm.h"
21
22 static const SkColor gColors[] = {
23 SK_ColorRED, SK_ColorYELLOW
24 };
25
26 // these arrays define the gradient stop points
27 // as x1, y1, x2, y2 per gradient to draw
28 static const SkPoint linearPts[][2] = {
29 {{0, 0}, {1, 0}},
30 {{0, 0}, {0, 1}},
31 {{1, 0}, {0, 0}},
32 {{0, 1}, {0, 0}},
33
34 {{0, 0}, {1, 1}},
35 {{1, 1}, {0, 0}},
36 {{1, 0}, {0, 1}},
37 {{0, 1}, {1, 0}}
38 };
39
40 static const SkScalar TESTGRID_X = 200; // pixels allocated to each image in x dimension
41 static const SkScalar TESTGRID_Y = 200; // pixels allocated to each image in y dimension
42
43 static const int IMAGES_X = 4; // number of images per row
44
45 static SkShader* make_linear_gradient(const SkPoint pts[2]) {
46 return SkGradientShader::CreateLinear(pts, gColors, NULL, SK_ARRAY_COUNT(gCo lors),
47 SkShader::kClamp_TileMode, NULL);
48 }
49
50 void draw_gradients(SkCanvas* canvas, SkShader* (*makeShader)(const SkPoint[2]),
51 const SkPoint ptsArray[][2], int numImages) {
52 // Use some nice prime numbers for the rectangle so that
53 // symmetry won't cause false negatives.
54 SkRect rectGrad = { 43, 61, 181, 167 };
55 // Make matrix consistent with the rectangle, and have different
reed1 2013/06/12 18:32:28 What does 'consistent' mean here? That the matrix'
ducky 2013/06/12 18:41:06 Yes. Otherwise, the shader gradient bounds won't l
56 // scaling and translation on the different axes
57 // (this was the bug this test addresses, where bad order
58 // of operations mixed up the axes).
59 SkMatrix shaderMat;
60 shaderMat.setAll(138, 0, 43,
61 0, 106, 61,
62 0, 0, 1);
63
64 canvas->save();
65 for (int i = 0; i < numImages; i++) {
66 // Advance line downwards if necessary.
67 if (i % IMAGES_X == 0 && i != 0) {
68 canvas->restore();
69 canvas->translate(0, TESTGRID_Y);
70 canvas->save();
71 }
72
73 // Setup shader and draw.
74 SkAutoTUnref<SkShader> shader(makeShader(*ptsArray));
75 shader->setLocalMatrix(shaderMat);
76
77 SkPaint paint;
78 paint.setShader(shader);
79 canvas->drawRect(rectGrad, paint);
80
81 // Advance to next position.
82 canvas->translate(TESTGRID_X, 0);
83 ptsArray++;
84 }
85 canvas->restore();
86 }
87
88 namespace skiagm {
89
90 class GradientMatrixGM : public GM {
91 public:
92 GradientMatrixGM() {
93 this->setBGColor(0xFFDDDDDD);
94 }
95
96 protected:
97 SkString onShortName() SK_OVERRIDE {
98 return SkString("gradient_matrix");
99 }
100
101 virtual SkISize onISize() SK_OVERRIDE {
102 return SkISize::Make(800, 800);
103 }
104
105 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
106 draw_gradients(canvas, &make_linear_gradient,
107 linearPts, SK_ARRAY_COUNT(linearPts));
108 }
109
110 private:
111 typedef GM INHERITED;
112 };
113
114 DEF_GM( return new GradientMatrixGM; )
115 }
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