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
This commit is contained in:
parent
20e3cd2c9f
commit
7b05659072
109
bench/BlurRoundRectBench.cpp
Normal file
109
bench/BlurRoundRectBench.cpp
Normal file
@ -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);)
|
211
gm/blurroundrect.cpp
Normal file
211
gm/blurroundrect.cpp
Normal file
@ -0,0 +1,211 @@
|
||||
/*
|
||||
* 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 "gm.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 BlurRoundRectGM : public skiagm::GM {
|
||||
public:
|
||||
BlurRoundRectGM(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,
|
||||
int scaleX, int scaleY)
|
||||
: fName("blurroundrect")
|
||||
, fWidth(width)
|
||||
, fHeight(height)
|
||||
, fScaleX(scaleX)
|
||||
, fScaleY(scaleY) {
|
||||
fName.appendf("-WH[%ix%i]-UL[%ix%i]-UR[%ix%i]-LR[%ix%i]-LL[%ix%i]-scale[%ix%i]",
|
||||
width, height,
|
||||
ulX, ulY,
|
||||
urX, urY,
|
||||
lrX, lrY,
|
||||
llX, llY,
|
||||
scaleX, scaleY);
|
||||
SkVector radii[4];
|
||||
radii[0].set(SkIntToScalar(ulX), SkIntToScalar(ulY));
|
||||
radii[1].set(SkIntToScalar(urX), SkIntToScalar(urY));
|
||||
radii[2].set(SkIntToScalar(lrX), SkIntToScalar(lrY));
|
||||
radii[3].set(SkIntToScalar(llX), SkIntToScalar(llY));
|
||||
SkRect r = SkRect::MakeWH(fWidth, fHeight);
|
||||
fRRect.setRectRadii(r, radii);
|
||||
}
|
||||
|
||||
virtual SkString onShortName() SK_OVERRIDE {
|
||||
return fName;
|
||||
}
|
||||
|
||||
virtual SkISize onISize() SK_OVERRIDE {
|
||||
SkISize size = this->getUnscaledSize();
|
||||
return SkISize::Make(SkScalarCeilToInt(SkScalarMul(size.fWidth, fScaleX)),
|
||||
SkScalarCeilToInt(SkScalarMul(size.fHeight, fScaleY)));
|
||||
}
|
||||
|
||||
virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
|
||||
canvas->scale(fScaleX, fScaleY);
|
||||
}
|
||||
|
||||
const SkRRect& getRRect() const {
|
||||
return fRRect;
|
||||
}
|
||||
|
||||
// The subclass will implement this to inform us how big they
|
||||
// draw before scaling.
|
||||
virtual SkISize getUnscaledSize() const = 0;
|
||||
|
||||
// So subclasses can modify the name.
|
||||
SkString* getName() {
|
||||
return &fName;
|
||||
}
|
||||
|
||||
private:
|
||||
SkString fName;
|
||||
const int fWidth;
|
||||
const int fHeight;
|
||||
const SkScalar fScaleX;
|
||||
const SkScalar fScaleY;
|
||||
SkRRect fRRect;
|
||||
typedef skiagm::GM INHERITED;
|
||||
};
|
||||
|
||||
class SKPBlurRoundRectGM : public BlurRoundRectGM {
|
||||
public:
|
||||
SKPBlurRoundRectGM(int width, int height,
|
||||
int ulX, int ulY,
|
||||
int urX, int urY,
|
||||
int lrX, int lrY,
|
||||
int llX, int llY,
|
||||
int scaleX, int scaleY)
|
||||
: INHERITED(width, height, ulX, ulY, urX, urY, lrX, lrY, llX, llY, scaleX, scaleY) {
|
||||
this->getName()->prepend("skp-");
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual SkISize getUnscaledSize() const SK_OVERRIDE {
|
||||
return SkISize::Make(this->getRRect().rect().width(),
|
||||
this->getRRect().rect().height());
|
||||
}
|
||||
|
||||
virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
|
||||
this->INHERITED::onDraw(canvas);
|
||||
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;
|
||||
canvas->drawRect(this->getRRect().rect(), paint);
|
||||
|
||||
paint.setLooper(looper)->unref();
|
||||
paint.setColor(4293848814);
|
||||
paint.setAntiAlias(true);
|
||||
|
||||
canvas->drawRRect(this->getRRect(), paint);
|
||||
}
|
||||
|
||||
private:
|
||||
typedef BlurRoundRectGM INHERITED;
|
||||
};
|
||||
|
||||
class SimpleBlurRoundRectGM : public BlurRoundRectGM {
|
||||
public:
|
||||
SimpleBlurRoundRectGM(int width, int height,
|
||||
int blurRadius, int cornerRadius,
|
||||
int scaleX = 1, int scaleY = 1)
|
||||
: INHERITED(width, height, cornerRadius, cornerRadius,
|
||||
cornerRadius, cornerRadius, cornerRadius,
|
||||
cornerRadius, cornerRadius, cornerRadius, scaleX, scaleY)
|
||||
, fBlurRadius(blurRadius) {
|
||||
// For now at least, change the name to reflect only the
|
||||
// variables that are changing.
|
||||
this->getName()->printf("blurround-blur[%i]-corner[%i]-scale[%ix%i]", fBlurRadius, cornerRadius, scaleX, scaleY);
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual SkISize getUnscaledSize() const SK_OVERRIDE {
|
||||
return SkISize::Make(this->getRRect().rect().width() + 20,
|
||||
this->getRRect().rect().height() + 20);
|
||||
}
|
||||
|
||||
virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
|
||||
// Handle the scaling.
|
||||
this->INHERITED::onDraw(canvas);
|
||||
canvas->translate(10, 10);
|
||||
SkMaskFilter* filter = SkBlurMaskFilter::Create(fBlurRadius,
|
||||
SkBlurMaskFilter::kNormal_BlurStyle);
|
||||
SkPaint paint;
|
||||
paint.setColor(SK_ColorBLUE);
|
||||
paint.setMaskFilter(filter)->unref();
|
||||
canvas->drawRRect(this->getRRect(), paint);
|
||||
}
|
||||
private:
|
||||
const int fBlurRadius;
|
||||
|
||||
typedef BlurRoundRectGM INHERITED;
|
||||
};
|
||||
|
||||
// Create one with dimensions/rounded corners based on the skp
|
||||
DEF_GM(return new SKPBlurRoundRectGM(600, 5514, 6, 6, 6, 6, 6, 6, 6, 6, 1, 1);)
|
||||
// Same radii, much smaller rectangle
|
||||
DEF_GM(return new SKPBlurRoundRectGM(100, 100, 6, 6, 6, 6, 6, 6, 6, 6, 2, 2);)
|
||||
// Rounded rect with two opposite corners with large radii, the other two
|
||||
// small.
|
||||
DEF_GM(return new SKPBlurRoundRectGM(100, 100, 30, 30, 10, 10, 30, 30, 10, 10, 3, 4);)
|
||||
DEF_GM(return new SKPBlurRoundRectGM(100, 100, 90, 90, 90, 90, 90, 90, 90, 90, 2, 3);)
|
||||
|
||||
// Try a few blur values with a small corner radius
|
||||
DEF_GM(return new SimpleBlurRoundRectGM(100, 100, 1, 1));
|
||||
DEF_GM(return new SimpleBlurRoundRectGM(100, 100, 3, 1, 2, 2));
|
||||
DEF_GM(return new SimpleBlurRoundRectGM(100, 100, 6, 1));
|
||||
DEF_GM(return new SimpleBlurRoundRectGM(100, 100, 10, 1, 3, 3));
|
||||
|
||||
// Now a few blur values with a larger corner radius
|
||||
DEF_GM(return new SimpleBlurRoundRectGM(100, 100, 1, 3, 2, 2));
|
||||
DEF_GM(return new SimpleBlurRoundRectGM(100, 100, 3, 3));
|
||||
DEF_GM(return new SimpleBlurRoundRectGM(100, 100, 6, 3, 3, 3));
|
||||
DEF_GM(return new SimpleBlurRoundRectGM(100, 100, 10, 3));
|
||||
|
||||
// Even larger corner radius
|
||||
DEF_GM(return new SimpleBlurRoundRectGM(100, 100, 1, 6, 2, 4));
|
||||
DEF_GM(return new SimpleBlurRoundRectGM(100, 100, 3, 6));
|
||||
DEF_GM(return new SimpleBlurRoundRectGM(100, 100, 6, 6));
|
||||
DEF_GM(return new SimpleBlurRoundRectGM(100, 100, 10, 6, 1, 3));
|
||||
|
@ -13,6 +13,7 @@
|
||||
'../bench/BlurBench.cpp',
|
||||
'../bench/BlurImageFilterBench.cpp',
|
||||
'../bench/BlurRectBench.cpp',
|
||||
'../bench/BlurRoundRectBench.cpp',
|
||||
'../bench/ChecksumBench.cpp',
|
||||
'../bench/ChartBench.cpp',
|
||||
'../bench/ChromeBench.cpp',
|
||||
|
@ -23,6 +23,7 @@
|
||||
'../gm/blurs.cpp',
|
||||
'../gm/blurquickreject.cpp',
|
||||
'../gm/blurrect.cpp',
|
||||
'../gm/blurroundrect.cpp',
|
||||
'../gm/canvasstate.cpp',
|
||||
'../gm/circles.cpp',
|
||||
'../gm/circularclips.cpp',
|
||||
|
Loading…
Reference in New Issue
Block a user