Commit 3fd29830 authored by Christopher Grant's avatar Christopher Grant Committed by Commit Bot

VR: Add UI module instantiation support

This change adds the plumbing necessary to create a UI using a future native
feature module library.  The code is currently behind a define, which will
become a feature flag.

Bug=

Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;luci.chromium.try:linux_optional_gpu_tests_rel;luci.chromium.try:linux_vr;luci.chromium.try:mac_optional_gpu_tests_rel;luci.chromium.try:win_optional_gpu_tests_rel
Change-Id: I8f71a78f980bda790517d0bd7c41ed091ce66c52
Reviewed-on: https://chromium-review.googlesource.com/1181924Reviewed-by: default avatarAldo Culquicondor <acondor@chromium.org>
Reviewed-by: default avatarIan Vollick <vollick@chromium.org>
Commit-Queue: Christopher Grant <cjgrant@chromium.org>
Cr-Commit-Position: refs/heads/master@{#584751}
parent 765a0cef
......@@ -38,6 +38,7 @@ RenderLoopFactory::Params::~Params() = default;
std::unique_ptr<VrShellGl> RenderLoopFactory::Create(
VrGLThread* vr_gl_thread,
UiFactory* ui_factory,
std::unique_ptr<Params> params) {
DCHECK(params);
auto keyboard_delegate = GvrKeyboardDelegate::Create();
......@@ -50,7 +51,7 @@ std::unique_ptr<VrShellGl> RenderLoopFactory::Create(
base::Unretained(keyboard_delegate.get())));
}
auto audio_delegate = std::make_unique<SoundsManagerAudioDelegate>();
auto ui = UiFactory::Create(
auto ui = ui_factory->Create(
vr_gl_thread, vr_gl_thread, std::move(keyboard_delegate),
std::move(text_input_delegate), std::move(audio_delegate),
params->ui_initial_state);
......
......@@ -22,6 +22,7 @@ class WaitableEvent;
namespace vr {
class UiFactory;
class VrGLThread;
class VrShellGl;
......@@ -49,6 +50,7 @@ class VR_EXPORT RenderLoopFactory {
// TODO(acondor): Build an instance of RenderLoop owning VrShellGl.
static std::unique_ptr<VrShellGl> Create(VrGLThread* vr_gl_thread,
UiFactory* ui_factory,
std::unique_ptr<Params> params);
};
......
......@@ -63,7 +63,9 @@ void VrGLThread::SetInputConnection(VrInputConnection* input_connection) {
}
void VrGLThread::Init() {
vr_shell_gl_ = RenderLoopFactory::Create(this, std::move(factory_params_));
ui_factory_ = std::make_unique<UiFactory>();
vr_shell_gl_ = RenderLoopFactory::Create(this, ui_factory_.get(),
std::move(factory_params_));
weak_browser_ui_ = vr_shell_gl_->GetBrowserUiWeakPtr();
}
......
......@@ -169,6 +169,7 @@ class VrGLThread : public base::android::JavaHandlerThread,
scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_;
// Created on GL thread.
std::unique_ptr<UiFactory> ui_factory_;
std::unique_ptr<VrShellGl> vr_shell_gl_;
std::unique_ptr<gvr::GvrApi> gvr_api_;
......
......@@ -830,4 +830,21 @@ Ui::FovRectangle Ui::GetMinimalFov(
top_degrees};
}
#if defined(FEATURE_MODULES)
extern "C" {
Ui* CreateUi(UiBrowserInterface* browser,
PlatformInputHandler* content_input_forwarder,
std::unique_ptr<KeyboardDelegate> keyboard_delegate,
std::unique_ptr<TextInputDelegate> text_input_delegate,
std::unique_ptr<AudioDelegate> audio_delegate,
const UiInitialState& ui_initial_state) {
return new Ui(browser, content_input_forwarder, std::move(keyboard_delegate),
std::move(text_input_delegate), std::move(audio_delegate),
ui_initial_state);
}
}
#endif // defined(FEATURE_MODULES)
} // namespace vr
......@@ -230,6 +230,33 @@ class VR_UI_EXPORT Ui : public UiInterface {
DISALLOW_COPY_AND_ASSIGN(Ui);
};
#if defined(FEATURE_MODULES)
extern "C" {
// The factory function obtained from the UI module library via dlsym() when
// preparing to instantiate a UI instance.
VR_UI_EXPORT Ui* CreateUi(
UiBrowserInterface* browser,
PlatformInputHandler* content_input_forwarder,
std::unique_ptr<KeyboardDelegate> keyboard_delegate,
std::unique_ptr<TextInputDelegate> text_input_delegate,
std::unique_ptr<AudioDelegate> audio_delegate,
const UiInitialState& ui_initial_state);
}
// After obtaining a void pointer to CreateUi() via dlsym, the resulting pointer
// should be cast to this type. Hence, the arguments to this type must exactly
// match the method above.
typedef Ui* CreateUiFunction(
UiBrowserInterface* browser,
PlatformInputHandler* content_input_forwarder,
std::unique_ptr<KeyboardDelegate> keyboard_delegate,
std::unique_ptr<TextInputDelegate> text_input_delegate,
std::unique_ptr<AudioDelegate> audio_delegate,
const UiInitialState& ui_initial_state);
#endif // defined(FEATURE_MODULES)
} // namespace vr
#endif // CHROME_BROWSER_VR_UI_H_
......@@ -6,14 +6,27 @@
#include <utility>
#include "base/memory/ptr_util.h"
#include "chrome/browser/vr/audio_delegate.h"
#include "chrome/browser/vr/content_input_delegate.h"
#include "chrome/browser/vr/keyboard_delegate.h"
#include "chrome/browser/vr/text_input_delegate.h"
#include "chrome/browser/vr/ui.h"
#if defined(FEATURE_MODULES)
#include <dlfcn.h>
#endif
namespace vr {
UiFactory::~UiFactory() {
#if defined(FEATURE_MODULES)
if (ui_library_handle_ != nullptr) {
dlclose(ui_library_handle_);
}
#endif // defined(FEATURE_MODULES)
}
std::unique_ptr<UiInterface> UiFactory::Create(
UiBrowserInterface* browser,
PlatformInputHandler* content_input_forwarder,
......@@ -21,10 +34,34 @@ std::unique_ptr<UiInterface> UiFactory::Create(
std::unique_ptr<TextInputDelegate> text_input_delegate,
std::unique_ptr<AudioDelegate> audio_delegate,
const UiInitialState& ui_initial_state) {
#if defined(FEATURE_MODULES)
DCHECK(ui_library_handle_ == nullptr);
// TODO(http://crbug.com/874584): Rather than attempting to open two different
// libraries, either package the library under a unified name, or run code
// conditionally based on whether we're monochrome or not.
ui_library_handle_ = dlopen("libvr_ui.so", RTLD_LOCAL | RTLD_NOW);
if (!ui_library_handle_) {
ui_library_handle_ =
dlopen("libvr_ui_monochrome.so", RTLD_LOCAL | RTLD_NOW);
}
CHECK(ui_library_handle_ != nullptr)
<< "Could not open VR UI library:" << dlerror();
CreateUiFunction* create_ui = reinterpret_cast<CreateUiFunction*>(
dlsym(ui_library_handle_, "CreateUi"));
CHECK(create_ui != nullptr) << "Could not obtain UI creation method";
return base::WrapUnique(
create_ui(browser, content_input_forwarder, std::move(keyboard_delegate),
std::move(text_input_delegate), std::move(audio_delegate),
ui_initial_state));
#else
return std::make_unique<Ui>(browser, content_input_forwarder,
std::move(keyboard_delegate),
std::move(text_input_delegate),
std::move(audio_delegate), ui_initial_state);
#endif // defined(FEATURE_MODULES)
}
} // namespace vr
......@@ -21,13 +21,20 @@ struct UiInitialState;
class VR_EXPORT UiFactory {
public:
static std::unique_ptr<UiInterface> Create(
~UiFactory();
std::unique_ptr<UiInterface> Create(
UiBrowserInterface* browser,
PlatformInputHandler* content_input_forwarder,
std::unique_ptr<KeyboardDelegate> keyboard_delegate,
std::unique_ptr<TextInputDelegate> text_input_delegate,
std::unique_ptr<AudioDelegate> audio_delegate,
const UiInitialState& ui_initial_state);
private:
#if defined(FEATURE_MODULES)
void* ui_library_handle_ = nullptr;
#endif
};
} // namespace vr
......
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