[go: up one dir, main page]

[M96] aw: Ignore vulkan draw to R8 framebuffer

Android HWUI has a bug in a feature unrelated to webview that can ask
webview draw functor to draw to a R8 framebuffer (for a second time in a
frame). Ideal fix is android not call draw functor at all. However the
bug is already shipped.

For vulkan, check the supplied VkFormat for R8 and just skip that draw
and the subsequent post draw. Guard it with sdk level == 31.

(cherry picked from commit a2ec5a490d5af411738e7bd7415749bffc3cca60)

Bug: 1268900
Change-Id: Ifc5e65a344770495d2e74ab9f5fa46dde6427cd8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3270644
Reviewed-by: Vasiliy Telezhnikov <vasilyt@chromium.org>
Commit-Queue: Bo <boliu@chromium.org>
Cr-Original-Commit-Position: refs/heads/main@{#940455}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3312018
Commit-Queue: Bo Liu <boliu@chromium.org>
Cr-Commit-Position: refs/branch-heads/4664@{#1200}
Cr-Branched-From: 24dc4ee75e01a29d390d43c9c264372a169273a7-refs/heads/main@{#929512}
diff --git a/android_webview/browser/gfx/aw_draw_fn_impl.cc b/android_webview/browser/gfx/aw_draw_fn_impl.cc
index 60add3fb..44cff03 100644
--- a/android_webview/browser/gfx/aw_draw_fn_impl.cc
+++ b/android_webview/browser/gfx/aw_draw_fn_impl.cc
@@ -8,6 +8,7 @@
 
 #include "android_webview/browser/gfx/aw_vulkan_context_provider.h"
 #include "android_webview/browser_jni_headers/AwDrawFnImpl_jni.h"
+#include "base/android/build_info.h"
 #include "base/trace_event/trace_event.h"
 #include "content/public/browser/browser_task_traits.h"
 #include "content/public/browser/browser_thread.h"
@@ -279,6 +280,17 @@
   if (!vulkan_context_provider_)
     return;
 
+  // Android HWUI has a bug that asks functor to draw into a 8-bit mask for
+  // functionality that is not related to and not needed by webview.
+  // GrVkSecondaryCBDrawContext currently does not expect or support R8 format
+  // so just skip these draw calls before Android side is fixed.
+  if (params->format == VK_FORMAT_R8_UNORM &&
+      base::android::BuildInfo::GetInstance()->sdk_int() ==
+          base::android::SDK_VERSION_S) {
+    skip_next_post_draw_vk_ = true;
+    return;
+  }
+
   auto color_space = CreateColorSpace(params);
   if (!color_space) {
     // If we weren't passed a valid colorspace, default to sRGB.
@@ -306,6 +318,11 @@
   if (!vulkan_context_provider_)
     return;
 
+  if (skip_next_post_draw_vk_) {
+    skip_next_post_draw_vk_ = false;
+    return;
+  }
+
   if (is_interop_mode_) {
     DCHECK(interop_);
     interop_->PostDrawVk();
diff --git a/android_webview/browser/gfx/aw_draw_fn_impl.h b/android_webview/browser/gfx/aw_draw_fn_impl.h
index 699fc8e6..9a6f8a5 100644
--- a/android_webview/browser/gfx/aw_draw_fn_impl.h
+++ b/android_webview/browser/gfx/aw_draw_fn_impl.h
@@ -71,6 +71,8 @@
       scoped_secondary_cb_draw_;
 
   absl::optional<VulkanGLInterop> interop_;
+
+  bool skip_next_post_draw_vk_ = false;
 };
 
 }  // namespace android_webview