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

Side by Side Diff: gm/xfermodes3.cpp

Issue 22866002: Make xfermodes3 GM also test stroked rects (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: int->size_t Created 7 years, 4 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 | no next file » | 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 /* 2 /*
3 * Copyright 2013 Google Inc. 3 * Copyright 2013 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 #include "gm.h" 8 #include "gm.h"
9 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkGradientShader.h" 10 #include "SkGradientShader.h"
(...skipping 14 matching lines...) Expand all
25 class Xfermodes3GM : public GM { 25 class Xfermodes3GM : public GM {
26 public: 26 public:
27 Xfermodes3GM() {} 27 Xfermodes3GM() {}
28 28
29 protected: 29 protected:
30 virtual SkString onShortName() SK_OVERRIDE { 30 virtual SkString onShortName() SK_OVERRIDE {
31 return SkString("xfermodes3"); 31 return SkString("xfermodes3");
32 } 32 }
33 33
34 virtual SkISize onISize() SK_OVERRIDE { 34 virtual SkISize onISize() SK_OVERRIDE {
35 return make_isize(630, 620); 35 return make_isize(630, 1215);
36 } 36 }
37 37
38 virtual void onDrawBackground(SkCanvas* canvas) SK_OVERRIDE { 38 virtual void onDrawBackground(SkCanvas* canvas) SK_OVERRIDE {
39 SkPaint bgPaint; 39 SkPaint bgPaint;
40 bgPaint.setColor(0xFF70D0E0); 40 bgPaint.setColor(0xFF70D0E0);
41 canvas->drawPaint(bgPaint); 41 canvas->drawPaint(bgPaint);
42 } 42 }
43 43
44 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { 44 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
45 canvas->translate(SkIntToScalar(10), SkIntToScalar(20)); 45 canvas->translate(SkIntToScalar(10), SkIntToScalar(20));
46 46
47 SkPaint labelP; 47 SkPaint labelP;
48 labelP.setAntiAlias(true); 48 labelP.setAntiAlias(true);
49 49
50 static const SkColor kSolidColors[] = { 50 static const SkColor kSolidColors[] = {
51 SK_ColorTRANSPARENT, 51 SK_ColorTRANSPARENT,
52 SK_ColorBLUE, 52 SK_ColorBLUE,
53 0x80808000 53 0x80808000
54 }; 54 };
55 55
56 static const SkColor kBmpAlphas[] = { 56 static const SkColor kBmpAlphas[] = {
57 0xff, 57 0xff,
58 0x80, 58 0x80,
59 }; 59 };
60 60
61 SkAutoTUnref<SkCanvas> tempCanvas(this->possiblyCreateTempCanvas(canvas, kSize, kSize)); 61 SkAutoTUnref<SkCanvas> tempCanvas(this->possiblyCreateTempCanvas(canvas, kSize, kSize));
62 62
63 int test = 0; 63 int test = 0;
64 int x = 0, y = 0; 64 int x = 0, y = 0;
65 for (size_t m = 0; m <= SkXfermode::kLastMode; ++m) { 65 static const struct { SkPaint::Style fStyle; SkScalar fWidth; } kStrokes [] = {
66 SkXfermode::Mode mode = static_cast<SkXfermode::Mode>(m); 66 {SkPaint::kFill_Style, 0},
67 canvas->drawText(SkXfermode::ModeName(mode), 67 {SkPaint::kStroke_Style, SkIntToScalar(kSize) / 2},
68 strlen(SkXfermode::ModeName(mode)), 68 };
69 SkIntToScalar(x), 69 for (size_t s = 0; s < SK_ARRAY_COUNT(kStrokes); ++s) {
70 SkIntToScalar(y + kSize + 3) + labelP.getTextSize() , 70 for (size_t m = 0; m <= SkXfermode::kLastMode; ++m) {
71 labelP); 71 SkXfermode::Mode mode = static_cast<SkXfermode::Mode>(m);
72 for (size_t c = 0; c < SK_ARRAY_COUNT(kSolidColors); ++c) { 72 canvas->drawText(SkXfermode::ModeName(mode),
73 SkPaint modePaint; 73 strlen(SkXfermode::ModeName(mode)),
74 modePaint.setXfermodeMode(mode); 74 SkIntToScalar(x),
75 modePaint.setColor(kSolidColors[c]); 75 SkIntToScalar(y + kSize + 3) + labelP.getTextSi ze(),
76 labelP);
77 for (size_t c = 0; c < SK_ARRAY_COUNT(kSolidColors); ++c) {
78 SkPaint modePaint;
79 modePaint.setXfermodeMode(mode);
80 modePaint.setColor(kSolidColors[c]);
81 modePaint.setStyle(kStrokes[s].fStyle);
82 modePaint.setStrokeWidth(kStrokes[s].fWidth);
76 83
77 this->drawMode(canvas, x, y, kSize, kSize, modePaint, tempCanvas .get()); 84 this->drawMode(canvas, x, y, kSize, kSize, modePaint, tempCa nvas.get());
78 85
79 ++test; 86 ++test;
80 x += kSize + 10; 87 x += kSize + 10;
81 if (!(test % kTestsPerRow)) { 88 if (!(test % kTestsPerRow)) {
82 x = 0; 89 x = 0;
83 y += kSize + 30; 90 y += kSize + 30;
91 }
84 } 92 }
85 } 93 for (size_t a = 0; a < SK_ARRAY_COUNT(kBmpAlphas); ++a) {
86 for (size_t a = 0; a < SK_ARRAY_COUNT(kBmpAlphas); ++a) { 94 SkPaint modePaint;
87 SkPaint modePaint; 95 modePaint.setXfermodeMode(mode);
88 modePaint.setXfermodeMode(mode); 96 modePaint.setAlpha(kBmpAlphas[a]);
89 modePaint.setAlpha(kBmpAlphas[a]); 97 modePaint.setShader(fBmpShader);
90 modePaint.setShader(fBmpShader); 98 modePaint.setStyle(kStrokes[s].fStyle);
99 modePaint.setStrokeWidth(kStrokes[s].fWidth);
91 100
92 this->drawMode(canvas, x, y, kSize, kSize, modePaint, tempCanvas .get()); 101 this->drawMode(canvas, x, y, kSize, kSize, modePaint, tempCa nvas.get());
93 102
94 ++test; 103 ++test;
95 x += kSize + 10; 104 x += kSize + 10;
96 if (!(test % kTestsPerRow)) { 105 if (!(test % kTestsPerRow)) {
97 x = 0; 106 x = 0;
98 y += kSize + 30; 107 y += kSize + 30;
108 }
99 } 109 }
100 } 110 }
101 } 111 }
102 } 112 }
103 113
104 private: 114 private:
105 /** 115 /**
106 * GrContext has optimizations around full rendertarget draws that can be re placed with clears. 116 * GrContext has optimizations around full rendertarget draws that can be re placed with clears.
107 * We are trying to test those. We could use saveLayer() to create small SkG puDevices but 117 * We are trying to test those. We could use saveLayer() to create small SkG puDevices but
108 * saveLayer() uses the texture cache. This means that the actual render tar get may be larger 118 * saveLayer() uses the texture cache. This means that the actual render tar get may be larger
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 SkAutoTUnref<SkShader> fBmpShader; 237 SkAutoTUnref<SkShader> fBmpShader;
228 238
229 typedef GM INHERITED; 239 typedef GM INHERITED;
230 }; 240 };
231 241
232 ////////////////////////////////////////////////////////////////////////////// 242 //////////////////////////////////////////////////////////////////////////////
233 243
234 DEF_GM(return new Xfermodes3GM;) 244 DEF_GM(return new Xfermodes3GM;)
235 245
236 } 246 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698