2016-06-01 19:40:15 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2016 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "bench/Benchmark.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
2022-03-31 19:07:44 +00:00
|
|
|
#include "include/core/SkColorSpace.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkImage.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkSurface.h"
|
2016-06-01 19:40:15 +00:00
|
|
|
|
|
|
|
class GrMipMapBench: public Benchmark {
|
|
|
|
sk_sp<SkSurface> fSurface;
|
|
|
|
SkString fName;
|
|
|
|
const int fW, fH;
|
|
|
|
|
|
|
|
public:
|
|
|
|
GrMipMapBench(int w, int h) : fW(w), fH(h) {
|
|
|
|
fName.printf("gr_mipmap_build_%dx%d", w, h);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
bool isSuitableFor(Backend backend) override {
|
|
|
|
return kGPU_Backend == backend;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* onGetName() override { return fName.c_str(); }
|
|
|
|
|
|
|
|
void onDraw(int loops, SkCanvas* canvas) override {
|
|
|
|
if (!fSurface) {
|
2020-07-07 14:20:27 +00:00
|
|
|
auto context = canvas->recordingContext();
|
|
|
|
if (!context) {
|
2016-06-01 19:40:15 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-02-07 18:56:11 +00:00
|
|
|
auto srgb = SkColorSpace::MakeSRGB();
|
2017-07-07 16:56:11 +00:00
|
|
|
SkImageInfo info =
|
|
|
|
SkImageInfo::Make(fW, fH, kRGBA_8888_SkColorType, kPremul_SkAlphaType, srgb);
|
2018-06-08 22:11:51 +00:00
|
|
|
// We're benching the regeneration of the mip levels not the need to allocate them every
|
|
|
|
// frame. Thus we create the surface with mips to begin with.
|
|
|
|
fSurface = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info, 0,
|
|
|
|
kBottomLeft_GrSurfaceOrigin, nullptr, true);
|
|
|
|
|
2016-06-01 19:40:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Clear surface once:
|
|
|
|
fSurface->getCanvas()->clear(SK_ColorBLACK);
|
|
|
|
|
2021-01-30 14:10:41 +00:00
|
|
|
SkSamplingOptions sampling(SkFilterMode::kLinear,
|
|
|
|
SkMipmapMode::kLinear);
|
2016-06-01 19:40:15 +00:00
|
|
|
SkPaint paint;
|
2017-02-22 18:21:42 +00:00
|
|
|
paint.setColor(SK_ColorWHITE);
|
2016-06-01 19:40:15 +00:00
|
|
|
for (int i = 0; i < loops; i++) {
|
|
|
|
// Touch surface so mips are dirtied
|
2017-02-22 18:21:42 +00:00
|
|
|
fSurface->getCanvas()->drawPoint(0, 0, paint);
|
2016-06-01 19:40:15 +00:00
|
|
|
|
|
|
|
// Draw reduced version of surface to original canvas, to trigger mip generation
|
|
|
|
canvas->save();
|
|
|
|
canvas->scale(0.1f, 0.1f);
|
2021-01-30 14:10:41 +00:00
|
|
|
canvas->drawImage(fSurface->makeImageSnapshot(), 0, 0, sampling, &paint);
|
2016-06-01 19:40:15 +00:00
|
|
|
canvas->restore();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-01 20:49:27 +00:00
|
|
|
void onPerCanvasPostDraw(SkCanvas*) override {
|
|
|
|
fSurface.reset(nullptr);
|
|
|
|
}
|
|
|
|
|
2016-06-01 19:40:15 +00:00
|
|
|
private:
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = Benchmark;
|
2016-06-01 19:40:15 +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-06-02 13:50:40 +00:00
|
|
|
DEF_BENCH( return new GrMipMapBench(511, 511); )
|
2016-06-01 19:40:15 +00:00
|
|
|
DEF_BENCH( return new GrMipMapBench(512, 511); )
|
|
|
|
DEF_BENCH( return new GrMipMapBench(511, 512); )
|
|
|
|
DEF_BENCH( return new GrMipMapBench(512, 512); )
|