skia2/bench/ShadowBench.cpp
Kevin Lubick 2d86f6f5db Reland "[includes] Remove include link between SkPathRef.h and SkRRect.h"
This is a reland of 37b8239bec

Upstack changes:
 - http://ag/17004908
 - https://github.com/flutter/engine/pull/31654

Original change's description:
> [includes] Remove include link between SkPathRef.h and SkRRect.h
>
> According to go/chrome-includes [1], this will save about
> 40MB (0.02%) off the Chrome build. http://screen/4GnPjFaYpwCVHVL
>
> I'm not quite sure why the link is so expensive, but we can
> forward declare it and move the implementation from the .h
> to the .cpp file easily enough.
>
> [1] https://commondatastorage.googleapis.com/chromium-browser-clang/include-analysis.html#view=edges&filter=%5Ethird_party%2Fskia%2Finclude%2Fprivate%2FSkPathRef%5C.h%24&sort=includes&reverse=&includer=%5Ethird_party%2Fskia%2Finclude%2Fprivate%2FSkPathRef%5C.h%24&included=&limit=1000
>
> Canary-Chromium-CL: 3485346
> Change-Id: Ie3a5e7a735426f883a6c06ddbd3b8bf148bf1709
> Bug: 242216
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/512158
> Reviewed-by: Robert Phillips <robertphillips@google.com>

Bug: 242216
Change-Id: I31288895528251fd59913427b95b9f88a871d14b
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/512776
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Kevin Lubick <kjlubick@google.com>
2022-03-07 15:15:05 +00:00

107 lines
3.1 KiB
C++

/*
* Copyright 2017 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/SkPaint.h"
#include "include/core/SkPath.h"
#include "include/core/SkRRect.h"
#include "include/utils/SkShadowUtils.h"
#include "src/core/SkDrawShadowInfo.h"
class ShadowBench : public Benchmark {
// Draws a set of shadowed rrects filling the canvas, in various modes:
// * opaque or transparent
// * use analytic fast path or geometric tessellation
public:
ShadowBench(bool transparent, bool forceGeometric)
: fTransparent(transparent)
, fForceGeometric(forceGeometric) {
computeName("shadows");
}
protected:
enum {
kWidth = 640,
kHeight = 480,
kRRSize = 50,
kRRRadius = 6,
kRRSpace = 8,
kRRStep = kRRSize + kRRSpace,
kElevation = 16,
kNumRRects = ((kWidth - kRRSpace) / kRRStep)*((kHeight - kRRSpace) / kRRStep)
};
void computeName(const char root[]) {
static const char kTransChars[2] = {
'o', 't'
};
static const char kGeomChars[2] = {
'a', 'g'
};
fBaseName.printf("%s_%c_%c", root, kTransChars[fTransparent], kGeomChars[fForceGeometric]);
}
void genRRects() {
int i = 0;
for (int x = kRRSpace; x < kWidth - kRRStep; x += kRRStep) {
for (int y = kRRSpace; y < kHeight - kRRStep; y += kRRStep) {
SkRect rect = SkRect::MakeXYWH(x, y, kRRSize, kRRSize);
fRRects[i].addRRect(SkRRect::MakeRectXY(rect, kRRRadius, kRRRadius));
++i;
}
}
SkASSERT(i == kNumRRects);
}
const char* onGetName() override { return fBaseName.c_str(); }
void onDelayedSetup() override {
fRec.fZPlaneParams = SkPoint3::Make(0, 0, kElevation);
fRec.fLightPos = SkPoint3::Make(270, 0, 600);
fRec.fLightRadius = 800;
fRec.fAmbientColor = 0x19000000;
fRec.fSpotColor = 0x40000000;
fRec.fFlags = 0;
if (fTransparent) {
fRec.fFlags |= SkShadowFlags::kTransparentOccluder_ShadowFlag;
}
if (fForceGeometric) {
fRec.fFlags |= SkShadowFlags::kGeometricOnly_ShadowFlag;
}
this->genRRects();
}
void onDraw(int loops, SkCanvas* canvas) override {
SkPaint paint;
paint.setColor(SK_ColorWHITE);
this->setupPaint(&paint);
for (int i = 0; i < loops; ++i) {
// use the private canvas call so we don't include the time to stuff data in the Rec
canvas->private_draw_shadow_rec(fRRects[i % kNumRRects], fRec);
}
}
private:
SkString fBaseName;
SkPath fRRects[kNumRRects];
SkDrawShadowRec fRec;
int fTransparent;
int fForceGeometric;
using INHERITED = Benchmark;
};
DEF_BENCH(return new ShadowBench(false, false);)
DEF_BENCH(return new ShadowBench(false, true);)
DEF_BENCH(return new ShadowBench(true, false);)
DEF_BENCH(return new ShadowBench(true, true);)