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

Unified Diff: bench/BlurImageFilterBench.cpp

Issue 1852743002: Update SkBlurImageFilter to sk_sp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Update to ToT & address code review comments Created 4 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | bench/ImageFilterDAGBench.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: bench/BlurImageFilterBench.cpp
diff --git a/bench/BlurImageFilterBench.cpp b/bench/BlurImageFilterBench.cpp
index cf93774178bd40b88edee8437869c1c17be7158a..9560263f1d24ffae7900770e6954382dd2b37362 100644
--- a/bench/BlurImageFilterBench.cpp
+++ b/bench/BlurImageFilterBench.cpp
@@ -34,6 +34,30 @@
// of the source (not inset). This is intended to exercise blurring a smaller source bitmap to a
// larger destination.
+static SkBitmap make_checkerboard(int width, int height) {
+ SkBitmap bm;
+ bm.allocN32Pixels(width, height);
+ SkCanvas canvas(bm);
+ canvas.clear(0x00000000);
+ SkPaint darkPaint;
+ darkPaint.setColor(0xFF804020);
+ SkPaint lightPaint;
+ lightPaint.setColor(0xFF244484);
+ for (int y = 0; y < height; y += 16) {
+ for (int x = 0; x < width; x += 16) {
+ canvas.save();
+ canvas.translate(SkIntToScalar(x), SkIntToScalar(y));
+ canvas.drawRect(SkRect::MakeXYWH(0, 0, 8, 8), darkPaint);
+ canvas.drawRect(SkRect::MakeXYWH(8, 0, 8, 8), lightPaint);
+ canvas.drawRect(SkRect::MakeXYWH(0, 8, 8, 8), lightPaint);
+ canvas.drawRect(SkRect::MakeXYWH(8, 8, 8, 8), darkPaint);
+ canvas.restore();
+ }
+ }
+
+ return bm;
+}
+
class BlurImageFilterBench : public Benchmark {
public:
BlurImageFilterBench(SkScalar sigmaX, SkScalar sigmaY, bool small, bool cropped,
@@ -59,13 +83,13 @@ protected:
void onDelayedSetup() override {
if (!fInitialized) {
- make_checkerboard();
+ fCheckerboard = make_checkerboard(fIsSmall ? FILTER_WIDTH_SMALL : FILTER_WIDTH_LARGE,
+ fIsSmall ? FILTER_HEIGHT_SMALL : FILTER_HEIGHT_LARGE);
fInitialized = true;
}
}
void onDraw(int loops, SkCanvas* canvas) override {
- SkPaint paint;
static const SkScalar kX = 0;
static const SkScalar kY = 0;
const SkRect bmpRect = SkRect::MakeXYWH(kX, kY,
@@ -73,14 +97,15 @@ protected:
SkIntToScalar(fCheckerboard.height()));
const SkImageFilter::CropRect cropRect(bmpRect.makeInset(10.f, 10.f));
const SkImageFilter::CropRect cropRectLarge(bmpRect);
- sk_sp<SkImageFilter> noOpCropped(SkOffsetImageFilter::Make(0, 0, nullptr, &cropRect));
- SkImageFilter* input = fIsExpanded ? noOpCropped.get() : nullptr;
+ sk_sp<SkImageFilter> input = fIsExpanded
+ ? SkOffsetImageFilter::Make(0, 0, nullptr, &cropRect)
+ : nullptr;
const SkImageFilter::CropRect* crop =
fIsExpanded ? &cropRectLarge : fIsCropped ? &cropRect : nullptr;
- SkAutoTUnref<SkImageFilter> blur(SkBlurImageFilter::Create(fSigmaX, fSigmaY, input, crop));
- paint.setImageFilter(blur);
+ SkPaint paint;
+ paint.setImageFilter(SkBlurImageFilter::Make(fSigmaX, fSigmaY, std::move(input), crop));
for (int i = 0; i < loops; i++) {
canvas->drawBitmap(fCheckerboard, kX, kY, &paint);
@@ -88,28 +113,6 @@ protected:
}
private:
- void make_checkerboard() {
- const int w = fIsSmall ? FILTER_WIDTH_SMALL : FILTER_WIDTH_LARGE;
- const int h = fIsSmall ? FILTER_HEIGHT_LARGE : FILTER_HEIGHT_LARGE;
- fCheckerboard.allocN32Pixels(w, h);
- SkCanvas canvas(fCheckerboard);
- canvas.clear(0x00000000);
- SkPaint darkPaint;
- darkPaint.setColor(0xFF804020);
- SkPaint lightPaint;
- lightPaint.setColor(0xFF244484);
- for (int y = 0; y < h; y += 16) {
- for (int x = 0; x < w; x += 16) {
- canvas.save();
- canvas.translate(SkIntToScalar(x), SkIntToScalar(y));
- canvas.drawRect(SkRect::MakeXYWH(0, 0, 8, 8), darkPaint);
- canvas.drawRect(SkRect::MakeXYWH(8, 0, 8, 8), lightPaint);
- canvas.drawRect(SkRect::MakeXYWH(0, 8, 8, 8), lightPaint);
- canvas.drawRect(SkRect::MakeXYWH(8, 8, 8, 8), darkPaint);
- canvas.restore();
- }
- }
- }
SkString fName;
bool fIsSmall;
« no previous file with comments | « no previous file | bench/ImageFilterDAGBench.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698