Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 */ | |
|
reed1
2013/06/12 13:34:33
nit: LF after */
ducky
2013/06/12 18:24:01
Done.
| |
| 7 #include "SkRefCnt.h" | |
| 8 | |
|
vandebo (ex-Chrome)
2013/06/12 16:25:33
Include what you use... SkColor, SkPoint, SkScalar
reed1
2013/06/12 17:11:26
Possibly, but almost no where in skia to we really
ducky
2013/06/12 18:24:01
Done - added additional includes.
| |
| 9 #include "gm.h" | |
| 10 #include "SkGradientShader.h" | |
| 11 | |
| 12 SkColor gColors[] = { | |
|
reed1
2013/06/12 13:34:33
static const
or move into scope of the caller
ducky
2013/06/12 18:24:01
Done.
| |
| 13 SK_ColorRED, SK_ColorYELLOW | |
| 14 }; | |
| 15 | |
| 16 // these arrays define the gradient stop points | |
| 17 // as x1, y1, x2, y2 per gradient to draw | |
| 18 SkPoint linearPts[][2] = { | |
|
reed1
2013/06/12 13:34:33
static const
or move into scope of the caller
ducky
2013/06/12 18:24:01
Done.
| |
| 19 {{0, 0}, {1, 0}}, | |
| 20 {{0, 0}, {0, 1}}, | |
| 21 {{1, 0}, {0, 0}}, | |
| 22 {{0, 1}, {0, 0}}, | |
| 23 | |
| 24 {{0, 0}, {1, 1}}, | |
| 25 {{1, 1}, {0, 0}}, | |
| 26 {{1, 0}, {0, 1}}, | |
| 27 {{0, 1}, {1, 0}} | |
| 28 }; | |
| 29 | |
| 30 const SkScalar TESTGRID_X = 200; // pixels allocated to each image in x dimen sion | |
| 31 const SkScalar TESTGRID_Y = 200; // pixels allocated to each image in y dimen sion | |
| 32 | |
| 33 const int IMAGES_X = 4; // number of images per row | |
| 34 | |
| 35 static SkShader* make_linear_gradient(SkPoint pts[2]) { | |
| 36 return SkGradientShader::CreateLinear(pts, gColors, NULL, SK_ARRAY_COUNT(gCo lors), | |
| 37 SkShader::kClamp_TileMode, NULL); | |
| 38 } | |
| 39 | |
| 40 void draw_gradients(SkCanvas* canvas, SkShader* (*makeShader)(SkPoint[2]), | |
| 41 SkPoint ptsArray[][2], int numImages) { | |
| 42 // common test parameters | |
| 43 SkMatrix shaderMat = SkMatrix(); | |
|
reed1
2013/06/12 13:34:33
not sure why you need this assignment?
ducky
2013/06/12 18:24:01
Done - removed.
| |
| 44 shaderMat.setAll(138, 0, 43, | |
|
reed1
2013/06/12 13:34:33
can we have a brief comment why you're using these
ducky
2013/06/12 18:24:01
Done.
| |
| 45 0, 106, 61, | |
| 46 0, 0, 1); | |
| 47 SkRect rectGrad = { 43, 61, 181, 167 }; // some nice prime numbers | |
| 48 | |
| 49 canvas->save(); | |
| 50 for (int i = 0; i < numImages; i++) { | |
| 51 // advance line if necessary | |
| 52 if (i % IMAGES_X == 0 && i != 0) { | |
| 53 canvas->restore(); | |
| 54 canvas->translate(0, TESTGRID_Y); | |
| 55 canvas->save(); | |
| 56 } | |
| 57 | |
| 58 // unpack points, setup shader, draw | |
|
vandebo (ex-Chrome)
2013/06/12 16:25:33
Update comment. Comments should be sentences, sta
ducky
2013/06/12 18:24:01
Done.
| |
| 59 SkAutoTUnref<SkShader> shader(makeShader(*ptsArray)); | |
| 60 shader->setLocalMatrix(shaderMat); | |
| 61 | |
| 62 SkPaint paint; | |
| 63 paint.setShader(shader); | |
| 64 canvas->drawRect(rectGrad, paint); | |
| 65 | |
| 66 // advance to next position | |
|
vandebo (ex-Chrome)
2013/06/12 16:25:33
Comments should explain why you're doing something
reed1
2013/06/12 17:11:26
Not sure I agree. I find this comment helpful to k
ducky
2013/06/12 18:24:01
Done - leaving as is.
| |
| 67 canvas->translate(TESTGRID_X, 0); | |
| 68 ptsArray++; | |
| 69 } | |
| 70 canvas->restore(); | |
| 71 } | |
| 72 | |
| 73 namespace skiagm { | |
| 74 | |
| 75 class GradientMatrixGM : public GM { | |
| 76 public: | |
| 77 GradientMatrixGM() { | |
| 78 this->setBGColor(0xFFDDDDDD); | |
| 79 } | |
| 80 | |
| 81 protected: | |
| 82 SkString onShortName() { | |
|
reed1
2013/06/12 13:34:33
SK_OVERRIDE
ducky
2013/06/12 18:24:01
Done.
| |
| 83 return SkString("gradient_matrix"); | |
| 84 } | |
| 85 | |
| 86 virtual SkISize onISize() { | |
|
reed1
2013/06/12 13:34:33
SK_OVERRIDE
ducky
2013/06/12 18:24:01
Done.
| |
| 87 return SkISize::Make(800, 800); | |
| 88 } | |
| 89 | |
| 90 virtual void onDraw(SkCanvas* canvas) { | |
|
reed1
2013/06/12 13:34:33
SK_OVERRIDE
ducky
2013/06/12 18:24:01
Done.
| |
| 91 draw_gradients(canvas, &make_linear_gradient, | |
| 92 linearPts, SK_ARRAY_COUNT(linearPts)); | |
| 93 } | |
| 94 | |
| 95 private: | |
| 96 typedef GM INHERITED; | |
| 97 }; | |
| 98 | |
| 99 static GM* MyFactory(void*) { return new GradientMatrixGM; } | |
|
reed1
2013/06/12 13:34:33
DEF_GM( return new GradientMatrixGM; )
ducky
2013/06/12 18:24:01
Done.
| |
| 100 static GMRegistry reg(MyFactory); | |
| 101 } | |
| OLD | NEW |