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

Side by Side Diff: gm/dstreadshuffle.cpp

Issue 845103005: GrBatchPrototype (Closed) Base URL: https://skia.googlesource.com/skia.git@lc2
Patch Set: file move Created 5 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
« 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 /*
3 * Copyright 2013 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8 #include "gm.h"
9 #include "SkBitmap.h"
10 #include "SkRandom.h"
11 #include "SkShader.h"
12 #include "SkXfermode.h"
13
14 namespace skiagm {
15
16 /**
17 * Renders overlapping shapes with colorburn against a checkerboard.
18 */
19 class DstReadShuffle : public GM {
20 public:
21 DstReadShuffle() {
22 this->setBGColor(SkColorSetARGB(0xff, 0xff, 0, 0xff));
23 }
24
25 protected:
26 enum ShapeType {
27 kShapeTypeCircle,
bsalomon 2015/01/26 18:46:18 style nit, kCircle_ShapeType, etc
28 kShapeTypeRoundRect,
29 kShapeTypeRect,
30 kShapeTypeConvexPath,
31 kShapeTypeConcavePath,
32 kText,
33 kNumShapeTypes
34 };
35
36 SkString onShortName() SK_OVERRIDE {
37 return SkString("dstreadshuffle");
38 }
39
40 SkISize onISize() SK_OVERRIDE {
41 return SkISize::Make(kWidth, kHeight);
42 }
43
44 void drawShape(SkCanvas* canvas,
45 SkPaint* paint,
46 ShapeType type) {
47 static const SkRect kRect = SkRect::MakeXYWH(SkIntToScalar(-50), SkIntTo Scalar(-50),
48 SkIntToScalar(75), SkIntToS calar(105));
49 switch (type) {
50 case kShapeTypeCircle:
51 canvas->drawCircle(0, 0, 50, *paint);
52 break;
53 case kShapeTypeRoundRect:
54 canvas->drawRoundRect(kRect, SkIntToScalar(10), SkIntToScalar(20 ), *paint);
55 break;
56 case kShapeTypeRect:
57 canvas->drawRect(kRect, *paint);
58 break;
59 case kShapeTypeConvexPath:
60 if (fConvexPath.isEmpty()) {
61 SkPoint points[4];
62 kRect.toQuad(points);
63 fConvexPath.moveTo(points[0]);
64 fConvexPath.quadTo(points[1], points[2]);
65 fConvexPath.quadTo(points[3], points[0]);
66 SkASSERT(fConvexPath.isConvex());
67 }
68 canvas->drawPath(fConvexPath, *paint);
69 break;
70 case kShapeTypeConcavePath:
71 if (fConcavePath.isEmpty()) {
72 SkPoint points[5] = {{0, SkIntToScalar(-50)} };
73 SkMatrix rot;
74 rot.setRotate(SkIntToScalar(360) / 5);
75 for (int i = 1; i < 5; ++i) {
76 rot.mapPoints(points + i, points + i - 1, 1);
77 }
78 fConcavePath.moveTo(points[0]);
79 for (int i = 0; i < 5; ++i) {
80 fConcavePath.lineTo(points[(2 * i) % 5]);
81 }
82 fConcavePath.setFillType(SkPath::kEvenOdd_FillType);
83 SkASSERT(!fConcavePath.isConvex());
84 }
85 canvas->drawPath(fConcavePath, *paint);
86 break;
87 case kText: {
88 const char* text = "Hello!";
89 paint->setTextSize(30);
90 canvas->drawText(text, strlen(text), 0, 0, *paint);
91 }
92 default:
93 break;
94 }
95 }
96
97 static SkColor GetColor(SkRandom* random, int i) {
98 SkColor color;
99 switch (i) {
100 case 0:
101 color = SK_ColorTRANSPARENT;
bsalomon 2015/01/26 18:46:18 breaks?
102 case 1:
103 color = SkColorSetARGB(0xff,
104 random->nextULessThan(256),
105 random->nextULessThan(256),
106 random->nextULessThan(256));
107 break;
108 default:
109 uint8_t alpha = random->nextULessThan(256);
110 color = SkColorSetARGB(alpha,
111 random->nextRangeU(0, alpha),
112 random->nextRangeU(0, alpha),
113 random->nextRangeU(0, alpha));
114 }
115 return color;
116 }
117
118 static void SetStyle(SkPaint* p, int style, int width) {
119 switch (style) {
120 case 0:
121 p->setStyle(SkPaint::kStroke_Style);
bsalomon 2015/01/26 18:46:18 breaks in here?
122 p->setStrokeWidth(width);
123 case 1:
124 p->setStyle(SkPaint::kStrokeAndFill_Style);
125 p->setStrokeWidth(width);
126 default:
127 p->setStyle(SkPaint::kFill_Style);
128 }
129 }
130
131 void onDraw(SkCanvas* canvas) SK_OVERRIDE {
132 SkRandom random;
133 int y = 100;
134 for (int i = 0; i < kNumShapeTypes; i++) {
135 ShapeType shapeType = static_cast<ShapeType>(i);
136 int x = 25;
137 for (int style = 0; style < 3; style++) {
138 for (int width = 0; width <= 1; width++) {
139 for (int alpha = 0; alpha <= 2; alpha++) {
140 for (int r = 0; r <= 5; r++) {
141 SkColor color = GetColor(&random, alpha);
142
143 SkPaint p;
144 p.setAntiAlias(true);
145 p.setColor(color);
146 p.setXfermodeMode(r % 3 == 0 ? SkXfermode::kHardLigh t_Mode :
147 SkXfermode::kSrcOver_ Mode);
148 SetStyle(&p, style, width);
149 canvas->save();
150 canvas->translate(x, y);
151 canvas->rotate(r < 3 ? 10 : 0);
152 this->drawShape(canvas, &p, shapeType);
153 canvas->restore();
154 x += 8;
155 }
156 }
157 }
158 }
159 y += 50;
160 }
161 }
162
163 private:
164 enum {
165 kNumShapes = 100,
166 };
167 SkAutoTUnref<SkShader> fBG;
168 SkPath fConcavePath;
169 SkPath fConvexPath;
170 static const int kWidth = 900;
171 static const int kHeight = 400;
172 typedef GM INHERITED;
173 };
174
175 //////////////////////////////////////////////////////////////////////////////
176
177 static GM* MyFactory(void*) { return new DstReadShuffle; }
178 static GMRegistry reg(MyFactory);
179
180 }
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