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

Side by Side Diff: bench/BlurRoundRectBench.cpp

Issue 59983004: Fixes for blurroundrect gm/bench. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Add scale Created 7 years, 1 month 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 | gm/blurroundrect.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 "SkBlurMask.h" 9 #include "SkBlurMask.h"
10 #include "SkBlurMaskFilter.h" 10 #include "SkBlurMaskFilter.h"
11 #include "SkCanvas.h" 11 #include "SkCanvas.h"
12 #include "SkColorFilter.h" 12 #include "SkColorFilter.h"
13 #include "SkLayerDrawLooper.h" 13 #include "SkLayerDrawLooper.h"
14 #include "SkPaint.h" 14 #include "SkPaint.h"
15 #include "SkPath.h" 15 #include "SkPath.h"
16 #include "SkPoint.h" 16 #include "SkPoint.h"
17 #include "SkRect.h" 17 #include "SkRect.h"
18 #include "SkRRect.h" 18 #include "SkRRect.h"
19 #include "SkString.h" 19 #include "SkString.h"
20 #include "SkXfermode.h" 20 #include "SkXfermode.h"
21 21
22 // Large blurred RR appear frequently on web pages. This benchmark measures our
23 // performance in this case.
22 class BlurRoundRectBench : public SkBenchmark { 24 class BlurRoundRectBench : public SkBenchmark {
23 public: 25 public:
24 BlurRoundRectBench(int width, int height, 26 BlurRoundRectBench(int width, int height, int cornerRadius)
25 // X and Y radii for the upper left corner 27 : fName("blurroundrect") {
26 int ulX, int ulY, 28 fName.appendf("_WH[%ix%i]_cr[%i]", width, height, cornerRadius);
27 // X and Y radii for the upper right corner 29 SkRect r = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(height));
28 int urX, int urY, 30 fRRect.setRectXY(r, SkIntToScalar(cornerRadius), SkIntToScalar(cornerRad ius));
29 // X and Y radii for the lower right corner
30 int lrX, int lrY,
31 // X and Y radii for the lower left corner
32 int llX, int llY)
33 : fName("blurroundrect")
34 , fWidth(width)
35 , fHeight(height) {
36 fName.appendf("_WH[%ix%i]_UL[%ix%i]_UR[%ix%i]_LR[%ix%i]_LL[%ix%i]",
37 width, height,
38 ulX, ulY,
39 urX, urY,
40 lrX, lrY,
41 llX, llY);
42 fRadii[0].set(SkIntToScalar(ulX), SkIntToScalar(ulY));
43 fRadii[1].set(SkIntToScalar(urX), SkIntToScalar(urY));
44 fRadii[2].set(SkIntToScalar(lrX), SkIntToScalar(lrY));
45 fRadii[3].set(SkIntToScalar(llX), SkIntToScalar(llY));
46 } 31 }
47 32
48 virtual const char* onGetName() SK_OVERRIDE { 33 virtual const char* onGetName() SK_OVERRIDE {
49 return fName.c_str(); 34 return fName.c_str();
50 } 35 }
51 36
52 virtual SkIPoint onGetSize() SK_OVERRIDE { 37 virtual SkIPoint onGetSize() SK_OVERRIDE {
53 return SkIPoint::Make(fWidth, fHeight); 38 return SkIPoint::Make(SkScalarCeilToInt(fRRect.rect().width()),
39 SkScalarCeilToInt(fRRect.rect().height()));
54 } 40 }
55 41
56 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { 42 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
43 SkLayerDrawLooper* looper = new SkLayerDrawLooper;
44 {
45 SkLayerDrawLooper::LayerInfo info;
46 info.fFlagsMask = 0;
47 info.fPaintBits = SkLayerDrawLooper::kMaskFilter_Bit
48 | SkLayerDrawLooper::kColorFilter_Bit;
49 info.fColorMode = SkXfermode::kSrc_Mode;
50 info.fOffset = SkPoint::Make(SkIntToScalar(-1), SkIntToScalar(0));
51 info.fPostTranslate = false;
52 SkPaint* paint = looper->addLayerOnTop(info);
53 SkMaskFilter* maskFilter = SkBlurMaskFilter::Create(SK_ScalarHalf,
54 SkBlurMaskFilter::kNormal_BlurStyle,
55 SkBlurMaskFilter::kHighQuality_BlurFlag);
56 paint->setMaskFilter(maskFilter)->unref();
57 SkColorFilter* colorFilter = SkColorFilter::CreateModeFilter(SK_Colo rLTGRAY,
58 SkXfermode::kSrcIn_Mode);
59 paint->setColorFilter(colorFilter)->unref();
60 paint->setColor(SK_ColorGRAY);
61 }
62 {
63 SkLayerDrawLooper::LayerInfo info;
64 looper->addLayerOnTop(info);
65 }
66 SkPaint dullPaint;
67 dullPaint.setAntiAlias(true);
68
69 SkPaint loopedPaint;
70 loopedPaint.setLooper(looper)->unref();
71 loopedPaint.setAntiAlias(true);
72 loopedPaint.setColor(SK_ColorCYAN);
73
57 for (int i = 0; i < this->getLoops(); i++) { 74 for (int i = 0; i < this->getLoops(); i++) {
58 SkLayerDrawLooper* looper = new SkLayerDrawLooper; 75 canvas->drawRect(fRRect.rect(), dullPaint);
59 { 76 canvas->drawRRect(fRRect, loopedPaint);
60 SkLayerDrawLooper::LayerInfo info;
61 info.fFlagsMask = 0;
62 info.fPaintBits = 40;
63 info.fColorMode = SkXfermode::kSrc_Mode;
64 info.fOffset = SkPoint::Make(SkIntToScalar(-1), SkIntToScalar(0) );
65 info.fPostTranslate = false;
66 SkPaint* paint = looper->addLayerOnTop(info);
67 SkMaskFilter* maskFilter = SkBlurMaskFilter::Create(SK_ScalarHal f,
68 SkBlurMaskFilter::kNormal_BlurStyle,
69 SkBlurMaskFilter::kHighQuality_BlurFlag);
70 paint->setMaskFilter(maskFilter)->unref();
71 SkColorFilter* colorFilter = SkColorFilter::CreateModeFilter(SK_ ColorLTGRAY,
72 SkXfermode::kSrcIn_Mode);
73 paint->setColorFilter(colorFilter)->unref();
74 paint->setColor(SK_ColorGRAY);
75 }
76 {
77 SkLayerDrawLooper::LayerInfo info;
78 looper->addLayerOnTop(info);
79 }
80 SkPaint paint;
81 SkRect rect = SkRect::MakeWH(SkIntToScalar(fWidth), SkIntToScalar(fH eight));
82 canvas->drawRect(rect, paint);
83
84 paint.setLooper(looper)->unref();
85 paint.setAntiAlias(true);
86 paint.setColor(SK_ColorCYAN);
87
88 SkRRect rrect;
89 rrect.setRectRadii(rect, fRadii);
90 canvas->drawRRect(rrect, paint);
91 } 77 }
92 } 78 }
93 79
94 private: 80 private:
95 SkString fName; 81 SkString fName;
96 const int fWidth; 82 SkRRect fRRect;
97 const int fHeight; 83
98 SkVector fRadii[4]; 84 typedef SkBenchmark INHERITED;
99 typedef SkBenchmark INHERITED;
100 }; 85 };
101 86
102 // Create one with dimensions/rounded corners based on the skp 87 // Create one with dimensions/rounded corners based on the skp
103 DEF_BENCH(return new BlurRoundRectBench(600, 5514, 6, 6, 6, 6, 6, 6, 6, 6);) 88 DEF_BENCH(return new BlurRoundRectBench(600, 5514, 6);)
104 // Same radii, much smaller rectangle 89 // Same radii, much smaller rectangle
105 DEF_BENCH(return new BlurRoundRectBench(100, 100, 6, 6, 6, 6, 6, 6, 6, 6);) 90 DEF_BENCH(return new BlurRoundRectBench(100, 100, 6);)
robertphillips 2013/11/05 21:07:04 Fix comment
106 // Rounded rect with two opposite corners with large radii, the other two 91 // Rounded rect with two opposite corners with large radii, the other two
107 // small. 92 // small.
108 DEF_BENCH(return new BlurRoundRectBench(100, 100, 30, 30, 10, 10, 30, 30, 10, 10 );) 93 DEF_BENCH(return new BlurRoundRectBench(100, 100, 30);)
109 DEF_BENCH(return new BlurRoundRectBench(100, 100, 90, 90, 90, 90, 90, 90, 90, 90 );) 94 DEF_BENCH(return new BlurRoundRectBench(100, 100, 90);)
OLDNEW
« no previous file with comments | « no previous file | gm/blurroundrect.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698