skia2/bench/BlurRoundRectBench.cpp
Mike Reed 0e39f97cd7 Revert "Revert "make it illegal to include SkXfermode.h""
This reverts commit e9d1b299cc.

Reason for revert: <INSERT REASONING HERE>

Original change's description:
> Revert "make it illegal to include SkXfermode.h"
> 
> This reverts commit 07764cefbb.
> 
> Reason for revert: breaking google3
> 
> Original change's description:
> > make it illegal to include SkXfermode.h
> > 
> > BUG=skia:
> > 
> > GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=5133
> > 
> > Change-Id: I6e8596dcb17cd7e8efa67859bb682bf9bfcac4db
> > Reviewed-on: https://skia-review.googlesource.com/5133
> > Reviewed-by: Mike Reed <reed@google.com>
> > Commit-Queue: Mike Reed <reed@google.com>
> > 
> 
> TBR=reed@google.com,reviews@skia.org
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> 
> Change-Id: I136f9e533eb60633c49dffa19b5747d50b6d98a8
> Reviewed-on: https://skia-review.googlesource.com/5196
> Commit-Queue: Greg Daniel <egdaniel@google.com>
> Reviewed-by: Greg Daniel <egdaniel@google.com>
> 

TBR=egdaniel@google.com,reviews@skia.org,reed@google.com
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true

Change-Id: I0b767ce778a4ade83c2f07d5ece486bb46d7712c
Reviewed-on: https://skia-review.googlesource.com/5223
Commit-Queue: Mike Reed <reed@google.com>
Reviewed-by: Mike Reed <reed@google.com>
2016-11-23 22:17:17 +00:00

90 lines
3.1 KiB
C++

/*
* 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 "Benchmark.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 "SkRRect.h"
#include "SkRect.h"
#include "SkString.h"
// Large blurred RR appear frequently on web pages. This benchmark measures our
// performance in this case.
class BlurRoundRectBench : public Benchmark {
public:
BlurRoundRectBench(int width, int height, int cornerRadius)
: fName("blurroundrect") {
fName.appendf("_WH_%ix%i_cr_%i", width, height, cornerRadius);
SkRect r = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(height));
fRRect.setRectXY(r, SkIntToScalar(cornerRadius), SkIntToScalar(cornerRadius));
}
const char* onGetName() override {
return fName.c_str();
}
SkIPoint onGetSize() override {
return SkIPoint::Make(SkScalarCeilToInt(fRRect.rect().width()),
SkScalarCeilToInt(fRRect.rect().height()));
}
void onDraw(int loops, SkCanvas* canvas) override {
SkLayerDrawLooper::Builder looperBuilder;
{
SkLayerDrawLooper::LayerInfo info;
info.fPaintBits = SkLayerDrawLooper::kMaskFilter_Bit
| SkLayerDrawLooper::kColorFilter_Bit;
info.fColorMode = SkBlendMode::kSrc;
info.fOffset = SkPoint::Make(SkIntToScalar(-1), SkIntToScalar(0));
info.fPostTranslate = false;
SkPaint* paint = looperBuilder.addLayerOnTop(info);
paint->setMaskFilter(SkBlurMaskFilter::Make(kNormal_SkBlurStyle,
SkBlurMask::ConvertRadiusToSigma(0.5),
SkBlurMaskFilter::kHighQuality_BlurFlag));
paint->setColorFilter(SkColorFilter::MakeModeFilter(SK_ColorLTGRAY,
SkBlendMode::kSrcIn));
paint->setColor(SK_ColorGRAY);
}
{
SkLayerDrawLooper::LayerInfo info;
looperBuilder.addLayerOnTop(info);
}
SkPaint dullPaint;
dullPaint.setAntiAlias(true);
SkPaint loopedPaint;
loopedPaint.setLooper(looperBuilder.detach());
loopedPaint.setAntiAlias(true);
loopedPaint.setColor(SK_ColorCYAN);
for (int i = 0; i < loops; i++) {
canvas->drawRect(fRRect.rect(), dullPaint);
canvas->drawRRect(fRRect, loopedPaint);
}
}
private:
SkString fName;
SkRRect fRRect;
typedef Benchmark INHERITED;
};
// Create one with dimensions/rounded corners based on the skp
DEF_BENCH(return new BlurRoundRectBench(600, 5514, 6);)
// Same radii, much smaller rectangle
DEF_BENCH(return new BlurRoundRectBench(100, 100, 6);)
// Other radii options
DEF_BENCH(return new BlurRoundRectBench(100, 100, 30);)
DEF_BENCH(return new BlurRoundRectBench(100, 100, 90);)