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

Side by Side Diff: samplecode/SampleRegion.cpp

Issue 1772463002: use Make instead of Create to return a shared shader (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: partial update of skia call-sites 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
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 #include "SampleCode.h" 8 #include "SampleCode.h"
8 #include "SkView.h" 9 #include "SkView.h"
9 #include "SkCanvas.h" 10 #include "SkCanvas.h"
10 #include "SkGradientShader.h" 11 #include "SkGradientShader.h"
11 #include "SkPath.h" 12 #include "SkPath.h"
12 #include "SkRegion.h" 13 #include "SkRegion.h"
13 #include "SkShader.h" 14 #include "SkShader.h"
14 #include "SkUtils.h" 15 #include "SkUtils.h"
15 #include "SkImageDecoder.h" 16 #include "SkImageDecoder.h"
16 17
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 const SkPoint pts[] = { 72 const SkPoint pts[] = {
72 { bounds.fLeft, y }, 73 { bounds.fLeft, y },
73 { bounds.fRight, y } 74 { bounds.fRight, y }
74 }; 75 };
75 const SkColor colors[] = { SK_ColorBLACK, SK_ColorBLACK, 0 }; 76 const SkColor colors[] = { SK_ColorBLACK, SK_ColorBLACK, 0 };
76 77
77 // pos[1] value is where we start to fade, relative to the width 78 // pos[1] value is where we start to fade, relative to the width
78 // of our pts[] array. 79 // of our pts[] array.
79 const SkScalar pos[] = { 0, 0.9f, SK_Scalar1 }; 80 const SkScalar pos[] = { 0, 0.9f, SK_Scalar1 };
80 81
81 SkShader* s = SkGradientShader::CreateLinear(pts, colors, pos, 3,
82 SkShader::kClamp_TileMode);
83 SkPaint p; 82 SkPaint p;
84 p.setShader(s)->unref(); 83 p.setShader(SkGradientShader::MakeLinear(pts, colors, pos, 3, SkShader::kCla mp_TileMode));
85 p.setXfermodeMode(SkXfermode::kDstIn_Mode); 84 p.setXfermodeMode(SkXfermode::kDstIn_Mode);
86 canvas->drawRect(bounds, p); 85 canvas->drawRect(bounds, p);
87 86
88 canvas->restore(); 87 canvas->restore();
89 } 88 }
90 89
91 static void test_text(SkCanvas* canvas) { 90 static void test_text(SkCanvas* canvas) {
92 SkPaint paint; 91 SkPaint paint;
93 paint.setAntiAlias(true); 92 paint.setAntiAlias(true);
94 paint.setTextSize(20); 93 paint.setTextSize(20);
95 94
96 const char* str = "Hamburgefons"; 95 const char* str = "Hamburgefons";
97 size_t len = strlen(str); 96 size_t len = strlen(str);
98 SkScalar x = 20; 97 SkScalar x = 20;
99 SkScalar y = 20; 98 SkScalar y = 20;
100 99
101 canvas->drawText(str, len, x, y, paint); 100 canvas->drawText(str, len, x, y, paint);
102 101
103 y += 20; 102 y += 20;
104 103
105 const SkPoint pts[] = { { x, y }, { x + paint.measureText(str, len), y } }; 104 const SkPoint pts[] = { { x, y }, { x + paint.measureText(str, len), y } };
106 const SkColor colors[] = { SK_ColorBLACK, SK_ColorBLACK, 0 }; 105 const SkColor colors[] = { SK_ColorBLACK, SK_ColorBLACK, 0 };
107 const SkScalar pos[] = { 0, 0.9f, 1 }; 106 const SkScalar pos[] = { 0, 0.9f, 1 };
108 SkShader* s = SkGradientShader::CreateLinear(pts, colors, pos, 107 paint.setShader(SkGradientShader::MakeLinear(pts, colors, pos,
109 SK_ARRAY_COUNT(colors), 108 SK_ARRAY_COUNT(colors),
110 SkShader::kClamp_TileMode); 109 SkShader::kClamp_TileMode));
111 paint.setShader(s)->unref();
112 canvas->drawText(str, len, x, y, paint); 110 canvas->drawText(str, len, x, y, paint);
113 111
114 y += 20; 112 y += 20;
115 paint.setShader(nullptr); 113 paint.setShader(nullptr);
116 drawFadingText(canvas, str, len, x, y, paint); 114 drawFadingText(canvas, str, len, x, y, paint);
117 } 115 }
118 116
119 #ifdef SK_DEBUG 117 #ifdef SK_DEBUG
120 static void make_rgn(SkRegion* rgn, int left, int top, int right, int bottom, 118 static void make_rgn(SkRegion* rgn, int left, int top, int right, int bottom,
121 int count, int32_t runs[]) { 119 int count, int32_t runs[]) {
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 private: 403 private:
406 SkIRect fBase, fRect; 404 SkIRect fBase, fRect;
407 405
408 typedef SampleView INHERITED; 406 typedef SampleView INHERITED;
409 }; 407 };
410 408
411 ////////////////////////////////////////////////////////////////////////////// 409 //////////////////////////////////////////////////////////////////////////////
412 410
413 static SkView* MyFactory() { return new RegionView; } 411 static SkView* MyFactory() { return new RegionView; }
414 static SkViewRegister reg(MyFactory); 412 static SkViewRegister reg(MyFactory);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698