mailbox_to_surface_bridge.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. // Copyright 2020 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef DEVICE_VR_ANDROID_MAILBOX_TO_SURFACE_BRIDGE_H_
  5. #define DEVICE_VR_ANDROID_MAILBOX_TO_SURFACE_BRIDGE_H_
  6. namespace gfx {
  7. class ColorSpace;
  8. class GpuFence;
  9. class Transform;
  10. } // namespace gfx
  11. namespace gl {
  12. class SurfaceTexture;
  13. } // namespace gl
  14. namespace gpu {
  15. class GpuMemoryBufferImplAndroidHardwareBuffer;
  16. struct MailboxHolder;
  17. struct SyncToken;
  18. } // namespace gpu
  19. namespace device {
  20. class MailboxToSurfaceBridge {
  21. public:
  22. virtual ~MailboxToSurfaceBridge() {}
  23. // Returns true if the GPU process connection is established and ready to use.
  24. // Equivalent to waiting for on_initialized to be called.
  25. virtual bool IsConnected() = 0;
  26. // Checks if a workaround from "gpu/config/gpu_driver_bug_workaround_type.h"
  27. // is active. Requires initialization to be complete.
  28. virtual bool IsGpuWorkaroundEnabled(int32_t workaround) = 0;
  29. // This call is needed for Surface transport, in that case it must be called
  30. // on the GL thread with a valid local native GL context. If it's not used,
  31. // only the SharedBuffer transport methods are available.
  32. virtual void CreateSurface(gl::SurfaceTexture*) = 0;
  33. // Asynchronously create the context using the surface provided by an earlier
  34. // CreateSurface call, or an offscreen context if that wasn't called. Also
  35. // binds the context provider to the current thread (making it the GL thread),
  36. // and calls the callback on the GL thread.
  37. virtual void CreateAndBindContextProvider(base::OnceClosure callback) = 0;
  38. // All other public methods below must be called on the GL thread
  39. // (except when marked otherwise).
  40. virtual void ResizeSurface(int width, int height) = 0;
  41. // Returns true if swapped successfully. This can fail if the GL
  42. // context isn't ready for use yet, in that case the caller
  43. // won't get a new frame on the SurfaceTexture.
  44. virtual bool CopyMailboxToSurfaceAndSwap(
  45. const gpu::MailboxHolder& mailbox) = 0;
  46. virtual bool CopyMailboxToSurfaceAndSwap(
  47. const gpu::MailboxHolder& mailbox,
  48. const gfx::Transform& uv_transform) = 0;
  49. virtual void GenSyncToken(gpu::SyncToken* out_sync_token) = 0;
  50. virtual void WaitSyncToken(const gpu::SyncToken& sync_token) = 0;
  51. // Copies a GpuFence from the local context to the GPU process,
  52. // and issues a server wait for it.
  53. virtual void WaitForClientGpuFence(gfx::GpuFence*) = 0;
  54. // Creates a GpuFence in the GPU process after the supplied sync_token
  55. // completes, and copies it for use in the local context. This is
  56. // asynchronous, the callback receives the GpuFence once it's available.
  57. virtual void CreateGpuFence(
  58. const gpu::SyncToken& sync_token,
  59. base::OnceCallback<void(std::unique_ptr<gfx::GpuFence>)> callback) = 0;
  60. // Creates a shared image bound to |buffer|. Returns a mailbox holder that
  61. // references the shared image with a sync token representing a point after
  62. // the creation. Caller must call DestroySharedImage to free the shared image.
  63. // Does not take ownership of |buffer| or retain any references to it.
  64. virtual gpu::MailboxHolder CreateSharedImage(
  65. gpu::GpuMemoryBufferImplAndroidHardwareBuffer* buffer,
  66. const gfx::ColorSpace& color_space,
  67. uint32_t usage) = 0;
  68. // Destroys a shared image created by CreateSharedImage. The mailbox_holder's
  69. // sync_token must have been updated to a sync token after the last use of the
  70. // shared image.
  71. virtual void DestroySharedImage(const gpu::MailboxHolder& mailbox_holder) = 0;
  72. };
  73. class MailboxToSurfaceBridgeFactory {
  74. public:
  75. virtual ~MailboxToSurfaceBridgeFactory() {}
  76. virtual std::unique_ptr<device::MailboxToSurfaceBridge> Create() const = 0;
  77. };
  78. } // namespace device
  79. #endif // DEVICE_VR_ANDROID_MAILBOX_TO_SURFACE_BRIDGE_H_