skia2/bench/GlyphQuadFillBench.cpp
John Stiles 008d60e58c Revert "Move SkSubRun to src/text"
This reverts commit 4a375fe213.

Reason for revert: breaks google3, probably needs public.bzl fix

Original change's description:
> Move SkSubRun to src/text
>
> Change-Id: I5c1040b8236dc792de20495a3fea3c0be6e31c20
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/549847
> Reviewed-by: Brian Osman <brianosman@google.com>
> Commit-Queue: Herb Derby <herb@google.com>

Change-Id: Ic6f3ecd81e2bfd03320f820bb5301b0d1c5d6c9a
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/550181
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
2022-06-15 22:33:12 +00:00

93 lines
3.2 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/SkCanvas.h"
#include "include/core/SkColorSpace.h"
#include "include/core/SkFont.h"
#include "include/core/SkTypeface.h"
#include "include/gpu/GrDirectContext.h"
#include "include/gpu/GrRecordingContext.h"
#include "src/core/SkStrikeCache.h"
#include "src/core/SkUtils.h"
#include "src/gpu/ganesh/GrRecordingContextPriv.h"
#include "src/gpu/ganesh/SkGr.h"
#include "src/text/gpu/StrikeCache.h"
#include "src/text/gpu/TextBlob.h"
#include "src/utils/SkTestCanvas.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 FillBench {};
template <> class SkTestCanvas<FillBench> {
public:
static SkBaseDevice* GetDevice(SkCanvas* canvas) {
return canvas->topDevice();
}
};
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;
auto glyphRunList = builder.textToGlyphRunList(font, paint, gText, len, {100, 100});
SkASSERT(!glyphRunList.empty());
auto device = SkTestCanvas<FillBench>::GetDevice(canvas);
SkMatrix drawMatrix = view;
const SkPoint drawOrigin = glyphRunList.origin();
drawMatrix.preTranslate(drawOrigin.x(), drawOrigin.y());
fBlob = sktext::gpu::TextBlob::Make(glyphRunList,
paint,
drawMatrix,
device->strikeDeviceInfo(),
SkStrikeCache::GlobalStrikeCache());
const sktext::gpu::AtlasSubRun* subRun = fBlob->testingOnlyFirstSubRun();
SkASSERT(subRun);
subRun->testingOnly_packedGlyphIDToGlyph(&fCache);
fVertices.reset(new char[subRun->vertexStride(drawMatrix) * subRun->glyphCount() * 4]);
}
void onDraw(int loops, SkCanvas* canvas) override {
const sktext::gpu::AtlasSubRun* subRun = fBlob->testingOnlyFirstSubRun();
SkASSERT(subRun);
SkIRect clip = SkIRect::MakeEmpty();
SkPaint paint;
GrColor grColor = SkColorToPremulGrColor(paint.getColor());
SkMatrix positionMatrix = SkMatrix::Translate(100, 100);
for (int loop = 0; loop < loops; loop++) {
subRun->fillVertexData(fVertices.get(), 0, subRun->glyphCount(),
grColor, positionMatrix, {0, 0}, clip);
}
}
private:
sk_sp<sktext::gpu::TextBlob> fBlob;
sktext::gpu::StrikeCache fCache;
std::unique_ptr<char[]> fVertices;
};
DEF_BENCH(return new DirectMaskGlyphVertexFillBenchmark{});