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

Side by Side Diff: bench/RectoriBench.cpp

Issue 23701006: Push sigma-based blur interface into our GMs/benches/tests/samplecode (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: cleaned up Created 7 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 | Annotate | Revision Log
« no previous file with comments | « bench/BlurRectBench.cpp ('k') | gm/bitmapmatrix.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 2013 Google Inc. 2 * Copyright 2013 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 "SkBenchmark.h" 8 #include "SkBenchmark.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkPaint.h" 10 #include "SkPaint.h"
(...skipping 10 matching lines...) Expand all
21 protected: 21 protected:
22 22
23 virtual const char* onGetName() { 23 virtual const char* onGetName() {
24 return "rectori"; 24 return "rectori";
25 } 25 }
26 26
27 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { 27 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
28 SkMWCRandom Random; 28 SkMWCRandom Random;
29 29
30 for (int i = 0; i < N; i++) { 30 for (int i = 0; i < N; i++) {
31 SkScalar blurRad = Random.nextRangeScalar(1.5f, 25.0f); 31 SkScalar blurSigma = Random.nextRangeScalar(1.5f, 25.0f);
32 SkScalar size = Random.nextRangeScalar(20*blurRad, 50*blurRad); 32 SkScalar size = Random.nextRangeScalar(20*blurSigma, 50*blurSigma);
33 33
34 SkScalar x = Random.nextRangeScalar(0.0f, W - size); 34 SkScalar x = Random.nextRangeScalar(0.0f, W - size);
35 SkScalar y = Random.nextRangeScalar(0.0f, H - size); 35 SkScalar y = Random.nextRangeScalar(0.0f, H - size);
36 36
37 SkRect inner = { x, y, x + size, y + size }; 37 SkRect inner = { x, y, x + size, y + size };
38 38
39 SkRect outer(inner); 39 SkRect outer(inner);
40 // outer is always outset either 2x or 4x the blur radius (we go wit h 2x) 40 // outer is always outset either 2x or 4x the blur radius (we go wit h 2x)
41 outer.outset(2*blurRad, 2*blurRad); 41 outer.outset(2*blurSigma, 2*blurSigma);
42 42
43 SkPath p; 43 SkPath p;
44 44
45 p.addRect(outer); 45 p.addRect(outer);
46 p.addRect(inner); 46 p.addRect(inner);
47 p.setFillType(SkPath::kEvenOdd_FillType); 47 p.setFillType(SkPath::kEvenOdd_FillType);
48 48
49 // This will be used to translate the normal draw outside the 49 // This will be used to translate the normal draw outside the
50 // clip rect and translate the blurred version back inside 50 // clip rect and translate the blurred version back inside
51 SkScalar translate = 2.0f * size; 51 SkScalar translate = 2.0f * size;
52 52
53 SkPaint paint; 53 SkPaint paint;
54 paint.setLooper(this->createLooper(-translate, blurRad))->unref(); 54 paint.setLooper(this->createLooper(-translate, blurSigma))->unref();
55 paint.setColor(0xff000000 | Random.nextU()); 55 paint.setColor(0xff000000 | Random.nextU());
56 paint.setAntiAlias(true); 56 paint.setAntiAlias(true);
57 57
58 canvas->save(); 58 canvas->save();
59 // clip always equals inner rect so we get the inside blur 59 // clip always equals inner rect so we get the inside blur
60 canvas->clipRect(inner); 60 canvas->clipRect(inner);
61 canvas->translate(translate, 0); 61 canvas->translate(translate, 0);
62 canvas->drawPath(p, paint); 62 canvas->drawPath(p, paint);
63 canvas->restore(); 63 canvas->restore();
64 } 64 }
65 } 65 }
66 66
67 private: 67 private:
68 enum { 68 enum {
69 W = 640, 69 W = 640,
70 H = 480, 70 H = 480,
71 }; 71 };
72 72
73 enum { N = SkBENCHLOOP(100) }; 73 enum { N = SkBENCHLOOP(100) };
74 74
75 SkLayerDrawLooper* createLooper(SkScalar xOff, SkScalar radius) { 75 SkLayerDrawLooper* createLooper(SkScalar xOff, SkScalar sigma) {
76 SkLayerDrawLooper* looper = new SkLayerDrawLooper; 76 SkLayerDrawLooper* looper = new SkLayerDrawLooper;
77 77
78 //----------------------------------------------- 78 //-----------------------------------------------
79 SkLayerDrawLooper::LayerInfo info; 79 SkLayerDrawLooper::LayerInfo info;
80 80
81 info.fFlagsMask = 0; 81 info.fFlagsMask = 0;
82 // TODO: add a color filter to better match what is seen in the wild 82 // TODO: add a color filter to better match what is seen in the wild
83 info.fPaintBits = /* SkLayerDrawLooper::kColorFilter_Bit |*/ 83 info.fPaintBits = /* SkLayerDrawLooper::kColorFilter_Bit |*/
84 SkLayerDrawLooper::kMaskFilter_Bit; 84 SkLayerDrawLooper::kMaskFilter_Bit;
85 info.fColorMode = SkXfermode::kDst_Mode; 85 info.fColorMode = SkXfermode::kDst_Mode;
86 info.fOffset.set(xOff, 0); 86 info.fOffset.set(xOff, 0);
87 info.fPostTranslate = false; 87 info.fPostTranslate = false;
88 88
89 SkPaint* paint = looper->addLayer(info); 89 SkPaint* paint = looper->addLayer(info);
90 90
91 SkMaskFilter* mf = SkBlurMaskFilter::Create(radius, 91 SkMaskFilter* mf = SkBlurMaskFilter::Create(SkBlurMaskFilter::kNormal_Bl urStyle,
92 SkBlurMaskFilter::kNormal_Bl urStyle, 92 sigma,
93 SkBlurMaskFilter::kHighQuali ty_BlurFlag); 93 SkBlurMaskFilter::kHighQuali ty_BlurFlag);
94 paint->setMaskFilter(mf)->unref(); 94 paint->setMaskFilter(mf)->unref();
95 95
96 //----------------------------------------------- 96 //-----------------------------------------------
97 info.fPaintBits = 0; 97 info.fPaintBits = 0;
98 info.fOffset.set(0, 0); 98 info.fOffset.set(0, 0);
99 99
100 paint = looper->addLayer(info); 100 paint = looper->addLayer(info);
101 return looper; 101 return looper;
102 } 102 }
103 103
104 typedef SkBenchmark INHERITED; 104 typedef SkBenchmark INHERITED;
105 }; 105 };
106 106
107 107
108 DEF_BENCH( return SkNEW_ARGS(RectoriBench, (p)); ) 108 DEF_BENCH( return SkNEW_ARGS(RectoriBench, (p)); )
OLDNEW
« no previous file with comments | « bench/BlurRectBench.cpp ('k') | gm/bitmapmatrix.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698