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

Side by Side Diff: samplecode/SampleDitherBitmap.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
8 #include "SampleCode.h" 8 #include "SampleCode.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkColorPriv.h" 10 #include "SkColorPriv.h"
11 #include "SkGradientShader.h" 11 #include "SkGradientShader.h"
12 #include "SkPath.h" 12 #include "SkPath.h"
13 #include "SkUtils.h" 13 #include "SkUtils.h"
14 #include "SkView.h" 14 #include "SkView.h"
15 15
16 static void draw_rect(SkCanvas* canvas, const SkRect& r, const SkPaint& p) { 16 static void draw_rect(SkCanvas* canvas, const SkRect& r, const SkPaint& p) {
17 canvas->drawRect(r, p); 17 canvas->drawRect(r, p);
18 18
19 SkPaint frame(p); 19 SkPaint frame(p);
20 frame.setShader(nullptr); 20 frame.setShader(nullptr);
21 frame.setStyle(SkPaint::kStroke_Style); 21 frame.setStyle(SkPaint::kStroke_Style);
22 canvas->drawRect(r, frame); 22 canvas->drawRect(r, frame);
23 } 23 }
24 24
25 static void draw_gradient(SkCanvas* canvas) { 25 static void draw_gradient(SkCanvas* canvas) {
26 SkRect r = { 0, 0, SkIntToScalar(256), SkIntToScalar(32) }; 26 SkRect r = { 0, 0, SkIntToScalar(256), SkIntToScalar(32) };
27 SkPoint pts[] = { { r.fLeft, r.fTop }, { r.fRight, r.fTop } }; 27 SkPoint pts[] = { { r.fLeft, r.fTop }, { r.fRight, r.fTop } };
28 SkColor colors[] = { 0xFF000000, 0xFFFF0000 }; 28 SkColor colors[] = { 0xFF000000, 0xFFFF0000 };
29 SkShader* s = SkGradientShader::CreateLinear(pts, colors, nullptr, 2,
30 SkShader::kClamp_TileMode);
31
32 SkPaint p; 29 SkPaint p;
33 p.setShader(s)->unref(); 30 p.setShader(SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkShader:: kClamp_TileMode));
34 draw_rect(canvas, r, p); 31 draw_rect(canvas, r, p);
35 32
36 canvas->translate(0, SkIntToScalar(40)); 33 canvas->translate(0, SkIntToScalar(40));
37 p.setDither(true); 34 p.setDither(true);
38 draw_rect(canvas, r, p); 35 draw_rect(canvas, r, p);
39 } 36 }
40 37
41 static bool test_pathregion() { 38 static bool test_pathregion() {
42 SkPath path; 39 SkPath path;
43 SkRegion region; 40 SkRegion region;
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 } 139 }
143 140
144 private: 141 private:
145 typedef SampleView INHERITED; 142 typedef SampleView INHERITED;
146 }; 143 };
147 144
148 ////////////////////////////////////////////////////////////////////////////// 145 //////////////////////////////////////////////////////////////////////////////
149 146
150 static SkView* MyFactory() { return new DitherBitmapView; } 147 static SkView* MyFactory() { return new DitherBitmapView; }
151 static SkViewRegister reg(MyFactory); 148 static SkViewRegister reg(MyFactory);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698