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

Side by Side Diff: bench/RectoriBench.cpp

Issue 14690014: add bench for blurred rectori case (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 7 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 | « no previous file | gyp/bench.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 /*
2 * Copyright 2013 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "SkBenchmark.h"
9 #include "SkCanvas.h"
10 #include "SkPaint.h"
11 #include "SkRandom.h"
12 #include "SkBlurMaskFilter.h"
13 #include "SkLayerDrawLooper.h"
14
15 // This bench replicates a problematic use case of a draw looper used
16 // to create an inner blurred rect
17 class RectoriBench : public SkBenchmark {
18 public:
19 enum {
bsalomon 2013/05/10 20:18:22 private?
robertphillips 2013/05/13 14:10:47 Done.
20 W = 640,
21 H = 480,
22 };
23
24 enum { N = SkBENCHLOOP(100) };
bsalomon 2013/05/10 20:18:22 private?
robertphillips 2013/05/13 14:10:47 Done.
25
26 RectoriBench(void* param) : INHERITED(param) {}
27
28 protected:
29
30 virtual const char* onGetName() {
31 return "rectori";
32 }
33
34 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
35 SkMWCRandom gRandom;
bsalomon 2013/05/10 20:18:22 this isn't global, maybe drop the g prefix?
robertphillips 2013/05/13 14:10:47 Done.
36
37 for (int i = 0; i < N; i++) {
38 SkScalar blurRad = gRandom.nextRangeScalar(1.5f, 25.0f);
39 SkScalar size = gRandom.nextRangeScalar(20*blurRad, 50*blurRad);
40
41 SkScalar x = gRandom.nextRangeScalar(0.0f, W - size);
42 SkScalar y = gRandom.nextRangeScalar(0.0f, H - size);
43
44 SkRect inner = { x, y, x + size, y + size };
45
46 SkRect outer(inner);
47 // outer is always outset either 2x or 4x the blur radius (we go wit h 2x)
48 outer.outset(SkIntToScalar(2*blurRad), SkIntToScalar(2*blurRad));
49
50 SkPath p;
51
52 p.addRect(outer);
53 p.addRect(inner);
54 p.setFillType(SkPath::kEvenOdd_FillType);
55
56 // This will be used to translate the normal draw outside the
57 // clip rect and translate the blurred version back inside
58 SkScalar translate = 2.0f * size;
59
60 SkPaint paint;
61 paint.setLooper(this->createLooper(-translate, blurRad))->unref();
62 paint.setColor(0xff000000 | gRandom.nextU());
63 paint.setAntiAlias(true);
64
65 canvas->save();
66 // clip always equals inner rect so we get the inside blur
67 canvas->clipRect(inner);
68 canvas->translate(translate, 0);
69 canvas->drawPath(p, paint);
70 canvas->restore();
71 }
72 }
73 private:
bsalomon 2013/05/10 20:18:22 \n
robertphillips 2013/05/13 14:10:47 Done - I think.
74 SkLayerDrawLooper* createLooper(SkScalar xOff, SkScalar radius) {
75 SkLayerDrawLooper* looper = new SkLayerDrawLooper;
76
77 //-----------------------------------------------
78 SkLayerDrawLooper::LayerInfo info;
79
80 info.fFlagsMask = 0;
81 // TODO: add a color filter to better match what is seen in the wild
82 info.fPaintBits = /* SkLayerDrawLooper::kColorFilter_Bit |*/
83 SkLayerDrawLooper::kMaskFilter_Bit;
84 info.fColorMode = SkXfermode::kDst_Mode;
85 info.fOffset.set(xOff, 0);
86 info.fPostTranslate = false;
87
88 SkPaint* paint = looper->addLayer(info);
89
90 SkMaskFilter* mf = SkBlurMaskFilter::Create(SkIntToScalar(radius),
91 SkBlurMaskFilter::kNormal_Bl urStyle,
92 SkBlurMaskFilter::kHighQuali ty_BlurFlag);
93 paint->setMaskFilter(mf)->unref();
94
95 //-----------------------------------------------
96 info.fPaintBits = 0;
97 info.fOffset.set(0, 0);
98
99 paint = looper->addLayer(info);
100 return looper;
101 }
102
103 typedef SkBenchmark INHERITED;
104 };
105
106
107 DEF_BENCH( return SkNEW_ARGS(RectoriBench, (p)); )
OLDNEW
« no previous file with comments | « no previous file | gyp/bench.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698