2020-08-12 17:58:34 +00:00
|
|
|
/*
|
|
|
|
* 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"
|
2022-05-16 19:42:02 +00:00
|
|
|
#include "include/core/SkCanvas.h"
|
2022-04-05 16:56:01 +00:00
|
|
|
#include "include/core/SkColorSpace.h"
|
2020-08-12 17:58:34 +00:00
|
|
|
#include "include/core/SkFont.h"
|
|
|
|
#include "include/core/SkTypeface.h"
|
|
|
|
#include "include/gpu/GrDirectContext.h"
|
|
|
|
#include "include/gpu/GrRecordingContext.h"
|
2021-11-05 19:44:41 +00:00
|
|
|
#include "src/core/SkStrikeCache.h"
|
2020-08-12 17:58:34 +00:00
|
|
|
#include "src/core/SkUtils.h"
|
2022-04-07 15:20:24 +00:00
|
|
|
#include "src/gpu/ganesh/GrRecordingContextPriv.h"
|
|
|
|
#include "src/gpu/ganesh/SkGr.h"
|
2022-05-05 15:08:03 +00:00
|
|
|
#include "src/text/gpu/StrikeCache.h"
|
2022-05-23 15:34:17 +00:00
|
|
|
#include "src/text/gpu/TextBlob.h"
|
2022-05-16 19:42:02 +00:00
|
|
|
#include "src/utils/SkTestCanvas.h"
|
2020-08-12 17:58:34 +00:00
|
|
|
#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";
|
|
|
|
|
2022-05-16 19:42:02 +00:00
|
|
|
class FillBench {};
|
|
|
|
template <> class SkTestCanvas<FillBench> {
|
|
|
|
public:
|
|
|
|
static SkBaseDevice* GetDevice(SkCanvas* canvas) {
|
|
|
|
return canvas->topDevice();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-08-12 17:58:34 +00:00
|
|
|
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);
|
2022-06-14 18:59:21 +00:00
|
|
|
sktext::GlyphRunBuilder builder;
|
2020-08-12 17:58:34 +00:00
|
|
|
SkPaint paint;
|
2021-04-13 20:13:54 +00:00
|
|
|
auto glyphRunList = builder.textToGlyphRunList(font, paint, gText, len, {100, 100});
|
2020-08-12 17:58:34 +00:00
|
|
|
SkASSERT(!glyphRunList.empty());
|
2022-05-16 19:42:02 +00:00
|
|
|
auto device = SkTestCanvas<FillBench>::GetDevice(canvas);
|
2021-02-26 21:49:06 +00:00
|
|
|
SkMatrix drawMatrix = view;
|
2021-03-08 18:22:56 +00:00
|
|
|
const SkPoint drawOrigin = glyphRunList.origin();
|
2021-02-26 21:49:06 +00:00
|
|
|
drawMatrix.preTranslate(drawOrigin.x(), drawOrigin.y());
|
2022-05-23 15:34:17 +00:00
|
|
|
fBlob = sktext::gpu::TextBlob::Make(glyphRunList,
|
|
|
|
paint,
|
|
|
|
drawMatrix,
|
|
|
|
device->strikeDeviceInfo(),
|
|
|
|
SkStrikeCache::GlobalStrikeCache());
|
2020-08-12 17:58:34 +00:00
|
|
|
|
2022-05-23 15:34:17 +00:00
|
|
|
const sktext::gpu::AtlasSubRun* subRun = fBlob->testingOnlyFirstSubRun();
|
2020-11-20 15:21:32 +00:00
|
|
|
SkASSERT(subRun);
|
2022-05-02 15:29:43 +00:00
|
|
|
subRun->testingOnly_packedGlyphIDToGlyph(&fCache);
|
2021-02-26 21:49:06 +00:00
|
|
|
fVertices.reset(new char[subRun->vertexStride(drawMatrix) * subRun->glyphCount() * 4]);
|
2020-08-12 17:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void onDraw(int loops, SkCanvas* canvas) override {
|
2022-05-23 15:34:17 +00:00
|
|
|
const sktext::gpu::AtlasSubRun* subRun = fBlob->testingOnlyFirstSubRun();
|
2020-11-20 15:21:32 +00:00
|
|
|
SkASSERT(subRun);
|
2020-08-12 17:58:34 +00:00
|
|
|
|
|
|
|
SkIRect clip = SkIRect::MakeEmpty();
|
|
|
|
SkPaint paint;
|
|
|
|
GrColor grColor = SkColorToPremulGrColor(paint.getColor());
|
2020-12-02 16:39:48 +00:00
|
|
|
SkMatrix positionMatrix = SkMatrix::Translate(100, 100);
|
2020-08-12 17:58:34 +00:00
|
|
|
|
|
|
|
for (int loop = 0; loop < loops; loop++) {
|
|
|
|
subRun->fillVertexData(fVertices.get(), 0, subRun->glyphCount(),
|
2021-11-18 17:00:50 +00:00
|
|
|
grColor, positionMatrix, {0, 0}, clip);
|
2020-08-12 17:58:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2022-05-23 15:34:17 +00:00
|
|
|
sk_sp<sktext::gpu::TextBlob> fBlob;
|
2022-05-05 15:08:03 +00:00
|
|
|
sktext::gpu::StrikeCache fCache;
|
2020-08-12 17:58:34 +00:00
|
|
|
std::unique_ptr<char[]> fVertices;
|
|
|
|
};
|
|
|
|
|
|
|
|
DEF_BENCH(return new DirectMaskGlyphVertexFillBenchmark{});
|