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

Side by Side Diff: gm/vertices.cpp

Issue 112913005: reenable vertices gm, adding picture support (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 11 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
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 "gm.h" 8 #include "gm.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkGradientShader.h" 10 #include "SkGradientShader.h"
11 #include "SkRandom.h" 11 #include "SkRandom.h"
12 12
13 static SkShader* make_shader(int w, int h) { 13 static SkShader* make_shader(SkScalar w, SkScalar h) {
14 const SkColor colors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE }; 14 const SkColor colors[] = {
15 const SkPoint center = { SkScalarHalf(w), SkScalarHalf(h) }; 15 SK_ColorRED, SK_ColorCYAN, SK_ColorGREEN, SK_ColorWHITE,
16 const SkScalar radius = w / 2; 16 SK_ColorMAGENTA, SK_ColorBLUE, SK_ColorYELLOW,
17 };
18 const SkPoint pts[] = { { w/4, 0 }, { 3*w/4, h } };
17 19
18 return SkGradientShader::CreateRadial(center, radius, colors, NULL, 20 return SkGradientShader::CreateLinear(pts, colors, NULL,
19 SK_ARRAY_COUNT(colors), 21 SK_ARRAY_COUNT(colors),
20 SkShader::kMirror_TileMode); 22 SkShader::kMirror_TileMode);
21 } 23 }
22 24
23 class VerticesGM : public skiagm::GM { 25 class VerticesGM : public skiagm::GM {
24 SkPoint fPts[9]; 26 SkPoint fPts[9];
25 SkPoint fTexs[9]; 27 SkPoint fTexs[9];
26 SkColor fColors[9]; 28 SkColor fColors[9];
27 SkShader* fShader; 29 SkShader* fShader;
28 30
29 public: 31 public:
30 VerticesGM() : fShader(NULL) { 32 VerticesGM() : fShader(NULL) {
31 } 33 }
32 34
33 virtual ~VerticesGM() { 35 virtual ~VerticesGM() {
34 SkSafeUnref(fShader); 36 SkSafeUnref(fShader);
35 } 37 }
36 38
37 protected: 39 protected:
38 virtual void onOnceBeforeDraw() SK_OVERRIDE { 40 virtual void onOnceBeforeDraw() SK_OVERRIDE {
39 fPts[0].set(0, 0); fPts[1].set(100, 10); fPts[2].set(200, 0); 41 const SkScalar X = 150;
40 fPts[3].set(10, 100); fPts[4].set(100, 100); fPts[5].set(190, 100); 42 const SkScalar Y = 150;
41 fPts[6].set(0, 200); fPts[7].set(100, 190); fPts[8].set(200, 200);
42 43
43 int w = 200; 44 fPts[0].set(0, 0); fPts[1].set(X/2, 10); fPts[2].set(X, 0);
44 int h = 200; 45 fPts[3].set(10, Y/2); fPts[4].set(X/2, Y/2); fPts[5].set(X-10, Y/2);
46 fPts[6].set(0, Y); fPts[7].set(X/2, Y-10); fPts[8].set(X, Y);
47
48 const SkScalar w = 200;
49 const SkScalar h = 200;
45 50
46 fTexs[0].set(0, 0); fTexs[1].set(w/2, 0); fTexs[2].set(w, 0); 51 fTexs[0].set(0, 0); fTexs[1].set(w/2, 0); fTexs[2].set(w, 0);
47 fTexs[3].set(0, h/2); fTexs[4].set(w/2, h/2); fTexs[5].set(w, h/2); 52 fTexs[3].set(0, h/2); fTexs[4].set(w/2, h/2); fTexs[5].set(w, h/2);
48 fTexs[6].set(0, h); fTexs[7].set(w/2, h); fTexs[8].set(w, h); 53 fTexs[6].set(0, h); fTexs[7].set(w/2, h); fTexs[8].set(w, h);
49 54
50 fShader = make_shader(w, h); 55 fShader = make_shader(w, h);
51 56
52 SkRandom rand; 57 SkRandom rand;
53 for (size_t i = 0; i < SK_ARRAY_COUNT(fColors); ++i) { 58 for (size_t i = 0; i < SK_ARRAY_COUNT(fColors); ++i) {
54 fColors[i] = rand.nextU() | 0xFF202020; 59 fColors[i] = rand.nextU() | 0xFF000000;
55 } 60 }
56 } 61 }
57 62
58 virtual SkString onShortName() SK_OVERRIDE { 63 virtual SkString onShortName() SK_OVERRIDE {
59 return SkString("vertices"); 64 return SkString("vertices");
60 } 65 }
61 66
62 virtual SkISize onISize() SK_OVERRIDE { 67 virtual SkISize onISize() SK_OVERRIDE {
63 return SkISize::Make(800, 800); 68 return SkISize::Make(600, 600);
64 } 69 }
65 70
66 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { 71 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
72 // start with the center of a 3x3 grid
67 static const uint16_t fan[] = { 73 static const uint16_t fan[] = {
68 4, 74 4,
69 0, 1, 2, 5, 8, 7, 6, 3, 0 75 0, 1, 2, 5, 8, 7, 6, 3, 0
70 }; 76 };
71 77
72 const struct { 78 const struct {
73 const SkColor* fColors; 79 const SkColor* fColors;
74 const SkPoint* fTexs; 80 const SkPoint* fTexs;
75 } rec[] = { 81 } rec[] = {
76 { fColors, NULL }, 82 { fColors, NULL },
(...skipping 12 matching lines...) Expand all
89 95
90 canvas->translate(20, 20); 96 canvas->translate(20, 20);
91 for (size_t j = 0; j < SK_ARRAY_COUNT(modes); ++j) { 97 for (size_t j = 0; j < SK_ARRAY_COUNT(modes); ++j) {
92 SkXfermode* xfer = SkXfermode::Create(modes[j]); 98 SkXfermode* xfer = SkXfermode::Create(modes[j]);
93 canvas->save(); 99 canvas->save();
94 for (size_t i = 0; i < SK_ARRAY_COUNT(rec); ++i) { 100 for (size_t i = 0; i < SK_ARRAY_COUNT(rec); ++i) {
95 canvas->drawVertices(SkCanvas::kTriangleFan_VertexMode, 101 canvas->drawVertices(SkCanvas::kTriangleFan_VertexMode,
96 SK_ARRAY_COUNT(fPts), fPts, 102 SK_ARRAY_COUNT(fPts), fPts,
97 rec[i].fTexs, rec[i].fColors, 103 rec[i].fTexs, rec[i].fColors,
98 xfer, fan, SK_ARRAY_COUNT(fan), paint); 104 xfer, fan, SK_ARRAY_COUNT(fan), paint);
99 canvas->translate(250, 0); 105 canvas->translate(200, 0);
100 } 106 }
101 canvas->restore(); 107 canvas->restore();
102 canvas->translate(0, 250); 108 canvas->translate(0, 200);
103 xfer->unref(); 109 xfer->unref();
104 } 110 }
105 } 111 }
106 112
113 #if 0
107 virtual uint32_t onGetFlags() const { 114 virtual uint32_t onGetFlags() const {
108 return kSkipPipe_Flag | kSkipPicture_Flag; 115 return kSkipPipe_Flag | kSkipPicture_Flag;
109 } 116 }
117 #endif
110 118
111 private: 119 private:
112 typedef skiagm::GM INHERITED; 120 typedef skiagm::GM INHERITED;
113 }; 121 };
114 122
115 DEF_GM( return SkNEW(VerticesGM); ) 123 DEF_GM( return SkNEW(VerticesGM); )
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