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/shadertext3.cpp

Issue 1790353002: Revert of more shader-->sp conversions (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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::MakeLinear(kPts0, kColors0, kPos, 29 paint.setShader(SkGradientShader::CreateLinear(kPts0, kColors0, kPos,
30 SK_ARRAY_COUNT(kColors0), SkShader::kClamp_TileMode)); 30 SK_ARRAY_COUNT(kColors0), SkShader::kClamp_TileMode))->unref ();
31 canvas.drawPaint(paint); 31 canvas.drawPaint(paint);
32 paint.setShader(SkGradientShader::MakeLinear(kPts1, kColors1, kPos, 32 paint.setShader(SkGradientShader::CreateLinear(kPts1, kColors1, kPos,
33 SK_ARRAY_COUNT(kColors1), SkShader::kClamp_TileMode)); 33 SK_ARRAY_COUNT(kColors1), SkShader::kClamp_TileMode))->unref ();
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
103 SkPaint fillPaint; 108 SkPaint fillPaint;
104 fillPaint.setAntiAlias(true); 109 fillPaint.setAntiAlias(true);
105 sk_tool_utils::set_portable_typeface(&fillPaint); 110 sk_tool_utils::set_portable_typeface(&fillPaint);
106 fillPaint.setTextSize(SkIntToScalar(kPointSize)); 111 fillPaint.setTextSize(SkIntToScalar(kPointSize));
107 fillPaint.setFilterQuality(kLow_SkFilterQuality); 112 fillPaint.setFilterQuality(kLow_SkFilterQuality);
108 fillPaint.setShader(SkShader::MakeBitmapShader(fBmp, kTileModes[ tm0], 113 fillPaint.setShader(shader);
109 kTileModes[tm1], &localM));
110 114
111 canvas->drawText(kText, kTextLen, 0, 0, fillPaint); 115 canvas->drawText(kText, kTextLen, 0, 0, fillPaint);
112 canvas->drawText(kText, kTextLen, 0, 0, outlinePaint); 116 canvas->drawText(kText, kTextLen, 0, 0, outlinePaint);
113 SkScalar w = fillPaint.measureText(kText, kTextLen); 117 SkScalar w = fillPaint.measureText(kText, kTextLen);
114 canvas->translate(w + 10.f, 0.f); 118 canvas->translate(w + 10.f, 0.f);
115 ++i; 119 ++i;
116 if (!(i % 2)) { 120 if (!(i % 2)) {
117 canvas->restore(); 121 canvas->restore();
118 canvas->translate(0, 0.75f * kPointSize); 122 canvas->translate(0, 0.75f * kPointSize);
119 canvas->save(); 123 canvas->save();
120 } 124 }
121 } 125 }
122 } 126 }
123 canvas->restore(); 127 canvas->restore();
124 } 128 }
125 129
126 private: 130 private:
127 SkBitmap fBmp; 131 SkBitmap fBmp;
128 typedef GM INHERITED; 132 typedef GM INHERITED;
129 }; 133 };
130 134
131 /////////////////////////////////////////////////////////////////////////////// 135 ///////////////////////////////////////////////////////////////////////////////
132 136
133 static GM* MyFactory(void*) { return new ShaderText3GM; } 137 static GM* MyFactory(void*) { return new ShaderText3GM; }
134 static GMRegistry reg(MyFactory); 138 static GMRegistry reg(MyFactory);
135 } 139 }
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