Flutter Engine
The Flutter Engine
GlyphQuadFillBench.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2020 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "bench/Benchmark.h"
11#include "include/core/SkFont.h"
15#include "src/base/SkUTF.h"
16#include "src/base/SkUtils.h"
19#include "src/gpu/ganesh/SkGr.h"
20#include "src/text/GlyphRun.h"
26
27// From Project Guttenberg. This is UTF-8 text.
28static const char* gText =
29 "Call me Ishmael. Some years ago--never mind how long precisely";
30
31class FillBench {};
32template <> class SkTestCanvas<FillBench> {
33public:
34 static SkDevice* GetDevice(SkCanvas* canvas) {
35 return canvas->topDevice();
36 }
37};
38
40 bool isSuitableFor(Backend backend) override {
41 return backend == Backend::kGanesh;
42 }
43
44 const char* onGetName() override {
45 return "DirectMaskGlyphVertexFillBenchmark";
46 }
47
48 void onPerCanvasPreDraw(SkCanvas* canvas) override {
49 auto typeface = ToolUtils::CreateTestTypeface("monospace", SkFontStyle());
50 SkFont font(typeface);
51
52 SkMatrix view = SkMatrix::I();
53 size_t len = strlen(gText);
56 auto glyphRunList = builder.textToGlyphRunList(font, paint, gText, len, {100, 100});
57 SkASSERT_RELEASE(!glyphRunList.empty());
59 SkMatrix drawMatrix = view;
60 const SkPoint drawOrigin = glyphRunList.origin();
61 drawMatrix.preTranslate(drawOrigin.x(), drawOrigin.y());
62 fBlob = sktext::gpu::TextBlob::Make(glyphRunList,
63 paint,
64 drawMatrix,
65 device->strikeDeviceInfo(),
67
68 const sktext::gpu::AtlasSubRun* subRun =
70 SkASSERT_RELEASE(subRun);
71 subRun->testingOnly_packedGlyphIDToGlyph(&fCache);
72 fVertices.reset(new char[subRun->vertexStride(drawMatrix) * subRun->glyphCount() * 4]);
73 }
74
75 void onDraw(int loops, SkCanvas* canvas) override {
76 const sktext::gpu::AtlasSubRun* subRun =
78 SkASSERT_RELEASE(subRun);
79
82 GrColor grColor = SkColorToPremulGrColor(paint.getColor());
83 SkMatrix positionMatrix = SkMatrix::Translate(100, 100);
84
85 for (int loop = 0; loop < loops; loop++) {
86 subRun->fillVertexData(fVertices.get(), 0, subRun->glyphCount(),
87 grColor, positionMatrix, {0, 0}, clip);
88 }
89 }
90
91private:
94 std::unique_ptr<char[]> fVertices;
95};
96
const char * backend
DEF_BENCH(return new DirectMaskGlyphVertexFillBenchmark{})
static const char * gText
uint32_t GrColor
Definition: GrColor.h:25
#define SkASSERT_RELEASE(cond)
Definition: SkAssert.h:100
static GrColor SkColorToPremulGrColor(SkColor c)
Definition: SkGr.h:51
static SkPath clip(const SkPath &path, const SkHalfPlane &plane)
Definition: SkPath.cpp:3892
Definition: SkFont.h:35
static SkMatrix Translate(SkScalar dx, SkScalar dy)
Definition: SkMatrix.h:91
static const SkMatrix & I()
Definition: SkMatrix.cpp:1544
SkMatrix & preTranslate(SkScalar dx, SkScalar dy)
Definition: SkMatrix.cpp:263
static SkStrikeCache * GlobalStrikeCache()
static SkDevice * GetDevice(SkCanvas *canvas)
T * get() const
Definition: SkRefCnt.h:303
virtual void testingOnly_packedGlyphIDToGlyph(StrikeCache *cache) const =0
virtual int glyphCount() const =0
static const AtlasSubRun * FirstSubRun(const TextBlob *)
static sk_sp< TextBlob > Make(const sktext::GlyphRunList &glyphRunList, const SkPaint &paint, const SkMatrix &positionMatrix, SkStrikeDeviceInfo strikeDeviceInfo, StrikeForGPUCacheInterface *strikeCache)
Definition: TextBlob.cpp:194
const Paint & paint
Definition: color_source.cc:38
VkDevice device
Definition: main.cc:53
sk_sp< SkTypeface > CreateTestTypeface(const char *name, SkFontStyle style)
font
Font Metadata and Metrics.
Definition: SkRect.h:32
static constexpr SkIRect MakeEmpty()
Definition: SkRect.h:45
constexpr float y() const
Definition: SkPoint_impl.h:187
constexpr float x() const
Definition: SkPoint_impl.h:181