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

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: Attempt at fixing Mac build 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 static void draw_gradients(SkCanvas* canvas, SkShader* (*makeShader)(const SkPoi nt[2]),
51 const SkPoint ptsArray[][2], int numImages) {
52 // Use some nice prime numbers for the rectangle and matrix with
53 // different scaling along the x and y axes (which is the bug this
54 // test addresses, where incorrect order of operations mixed up the axes)
55 SkRect rectGrad = { 43, 61, 181, 167 };
56 SkMatrix shaderMat;
57 shaderMat.setScale(rectGrad.width(), rectGrad.height());
58 shaderMat.postTranslate(rectGrad.left(), rectGrad.top());
59
60 canvas->save();
61 for (int i = 0; i < numImages; i++) {
62 // Advance line downwards if necessary.
63 if (i % IMAGES_X == 0 && i != 0) {
64 canvas->restore();
65 canvas->translate(0, TESTGRID_Y);
66 canvas->save();
67 }
68
69 // Setup shader and draw.
70 SkAutoTUnref<SkShader> shader(makeShader(*ptsArray));
71 shader->setLocalMatrix(shaderMat);
72
73 SkPaint paint;
74 paint.setShader(shader);
75 canvas->drawRect(rectGrad, paint);
76
77 // Advance to next position.
78 canvas->translate(TESTGRID_X, 0);
79 ptsArray++;
80 }
81 canvas->restore();
82 }
83
84 namespace skiagm {
85
86 class GradientMatrixGM : public GM {
87 public:
88 GradientMatrixGM() {
89 this->setBGColor(0xFFDDDDDD);
90 }
91
92 protected:
93 SkString onShortName() SK_OVERRIDE {
94 return SkString("gradient_matrix");
95 }
96
97 virtual SkISize onISize() SK_OVERRIDE {
98 return SkISize::Make(800, 800);
99 }
100
101 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
102 draw_gradients(canvas, &make_linear_gradient,
103 linearPts, SK_ARRAY_COUNT(linearPts));
104 }
105
106 private:
107 typedef GM INHERITED;
108 };
109
110 DEF_GM( return new GradientMatrixGM; )
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