blob: c2f8b03ccc9c4923c3e6850b31929108730018e3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
/*
* Copyright 2022 Google LLC
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "src/text/StrikeForGPU.h"
#include <memory>
#include <utility>
#include "include/private/chromium/SkChromeRemoteGlyphCache.h"
#include "src/core/SkDescriptor.h"
#include "src/core/SkReadBuffer.h"
#include "src/core/SkStrike.h"
#include "src/core/SkStrikeCache.h"
#include "src/core/SkWriteBuffer.h"
namespace sktext {
// -- SkStrikePromise ------------------------------------------------------------------------------
SkStrikePromise::SkStrikePromise(sktext::SkStrikePromise&&) = default;
SkStrikePromise& SkStrikePromise::operator=(sktext::SkStrikePromise&&) = default;
SkStrikePromise::SkStrikePromise(sk_sp<SkStrike>&& strike)
: fStrikeOrSpec{std::move(strike)} {}
SkStrikePromise::SkStrikePromise(const SkStrikeSpec& spec)
: fStrikeOrSpec{std::make_unique<SkStrikeSpec>(spec)} {}
SkStrike* SkStrikePromise::strike() {
if (std::holds_alternative<std::unique_ptr<SkStrikeSpec>>(fStrikeOrSpec)) {
// Turn the strike spec into a strike.
std::unique_ptr<SkStrikeSpec> spec =
std::exchange(std::get<std::unique_ptr<SkStrikeSpec>>(fStrikeOrSpec), nullptr);
fStrikeOrSpec = SkStrikeCache::GlobalStrikeCache()->findOrCreateStrike(*spec);
}
return std::get<sk_sp<SkStrike>>(fStrikeOrSpec).get();
}
void SkStrikePromise::resetStrike() {
fStrikeOrSpec = sk_sp<SkStrike>();
}
const SkDescriptor& SkStrikePromise::descriptor() const {
if (std::holds_alternative<std::unique_ptr<SkStrikeSpec>>(fStrikeOrSpec)) {
return std::get<std::unique_ptr<SkStrikeSpec>>(fStrikeOrSpec)->descriptor();
}
return std::get<sk_sp<SkStrike>>(fStrikeOrSpec)->getDescriptor();
}
void SkStrikePromise::flatten(SkWriteBuffer& buffer) const {
this->descriptor().flatten(buffer);
}
std::optional<SkStrikePromise> SkStrikePromise::MakeFromBuffer(
SkReadBuffer& buffer, const SkStrikeClient* client, SkStrikeCache* strikeCache) {
std::optional<SkAutoDescriptor> descriptor = SkAutoDescriptor::MakeFromBuffer(buffer);
if (!buffer.validate(descriptor.has_value())) {
return std::nullopt;
}
// If there is a client, then this from a different process. Translate the SkTypefaceID from
// the strike server (Renderer) process to strike client (GPU) process.
if (client != nullptr) {
if (!client->translateTypefaceID(&descriptor.value())) {
return std::nullopt;
}
}
sk_sp<SkStrike> strike = strikeCache->findStrike(*descriptor->getDesc());
SkASSERT(strike != nullptr);
if (!buffer.validate(strike != nullptr)) {
return std::nullopt;
}
return SkStrikePromise{std::move(strike)};
}
// -- StrikeMutationMonitor ------------------------------------------------------------------------
StrikeMutationMonitor::StrikeMutationMonitor(StrikeForGPU* strike)
: fStrike{strike} {
fStrike->lock();
}
StrikeMutationMonitor::~StrikeMutationMonitor() {
fStrike->unlock();
}
} // namespace sktext
|