ae4bb98f13
This is a reland of c1916c34fe
As it turns out, benches are not always given a canvas.
Original change's description:
> Remove use of legacy display globals.
>
> In the ongoing effort to remove the display globals from Skia, allow
> their use only if SK_LEGACY_SURFACE_PROPS is defined. Do not define this
> in a normal Skia build and remove all use from Skia code.
>
> Change-Id: I9ff550f5db246b9024aac687a1bc01321f1be4c8
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/319343
> Reviewed-by: Herb Derby <herb@google.com>
> Commit-Queue: Ben Wagner <bungeman@google.com>
Change-Id: I61a2ac058fafc99653e3304876cf4b97350dac8b
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/322490
Reviewed-by: Ben Wagner <bungeman@google.com>
Reviewed-by: Herb Derby <herb@google.com>
Commit-Queue: Ben Wagner <bungeman@google.com>
83 lines
2.8 KiB
C++
83 lines
2.8 KiB
C++
/*
|
|
* Copyright 2020 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/SkFont.h"
|
|
#include "include/core/SkTypeface.h"
|
|
#include "include/gpu/GrDirectContext.h"
|
|
#include "include/gpu/GrRecordingContext.h"
|
|
#include "src/core/SkUtils.h"
|
|
#include "src/gpu/GrRecordingContextPriv.h"
|
|
#include "src/gpu/GrRenderTargetContext.h"
|
|
#include "src/gpu/SkGr.h"
|
|
#include "src/gpu/text/GrTextBlob.h"
|
|
#include "src/utils/SkUTF.h"
|
|
|
|
|
|
// From Project Guttenberg. This is UTF-8 text.
|
|
static const char* gText =
|
|
"Call me Ishmael. Some years ago--never mind how long precisely";
|
|
|
|
class DirectMaskGlyphVertexFillBenchmark : public Benchmark {
|
|
bool isSuitableFor(Backend backend) override {
|
|
return backend == kGPU_Backend;
|
|
}
|
|
|
|
const char* onGetName() override {
|
|
return "DirectMaskGlyphVertexFillBenchmark";
|
|
}
|
|
|
|
void onPerCanvasPreDraw(SkCanvas* canvas) override {
|
|
auto typeface = SkTypeface::MakeFromName("monospace", SkFontStyle());
|
|
SkFont font(typeface);
|
|
|
|
SkMatrix view = SkMatrix::I();
|
|
size_t len = strlen(gText);
|
|
SkGlyphRunBuilder builder;
|
|
SkPaint paint;
|
|
builder.drawTextUTF8(paint, font, gText, len, {100, 100});
|
|
auto glyphRunList = builder.useGlyphRunList();
|
|
SkASSERT(!glyphRunList.empty());
|
|
fBlob = GrTextBlob::Make(glyphRunList, view);
|
|
SkSurfaceProps props;
|
|
if (canvas) { canvas->getProps(&props); }
|
|
auto colorSpace = SkColorSpace::MakeSRGB();
|
|
SkGlyphRunListPainter painter{props, kUnknown_SkColorType,
|
|
colorSpace.get(), SkStrikeCache::GlobalStrikeCache()};
|
|
|
|
GrSDFTOptions options{256, 256};
|
|
painter.processGlyphRunList(
|
|
glyphRunList, view, props, false, options, fBlob.get());
|
|
|
|
|
|
SkASSERT(fBlob->subRunList().head() != nullptr);
|
|
GrAtlasSubRun* subRun = static_cast<GrAtlasSubRun*>(fBlob->subRunList().head());
|
|
subRun->testingOnly_packedGlyphIDToGrGlyph(&fCache);
|
|
fVertices.reset(new char[subRun->vertexStride() * subRun->glyphCount() * 4]);
|
|
}
|
|
|
|
void onDraw(int loops, SkCanvas* canvas) override {
|
|
GrAtlasSubRun* subRun = static_cast<GrAtlasSubRun*>(fBlob->subRunList().head());
|
|
|
|
SkIRect clip = SkIRect::MakeEmpty();
|
|
SkPaint paint;
|
|
GrColor grColor = SkColorToPremulGrColor(paint.getColor());
|
|
|
|
for (int loop = 0; loop < loops; loop++) {
|
|
subRun->fillVertexData(fVertices.get(), 0, subRun->glyphCount(),
|
|
grColor, SkMatrix::I(), {100, 100}, clip);
|
|
}
|
|
}
|
|
|
|
private:
|
|
sk_sp<GrTextBlob> fBlob;
|
|
GrStrikeCache fCache;
|
|
std::unique_ptr<char[]> fVertices;
|
|
};
|
|
|
|
DEF_BENCH(return new DirectMaskGlyphVertexFillBenchmark{});
|