From 7b0565907272bfe6682b09a36f7a8fef85e0f73d Mon Sep 17 00:00:00 2001 From: "scroggo@google.com" Date: Tue, 5 Nov 2013 15:57:21 +0000 Subject: Add gms and benchmarks for drawing blurry round rects. Further changes (https://codereview.chromium.org/48623006) will change the speed at which the bench draws and the drawing of the gm (the gm change is small). One of these round rects causes slow drawing in a webpage that we have observed. BUG=https://b.corp.google.com/issue?id=11174385 Review URL: https://codereview.chromium.org/52793005 git-svn-id: http://skia.googlecode.com/svn/trunk@12133 2bbb7eff-a529-9590-31e7-b0007b416f81 --- bench/BlurRoundRectBench.cpp | 109 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 bench/BlurRoundRectBench.cpp (limited to 'bench/BlurRoundRectBench.cpp') diff --git a/bench/BlurRoundRectBench.cpp b/bench/BlurRoundRectBench.cpp new file mode 100644 index 0000000000..486de3d4d0 --- /dev/null +++ b/bench/BlurRoundRectBench.cpp @@ -0,0 +1,109 @@ +/* +* Copyright 2013 Google Inc. +* +* Use of this source code is governed by a BSD-style license that can be +* found in the LICENSE file. +*/ + +#include "SkBenchmark.h" +#include "SkBlurMask.h" +#include "SkBlurMaskFilter.h" +#include "SkCanvas.h" +#include "SkColorFilter.h" +#include "SkLayerDrawLooper.h" +#include "SkPaint.h" +#include "SkPath.h" +#include "SkPoint.h" +#include "SkRect.h" +#include "SkRRect.h" +#include "SkString.h" +#include "SkXfermode.h" + +class BlurRoundRectBench : public SkBenchmark { +public: + BlurRoundRectBench(int width, int height, + // X and Y radii for the upper left corner + int ulX, int ulY, + // X and Y radii for the upper right corner + int urX, int urY, + // X and Y radii for the lower right corner + int lrX, int lrY, + // X and Y radii for the lower left corner + int llX, int llY) + : fName("blurroundrect") + , fWidth(width) + , fHeight(height) { + fName.appendf("_WH[%ix%i]_UL[%ix%i]_UR[%ix%i]_LR[%ix%i]_LL[%ix%i]", + width, height, + ulX, ulY, + urX, urY, + lrX, lrY, + llX, llY); + fRadii[0].set(SkIntToScalar(ulX), SkIntToScalar(ulY)); + fRadii[1].set(SkIntToScalar(urX), SkIntToScalar(urY)); + fRadii[2].set(SkIntToScalar(lrX), SkIntToScalar(lrY)); + fRadii[3].set(SkIntToScalar(llX), SkIntToScalar(llY)); + } + + virtual const char* onGetName() SK_OVERRIDE { + return fName.c_str(); + } + + virtual SkIPoint onGetSize() SK_OVERRIDE { + return SkIPoint::Make(fWidth, fHeight); + } + + virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { + for (int i = 0; i < this->getLoops(); i++) { + SkLayerDrawLooper* looper = new SkLayerDrawLooper; + { + SkLayerDrawLooper::LayerInfo info; + info.fFlagsMask = 0; + info.fPaintBits = 40; + info.fColorMode = SkXfermode::kSrc_Mode; + info.fOffset = SkPoint::Make(SkIntToScalar(-1), SkIntToScalar(0)); + info.fPostTranslate = false; + SkPaint* paint = looper->addLayerOnTop(info); + SkMaskFilter* maskFilter = SkBlurMaskFilter::Create(SK_ScalarHalf, + SkBlurMaskFilter::kNormal_BlurStyle, + SkBlurMaskFilter::kHighQuality_BlurFlag); + paint->setMaskFilter(maskFilter)->unref(); + SkColorFilter* colorFilter = SkColorFilter::CreateModeFilter(4279308561, + SkXfermode::kSrcIn_Mode); + paint->setColorFilter(colorFilter)->unref(); + paint->setColor(4278190080); + } + { + SkLayerDrawLooper::LayerInfo info; + looper->addLayerOnTop(info); + } + SkPaint paint; + SkRect rect = SkRect::MakeWH(fWidth, fHeight); + canvas->drawRect(rect, paint); + + paint.setLooper(looper)->unref(); + paint.setColor(4293848814); + paint.setAntiAlias(true); + + SkRRect rrect; + rrect.setRectRadii(rect, fRadii); + canvas->drawRRect(rrect, paint); + } + } + +private: + SkString fName; + const int fWidth; + const int fHeight; + SkVector fRadii[4]; + typedef SkBenchmark INHERITED; +}; + +// Create one with dimensions/rounded corners based on the skp +DEF_BENCH(return new BlurRoundRectBench(600, 5514, 6, 6, 6, 6, 6, 6, 6, 6);) +// Same radii, much smaller rectangle +DEF_BENCH(return new BlurRoundRectBench(100, 100, 6, 6, 6, 6, 6, 6, 6, 6);) +// Rounded rect with two opposite corners with large radii, the other two +// small. +DEF_BENCH(return new BlurRoundRectBench(100, 100, 30, 30, 10, 10, 30, 30, 10, 10);) +DEF_BENCH(return new BlurRoundRectBench(100, 100, 90, 90, 90, 90, 90, 90, 90, 90);) -- cgit v1.2.3