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"
|
|
|
|
#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/SkGr.h"
|
2021-04-16 13:07:24 +00:00
|
|
|
#include "src/gpu/text/GrStrikeCache.h"
|
2020-08-12 17:58:34 +00:00
|
|
|
#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;
|
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());
|
2020-09-24 18:49:00 +00:00
|
|
|
SkSurfaceProps props;
|
|
|
|
if (canvas) { canvas->getProps(&props); }
|
2021-03-08 18:22:56 +00:00
|
|
|
|
2020-08-12 17:58:34 +00:00
|
|
|
auto colorSpace = SkColorSpace::MakeSRGB();
|
|
|
|
SkGlyphRunListPainter painter{props, kUnknown_SkColorType,
|
|
|
|
colorSpace.get(), SkStrikeCache::GlobalStrikeCache()};
|
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());
|
2021-03-08 18:22:56 +00:00
|
|
|
GrSDFTControl control{false, props.isUseDeviceIndependentFonts(), 256, 256};
|
2021-03-22 19:28:23 +00:00
|
|
|
fBlob = GrTextBlob::Make(glyphRunList, paint, drawMatrix, control, &painter);
|
2020-08-12 17:58:34 +00:00
|
|
|
|
2021-02-05 18:45:05 +00:00
|
|
|
SkASSERT(!fBlob->subRunList().isEmpty());
|
|
|
|
GrAtlasSubRun* subRun = fBlob->subRunList().front().testingOnly_atlasSubRun();
|
2020-11-20 15:21:32 +00:00
|
|
|
SkASSERT(subRun);
|
2020-08-12 17:58:34 +00:00
|
|
|
subRun->testingOnly_packedGlyphIDToGrGlyph(&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 {
|
2021-02-05 18:45:05 +00:00
|
|
|
GrAtlasSubRun* subRun = fBlob->subRunList().front().testingOnly_atlasSubRun();
|
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(),
|
2020-12-02 16:39:48 +00:00
|
|
|
grColor, positionMatrix, clip);
|
2020-08-12 17:58:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
sk_sp<GrTextBlob> fBlob;
|
|
|
|
GrStrikeCache fCache;
|
|
|
|
std::unique_ptr<char[]> fVertices;
|
|
|
|
};
|
|
|
|
|
|
|
|
DEF_BENCH(return new DirectMaskGlyphVertexFillBenchmark{});
|