File: webgpu_mailbox_texture.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (114 lines) | stat: -rw-r--r-- 4,869 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_GRAPHICS_GPU_WEBGPU_MAILBOX_TEXTURE_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_GRAPHICS_GPU_WEBGPU_MAILBOX_TEXTURE_H_

#include "base/functional/callback.h"
#include "base/memory/scoped_refptr.h"
#include "gpu/command_buffer/client/client_shared_image.h"
#include "gpu/command_buffer/common/sync_token.h"
#include "third_party/blink/renderer/platform/graphics/gpu/dawn_control_client_holder.h"
#include "third_party/blink/renderer/platform/graphics/gpu/webgpu_cpp.h"
#include "third_party/blink/renderer/platform/graphics/gpu/webgpu_resource_provider_cache.h"
#include "third_party/blink/renderer/platform/platform_export.h"
#include "third_party/blink/renderer/platform/wtf/ref_counted.h"
#include "ui/gfx/geometry/rect.h"
#include "xr_webgl_drawing_buffer.h"

namespace media {
class VideoFrame;
}  // namespace media

namespace blink {

class DawnControlClientHolder;
class StaticBitmapImage;
class WebGPUTextureAlphaClearer;

class PLATFORM_EXPORT WebGPUMailboxTexture
    : public RefCounted<WebGPUMailboxTexture> {
 public:
  static scoped_refptr<WebGPUMailboxTexture> FromStaticBitmapImage(
      scoped_refptr<DawnControlClientHolder> dawn_control_client,
      const wgpu::Device& device,
      wgpu::TextureUsage usage,
      scoped_refptr<StaticBitmapImage> image,
      const SkImageInfo& info,
      const gfx::Rect& image_sub_rect,
      bool is_dummy_mailbox_texture);

  static scoped_refptr<WebGPUMailboxTexture> FromCanvasResource(
      scoped_refptr<DawnControlClientHolder> dawn_control_client,
      const wgpu::Device& device,
      wgpu::TextureUsage usage,
      std::unique_ptr<RecyclableCanvasResource> recyclable_canvas_resource);

  static scoped_refptr<WebGPUMailboxTexture> FromExistingSharedImage(
      scoped_refptr<DawnControlClientHolder> dawn_control_client,
      const wgpu::Device& device,
      const wgpu::TextureDescriptor& desc,
      scoped_refptr<gpu::ClientSharedImage> shared_image,
      const gpu::SyncToken& sync_token,
      gpu::webgpu::MailboxFlags mailbox_flags =
          gpu::webgpu::WEBGPU_MAILBOX_NONE,
      wgpu::TextureUsage additional_internal_usage = wgpu::TextureUsage::None,
      base::OnceCallback<void(const gpu::SyncToken&)> finished_access_callback =
          {});

  static scoped_refptr<WebGPUMailboxTexture> FromVideoFrame(
      scoped_refptr<DawnControlClientHolder> dawn_control_client,
      const wgpu::Device& device,
      wgpu::TextureUsage usage,
      scoped_refptr<media::VideoFrame> video_frame);

  void SetNeedsPresent(bool needs_present) { needs_present_ = needs_present; }
  void SetAlphaClearer(scoped_refptr<WebGPUTextureAlphaClearer> alpha_clearer);

  // Dissociates this mailbox texture from WebGPU, presenting the image if
  // necessary. Returns a sync token which will satisfy when the mailbox's
  // commands have been fully processed; this return value can safely be ignored
  // if the mailbox texture is not going to be accessed further.
  gpu::SyncToken Dissociate();

  // Sets a SyncToken which gates recycling of the associated recyclable canvas
  // resource. A recyclable canvas resource must be set to use this method.
  void SetCompletionSyncToken(const gpu::SyncToken& token);

  ~WebGPUMailboxTexture();

  const wgpu::Texture& GetTexture() { return texture_; }
  uint32_t GetTextureIdForTest() { return wire_texture_id_; }
  uint32_t GetTextureGenerationForTest() { return wire_texture_generation_; }
  const wgpu::Device& GetDeviceForTest() { return device_; }

 private:
  WebGPUMailboxTexture(
      scoped_refptr<DawnControlClientHolder> dawn_control_client,
      const wgpu::Device& device,
      const wgpu::TextureDescriptor& desc,
      scoped_refptr<gpu::ClientSharedImage> shared_image,
      const gpu::SyncToken& sync_token,
      gpu::webgpu::MailboxFlags mailbox_flags,
      wgpu::TextureUsage additional_internal_usage,
      base::OnceCallback<void(const gpu::SyncToken&)> finished_access_callback,
      std::unique_ptr<RecyclableCanvasResource> recyclable_canvas_resource);

  scoped_refptr<DawnControlClientHolder> dawn_control_client_;
  wgpu::Device device_;
  scoped_refptr<gpu::ClientSharedImage> shared_image_;
  base::OnceCallback<void(const gpu::SyncToken&)> finished_access_callback_;
  wgpu::Texture texture_;
  uint32_t wire_device_id_ = 0;
  uint32_t wire_device_generation_ = 0;
  uint32_t wire_texture_id_ = 0;
  uint32_t wire_texture_generation_ = 0;
  std::unique_ptr<RecyclableCanvasResource> recyclable_canvas_resource_;
  bool needs_present_ = false;
  scoped_refptr<WebGPUTextureAlphaClearer> alpha_clearer_;
};

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_PLATFORM_GRAPHICS_GPU_WEBGPU_MAILBOX_TEXTURE_H_