diff options
author | John Reck <jreck@google.com> | 2021-05-13 10:28:38 -0400 |
---|---|---|
committer | John Reck <jreck@google.com> | 2021-05-13 17:17:21 -0400 |
commit | faa1b0ab2a63993db5e2b8d1ab207190c9d55880 (patch) | |
tree | c909ebdbca8fa96157e3a9fd663d807b7918ed6e /libs/hwui/WebViewFunctorManager.cpp | |
parent | c49b886d7316354cede2b9510777882bc4c8598e (diff) |
Have HWUI validate the WebViewFunctors at registration
Also tweak how webview's plat_support creates the functor
sruct to be thread-safe, avoids any potential race conditions
even though WebView itself is stated to be thread-hostile in
general. It's too easy to have this just be defined-safe instead.
Bug: 186814981
Test: build & boot, no crashes in real-webview apps
Change-Id: I06f02a279e248fee375ce133c5ce9a2250665ad9
Diffstat (limited to 'libs/hwui/WebViewFunctorManager.cpp')
-rw-r--r-- | libs/hwui/WebViewFunctorManager.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/libs/hwui/WebViewFunctorManager.cpp b/libs/hwui/WebViewFunctorManager.cpp index 979678d1c4b6..d9b9e2456fff 100644 --- a/libs/hwui/WebViewFunctorManager.cpp +++ b/libs/hwui/WebViewFunctorManager.cpp @@ -221,8 +221,30 @@ WebViewFunctorManager& WebViewFunctorManager::instance() { return sInstance; } +static void validateCallbacks(const WebViewFunctorCallbacks& callbacks) { + // TODO: Should we do a stack peek to see if this is really webview? + LOG_ALWAYS_FATAL_IF(callbacks.onSync == nullptr, "onSync is null"); + LOG_ALWAYS_FATAL_IF(callbacks.onContextDestroyed == nullptr, "onContextDestroyed is null"); + LOG_ALWAYS_FATAL_IF(callbacks.onDestroyed == nullptr, "onDestroyed is null"); + LOG_ALWAYS_FATAL_IF(callbacks.removeOverlays == nullptr, "removeOverlays is null"); + switch (auto mode = WebViewFunctor_queryPlatformRenderMode()) { + case RenderMode::OpenGL_ES: + LOG_ALWAYS_FATAL_IF(callbacks.gles.draw == nullptr, "gles.draw is null"); + break; + case RenderMode::Vulkan: + LOG_ALWAYS_FATAL_IF(callbacks.vk.initialize == nullptr, "vk.initialize is null"); + LOG_ALWAYS_FATAL_IF(callbacks.vk.draw == nullptr, "vk.draw is null"); + LOG_ALWAYS_FATAL_IF(callbacks.vk.postDraw == nullptr, "vk.postDraw is null"); + break; + default: + LOG_ALWAYS_FATAL("unknown platform mode? %d", (int)mode); + break; + } +} + int WebViewFunctorManager::createFunctor(void* data, const WebViewFunctorCallbacks& callbacks, RenderMode functorMode) { + validateCallbacks(callbacks); auto object = std::make_unique<WebViewFunctor>(data, callbacks, functorMode); int id = object->id(); auto handle = object->createHandle(); |