Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
third_party
skia
src
gpu
graphite
dawn
DawnAsyncWait.h
Go to the documentation of this file.
1
/*
2
* Copyright 2022 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
8
#ifndef skgpu_graphite_DawnAsyncWait_DEFINED
9
#define skgpu_graphite_DawnAsyncWait_DEFINED
10
11
#include "
include/core/SkTypes.h
"
12
13
#include "webgpu/webgpu_cpp.h"
// NO_G3_REWRITE
14
15
#include <atomic>
16
#include <functional>
17
18
namespace
skgpu::graphite
{
19
20
class
DawnSharedContext;
21
22
class
DawnAsyncWait
{
23
public
:
24
DawnAsyncWait
(
const
DawnSharedContext
*);
25
26
// Returns true if the wait has been signaled and false otherwise. If the Context allows
27
// yielding, then this function yields execution to the event loop where Dawn's asynchronous
28
// tasks get scheduled and returns as soon as the loop yields the execution back to the caller.
29
// Otherwise, it just checks.
30
bool
yieldAndCheck
()
const
;
31
32
// Returns true if it is legal to call busyWait().
33
bool
mayBusyWait
()
const
;
34
35
// Busy-waits until this wait has been signaled. May only be called if the Context allows
36
// yielding.
37
// TODO(armansito): This could benefit from a timeout in the case the wait never gets signaled.
38
void
busyWait
()
const
;
39
40
// Marks this wait as resolved. Once called, all calls to `yieldAndCheck` and `busyWait` will
41
// return true immediately.
42
void
signal
() { fSignaled =
true
; }
43
44
// Resets this object into its unsignaled state.
45
void
reset
() { fSignaled =
false
; }
46
47
private
:
48
const
DawnSharedContext
* fSharedContext;
49
std::atomic_bool fSignaled;
50
};
51
52
template
<
typename
T>
class
DawnAsyncResult
{
53
public
:
54
DawnAsyncResult
(
const
DawnSharedContext
* sharedContext) : fSync(sharedContext) {}
55
56
~DawnAsyncResult
() {
57
if
(fSync.
mayBusyWait
()) {
58
fSync.
busyWait
();
59
}
60
SkASSERT
(fSync.
yieldAndCheck
());
61
}
62
63
void
set
(
const
T
&
result
) {
64
fResult =
result
;
65
fSync.
signal
();
66
}
67
68
const
T
*
getIfReady
()
const
{
return
fSync.
yieldAndCheck
() ? &fResult :
nullptr
; }
69
70
const
T
&
waitAndGet
()
const
{
71
// If fSync is already signaled, the wait will return immediately.
72
fSync.
busyWait
();
73
return
fResult;
74
}
75
76
private
:
77
DawnAsyncWait
fSync;
78
T
fResult;
79
};
80
81
}
// namespace skgpu::graphite
82
83
#endif
// skgpu_graphite_DawnAsyncWait_DEFINED
SkASSERT
#define SkASSERT(cond)
Definition
SkAssert.h:116
SkTypes.h
skgpu::graphite::DawnAsyncResult
Definition
DawnAsyncWait.h:52
skgpu::graphite::DawnAsyncResult::~DawnAsyncResult
~DawnAsyncResult()
Definition
DawnAsyncWait.h:56
skgpu::graphite::DawnAsyncResult::set
void set(const T &result)
Definition
DawnAsyncWait.h:63
skgpu::graphite::DawnAsyncResult::DawnAsyncResult
DawnAsyncResult(const DawnSharedContext *sharedContext)
Definition
DawnAsyncWait.h:54
skgpu::graphite::DawnAsyncResult::waitAndGet
const T & waitAndGet() const
Definition
DawnAsyncWait.h:70
skgpu::graphite::DawnAsyncResult::getIfReady
const T * getIfReady() const
Definition
DawnAsyncWait.h:68
skgpu::graphite::DawnAsyncWait
Definition
DawnAsyncWait.h:22
skgpu::graphite::DawnAsyncWait::reset
void reset()
Definition
DawnAsyncWait.h:45
skgpu::graphite::DawnAsyncWait::yieldAndCheck
bool yieldAndCheck() const
Definition
DawnAsyncWait.cpp:20
skgpu::graphite::DawnAsyncWait::busyWait
void busyWait() const
Definition
DawnAsyncWait.cpp:33
skgpu::graphite::DawnAsyncWait::signal
void signal()
Definition
DawnAsyncWait.h:42
skgpu::graphite::DawnAsyncWait::mayBusyWait
bool mayBusyWait() const
Definition
DawnAsyncWait.cpp:31
skgpu::graphite::DawnSharedContext
Definition
DawnSharedContext.h:22
result
GAsyncResult * result
Definition
fl_text_input_plugin.cc:106
skgpu::graphite
Definition
BoundsManagerBench.cpp:27
T
#define T
Definition
precompiler.cc:65
Generated on Fri Apr 26 2024 06:17:16 for Flutter Engine by
1.9.8