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

Side by Side Diff: gm/blurs.cpp

Issue 1852113003: switch maskfilters to sk_sp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 8 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/blurroundrect.cpp ('k') | gm/circles.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 "SkBlurMask.h" 9 #include "SkBlurMask.h"
10 #include "SkBlurMaskFilter.h" 10 #include "SkBlurMaskFilter.h"
(...skipping 17 matching lines...) Expand all
28 sk_tool_utils::set_portable_typeface(&paint); 28 sk_tool_utils::set_portable_typeface(&paint);
29 paint.setTextSize(SkIntToScalar(25)); 29 paint.setTextSize(SkIntToScalar(25));
30 canvas->translate(SkIntToScalar(-40), SkIntToScalar(0)); 30 canvas->translate(SkIntToScalar(-40), SkIntToScalar(0));
31 31
32 SkBlurMaskFilter::BlurFlags flags = SkBlurMaskFilter::kNone_BlurFlag; 32 SkBlurMaskFilter::BlurFlags flags = SkBlurMaskFilter::kNone_BlurFlag;
33 for (int j = 0; j < 2; j++) { 33 for (int j = 0; j < 2; j++) {
34 canvas->save(); 34 canvas->save();
35 paint.setColor(SK_ColorBLUE); 35 paint.setColor(SK_ColorBLUE);
36 for (size_t i = 0; i < SK_ARRAY_COUNT(gRecs); i++) { 36 for (size_t i = 0; i < SK_ARRAY_COUNT(gRecs); i++) {
37 if (gRecs[i].fStyle != NONE) { 37 if (gRecs[i].fStyle != NONE) {
38 SkMaskFilter* mf = SkBlurMaskFilter::Create(gRecs[i].fStyle, 38 paint.setMaskFilter(SkBlurMaskFilter::Make(gRecs[i].fStyle,
39 SkBlurMask::ConvertRadiusToSigma(SkIn tToScalar(20)), 39 SkBlurMask::ConvertRadiusToSigma(SkIn tToScalar(20)),
40 flags); 40 flags));
41 paint.setMaskFilter(mf)->unref();
42 } else { 41 } else {
43 paint.setMaskFilter(nullptr); 42 paint.setMaskFilter(nullptr);
44 } 43 }
45 canvas->drawCircle(SkIntToScalar(200 + gRecs[i].fCx*100), 44 canvas->drawCircle(SkIntToScalar(200 + gRecs[i].fCx*100),
46 SkIntToScalar(200 + gRecs[i].fCy*100), 45 SkIntToScalar(200 + gRecs[i].fCy*100),
47 SkIntToScalar(50), 46 SkIntToScalar(50),
48 paint); 47 paint);
49 } 48 }
50 // draw text 49 // draw text
51 { 50 {
52 SkMaskFilter* mf = SkBlurMaskFilter::Create(kNormal_SkBlurStyle, 51 paint.setMaskFilter(SkBlurMaskFilter::Make(kNormal_SkBlurStyle,
53 SkBlurMask::ConvertRadiusToSigma(SkIn tToScalar(4)), 52 SkBlurMask::ConvertRadiusToSigma(SkIn tToScalar(4)),
54 flags); 53 flags));
55 paint.setMaskFilter(mf)->unref();
56 SkScalar x = SkIntToScalar(70); 54 SkScalar x = SkIntToScalar(70);
57 SkScalar y = SkIntToScalar(400); 55 SkScalar y = SkIntToScalar(400);
58 paint.setColor(SK_ColorBLACK); 56 paint.setColor(SK_ColorBLACK);
59 canvas->drawText("Hamburgefons Style", 18, x, y, paint); 57 canvas->drawText("Hamburgefons Style", 18, x, y, paint);
60 canvas->drawText("Hamburgefons Style", 18, 58 canvas->drawText("Hamburgefons Style", 18,
61 x, y + SkIntToScalar(50), paint); 59 x, y + SkIntToScalar(50), paint);
62 paint.setMaskFilter(nullptr); 60 paint.setMaskFilter(nullptr);
63 paint.setColor(SK_ColorWHITE); 61 paint.setColor(SK_ColorWHITE);
64 x -= SkIntToScalar(2); 62 x -= SkIntToScalar(2);
65 y -= SkIntToScalar(2); 63 y -= SkIntToScalar(2);
66 canvas->drawText("Hamburgefons Style", 18, x, y, paint); 64 canvas->drawText("Hamburgefons Style", 18, x, y, paint);
67 } 65 }
68 canvas->restore(); 66 canvas->restore();
69 flags = SkBlurMaskFilter::kHighQuality_BlurFlag; 67 flags = SkBlurMaskFilter::kHighQuality_BlurFlag;
70 canvas->translate(SkIntToScalar(350), SkIntToScalar(0)); 68 canvas->translate(SkIntToScalar(350), SkIntToScalar(0));
71 } 69 }
72 } 70 }
73 71
74 //////////////////////////////////////////////////////////////////////////////// ////////////// 72 //////////////////////////////////////////////////////////////////////////////// //////////////
75 73
76 // exercise a special-case of blurs, which is two nested rects. These are drawn specially, 74 // exercise a special-case of blurs, which is two nested rects. These are drawn specially,
77 // and possibly cached. 75 // and possibly cached.
78 // 76 //
79 // in particular, we want to notice that the 2nd rect draws slightly differently , since it 77 // in particular, we want to notice that the 2nd rect draws slightly differently , since it
80 // is translated a fractional amount. 78 // is translated a fractional amount.
81 // 79 //
82 DEF_SIMPLE_GM(blur2rects, canvas, 700, 500) { 80 DEF_SIMPLE_GM(blur2rects, canvas, 700, 500) {
83 SkPaint paint; 81 SkPaint paint;
84 82
85 paint.setMaskFilter(SkBlurMaskFilter::Create(kNormal_SkBlurStyle, 83 paint.setMaskFilter(SkBlurMaskFilter::Make(kNormal_SkBlurStyle, 2.3f));
86 2.3f))->unref();
87 84
88 SkRect outer = SkRect::MakeXYWH(10.125f, 10.125f, 100.125f, 100); 85 SkRect outer = SkRect::MakeXYWH(10.125f, 10.125f, 100.125f, 100);
89 SkRect inner = SkRect::MakeXYWH(20.25f, 20.125f, 80, 80); 86 SkRect inner = SkRect::MakeXYWH(20.25f, 20.125f, 80, 80);
90 SkPath path; 87 SkPath path;
91 path.addRect(outer, SkPath::kCW_Direction); 88 path.addRect(outer, SkPath::kCW_Direction);
92 path.addRect(inner, SkPath::kCCW_Direction); 89 path.addRect(inner, SkPath::kCCW_Direction);
93 90
94 canvas->drawPath(path, paint); 91 canvas->drawPath(path, paint);
95 // important to translate by a factional amount to exercise a different "phase" 92 // important to translate by a factional amount to exercise a different "phase"
96 // of the same path w.r.t. the pixel grid 93 // of the same path w.r.t. the pixel grid
97 SkScalar dx = SkScalarRoundToScalar(path.getBounds().width()) + 14 + 0.2 5f; 94 SkScalar dx = SkScalarRoundToScalar(path.getBounds().width()) + 14 + 0.2 5f;
98 canvas->translate(dx, 0); 95 canvas->translate(dx, 0);
99 canvas->drawPath(path, paint); 96 canvas->drawPath(path, paint);
100 } 97 }
101 98
102 DEF_SIMPLE_GM(blur2rectsnonninepatch, canvas, 700, 500) { 99 DEF_SIMPLE_GM(blur2rectsnonninepatch, canvas, 700, 500) {
103 SkPaint paint; 100 SkPaint paint;
104 paint.setMaskFilter(SkBlurMaskFilter::Create(kNormal_SkBlurStyle, 101 paint.setMaskFilter(SkBlurMaskFilter::Make(kNormal_SkBlurStyle, 4.3f));
105 4.3f))->unref();
106 102
107 SkRect outer = SkRect::MakeXYWH(10, 110, 100, 100); 103 SkRect outer = SkRect::MakeXYWH(10, 110, 100, 100);
108 SkRect inner = SkRect::MakeXYWH(50, 150, 10, 10); 104 SkRect inner = SkRect::MakeXYWH(50, 150, 10, 10);
109 SkPath path; 105 SkPath path;
110 path.addRect(outer, SkPath::kCW_Direction); 106 path.addRect(outer, SkPath::kCW_Direction);
111 path.addRect(inner, SkPath::kCW_Direction); 107 path.addRect(inner, SkPath::kCW_Direction);
112 canvas->drawPath(path, paint); 108 canvas->drawPath(path, paint);
113 109
114 SkScalar dx = SkScalarRoundToScalar(path.getBounds().width()) + 40 + 0.2 5f; 110 SkScalar dx = SkScalarRoundToScalar(path.getBounds().width()) + 40 + 0.2 5f;
115 canvas->translate(dx, 0); 111 canvas->translate(dx, 0);
116 canvas->drawPath(path, paint); 112 canvas->drawPath(path, paint);
117 113
118 // Translate to outside of clip bounds. 114 // Translate to outside of clip bounds.
119 canvas->translate(-dx, 0); 115 canvas->translate(-dx, 0);
120 canvas->translate(-30, -150); 116 canvas->translate(-30, -150);
121 canvas->drawPath(path, paint); 117 canvas->drawPath(path, paint);
122 } 118 }
OLDNEW
« no previous file with comments | « gm/blurroundrect.cpp ('k') | gm/circles.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698