10
10
#include " ../../helpers/sync/SyncReleaser.hpp"
11
11
#include " ../PresentationTime.hpp"
12
12
#include " ../DRMSyncobj.hpp"
13
+ #include " ../types/DMABuffer.hpp"
13
14
#include " ../../render/Renderer.hpp"
14
15
#include " config/ConfigValue.hpp"
16
+ #include " ../../managers/eventLoop/EventLoopManager.hpp"
15
17
#include " protocols/types/SurfaceRole.hpp"
16
18
#include " render/Texture.hpp"
17
19
#include < cstring>
@@ -123,16 +125,15 @@ CWLSurfaceResource::CWLSurfaceResource(SP<CWlSurface> resource_) : resource(reso
123
125
return ;
124
126
}
125
127
126
- if ((!pending.updated .buffer ) || // no new buffer attached
127
- (!pending.buffer && !pending.texture ) || // null buffer attached
128
- (!pending.updated .acquire && pending.buffer ->isSynchronous ()) // synchronous buffers (ex. shm) can be read immediately
128
+ if ((!pending.updated .buffer ) || // no new buffer attached
129
+ (!pending.buffer && !pending.texture ) // null buffer attached
129
130
) {
130
131
commitState (pending);
131
132
pending.reset ();
132
133
return ;
133
134
}
134
135
135
- // save state while we wait for buffer to become ready
136
+ // save state while we wait for buffer to become ready to read
136
137
const auto & state = pendingStates.emplace (makeUnique<SSurfaceState>(pending));
137
138
pending.reset ();
138
139
@@ -152,13 +153,19 @@ CWLSurfaceResource::CWLSurfaceResource(SP<CWlSurface> resource_) : resource(reso
152
153
if (state->updated .acquire ) {
153
154
// wait on acquire point for this surface, from explicit sync protocol
154
155
state->acquire .addWaiter (whenReadable);
155
- } else if (state->buffer ->dmabuf ().success ) {
156
- // https://www.kernel.org/doc/html/latest/driver-api/dma-buf.html#implicit-fence-poll-support
157
- // TODO: wait for the dma-buf fd's to become readable
156
+ } else if (state->buffer ->isSynchronous ()) {
157
+ // synchronous (shm) buffers can be read immediately
158
158
whenReadable ();
159
+ } else if (state->buffer ->type () == Aquamarine::BUFFER_TYPE_DMABUF && state->buffer ->dmabuf ().success ) {
160
+ // async buffer and is dmabuf, then we can wait on implicit fences
161
+ auto syncFd = dynamic_cast <CDMABuffer*>(state->buffer .buffer .get ())->exportSyncFile ();
162
+
163
+ if (syncFd.isValid ())
164
+ g_pEventLoopManager->doOnReadable (std::move (syncFd), whenReadable);
165
+ else
166
+ whenReadable ();
159
167
} else {
160
- // huh??? only buffers with acquire or dmabuf should get through here...
161
- Debug::log (ERR, " BUG THIS: wl_surface.commit: non-acquire non-dmabuf buffers needs wait..." );
168
+ Debug::log (ERR, " BUG THIS: wl_surface.commit: no acquire, non-dmabuf, async buffer, needs wait... this shouldn't happen" );
162
169
whenReadable ();
163
170
}
164
171
});
0 commit comments