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

Side by Side Diff: gm/shadertext3.cpp

Issue 1793303002: Reland of "more shader-->sp conversions (patchset #5 id:80001 of https://codereview.chromium… (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: make pictureRef a value, so its clearer what's going on Created 4 years, 9 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 | « gm/shadertext2.cpp ('k') | gm/shadows.cpp » ('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 2011 Google Inc. 2 * Copyright 2011 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 11
12 namespace skiagm { 12 namespace skiagm {
13 13
14 static void makebm(SkBitmap* bm, int w, int h) { 14 static void makebm(SkBitmap* bm, int w, int h) {
15 bm->allocN32Pixels(w, h); 15 bm->allocN32Pixels(w, h);
16 bm->eraseColor(SK_ColorTRANSPARENT); 16 bm->eraseColor(SK_ColorTRANSPARENT);
17 17
18 SkCanvas canvas(*bm); 18 SkCanvas canvas(*bm);
19 SkScalar s = SkIntToScalar(SkMin32(w, h)); 19 SkScalar s = SkIntToScalar(SkMin32(w, h));
20 static const SkPoint kPts0[] = { { 0, 0 }, { s, s } }; 20 static const SkPoint kPts0[] = { { 0, 0 }, { s, s } };
21 static const SkPoint kPts1[] = { { s/2, 0 }, { s/2, s } }; 21 static const SkPoint kPts1[] = { { s/2, 0 }, { s/2, s } };
22 static const SkScalar kPos[] = { 0, SK_Scalar1/2, SK_Scalar1 }; 22 static const SkScalar kPos[] = { 0, SK_Scalar1/2, SK_Scalar1 };
23 static const SkColor kColors0[] = {0x80F00080, 0xF0F08000, 0x800080F0 }; 23 static const SkColor kColors0[] = {0x80F00080, 0xF0F08000, 0x800080F0 };
24 static const SkColor kColors1[] = {0xF08000F0, 0x8080F000, 0xF000F080 }; 24 static const SkColor kColors1[] = {0xF08000F0, 0x8080F000, 0xF000F080 };
25 25
26 26
27 SkPaint paint; 27 SkPaint paint;
28 28
29 paint.setShader(SkGradientShader::CreateLinear(kPts0, kColors0, kPos, 29 paint.setShader(SkGradientShader::MakeLinear(kPts0, kColors0, kPos,
30 SK_ARRAY_COUNT(kColors0), SkShader::kClamp_TileMode))->unref (); 30 SK_ARRAY_COUNT(kColors0), SkShader::kClamp_TileMode));
31 canvas.drawPaint(paint); 31 canvas.drawPaint(paint);
32 paint.setShader(SkGradientShader::CreateLinear(kPts1, kColors1, kPos, 32 paint.setShader(SkGradientShader::MakeLinear(kPts1, kColors1, kPos,
33 SK_ARRAY_COUNT(kColors1), SkShader::kClamp_TileMode))->unref (); 33 SK_ARRAY_COUNT(kColors1), SkShader::kClamp_TileMode));
34 canvas.drawPaint(paint); 34 canvas.drawPaint(paint);
35 } 35 }
36 36
37 /////////////////////////////////////////////////////////////////////////////// 37 ///////////////////////////////////////////////////////////////////////////////
38 38
39 struct LabeledMatrix { 39 struct LabeledMatrix {
40 SkMatrix fMatrix; 40 SkMatrix fMatrix;
41 const char* fLabel; 41 const char* fLabel;
42 }; 42 };
43 43
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 93
94 canvas->save(); 94 canvas->save();
95 int i = 0; 95 int i = 0;
96 for (size_t tm0 = 0; tm0 < SK_ARRAY_COUNT(kTileModes); ++tm0) { 96 for (size_t tm0 = 0; tm0 < SK_ARRAY_COUNT(kTileModes); ++tm0) {
97 for (size_t tm1 = 0; tm1 < SK_ARRAY_COUNT(kTileModes); ++tm1) { 97 for (size_t tm1 = 0; tm1 < SK_ARRAY_COUNT(kTileModes); ++tm1) {
98 SkMatrix localM; 98 SkMatrix localM;
99 localM.setTranslate(5.f, 5.f); 99 localM.setTranslate(5.f, 5.f);
100 localM.postRotate(20); 100 localM.postRotate(20);
101 localM.postScale(1.15f, .85f); 101 localM.postScale(1.15f, .85f);
102 102
103 SkAutoTUnref<SkShader> shader(SkShader::CreateBitmapShader(fBmp,
104 kTile Modes[tm0],
105 kTile Modes[tm1],
106 &loca lM));
107
108 SkPaint fillPaint; 103 SkPaint fillPaint;
109 fillPaint.setAntiAlias(true); 104 fillPaint.setAntiAlias(true);
110 sk_tool_utils::set_portable_typeface(&fillPaint); 105 sk_tool_utils::set_portable_typeface(&fillPaint);
111 fillPaint.setTextSize(SkIntToScalar(kPointSize)); 106 fillPaint.setTextSize(SkIntToScalar(kPointSize));
112 fillPaint.setFilterQuality(kLow_SkFilterQuality); 107 fillPaint.setFilterQuality(kLow_SkFilterQuality);
113 fillPaint.setShader(shader); 108 fillPaint.setShader(SkShader::MakeBitmapShader(fBmp, kTileModes[ tm0],
109 kTileModes[tm1], &localM));
114 110
115 canvas->drawText(kText, kTextLen, 0, 0, fillPaint); 111 canvas->drawText(kText, kTextLen, 0, 0, fillPaint);
116 canvas->drawText(kText, kTextLen, 0, 0, outlinePaint); 112 canvas->drawText(kText, kTextLen, 0, 0, outlinePaint);
117 SkScalar w = fillPaint.measureText(kText, kTextLen); 113 SkScalar w = fillPaint.measureText(kText, kTextLen);
118 canvas->translate(w + 10.f, 0.f); 114 canvas->translate(w + 10.f, 0.f);
119 ++i; 115 ++i;
120 if (!(i % 2)) { 116 if (!(i % 2)) {
121 canvas->restore(); 117 canvas->restore();
122 canvas->translate(0, 0.75f * kPointSize); 118 canvas->translate(0, 0.75f * kPointSize);
123 canvas->save(); 119 canvas->save();
124 } 120 }
125 } 121 }
126 } 122 }
127 canvas->restore(); 123 canvas->restore();
128 } 124 }
129 125
130 private: 126 private:
131 SkBitmap fBmp; 127 SkBitmap fBmp;
132 typedef GM INHERITED; 128 typedef GM INHERITED;
133 }; 129 };
134 130
135 /////////////////////////////////////////////////////////////////////////////// 131 ///////////////////////////////////////////////////////////////////////////////
136 132
137 static GM* MyFactory(void*) { return new ShaderText3GM; } 133 static GM* MyFactory(void*) { return new ShaderText3GM; }
138 static GMRegistry reg(MyFactory); 134 static GMRegistry reg(MyFactory);
139 } 135 }
OLDNEW
« no previous file with comments | « gm/shadertext2.cpp ('k') | gm/shadows.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698