diff options
author | Chris Blume <cblume@google.com> | 2018-11-06 11:47:03 -0800 |
---|---|---|
committer | Chris Blume <cblume@google.com> | 2018-12-05 16:26:59 -0800 |
commit | 414233938102e90b2e1ec05d823e3b25a3fa3219 (patch) | |
tree | f8317116d64260271afd87f9f584ddeb6c976109 /native/webview | |
parent | fdb30ae286ea2dd7435e12d64c09009c39e149ac (diff) |
Add non-interop Vulkan functor
An interop Vulkan functor already exists. It will call the OpenGL
functor and use AHardwareBuffer to translate the OpenGL textures into
something which can be used in Vulkan.
This CL adds the frameworks for a non-interop Vulkan functor. This
functor is not yet complete (and as a result cannot yet be tested). This
is just setting the stage for future work.
Test: This is dead code and cannot yet be tested.
BUG=115613038
Change-Id: I2b87c86cb511abb961c31c17c2fbbc085b07ca4a
Diffstat (limited to 'native/webview')
-rw-r--r-- | native/webview/plat_support/Android.bp | 3 | ||||
-rw-r--r-- | native/webview/plat_support/draw_gl_functor.cpp | 27 | ||||
-rw-r--r-- | native/webview/plat_support/draw_vk.h | 125 | ||||
-rw-r--r-- | native/webview/plat_support/draw_vk_functor.cpp | 141 | ||||
-rw-r--r-- | native/webview/plat_support/functor_utils.cpp | 45 | ||||
-rw-r--r-- | native/webview/plat_support/functor_utils.h | 25 |
6 files changed, 341 insertions, 25 deletions
diff --git a/native/webview/plat_support/Android.bp b/native/webview/plat_support/Android.bp index d8c5ac969128..96c9c1c85a60 100644 --- a/native/webview/plat_support/Android.bp +++ b/native/webview/plat_support/Android.bp @@ -23,6 +23,8 @@ cc_library_shared { srcs: [ "draw_gl_functor.cpp", + "draw_vk_functor.cpp", + "functor_utils.cpp", "jni_entry_point.cpp", "graphics_utils.cpp", "graphic_buffer_impl.cpp", @@ -36,6 +38,7 @@ cc_library_shared { "liblog", "libui", "libutils", + "libvulkan", ], // To remove warnings from skia header files diff --git a/native/webview/plat_support/draw_gl_functor.cpp b/native/webview/plat_support/draw_gl_functor.cpp index e3e52b1ea1f1..be36b6742037 100644 --- a/native/webview/plat_support/draw_gl_functor.cpp +++ b/native/webview/plat_support/draw_gl_functor.cpp @@ -21,15 +21,13 @@ #include "draw_gl.h" -#include <errno.h> #include <jni.h> #include <private/hwui/DrawGlInfo.h> -#include <string.h> -#include <sys/resource.h> -#include <sys/time.h> #include <utils/Functor.h> #include <utils/Log.h> +#include "functor_utils.h" + #define NELEM(x) ((int) (sizeof(x) / sizeof((x)[0]))) #define COMPILE_ASSERT(expr, err) \ __unused static const char (err)[(expr) ? 1 : -1] = ""; @@ -98,27 +96,6 @@ class DrawGLFunctor : public Functor { intptr_t view_context_; }; -// Raise the file handle soft limit to the hard limit since gralloc buffers -// uses file handles. -void RaiseFileNumberLimit() { - static bool have_raised_limit = false; - if (have_raised_limit) - return; - - have_raised_limit = true; - struct rlimit limit_struct; - limit_struct.rlim_cur = 0; - limit_struct.rlim_max = 0; - if (getrlimit(RLIMIT_NOFILE, &limit_struct) == 0) { - limit_struct.rlim_cur = limit_struct.rlim_max; - if (setrlimit(RLIMIT_NOFILE, &limit_struct) != 0) { - ALOGE("setrlimit failed: %s", strerror(errno)); - } - } else { - ALOGE("getrlimit failed: %s", strerror(errno)); - } -} - jlong CreateGLFunctor(JNIEnv*, jclass, jlong view_context) { RaiseFileNumberLimit(); return reinterpret_cast<jlong>(new DrawGLFunctor(view_context)); diff --git a/native/webview/plat_support/draw_vk.h b/native/webview/plat_support/draw_vk.h new file mode 100644 index 000000000000..6b7d8d0b9118 --- /dev/null +++ b/native/webview/plat_support/draw_vk.h @@ -0,0 +1,125 @@ +// Copyright 2018 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. +// +//****************************************************************************** +// This is a copy of the coresponding android_webview/public/browser header. +// Any changes to the interface should be made there. +// +// The purpose of having the copy is twofold: +// - it removes the need to have Chromium sources present in the tree in order +// to build the plat_support library, +// - it captures API that the corresponding Android release supports. +//****************************************************************************** + +#ifndef ANDROID_WEBVIEW_PUBLIC_BROWSER_DRAW_VK_H_ +#define ANDROID_WEBVIEW_PUBLIC_BROWSER_DRAW_VK_H_ + +#include <vulkan/vulkan.h> + +#ifdef __cplusplus +extern "C" { +#endif + +static const int kAwDrawVKInfoVersion = 1; + +// Holds the information required to trigger initialization of the Vulkan +// functor. +struct InitParams { + // All params are input + VkInstance instance; + VkPhysicalDevice physical_device; + VkDevice device; + VkQueue queue; + uint32_t graphics_queue_index; + uint32_t instance_version; + const char* const* enabled_extension_names; + // Only one of device_features and device_features_2 should be non-null. + // If both are null then no features are enabled. + VkPhysicalDeviceFeatures* device_features; + VkPhysicalDeviceFeatures2* device_features_2; +}; + +// Holds the information required to trigger an Vulkan composite operation. +struct CompositeParams { + // Input: current width/height of destination surface. + int width; + int height; + + // Input: is the render target a FBO + bool is_layer; + + // Input: current transform matrix + float transform[16]; + + // Input WebView should do its main compositing draws into this. It cannot do + // anything that would require stopping the render pass. + VkCommandBuffer secondary_command_buffer; + + // Input: The main color attachment index where secondary_command_buffer will + // eventually be submitted. + uint32_t color_attachment_index; + + // Input: A render pass which will be compatible to the one which the + // secondary_command_buffer will be submitted into. + VkRenderPass compatible_render_pass; + + // Input: Format of the destination surface. + VkFormat format; + + // Input: Color space transfer params + float G; + float A; + float B; + float C; + float D; + float E; + float F; + + // Input: Color space transformation from linear RGB to D50-adapted XYZ + float matrix[9]; + + // Input: current clip rect + int clip_left; + int clip_top; + int clip_right; + int clip_bottom; +}; + +// Holds the information for the post-submission callback of main composite +// draw. +struct PostCompositeParams { + // Input: Fence for the composite command buffer to signal it has finished its + // work on the GPU. + int fd; +}; + +// Holds the information required to trigger an Vulkan operation. +struct AwDrawVKInfo { + int version; // The AwDrawVKInfo this struct was built with. + + // Input: tells the draw function what action to perform. + enum Mode { + kModeInit = 0, + kModeReInit = 1, + kModePreComposite = 2, + kModeComposite = 3, + kModePostComposite = 4, + kModeSync = 5, + } mode; + + // Input: The parameters for the functor being called + union ParamUnion { + struct InitParams init_params; + struct CompositeParams composite_params; + struct PostCompositeParams post_composite_params; + } info; +}; + +typedef void(AwDrawVKFunction)(long view_context, AwDrawVKInfo* draw_info); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // ANDROID_WEBVIEW_PUBLIC_BROWSER_DRAW_VK_H_ diff --git a/native/webview/plat_support/draw_vk_functor.cpp b/native/webview/plat_support/draw_vk_functor.cpp new file mode 100644 index 000000000000..1ba559d9afdf --- /dev/null +++ b/native/webview/plat_support/draw_vk_functor.cpp @@ -0,0 +1,141 @@ +/* + * Copyright (C) 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Provides a webviewchromium glue layer adapter from the internal Android +// Vulkan Functor data types into the types the chromium stack expects, and +// back. + +#define LOG_TAG "webviewchromium_plat_support" + +#include "draw_vk.h" + +#include <jni.h> +#include <private/hwui/DrawVkInfo.h> +#include <utils/Functor.h> +#include <utils/Log.h> + +#include "functor_utils.h" + +#define NELEM(x) ((int) (sizeof(x) / sizeof((x)[0]))) + +namespace android { +namespace { + +AwDrawVKFunction* g_aw_drawvk_function = NULL; + +class DrawVKFunctor : public Functor { + public: + explicit DrawVKFunctor(jlong view_context) : view_context_(view_context) {} + ~DrawVKFunctor() override {} + + // Functor + status_t operator ()(int what, void* data) override { + using uirenderer::DrawVkInfo; + if (!g_aw_drawvk_function) { + ALOGE("Cannot draw: no DrawVK Function installed"); + return DrawVkInfo::kStatusDone; + } + + AwDrawVKInfo aw_info; + aw_info.version = kAwDrawVKInfoVersion; + switch (what) { + case DrawVkInfo::kModeComposite: { + aw_info.mode = AwDrawVKInfo::kModeComposite; + DrawVkInfo* vk_info = reinterpret_cast<DrawVkInfo*>(data); + + // Map across the input values. + CompositeParams& params = aw_info.info.composite_params; + params.width = vk_info->width; + params.height = vk_info->height; + params.is_layer = vk_info->isLayer; + for (size_t i = 0; i < 16; i++) { + params.transform[i] = vk_info->transform[i]; + } + params.secondary_command_buffer = vk_info->secondaryCommandBuffer; + params.color_attachment_index = vk_info->colorAttachmentIndex; + params.compatible_render_pass = vk_info->compatibleRenderPass; + params.format = vk_info->format; + params.G = vk_info->G; + params.A = vk_info->A; + params.B = vk_info->B; + params.C = vk_info->C; + params.D = vk_info->D; + params.E = vk_info->E; + params.F = vk_info->F; + for (size_t i = 0; i < 9; i++) { + params.matrix[i] = vk_info->matrix[i]; + } + params.clip_left = vk_info->clipLeft; + params.clip_top = vk_info->clipTop; + params.clip_right = vk_info->clipRight; + params.clip_bottom = vk_info->clipBottom; + + break; + } + case DrawVkInfo::kModePostComposite: + break; + case DrawVkInfo::kModeSync: + aw_info.mode = AwDrawVKInfo::kModeSync; + break; + default: + ALOGE("Unexpected DrawVKInfo type %d", what); + return DrawVkInfo::kStatusDone; + } + + // Invoke the DrawVK method. + g_aw_drawvk_function(view_context_, &aw_info); + + return DrawVkInfo::kStatusDone; + } + + private: + intptr_t view_context_; +}; + +jlong CreateVKFunctor(JNIEnv*, jclass, jlong view_context) { + RaiseFileNumberLimit(); + return reinterpret_cast<jlong>(new DrawVKFunctor(view_context)); +} + +void DestroyVKFunctor(JNIEnv*, jclass, jlong functor) { + delete reinterpret_cast<DrawVKFunctor*>(functor); +} + +void SetChromiumAwDrawVKFunction(JNIEnv*, jclass, jlong draw_function) { + g_aw_drawvk_function = reinterpret_cast<AwDrawVKFunction*>(draw_function); +} + +const char kClassName[] = "com/android/webview/chromium/DrawVKFunctor"; +const JNINativeMethod kJniMethods[] = { + { "nativeCreateVKFunctor", "(J)J", + reinterpret_cast<void*>(CreateVKFunctor) }, + { "nativeDestroyVKFunctor", "(J)V", + reinterpret_cast<void*>(DestroyVKFunctor) }, + { "nativeSetChromiumAwDrawVKFunction", "(J)V", + reinterpret_cast<void*>(SetChromiumAwDrawVKFunction) }, +}; + +} // namespace + +void RegisterDrawVKFunctor(JNIEnv* env) { + jclass clazz = env->FindClass(kClassName); + LOG_ALWAYS_FATAL_IF(!clazz, "Unable to find class '%s'", kClassName); + + int res = env->RegisterNatives(clazz, kJniMethods, NELEM(kJniMethods)); + LOG_ALWAYS_FATAL_IF(res < 0, "register native methods failed: res=%d", res); +} + +} // namespace android diff --git a/native/webview/plat_support/functor_utils.cpp b/native/webview/plat_support/functor_utils.cpp new file mode 100644 index 000000000000..235762dc2679 --- /dev/null +++ b/native/webview/plat_support/functor_utils.cpp @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "functor_utils.h" + +#include <errno.h> +#include <string.h> +#include <sys/resource.h> +#include <utils/Log.h> + +namespace android { + +void RaiseFileNumberLimit() { + static bool have_raised_limit = false; + if (have_raised_limit) + return; + + have_raised_limit = true; + struct rlimit limit_struct; + limit_struct.rlim_cur = 0; + limit_struct.rlim_max = 0; + if (getrlimit(RLIMIT_NOFILE, &limit_struct) == 0) { + limit_struct.rlim_cur = limit_struct.rlim_max; + if (setrlimit(RLIMIT_NOFILE, &limit_struct) != 0) { + ALOGE("setrlimit failed: %s", strerror(errno)); + } + } else { + ALOGE("getrlimit failed: %s", strerror(errno)); + } +} + +} // namespace android diff --git a/native/webview/plat_support/functor_utils.h b/native/webview/plat_support/functor_utils.h new file mode 100644 index 000000000000..76c0bb67d275 --- /dev/null +++ b/native/webview/plat_support/functor_utils.h @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +namespace android { + +// Raise the file handle soft limit to the hard limit since gralloc buffers +// uses file handles. +void RaiseFileNumberLimit(); + +} // namespace android |