Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
/*
* 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 "SkCanvas.h"
#include "SkPaint.h"
#include "SkRandom.h"
#include "SkShader.h"
#include "SkString.h"
#include "SkBitmapScaler.h"
class PixmapScalerBench: public Benchmark {
SkBitmapScaler::ResizeMethod fMethod;
SkString fName;
SkBitmap fSrc;
int fWidth;
int fHeight;
public:
PixmapScalerBench(SkBitmapScaler::ResizeMethod method, int width, int height, const char suffix[]) :
fMethod(method)
{
fName.printf("pixmapscaler %dx%d %s", width, height, suffix);
fWidth = width;
fHeight = height;
}
protected:
const char* onGetName() override {
return fName.c_str();
}
SkIPoint onGetSize() override { return{ 100, 100 }; }
bool isSuitableFor(Backend backend) override {
return backend == kNonRendering_Backend;
}
void onDelayedSetup() override {
fSrc.allocN32Pixels(2560, 1600);
fSrc.eraseColor(SK_ColorWHITE);
}
void onDraw(int loops, SkCanvas*) override {
SkPixmap src, dst;
SkBitmap fDst;
fSrc.peekPixels(&src);
fDst.allocN32Pixels(fWidth, fHeight);
fDst.peekPixels(&dst);
for (int i = 0; i < loops; i++) {
SkBitmapScaler::Resize(dst, src, fMethod);
}
}
private:
typedef Benchmark INHERITED;
};
DEF_BENCH( return new PixmapScalerBench(SkBitmapScaler::RESIZE_LANCZOS3, 5478, 3424, "6lzs"); )
DEF_BENCH( return new PixmapScalerBench(SkBitmapScaler::RESIZE_MITCHELL, 5478, 3424, "4bic"); )
DEF_BENCH( return new PixmapScalerBench(SkBitmapScaler::RESIZE_TRIANGLE, 5478, 3424, "2bil"); )
DEF_BENCH( return new PixmapScalerBench(SkBitmapScaler::RESIZE_LANCZOS3, 2048, 1280, "6lzs"); )
DEF_BENCH( return new PixmapScalerBench(SkBitmapScaler::RESIZE_MITCHELL, 2048, 1280, "4bic"); )
DEF_BENCH( return new PixmapScalerBench(SkBitmapScaler::RESIZE_TRIANGLE, 2048, 1280, "2bil"); )
DEF_BENCH( return new PixmapScalerBench(SkBitmapScaler::RESIZE_LANCZOS3, 320, 200, "6lzs"); )
DEF_BENCH( return new PixmapScalerBench(SkBitmapScaler::RESIZE_MITCHELL, 320, 200, "4bic"); )
DEF_BENCH( return new PixmapScalerBench(SkBitmapScaler::RESIZE_TRIANGLE, 320, 200, "2bil"); )
DEF_BENCH( return new PixmapScalerBench(SkBitmapScaler::RESIZE_LANCZOS3, 26, 16, "6lzs"); )
DEF_BENCH( return new PixmapScalerBench(SkBitmapScaler::RESIZE_MITCHELL, 26, 16, "4bic"); )
DEF_BENCH( return new PixmapScalerBench(SkBitmapScaler::RESIZE_TRIANGLE, 26, 16, "2bil"); )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment