Commit 3563e39f authored by Bo Liu's avatar Bo Liu Committed by Chromium LUCI CQ

Webview vulkan composite with intermediate buffer

Add a code path to have vulkan webview draw into an intermediate buffer
and draw the buffer into the secondary command buffer.

Add a Feature to turn it on globally, which is only helpful for
debugging any potential problems from vulkan composite. Dynamically
switching between direct compopsite and intermediate buffer requires
more plumbing.

Bug: 919868
Change-Id: I059087432f3130372b795da6588069aa44dd4d9a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2605725Reviewed-by: default avatarPeng Huang <penghuang@chromium.org>
Reviewed-by: default avatarVasiliy Telezhnikov <vasilyt@chromium.org>
Commit-Queue: Bo <boliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#840850}
parent 017a27b6
......@@ -78,6 +78,8 @@ public final class ProductionSupportedFlagList {
"Use Vulkan for composite. Requires VizForWebView and Android device and "
+ "OS support. May crash if enabled on unsupported device."),
Flag.baseFeature(VizFeatures.VIZ_FOR_WEBVIEW, "Enables Viz for WebView."),
Flag.baseFeature(
VizFeatures.WEBVIEW_VULKAN_INTERMEDIATE_BUFFER, "For debugging vulkan"),
Flag.baseFeature(
GpuFeatures.USE_GLES2_FOR_OOP_R, "Force Skia context to use es2 only."),
Flag.baseFeature(AwFeatures.WEBVIEW_CONNECTIONLESS_SAFE_BROWSING,
......
......@@ -115,6 +115,11 @@ const base::Feature kUseX11Present{"UseX11Present",
base::FEATURE_DISABLED_BY_DEFAULT};
#endif
// Used to debug Android WebView Vulkan composite. Composite to an intermediate
// buffer and draw the intermediate buffer to the secondary command buffer.
const base::Feature kWebViewVulkanIntermediateBuffer{
"WebViewVulkanIntermediateBuffer", base::FEATURE_DISABLED_BY_DEFAULT};
bool IsOverlayPrioritizationEnabled() {
return base::FeatureList::IsEnabled(kEnableOverlayPrioritization);
}
......
......@@ -36,6 +36,7 @@ VIZ_COMMON_EXPORT extern const base::Feature kUseSetPresentDuration;
#if defined(USE_X11)
VIZ_COMMON_EXPORT extern const base::Feature kUseX11Present;
#endif
VIZ_COMMON_EXPORT extern const base::Feature kWebViewVulkanIntermediateBuffer;
VIZ_COMMON_EXPORT bool IsForcePreferredIntervalForVideoEnabled();
VIZ_COMMON_EXPORT bool IsVizHitTestingDebugEnabled();
......
......@@ -433,12 +433,19 @@ viz_source_set("gpu_service_dependencies") {
sources += [
"display_embedder/skia_output_device_vulkan.cc",
"display_embedder/skia_output_device_vulkan.h",
"display_embedder/skia_output_device_vulkan_secondary_cb.cc",
"display_embedder/skia_output_device_vulkan_secondary_cb.h",
]
public_deps += [ "//gpu/vulkan" ]
if (is_android) {
sources += [
"display_embedder/skia_output_device_vulkan_secondary_cb.cc",
"display_embedder/skia_output_device_vulkan_secondary_cb.h",
"display_embedder/skia_output_device_vulkan_secondary_cb_offscreen.cc",
"display_embedder/skia_output_device_vulkan_secondary_cb_offscreen.h",
]
}
if (use_x11 || ozone_platform_x11) {
sources += [
"display_embedder/output_presenter_x11.cc",
......
......@@ -48,13 +48,13 @@ class SkiaOutputDeviceOffscreen : public SkiaOutputDevice {
sk_sp<SkSurface> sk_surface_;
GrBackendTexture backend_texture_;
bool supports_rgbx_ = true;
private:
gfx::Size size_;
gfx::BufferFormat format_ = gfx::BufferFormat::RGBA_8888;
uint64_t backbuffer_estimated_size_ = 0;
sk_sp<SkColorSpace> sk_color_space_;
private:
uint64_t backbuffer_estimated_size_ = 0;
DISALLOW_COPY_AND_ASSIGN(SkiaOutputDeviceOffscreen);
};
......
// Copyright 2021 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.
#include "components/viz/service/display_embedder/skia_output_device_vulkan_secondary_cb_offscreen.h"
#include <utility>
#include "components/viz/common/gpu/vulkan_context_provider.h"
#include "gpu/command_buffer/service/skia_utils.h"
#include "gpu/vulkan/vulkan_device_queue.h"
#include "gpu/vulkan/vulkan_function_pointers.h"
#include "skia/ext/legacy_display_globals.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkColor.h"
#include "third_party/skia/include/core/SkDeferredDisplayList.h"
#include "third_party/skia/include/core/SkSurface.h"
#include "third_party/skia/include/core/SkSurfaceCharacterization.h"
#include "third_party/skia/include/gpu/GrBackendSurface.h"
#include "third_party/skia/include/gpu/GrDirectContext.h"
#include "third_party/skia/src/gpu/vk/GrVkSecondaryCBDrawContext.h"
#include "ui/gfx/presentation_feedback.h"
#include "ui/gfx/swap_result.h"
namespace viz {
SkiaOutputDeviceVulkanSecondaryCBOffscreen::
SkiaOutputDeviceVulkanSecondaryCBOffscreen(
scoped_refptr<gpu::SharedContextState> context_state,
gpu::MemoryTracker* memory_tracker,
DidSwapBufferCompleteCallback did_swap_buffer_complete_callback)
: SkiaOutputDeviceOffscreen(std::move(context_state),
gfx::SurfaceOrigin::kTopLeft,
/*has_alpha=*/true,
memory_tracker,
std::move(did_swap_buffer_complete_callback)) {
DCHECK(context_state_->vk_context_provider());
capabilities_.max_frames_pending = 1;
capabilities_.preserve_buffer_content = false;
capabilities_.supports_post_sub_buffer = false;
}
SkiaOutputDeviceVulkanSecondaryCBOffscreen::
~SkiaOutputDeviceVulkanSecondaryCBOffscreen() = default;
SkSurface* SkiaOutputDeviceVulkanSecondaryCBOffscreen::BeginPaint(
std::vector<GrBackendSemaphore>* end_semaphores) {
SkSurface* sk_surface = SkiaOutputDeviceOffscreen::BeginPaint(end_semaphores);
sk_surface->getCanvas()->clear(SK_ColorTRANSPARENT);
return sk_surface;
}
void SkiaOutputDeviceVulkanSecondaryCBOffscreen::SwapBuffers(
BufferPresentedCallback feedback,
std::vector<ui::LatencyInfo> latency_info) {
StartSwapBuffers(std::move(feedback));
auto format_index = static_cast<int>(format_);
const auto& sk_color_type = capabilities_.sk_color_types[format_index];
DCHECK(sk_color_type != kUnknown_SkColorType)
<< "SkColorType is invalid for format: " << format_index;
sk_sp<SkImage> sk_image = SkImage::MakeFromTexture(
context_state_->vk_context_provider()->GetGrContext(), backend_texture_,
kTopLeft_GrSurfaceOrigin, sk_color_type, kPremul_SkAlphaType,
sk_color_space_);
gfx::SwapResult result = gfx::SwapResult::SWAP_ACK;
if (sk_image) {
SkPaint paint;
paint.setBlendMode(SkBlendMode::kSrcOver);
context_state_->vk_context_provider()
->GetGrSecondaryCBDrawContext()
->getCanvas()
->drawImage(sk_image, 0, 0, &paint);
context_state_->vk_context_provider()
->GetGrSecondaryCBDrawContext()
->flush();
} else {
result = gfx::SwapResult::SWAP_FAILED;
}
FinishSwapBuffers(gfx::SwapCompletionResult(result),
gfx::Size(size_.width(), size_.height()),
std::move(latency_info));
}
} // namespace viz
// Copyright 2021 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 COMPONENTS_VIZ_SERVICE_DISPLAY_EMBEDDER_SKIA_OUTPUT_DEVICE_VULKAN_SECONDARY_CB_OFFSCREEN_H_
#define COMPONENTS_VIZ_SERVICE_DISPLAY_EMBEDDER_SKIA_OUTPUT_DEVICE_VULKAN_SECONDARY_CB_OFFSCREEN_H_
#include <vector>
#include "components/viz/service/display_embedder/skia_output_device_offscreen.h"
#include "gpu/command_buffer/service/shared_context_state.h"
namespace viz {
// Draw into an offscreen buffer which is then drawn to into the secondary
// command buffer. This is meant to for debugging direct compositing with
// secondary command buffers.
class SkiaOutputDeviceVulkanSecondaryCBOffscreen final
: public SkiaOutputDeviceOffscreen {
public:
SkiaOutputDeviceVulkanSecondaryCBOffscreen(
scoped_refptr<gpu::SharedContextState> context_state,
gpu::MemoryTracker* memory_tracker,
DidSwapBufferCompleteCallback did_swap_buffer_complete_callback);
~SkiaOutputDeviceVulkanSecondaryCBOffscreen() override;
SkSurface* BeginPaint(
std::vector<GrBackendSemaphore>* end_semaphores) override;
void SwapBuffers(BufferPresentedCallback feedback,
std::vector<ui::LatencyInfo> latency_info) override;
};
} // namespace viz
#endif // COMPONENTS_VIZ_SERVICE_DISPLAY_EMBEDDER_SKIA_OUTPUT_DEVICE_VULKAN_SECONDARY_CB_OFFSCREEN_H_
......@@ -50,8 +50,11 @@
#if BUILDFLAG(ENABLE_VULKAN)
#include "components/viz/service/display_embedder/skia_output_device_vulkan.h"
#include "components/viz/service/display_embedder/skia_output_device_vulkan_secondary_cb.h"
#include "gpu/vulkan/vulkan_util.h"
#if defined(OS_ANDROID)
#include "components/viz/service/display_embedder/skia_output_device_vulkan_secondary_cb.h"
#include "components/viz/service/display_embedder/skia_output_device_vulkan_secondary_cb_offscreen.h"
#endif
#endif
#if (BUILDFLAG(ENABLE_VULKAN) || BUILDFLAG(SKIA_USE_DAWN)) && defined(USE_X11)
......@@ -1249,12 +1252,22 @@ bool SkiaOutputSurfaceImplOnGpu::InitializeForVulkan() {
#endif // !defined(OS_WIN)
(void)needs_background_image;
#if defined(OS_ANDROID)
if (vulkan_context_provider_->GetGrSecondaryCBDrawContext()) {
output_device_ = std::make_unique<SkiaOutputDeviceVulkanSecondaryCB>(
vulkan_context_provider_, shared_gpu_deps_->memory_tracker(),
GetDidSwapBuffersCompleteCallback());
if (base::FeatureList::IsEnabled(
features::kWebViewVulkanIntermediateBuffer)) {
output_device_ =
std::make_unique<SkiaOutputDeviceVulkanSecondaryCBOffscreen>(
context_state_, shared_gpu_deps_->memory_tracker(),
GetDidSwapBuffersCompleteCallback());
} else {
output_device_ = std::make_unique<SkiaOutputDeviceVulkanSecondaryCB>(
vulkan_context_provider_, shared_gpu_deps_->memory_tracker(),
GetDidSwapBuffersCompleteCallback());
}
return true;
}
#endif
#if defined(USE_X11)
if (!features::IsUsingOzonePlatform()) {
......
......@@ -42142,6 +42142,7 @@ from previous Chrome versions.
<int value="-2105133782" label="GesturePropertiesDBusService:enabled"/>
<int value="-2104950596" label="HandwritingGesture:enabled"/>
<int value="-2104654357" label="GamesHub:enabled"/>
<int value="-2102286055" label="WebViewVulkanIntermediateBuffer:disabled"/>
<int value="-2101682955" label="EnableNotificationIndicator:enabled"/>
<int value="-2101337189" label="AutofillOffNoServerData:disabled"/>
<int value="-2099486626" label="DownloadLater:enabled"/>
......@@ -43579,6 +43580,7 @@ from previous Chrome versions.
<int value="-810684526"
label="AutofillToolkitViewsCreditCardDialogsMac:disabled"/>
<int value="-810110236" label="EditPasswordsInSettings:enabled"/>
<int value="-809456392" label="WebViewVulkanIntermediateBuffer:enabled"/>
<int value="-808486493" label="NewWallpaperPicker:disabled"/>
<int value="-806549905"
label="TabbedAppOverflowMenuThreeButtonActionbar:disabled"/>
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