Upload upstream chromium 120.0.6099.5
[platform/framework/web/chromium-efl.git] / media / renderers / resource_sync_token_client.cc
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.
4
5 #include "media/renderers/resource_sync_token_client.h"
6 #include "gpu/command_buffer/client/interface_base.h"
7
8 namespace media {
9
10 ResourceSyncTokenClient::ResourceSyncTokenClient(
11     gpu::InterfaceBase* ib,
12     gpu::SyncToken old_frame_release_token,
13     gpu::SyncToken new_plane_release_token)
14     : ib_(ib),
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());
18   DCHECK(ib_);
19 }
20
21 ResourceSyncTokenClient::~ResourceSyncTokenClient() = default;
22
23 void ResourceSyncTokenClient::GenerateSyncToken(gpu::SyncToken* sync_token) {
24   if (new_plane_release_token_.HasData()) {
25     *sync_token = new_plane_release_token_;
26     return;
27   }
28
29   ib_->GenSyncTokenCHROMIUM(sync_token->GetData());
30 }
31
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());
35
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) {
40     return;
41   }
42
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) {
47     return;
48   }
49
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();
55 }
56
57 }  // namespace media