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

Side by Side Diff: gm/blurcircles.cpp

Issue 1311583005: Add special case circle blur for Ganesh (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix no-GPU build Created 5 years, 3 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 | « no previous file | gyp/effects.gypi » ('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 2014 Google Inc. 2 * Copyright 2014 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"
11 #include "SkCanvas.h" 11 #include "SkCanvas.h"
12 #include "SkPaint.h" 12 #include "SkPaint.h"
13 #include "SkString.h" 13 #include "SkString.h"
14 14
15 class BlurCirclesGM : public skiagm::GM { 15 class BlurCirclesGM : public skiagm::GM {
16 public: 16 public:
17 BlurCirclesGM() 17 BlurCirclesGM() { }
18 : fName("blurcircles") {
19 }
20 18
21 protected: 19 protected:
20 bool runAsBench() const override { return true; }
22 21
23 SkString onShortName() override { 22 SkString onShortName() override {
24 return fName; 23 return SkString("blurcircles");
25 } 24 }
26 25
27 SkISize onISize() override { 26 SkISize onISize() override {
28 return SkISize::Make(950, 950); 27 return SkISize::Make(950, 950);
29 } 28 }
30 29
30 void onOnceBeforeDraw() override {
31 const float blurRadii[kNumBlurs] = { 1,5,10,20 };
32
33 for (int i = 0; i < kNumBlurs; ++i) {
34 fBlurFilters[i].reset(SkBlurMaskFilter::Create(
35 kNormal_SkBlurStyle,
36 SkBlurMask::ConvertRadiusToSigma(SkIntToScal ar(blurRadii[i])),
37 SkBlurMaskFilter::kHighQuality_BlurFlag));
38 }
39 }
40
31 void onDraw(SkCanvas* canvas) override { 41 void onDraw(SkCanvas* canvas) override {
32 canvas->scale(1.5f, 1.5f); 42 canvas->scale(1.5f, 1.5f);
33 canvas->translate(50,50); 43 canvas->translate(50,50);
34 44
35 const float blurRadii[] = { 1,5,10,20 };
36 const int circleRadii[] = { 5,10,25,50 }; 45 const int circleRadii[] = { 5,10,25,50 };
37 for (size_t i = 0; i < SK_ARRAY_COUNT(blurRadii); ++i) { 46
47 for (size_t i = 0; i < kNumBlurs; ++i) {
38 SkAutoCanvasRestore autoRestore(canvas, true); 48 SkAutoCanvasRestore autoRestore(canvas, true);
39 canvas->translate(0, SkIntToScalar(150*i)); 49 canvas->translate(0, SkIntToScalar(150*i));
40 for (size_t j = 0; j < SK_ARRAY_COUNT(circleRadii); ++j) { 50 for (size_t j = 0; j < SK_ARRAY_COUNT(circleRadii); ++j) {
41 SkMaskFilter* filter = SkBlurMaskFilter::Create(
42 kNormal_SkBlurStyle,
43 SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(blurRadii[i]) ),
44 SkBlurMaskFilter::kHighQuality_BlurFlag);
45 SkPaint paint; 51 SkPaint paint;
46 paint.setColor(SK_ColorBLACK); 52 paint.setColor(SK_ColorBLACK);
47 paint.setMaskFilter(filter)->unref(); 53 paint.setMaskFilter(fBlurFilters[i]);
48 54
49 canvas->drawCircle(SkIntToScalar(50),SkIntToScalar(50),SkIntToSc alar(circleRadii[j]),paint); 55 canvas->drawCircle(SkIntToScalar(50),SkIntToScalar(50),SkIntToSc alar(circleRadii[j]),paint);
50 canvas->translate(SkIntToScalar(150), 0); 56 canvas->translate(SkIntToScalar(150), 0);
51 } 57 }
52 } 58 }
53 } 59 }
54 private: 60 private:
55 const SkString fName; 61 static const int kNumBlurs = 4;
62
63 SkAutoTUnref<SkMaskFilter> fBlurFilters[kNumBlurs];
56 64
57 typedef skiagm::GM INHERITED; 65 typedef skiagm::GM INHERITED;
58 }; 66 };
59 67
60 DEF_GM(return new BlurCirclesGM();) 68 DEF_GM(return new BlurCirclesGM();)
OLDNEW
« no previous file with comments | « no previous file | gyp/effects.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698