Commit 442f3e3a authored by Bo Liu's avatar Bo Liu Committed by Commit Bot

aw: Factor out vulkan gl interop

Keep comment code such as creating SkColorSpace or converting parameters
in AwDrawFnImpl.

Fixed: 1141685
Change-Id: I0c7191b59fffe413259d7ee308eb2f4610424ba6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2495918
Commit-Queue: Bo <boliu@chromium.org>
Reviewed-by: default avatarVasiliy Telezhnikov <vasilyt@chromium.org>
Cr-Commit-Position: refs/heads/master@{#820871}
parent cc66c8f5
......@@ -70,6 +70,8 @@ source_set("gfx") {
"task_queue_web_view.h",
"viz_compositor_thread_runner_webview.cc",
"viz_compositor_thread_runner_webview.h",
"vulkan_gl_interop.cc",
"vulkan_gl_interop.h",
]
deps = [
......
......@@ -10,27 +10,14 @@
#include "android_webview/browser/gfx/aw_vulkan_context_provider.h"
#include "android_webview/browser/gfx/compositor_frame_consumer.h"
#include "android_webview/browser/gfx/render_thread_manager.h"
#include "android_webview/browser/gfx/vulkan_gl_interop.h"
#include "android_webview/public/browser/draw_fn.h"
#include "base/android/jni_weak_ref.h"
#include "base/containers/queue.h"
#include "base/files/scoped_file.h"
#include "base/android/scoped_java_ref.h"
#include "base/macros.h"
#include "base/optional.h"
#include "third_party/skia/include/core/SkRefCnt.h"
#include "third_party/skia/include/gpu/vk/GrVkTypes.h"
class GrVkSecondaryCBDrawContext;
namespace gl {
class GLImageAHardwareBuffer;
}
namespace gpu {
class VulkanImage;
}
namespace android_webview {
class GLNonOwnedCompatibilityContext;
class AwDrawFnImpl {
public:
......@@ -55,36 +42,11 @@ class AwDrawFnImpl {
private:
// With direct mode, we will render frames with Vulkan API directly.
void DrawVkDirect(AwDrawFn_DrawVkParams* params);
void DrawVkDirect(sk_sp<GrVkSecondaryCBDrawContext> draw_context,
sk_sp<SkColorSpace> color_space,
HardwareRendererDrawParams* params);
void PostDrawVkDirect(AwDrawFn_PostDrawVkParams* params);
// With interop mode, we will render frames on AHBs with GL api, and then draw
// AHBs with Vulkan API on the final target.
void DrawVkInterop(AwDrawFn_DrawVkParams* params);
void PostDrawVkInterop(AwDrawFn_PostDrawVkParams* params);
template <typename T>
void DrawInternal(T* params, SkColorSpace* color_space);
// Struct which represents one in-flight draw for the Vk interop path.
struct InFlightInteropDraw {
explicit InFlightInteropDraw(AwVulkanContextProvider* vk_context_provider);
~InFlightInteropDraw();
sk_sp<GrVkSecondaryCBDrawContext> draw_context;
VkFence post_draw_fence = VK_NULL_HANDLE;
VkSemaphore post_draw_semaphore = VK_NULL_HANDLE;
base::ScopedFD sync_fd;
scoped_refptr<gl::GLImageAHardwareBuffer> ahb_image;
sk_sp<SkImage> ahb_skimage;
uint32_t texture_id = 0;
uint32_t framebuffer_id = 0;
std::unique_ptr<gpu::VulkanImage> vulkan_image;
GrVkImageInfo image_info;
// Used to clean up Vulkan objects.
AwVulkanContextProvider* vk_context_provider;
};
CompositorFrameConsumer* GetCompositorFrameConsumer() {
return &render_thread_manager_;
}
......@@ -101,12 +63,7 @@ class AwDrawFnImpl {
base::Optional<AwVulkanContextProvider::ScopedSecondaryCBDraw>
scoped_secondary_cb_draw_;
// GL context used to draw via GL in Vk interop path.
scoped_refptr<GLNonOwnedCompatibilityContext> gl_context_;
// Queue of draw contexts pending cleanup.
base::queue<std::unique_ptr<InFlightInteropDraw>> in_flight_interop_draws_;
std::unique_ptr<InFlightInteropDraw> pending_draw_;
base::Optional<VulkanGLInterop> interop_;
DISALLOW_COPY_AND_ASSIGN(AwDrawFnImpl);
};
......
This diff is collapsed.
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ANDROID_WEBVIEW_BROWSER_GFX_VULKAN_GL_INTEROP_H_
#define ANDROID_WEBVIEW_BROWSER_GFX_VULKAN_GL_INTEROP_H_
#include <memory>
#include "android_webview/browser/gfx/aw_vulkan_context_provider.h"
#include "android_webview/public/browser/draw_fn.h"
#include "base/containers/queue.h"
#include "base/files/scoped_file.h"
#include "base/memory/scoped_refptr.h"
#include "third_party/skia/include/core/SkRefCnt.h"
#include "third_party/skia/include/gpu/vk/GrVkTypes.h"
class GrVkSecondaryCBDrawContext;
class SkColorSpace;
namespace gl {
class GLImageAHardwareBuffer;
}
namespace gpu {
class VulkanImage;
}
namespace android_webview {
class RenderThreadManager;
struct HardwareRendererDrawParams;
// With interop mode, we will render frames on AHBs with GL api, and then draw
// AHBs with Vulkan API on the final target.
class VulkanGLInterop {
public:
VulkanGLInterop(RenderThreadManager* render_thread_manager,
AwVulkanContextProvider* vulkan_context_provider);
~VulkanGLInterop();
void DrawVk(sk_sp<GrVkSecondaryCBDrawContext> draw_context,
sk_sp<SkColorSpace> color_space,
HardwareRendererDrawParams* params);
void PostDrawVk();
// For clean up.
void MakeGLContextCurrentIgnoreFailure();
private:
class GLNonOwnedCompatibilityContext;
static GLNonOwnedCompatibilityContext* g_gl_context;
// Struct which represents one in-flight draw for the Vk interop path.
struct InFlightInteropDraw {
explicit InFlightInteropDraw(AwVulkanContextProvider* vk_context_provider);
~InFlightInteropDraw();
sk_sp<GrVkSecondaryCBDrawContext> draw_context;
VkFence post_draw_fence = VK_NULL_HANDLE;
VkSemaphore post_draw_semaphore = VK_NULL_HANDLE;
base::ScopedFD sync_fd;
scoped_refptr<gl::GLImageAHardwareBuffer> ahb_image;
sk_sp<SkImage> ahb_skimage;
uint32_t texture_id = 0;
uint32_t framebuffer_id = 0;
std::unique_ptr<gpu::VulkanImage> vulkan_image;
GrVkImageInfo image_info;
// Used to clean up Vulkan objects.
AwVulkanContextProvider* vk_context_provider;
};
RenderThreadManager* const render_thread_manager_;
AwVulkanContextProvider* const vulkan_context_provider_;
// GL context used to draw via GL in Vk interop path.
scoped_refptr<GLNonOwnedCompatibilityContext> gl_context_;
// Queue of draw contexts pending cleanup.
base::queue<std::unique_ptr<InFlightInteropDraw>> in_flight_interop_draws_;
std::unique_ptr<InFlightInteropDraw> pending_draw_;
};
} // namespace android_webview
#endif // ANDROID_WEBVIEW_BROWSER_GFX_VULKAN_GL_INTEROP_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment