vulkan_gl_interop.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 ANDROID_WEBVIEW_BROWSER_GFX_VULKAN_GL_INTEROP_H_
  5. #define ANDROID_WEBVIEW_BROWSER_GFX_VULKAN_GL_INTEROP_H_
  6. #include <memory>
  7. #include "android_webview/browser/gfx/aw_vulkan_context_provider.h"
  8. #include "android_webview/public/browser/draw_fn.h"
  9. #include "base/containers/queue.h"
  10. #include "base/files/scoped_file.h"
  11. #include "base/memory/raw_ptr.h"
  12. #include "base/memory/scoped_refptr.h"
  13. #include "third_party/skia/include/core/SkRefCnt.h"
  14. #include "third_party/skia/include/gpu/vk/GrVkTypes.h"
  15. class GrVkSecondaryCBDrawContext;
  16. class SkColorSpace;
  17. namespace gl {
  18. class GLImageAHardwareBuffer;
  19. }
  20. namespace gpu {
  21. class VulkanImage;
  22. }
  23. namespace android_webview {
  24. class RenderThreadManager;
  25. struct HardwareRendererDrawParams;
  26. struct OverlaysParams;
  27. // With interop mode, we will render frames on AHBs with GL api, and then draw
  28. // AHBs with Vulkan API on the final target.
  29. class VulkanGLInterop {
  30. public:
  31. VulkanGLInterop(RenderThreadManager* render_thread_manager,
  32. AwVulkanContextProvider* vulkan_context_provider);
  33. ~VulkanGLInterop();
  34. void DrawVk(sk_sp<GrVkSecondaryCBDrawContext> draw_context,
  35. sk_sp<SkColorSpace> color_space,
  36. const HardwareRendererDrawParams& params,
  37. const OverlaysParams& overlays_params);
  38. void PostDrawVk();
  39. // For clean up.
  40. void MakeGLContextCurrentIgnoreFailure();
  41. private:
  42. class GLNonOwnedCompatibilityContext;
  43. static GLNonOwnedCompatibilityContext* g_gl_context;
  44. // Struct which represents one in-flight draw for the Vk interop path.
  45. struct InFlightInteropDraw {
  46. explicit InFlightInteropDraw(AwVulkanContextProvider* vk_context_provider);
  47. ~InFlightInteropDraw();
  48. sk_sp<GrVkSecondaryCBDrawContext> draw_context;
  49. VkFence post_draw_fence = VK_NULL_HANDLE;
  50. VkSemaphore post_draw_semaphore = VK_NULL_HANDLE;
  51. base::ScopedFD sync_fd;
  52. scoped_refptr<gl::GLImageAHardwareBuffer> ahb_image;
  53. sk_sp<SkImage> ahb_skimage;
  54. uint32_t texture_id = 0;
  55. uint32_t framebuffer_id = 0;
  56. std::unique_ptr<gpu::VulkanImage> vulkan_image;
  57. GrVkImageInfo image_info;
  58. // Used to clean up Vulkan objects.
  59. raw_ptr<AwVulkanContextProvider> vk_context_provider;
  60. };
  61. RenderThreadManager* const render_thread_manager_;
  62. AwVulkanContextProvider* const vulkan_context_provider_;
  63. // GL context used to draw via GL in Vk interop path.
  64. scoped_refptr<GLNonOwnedCompatibilityContext> gl_context_;
  65. // Queue of draw contexts pending cleanup.
  66. base::queue<std::unique_ptr<InFlightInteropDraw>> in_flight_interop_draws_;
  67. std::unique_ptr<InFlightInteropDraw> pending_draw_;
  68. };
  69. } // namespace android_webview
  70. #endif // ANDROID_WEBVIEW_BROWSER_GFX_VULKAN_GL_INTEROP_H_