2015-01-26 20:28:54 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2015 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 "SkBitmap.h"
|
|
|
|
#include "SkMipMap.h"
|
|
|
|
|
|
|
|
class MipMapBench: public Benchmark {
|
|
|
|
SkBitmap fBitmap;
|
2016-01-15 15:41:07 +00:00
|
|
|
SkString fName;
|
2016-01-16 02:47:38 +00:00
|
|
|
const int fW, fH;
|
2016-11-08 22:08:54 +00:00
|
|
|
SkDestinationSurfaceColorMode fColorMode;
|
2017-03-06 21:16:15 +00:00
|
|
|
bool fHalfFoat;
|
2015-01-26 20:28:54 +00:00
|
|
|
|
|
|
|
public:
|
2017-03-06 21:16:15 +00:00
|
|
|
MipMapBench(int w, int h, SkDestinationSurfaceColorMode colorMode, bool halfFloat = false)
|
|
|
|
: fW(w), fH(h), fColorMode(colorMode), fHalfFoat(halfFloat)
|
2016-06-10 18:41:47 +00:00
|
|
|
{
|
2016-11-08 22:08:54 +00:00
|
|
|
fName.printf("mipmap_build_%dx%d_%d_gamma", w, h, static_cast<int>(colorMode));
|
2017-03-06 21:16:15 +00:00
|
|
|
if (halfFloat) {
|
|
|
|
fName.append("_f16");
|
|
|
|
}
|
2016-01-15 15:41:07 +00:00
|
|
|
}
|
2015-01-26 20:28:54 +00:00
|
|
|
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
bool isSuitableFor(Backend backend) override {
|
2015-01-26 20:28:54 +00:00
|
|
|
return kNonRendering_Backend == backend;
|
|
|
|
}
|
|
|
|
|
2016-01-15 15:41:07 +00:00
|
|
|
const char* onGetName() override { return fName.c_str(); }
|
2015-01-26 20:28:54 +00:00
|
|
|
|
2015-09-30 19:11:07 +00:00
|
|
|
void onDelayedSetup() override {
|
2017-03-06 21:16:15 +00:00
|
|
|
SkImageInfo info = fHalfFoat ? SkImageInfo::Make(fW, fH, kRGBA_F16_SkColorType,
|
|
|
|
kPremul_SkAlphaType,
|
|
|
|
SkColorSpace::MakeSRGBLinear())
|
|
|
|
: SkImageInfo::MakeS32(fW, fH, kPremul_SkAlphaType);
|
2016-06-10 18:41:47 +00:00
|
|
|
fBitmap.allocPixels(info);
|
2015-01-26 20:28:54 +00:00
|
|
|
fBitmap.eraseColor(SK_ColorWHITE); // so we don't read uninitialized memory
|
|
|
|
}
|
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas*) override {
|
2016-01-15 15:41:07 +00:00
|
|
|
for (int i = 0; i < loops * 4; i++) {
|
2016-11-08 22:08:54 +00:00
|
|
|
SkMipMap::Build(fBitmap, fColorMode, nullptr)->unref();
|
2015-01-26 20:28:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef Benchmark INHERITED;
|
|
|
|
};
|
|
|
|
|
2016-01-16 02:47:38 +00:00
|
|
|
// Build variants that exercise the width and heights being even or odd at each level, as the
|
|
|
|
// impl specializes on each of these.
|
|
|
|
//
|
2016-11-08 22:08:54 +00:00
|
|
|
DEF_BENCH( return new MipMapBench(511, 511, SkDestinationSurfaceColorMode::kLegacy); )
|
|
|
|
DEF_BENCH( return new MipMapBench(512, 511, SkDestinationSurfaceColorMode::kLegacy); )
|
|
|
|
DEF_BENCH( return new MipMapBench(511, 512, SkDestinationSurfaceColorMode::kLegacy); )
|
|
|
|
DEF_BENCH( return new MipMapBench(512, 512, SkDestinationSurfaceColorMode::kLegacy); )
|
|
|
|
DEF_BENCH( return new MipMapBench(512, 512,
|
|
|
|
SkDestinationSurfaceColorMode::kGammaAndColorSpaceAware); )
|
2017-03-06 18:58:54 +00:00
|
|
|
DEF_BENCH( return new MipMapBench(511, 511,
|
|
|
|
SkDestinationSurfaceColorMode::kGammaAndColorSpaceAware); )
|
2017-03-06 21:16:15 +00:00
|
|
|
DEF_BENCH( return new MipMapBench(512, 512, SkDestinationSurfaceColorMode::kLegacy, true); )
|
|
|
|
DEF_BENCH( return new MipMapBench(511, 511, SkDestinationSurfaceColorMode::kLegacy, true); )
|
2017-03-08 21:30:18 +00:00
|
|
|
DEF_BENCH( return new MipMapBench(2048, 2048, SkDestinationSurfaceColorMode::kLegacy); )
|
|
|
|
DEF_BENCH( return new MipMapBench(2048, 2048,
|
|
|
|
SkDestinationSurfaceColorMode::kGammaAndColorSpaceAware); )
|
2017-03-22 13:20:02 +00:00
|
|
|
DEF_BENCH( return new MipMapBench(2047, 2047, SkDestinationSurfaceColorMode::kLegacy); )
|
|
|
|
DEF_BENCH( return new MipMapBench(2047, 2047,
|
|
|
|
SkDestinationSurfaceColorMode::kGammaAndColorSpaceAware); )
|