Flutter Engine
The Flutter Engine
SkTestCanvas.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2023 Google LLC
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
9
11#include "include/core/SkColorSpace.h" // IWYU pragma: keep
12#include "include/core/SkData.h"
14#include "include/core/SkRect.h"
20#include "src/core/SkDevice.h"
21#include "src/text/GlyphRun.h"
22
23#include <cstdint>
24#include <memory>
25#include <optional>
26#include <vector>
27
28class SkPaint;
29
31 : SkCanvas(sk_ref_sp(canvas->rootDevice())) {}
32
34 const sktext::GlyphRunList& glyphRunList, const SkPaint& paint) {
35 SkRect bounds = glyphRunList.sourceBoundsWithOrigin();
36 if (this->internalQuickReject(bounds, paint)) {
37 return;
38 }
39 auto layer = this->aboutToDraw(paint, &bounds);
40 if (layer) {
41 if (glyphRunList.hasRSXForm()) {
42 this->SkCanvas::onDrawGlyphRunList(glyphRunList, layer->paint());
43 } else {
44 auto slug = this->onConvertGlyphRunListToSlug(glyphRunList, layer->paint());
45 this->drawSlug(slug.get(), layer->paint());
46 }
47 }
48}
49
51 : SkCanvas(sk_ref_sp(canvas->rootDevice())) {}
52
54 const sktext::GlyphRunList& glyphRunList, const SkPaint& paint) {
55 SkRect bounds = glyphRunList.sourceBoundsWithOrigin();
56 if (this->internalQuickReject(bounds, paint)) {
57 return;
58 }
59 auto layer = this->aboutToDraw(paint, &bounds);
60 if (layer) {
61 if (glyphRunList.hasRSXForm()) {
62 this->SkCanvas::onDrawGlyphRunList(glyphRunList, layer->paint());
63 } else {
64 sk_sp<SkData> bytes;
65 {
66 auto slug = this->onConvertGlyphRunListToSlug(glyphRunList, layer->paint());
67 if (slug != nullptr) {
68 bytes = slug->serialize();
69 }
70 }
71 {
72 if (bytes != nullptr) {
73 auto slug = sktext::gpu::Slug::Deserialize(bytes->data(), bytes->size());
74 this->drawSlug(slug.get(), layer->paint());
75 }
76 }
77 }
78 }
79}
80
81
82// A do nothing handle manager for the remote strike server.
84public:
86 return 0;
87 }
88
90 return true;
91 }
92
94 return false;
95 }
96};
97
98// Lock the strikes into the cache for the length of the test. This handler is tied to the lifetime
99// of the canvas used to render the entire test.
101public:
103 return fIsLocked;
104 }
105
107 DiscardableHandleManager::assertHandleValid(id);
108 }
109
111
112 }
113
114 void notifyReadFailure(const ReadFailureData& data) override {
115 DiscardableHandleManager::notifyReadFailure(data);
116 }
117
118 void unlock() {
119 fIsLocked = true;
120 }
121
122private:
123 bool fIsLocked{false};
124};
125
127 : SkCanvas(sk_ref_sp(canvas->rootDevice()))
128 , fServerHandleManager(new ServerHandleManager{})
129 , fClientHandleManager(new ClientHandleManager{})
130 , fStrikeServer(fServerHandleManager.get())
131 , fStrikeClient(fClientHandleManager) {}
132
133// Allow the strikes to be freed from the strike cache after the test has been drawn.
135 static_cast<ClientHandleManager*>(fClientHandleManager.get())->unlock();
136}
137
139 const sktext::GlyphRunList& glyphRunList, const SkPaint& paint) {
140 SkRect bounds = glyphRunList.sourceBoundsWithOrigin();
141 if (this->internalQuickReject(bounds, paint)) {
142 return;
143 }
144 auto layer = this->aboutToDraw(paint, &bounds);
145 if (layer) {
146 if (glyphRunList.hasRSXForm()) {
147 this->SkCanvas::onDrawGlyphRunList(glyphRunList, layer->paint());
148 } else {
149 sk_sp<SkData> slugBytes;
150 std::vector<uint8_t> glyphBytes;
151 {
152 auto analysisCanvas = fStrikeServer.makeAnalysisCanvas(
153 this->topDevice()->width(),
154 this->topDevice()->height(),
155 this->fProps,
156 this->topDevice()->imageInfo().refColorSpace(),
157 // TODO: Where should we get this value from?
158 /*DFTSupport=*/ true);
159
160 // TODO: Move the analysis canvas processing up to the via to handle a whole
161 // document at a time. This is not the correct way to handle the CTM; it doesn't
162 // work for layers.
163 analysisCanvas->setMatrix(this->getLocalToDevice());
164 auto slug = analysisCanvas->onConvertGlyphRunListToSlug(glyphRunList,
165 layer->paint());
166 if (slug != nullptr) {
167 slugBytes = slug->serialize();
168 }
169 fStrikeServer.writeStrikeData(&glyphBytes);
170 }
171 {
172 if (!glyphBytes.empty()) {
173 fStrikeClient.readStrikeData(glyphBytes.data(), glyphBytes.size());
174 }
175 if (slugBytes != nullptr) {
177 slugBytes->data(), slugBytes->size(), &fStrikeClient);
178 this->drawSlug(slug.get(), layer->paint());
179 }
180 }
181 }
182 }
183}
uint32_t SkDiscardableHandleId
sk_sp< T > sk_ref_sp(T *obj)
Definition: SkRefCnt.h:381
GLenum type
bool deleteHandle(SkDiscardableHandleId id) override
void notifyReadFailure(const ReadFailureData &data) override
void assertHandleValid(SkDiscardableHandleId id) override
void notifyCacheMiss(SkStrikeClient::CacheMissType type, int fontSize) override
bool lockHandle(SkDiscardableHandleId id) override
SkDiscardableHandleId createHandle() override
bool isHandleDeleted(SkDiscardableHandleId id) override
virtual void onDrawGlyphRunList(const sktext::GlyphRunList &glyphRunList, const SkPaint &paint)
Definition: SkCanvas.cpp:2356
const void * data() const
Definition: SkData.h:37
size_t size() const
Definition: SkData.h:30
bool hasRSXForm() const
Definition: GlyphRun.h:105
SkRect sourceBoundsWithOrigin() const
Definition: GlyphRun.h:116
static sk_sp< Slug > Deserialize(const void *data, size_t size, const SkStrikeClient *client=nullptr)
Definition: Slug.cpp:42
const Paint & paint
Definition: color_source.cc:38
drawSlug(r.slug.get(), r.paint)) DRAW(DrawAtlas
Optional< SkRect > bounds
Definition: SkRecords.h:189
const myers::Point & get(const myers::Segment &)
int32_t height
int32_t width
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63