skia2/bench/GrMipmapBench.cpp
Kevin Lubick 5e8f45faf1 [includes] Prepare for moving SkColorSpace to forward declare
This updates all our callsites in preparation for removing
the #include "include/core/SkColorSpace.h" from SkImageInfo.h

According to go/chrome-includes [1], this will save ~150MB
(0.07%) from the compilation size. I think SkColorSpace is
a big include because it loads the skcms header, which is
big.

The follow-on CL will remove that link, once clients have
been updated as well.

[1] https://commondatastorage.googleapis.com/chromium-browser-clang/chrome_includes_2022-03-31_124042.html#view=edges&filter=%5Ethird_party%2Fskia%2Finclude%2Fcore%2FSkImageInfo%5C.h%24&sort=asize&reverse=&includer=%5Ethird_party%2Fskia%2Finclude%2Fcore%2FSkImageInfo%5C.h%24&included=&limit=1000

Change-Id: I1b5ff491ac495317b0e5af3a2082b080d43697ae
Bug: skia:13052
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/525639
Reviewed-by: Robert Phillips <robertphillips@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Reviewed-by: Florin Malita <fmalita@google.com>
Commit-Queue: Kevin Lubick <kjlubick@google.com>
2022-03-31 19:50:10 +00:00

82 lines
2.6 KiB
C++

/*
* Copyright 2016 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "bench/Benchmark.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColorSpace.h"
#include "include/core/SkImage.h"
#include "include/core/SkPaint.h"
#include "include/core/SkSurface.h"
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) {
auto context = canvas->recordingContext();
if (!context) {
return;
}
auto srgb = SkColorSpace::MakeSRGB();
SkImageInfo info =
SkImageInfo::Make(fW, fH, kRGBA_8888_SkColorType, kPremul_SkAlphaType, srgb);
// 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);
}
// Clear surface once:
fSurface->getCanvas()->clear(SK_ColorBLACK);
SkSamplingOptions sampling(SkFilterMode::kLinear,
SkMipmapMode::kLinear);
SkPaint paint;
paint.setColor(SK_ColorWHITE);
for (int i = 0; i < loops; i++) {
// Touch surface so mips are dirtied
fSurface->getCanvas()->drawPoint(0, 0, paint);
// Draw reduced version of surface to original canvas, to trigger mip generation
canvas->save();
canvas->scale(0.1f, 0.1f);
canvas->drawImage(fSurface->makeImageSnapshot(), 0, 0, sampling, &paint);
canvas->restore();
}
}
void onPerCanvasPostDraw(SkCanvas*) override {
fSurface.reset(nullptr);
}
private:
using INHERITED = Benchmark;
};
// Build variants that exercise the width and heights being even or odd at each level, as the
// impl specializes on each of these.
//
DEF_BENCH( return new GrMipMapBench(511, 511); )
DEF_BENCH( return new GrMipMapBench(512, 511); )
DEF_BENCH( return new GrMipMapBench(511, 512); )
DEF_BENCH( return new GrMipMapBench(512, 512); )