8#ifndef SkMessageBus_DEFINED
9#define SkMessageBus_DEFINED
29template <
typename Message,
typename IDType,
bool AllowCopyableMessage = true>
32 template <
typename T>
struct is_sk_sp : std::false_type {};
39 "The message type must be sk_sp or non copyable.");
57 SkMutex fMessagesMutex;
58 const IDType fUniqueID;
69 SkMutex fInboxesMutex;
74#define DECLARE_SKMESSAGEBUS_MESSAGE(Message, IDType, AllowCopyableMessage) \
76 SkMessageBus<Message, IDType, AllowCopyableMessage>* \
77 SkMessageBus<Message, IDType, AllowCopyableMessage>::Get() { \
79 static SkMessageBus<Message, IDType, AllowCopyableMessage>* bus; \
80 once([] { bus = new SkMessageBus<Message, IDType, AllowCopyableMessage>(); }); \
86template <
typename Message,
typename IDType,
bool AllowCopyableMessage>
88 : fUniqueID(uniqueID) {
92 bus->fInboxes.push_back(
this);
95template <
typename Message,
typename IDType,
bool AllowCopyableMessage>
101 for (
int i = 0;
i < bus->fInboxes.size();
i++) {
102 if (
this == bus->fInboxes[
i]) {
103 bus->fInboxes.removeShuffle(
i);
109template <
typename Message,
typename IDType,
bool AllowCopyableMessage>
112 fMessages.push_back(std::move(
m));
115template <
typename Message,
typename IDType,
bool AllowCopyableMessage>
121 fMessages.swap(*messages);
126template <
typename Message,
typename IDType,
bool AllowCopyableMessage>
129template <
typename Message,
typename IDType,
bool AllowCopyableMessage>
133 for (
int i = 0;
i < bus->fInboxes.size();
i++) {
135 if constexpr (AllowCopyableMessage) {
136 bus->fInboxes[
i]->receive(
m);
141 bus->fInboxes[
i]->receive(std::move(
m));
bool SkShouldPostMessageToBus(const GrClientMappedBufferManager::BufferFinishedMessage &, GrDirectContext::DirectContextID potentialRecipient)
void poll(skia_private::TArray< Message > *out)
static void Post(Message m)