Flutter Engine
The Flutter Engine
StrikeForGPU.h
Go to the documentation of this file.
1/*
2 * Copyright 2019 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#ifndef sktext_StrikeForGPU_DEFINED
9#define sktext_StrikeForGPU_DEFINED
10
11#include "include/core/SkPath.h"
14#include "src/core/SkGlyph.h"
15
16#include <memory>
17#include <optional>
18#include <variant>
19
20class SkDescriptor;
21class SkDrawable;
22class SkReadBuffer;
23class SkStrike;
24class SkStrikeCache;
25class SkStrikeClient;
26class SkStrikeSpec;
27class SkWriteBuffer;
28
29namespace sktext {
30// -- SkStrikePromise ------------------------------------------------------------------------------
31// SkStrikePromise produces an SkStrike when needed by GPU glyph rendering. In ordinary
32// operation, it just wraps an SkStrike. When used for remote glyph cache operation, the promise is
33// serialized to an SkDescriptor. When SkStrikePromise is deserialized, it uses the descriptor to
34// look up the SkStrike.
35//
36// When deserializing some care must be taken; if the needed SkStrike is removed from the cache,
37// then looking up using the descriptor will fail resulting in a deserialization failure. The
38// Renderer/GPU system solves this problem by pinning all the strikes needed into the cache.
40public:
41 SkStrikePromise() = delete;
46
48 explicit SkStrikePromise(const SkStrikeSpec& spec);
49
50 // This only works when the GPU code is compiled in.
51 static std::optional<SkStrikePromise> MakeFromBuffer(SkReadBuffer& buffer,
52 const SkStrikeClient* client,
53 SkStrikeCache* strikeCache);
54 void flatten(SkWriteBuffer& buffer) const;
55
56 // Do what is needed to return a strike.
58
59 // Reset the sk_sp<SkStrike> to nullptr.
60 void resetStrike();
61
62 // Return a descriptor used to look up the SkStrike.
63 const SkDescriptor& descriptor() const;
64
65private:
66 std::variant<sk_sp<SkStrike>, std::unique_ptr<SkStrikeSpec>> fStrikeOrSpec;
67};
68
69// -- StrikeForGPU ---------------------------------------------------------------------------------
70class StrikeForGPU : public SkRefCnt {
71public:
72 virtual void lock() = 0;
73 virtual void unlock() = 0;
74
75 // Generate a digest for a given packed glyph ID as drawn using the give action type.
77
78 // Prepare the glyph to draw an image, and return if the image exists.
79 virtual bool prepareForImage(SkGlyph*) = 0;
80
81 // Prepare the glyph to draw a path, and return if the path exists.
82 virtual bool prepareForPath(SkGlyph*) = 0;
83
84 // Prepare the glyph to draw a drawable, and return if the drawable exists.
85 virtual bool prepareForDrawable(SkGlyph*) = 0;
86
87
88 virtual const SkDescriptor& getDescriptor() const = 0;
89
90 virtual const SkGlyphPositionRoundingSpec& roundingSpec() const = 0;
91
92 // Return a strike promise.
94};
95
96// prepareForPathDrawing uses this union to convert glyph ids to paths.
97union IDOrPath {
99 IDOrPath(SkGlyphID glyphID) : fGlyphID{glyphID} {}
100
101 // PathOpSubmitter takes care of destroying the paths.
105};
106
107// prepareForDrawableDrawing uses this union to convert glyph ids to drawables.
111};
112
113// -- StrikeMutationMonitor ------------------------------------------------------------------------
115public:
118
119private:
120 StrikeForGPU* fStrike;
121};
122
123// -- StrikeForGPUCacheInterface -------------------------------------------------------------------
125public:
126 virtual ~StrikeForGPUCacheInterface() = default;
128};
129} // namespace sktext
130#endif // sktext_StrikeForGPU_DEFINED
uint16_t SkGlyphID
Definition: SkTypes.h:179
Definition: SkPath.h:59
static std::optional< SkStrikePromise > MakeFromBuffer(SkReadBuffer &buffer, const SkStrikeClient *client, SkStrikeCache *strikeCache)
Definition: StrikeCache.cpp:77
void flatten(SkWriteBuffer &buffer) const
SkStrikePromise(SkStrikePromise &&)
SkStrikePromise & operator=(SkStrikePromise &&)
const SkDescriptor & descriptor() const
SkStrikePromise & operator=(const SkStrikePromise &)=delete
SkStrikePromise(const SkStrikePromise &)=delete
virtual sk_sp< StrikeForGPU > findOrCreateScopedStrike(const SkStrikeSpec &strikeSpec)=0
virtual ~StrikeForGPUCacheInterface()=default
virtual void unlock()=0
virtual SkStrikePromise strikePromise()=0
virtual const SkDescriptor & getDescriptor() const =0
virtual bool prepareForPath(SkGlyph *)=0
virtual bool prepareForDrawable(SkGlyph *)=0
virtual bool prepareForImage(SkGlyph *)=0
virtual SkGlyphDigest digestFor(skglyph::ActionType, SkPackedGlyphID)=0
virtual const SkGlyphPositionRoundingSpec & roundingSpec() const =0
virtual void lock()=0
StrikeMutationMonitor(StrikeForGPU *strike)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126
ActionType
Definition: SkGlyph.h:312
SkDrawable * fDrawable
Definition: StrikeForGPU.h:110
SkGlyphID fGlyphID
Definition: StrikeForGPU.h:103
IDOrPath(SkGlyphID glyphID)
Definition: StrikeForGPU.h:99