1 // Copyright 2023 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "media/renderers/resource_sync_token_client.h"
6 #include "gpu/command_buffer/client/interface_base.h"
10 ResourceSyncTokenClient::ResourceSyncTokenClient(
11 gpu::InterfaceBase* ib,
12 gpu::SyncToken old_frame_release_token,
13 gpu::SyncToken new_plane_release_token)
15 old_frame_release_token_(std::move(old_frame_release_token)),
16 new_plane_release_token_(std::move(new_plane_release_token)) {
17 DCHECK(new_plane_release_token_.HasData());
21 ResourceSyncTokenClient::~ResourceSyncTokenClient() = default;
23 void ResourceSyncTokenClient::GenerateSyncToken(gpu::SyncToken* sync_token) {
24 if (new_plane_release_token_.HasData()) {
25 *sync_token = new_plane_release_token_;
29 ib_->GenSyncTokenCHROMIUM(sync_token->GetData());
32 void ResourceSyncTokenClient::WaitSyncToken(const gpu::SyncToken& sync_token) {
33 // This function isn't called if `sync_token` is null.
34 DCHECK(sync_token.HasData());
36 // Do nothing if `sync_token` matches the one we're injecting. It can end up
37 // matching since we can get the same SyncToken back for each plane in the
38 // VideoFrame yet we only have a single per-frame release token.
39 if (new_plane_release_token_ == sync_token) {
43 // If the frame's release token is the same as it was when the resource was
44 // imported by viz, we can adopt 'new_plane_release_token_' without waiting
45 // since it's guaranteed to be later in sequence.
46 if (old_frame_release_token_ == sync_token) {
50 // Otherwise we must wait on the old one and the new one and generate an even
51 // newer one during the GenerateSyncToken() call above.
52 ib_->WaitSyncTokenCHROMIUM(sync_token.GetConstData());
53 ib_->WaitSyncTokenCHROMIUM(new_plane_release_token_.GetConstData());
54 new_plane_release_token_.Clear();