Commit 173c0a14 authored by Aldo Culquicondor's avatar Aldo Culquicondor Committed by Commit Bot

VR: Add RenderLoopFactory for android

The RenderLoopFactory is responsible of instantiating the delegates
that Ui and RenderLoop require. In this CL, we are still instantiating
a VrShellGl object, as the split-up has not been completed yet. Also, we
make sure that the variables passed to VrGLThread are freed once the
RenderLoop has been built.

The testapp starts to be prepared to make use of RenderLoop. We simplify
the VrTestContext creation (soon to be the RenderLoop) by initializing it
once a GL context was set.

Bug=767282

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: Ie0f580f77fb109463dc41093919a7c535976e321
Reviewed-on: https://chromium-review.googlesource.com/1175852Reviewed-by: default avatarMichael Thiessen <mthiesse@chromium.org>
Commit-Queue: Aldo Culquicondor <acondor@chromium.org>
Cr-Commit-Position: refs/heads/master@{#583663}
parent 23375b76
...@@ -32,6 +32,8 @@ static_library("vr_android") { ...@@ -32,6 +32,8 @@ static_library("vr_android") {
"metrics_util_android.cc", "metrics_util_android.cc",
"metrics_util_android.h", "metrics_util_android.h",
"register_jni.h", "register_jni.h",
"render_loop_factory.cc",
"render_loop_factory.h",
"scoped_gpu_trace.cc", "scoped_gpu_trace.cc",
"scoped_gpu_trace.h", "scoped_gpu_trace.h",
"vr_controller.cc", "vr_controller.cc",
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <utility> #include <utility>
#include "chrome/browser/android/vr/gl_browser_interface.h" #include "chrome/browser/android/vr/gl_browser_interface.h"
#include "chrome/browser/android/vr/vr_controller.h"
#include "chrome/browser/vr/input_event.h" #include "chrome/browser/vr/input_event.h"
#include "chrome/browser/vr/model/controller_model.h" #include "chrome/browser/vr/model/controller_model.h"
#include "chrome/browser/vr/pose_util.h" #include "chrome/browser/vr/pose_util.h"
...@@ -18,10 +19,9 @@ constexpr gfx::Vector3dF kForwardVector = {0.0f, 0.0f, -1.0f}; ...@@ -18,10 +19,9 @@ constexpr gfx::Vector3dF kForwardVector = {0.0f, 0.0f, -1.0f};
namespace vr { namespace vr {
GvrControllerDelegate::GvrControllerDelegate( GvrControllerDelegate::GvrControllerDelegate(gvr::GvrApi* gvr_api,
std::unique_ptr<VrController> controller,
GlBrowserInterface* browser) GlBrowserInterface* browser)
: controller_(std::move(controller)), browser_(browser) {} : controller_(std::make_unique<VrController>(gvr_api)), browser_(browser) {}
GvrControllerDelegate::~GvrControllerDelegate() = default; GvrControllerDelegate::~GvrControllerDelegate() = default;
......
...@@ -11,6 +11,10 @@ ...@@ -11,6 +11,10 @@
#include "chrome/browser/android/vr/vr_controller.h" #include "chrome/browser/android/vr/vr_controller.h"
#include "chrome/browser/vr/controller_delegate.h" #include "chrome/browser/vr/controller_delegate.h"
namespace gvr {
class GvrApi;
}
namespace vr { namespace vr {
class GestureDetector; class GestureDetector;
...@@ -18,8 +22,7 @@ class GlBrowserInterface; ...@@ -18,8 +22,7 @@ class GlBrowserInterface;
class GvrControllerDelegate : public ControllerDelegate { class GvrControllerDelegate : public ControllerDelegate {
public: public:
GvrControllerDelegate(std::unique_ptr<VrController> controller, GvrControllerDelegate(gvr::GvrApi* gvr_api, GlBrowserInterface* browser);
GlBrowserInterface* browser);
~GvrControllerDelegate() override; ~GvrControllerDelegate() override;
// ControllerDelegate implementation. // ControllerDelegate implementation.
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#ifndef CHROME_BROWSER_ANDROID_VR_GVR_KEYBOARD_DELEGATE_H_ #ifndef CHROME_BROWSER_ANDROID_VR_GVR_KEYBOARD_DELEGATE_H_
#define CHROME_BROWSER_ANDROID_VR_GVR_KEYBOARD_DELEGATE_H_ #define CHROME_BROWSER_ANDROID_VR_GVR_KEYBOARD_DELEGATE_H_
#include <memory>
#include "base/callback.h" #include "base/callback.h"
#include "base/macros.h" #include "base/macros.h"
#include "chrome/browser/vr/keyboard_delegate.h" #include "chrome/browser/vr/keyboard_delegate.h"
...@@ -13,8 +15,6 @@ ...@@ -13,8 +15,6 @@
namespace vr { namespace vr {
struct TextInputInfo;
class GvrKeyboardDelegate : public KeyboardDelegate { class GvrKeyboardDelegate : public KeyboardDelegate {
public: public:
// Constructs a GvrKeyboardDelegate by dynamically loading the GVR keyboard // Constructs a GvrKeyboardDelegate by dynamically loading the GVR keyboard
...@@ -22,12 +22,11 @@ class GvrKeyboardDelegate : public KeyboardDelegate { ...@@ -22,12 +22,11 @@ class GvrKeyboardDelegate : public KeyboardDelegate {
static std::unique_ptr<GvrKeyboardDelegate> Create(); static std::unique_ptr<GvrKeyboardDelegate> Create();
~GvrKeyboardDelegate() override; ~GvrKeyboardDelegate() override;
void SetUiInterface(KeyboardUiInterface* ui);
typedef int32_t EventType; typedef int32_t EventType;
typedef base::RepeatingCallback<void(EventType)> OnEventCallback; typedef base::RepeatingCallback<void(EventType)> OnEventCallback;
// KeyboardDelegate implementation. // KeyboardDelegate implementation.
void SetUiInterface(KeyboardUiInterface* ui) override;
void OnBeginFrame() override; void OnBeginFrame() override;
void ShowKeyboard() override; void ShowKeyboard() override;
void HideKeyboard() override; void HideKeyboard() override;
...@@ -41,9 +40,8 @@ class GvrKeyboardDelegate : public KeyboardDelegate { ...@@ -41,9 +40,8 @@ class GvrKeyboardDelegate : public KeyboardDelegate {
bool SupportsSelection() override; bool SupportsSelection() override;
void OnButtonDown(const gfx::PointF& position) override; void OnButtonDown(const gfx::PointF& position) override;
void OnButtonUp(const gfx::PointF& position) override; void OnButtonUp(const gfx::PointF& position) override;
// Called to update GVR keyboard with the given text input info. // Called to update GVR keyboard with the given text input info.
void UpdateInput(const TextInputInfo& info); void UpdateInput(const TextInputInfo& info) override;
private: private:
GvrKeyboardDelegate(); GvrKeyboardDelegate();
......
// 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.
#include "chrome/browser/android/vr/render_loop_factory.h"
#include <utility>
#include "chrome/browser/android/vr/gvr_controller_delegate.h"
#include "chrome/browser/android/vr/gvr_keyboard_delegate.h"
#include "chrome/browser/android/vr/vr_gl_thread.h"
#include "chrome/browser/android/vr/vr_shell_gl.h"
#include "chrome/browser/vr/sounds_manager_audio_delegate.h"
#include "chrome/browser/vr/text_input_delegate.h"
#include "chrome/browser/vr/ui_factory.h"
namespace vr {
RenderLoopFactory::Params::Params(
gvr::GvrApi* gvr_api,
const UiInitialState& ui_initial_state,
bool reprojected_rendering,
bool daydream_support,
bool pause_content,
bool low_density,
base::WaitableEvent* gl_surface_created_event,
base::OnceCallback<gfx::AcceleratedWidget()> surface_callback)
: gvr_api(gvr_api),
ui_initial_state(ui_initial_state),
reprojected_rendering(reprojected_rendering),
daydream_support(daydream_support),
pause_content(pause_content),
low_density(low_density),
gl_surface_created_event(gl_surface_created_event),
surface_callback(std::move(surface_callback)) {}
RenderLoopFactory::Params::~Params() = default;
std::unique_ptr<VrShellGl> RenderLoopFactory::Create(
VrGLThread* vr_gl_thread,
std::unique_ptr<Params> params) {
DCHECK(params);
auto keyboard_delegate = GvrKeyboardDelegate::Create();
auto text_input_delegate = std::make_unique<TextInputDelegate>();
if (!keyboard_delegate) {
params->ui_initial_state.needs_keyboard_update = true;
} else {
text_input_delegate->SetUpdateInputCallback(
base::BindRepeating(&KeyboardDelegate::UpdateInput,
base::Unretained(keyboard_delegate.get())));
}
auto audio_delegate = std::make_unique<SoundsManagerAudioDelegate>();
auto ui = UiFactory::Create(
vr_gl_thread, vr_gl_thread, std::move(keyboard_delegate),
std::move(text_input_delegate), std::move(audio_delegate),
params->ui_initial_state);
auto controller_delegate =
std::make_unique<GvrControllerDelegate>(params->gvr_api, vr_gl_thread);
auto vr_shell_gl = std::make_unique<VrShellGl>(
vr_gl_thread, std::move(ui), std::move(controller_delegate),
params->gvr_api, params->reprojected_rendering, params->daydream_support,
params->ui_initial_state.in_web_vr, params->pause_content,
params->low_density);
vr_gl_thread->task_runner()->PostTask(
FROM_HERE,
base::BindOnce(&VrShellGl::Init, vr_shell_gl->GetWeakPtr(),
base::Unretained(params->gl_surface_created_event),
base::Passed(std::move(params->surface_callback))));
return vr_shell_gl;
}
} // namespace vr
// 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.
#ifndef CHROME_BROWSER_ANDROID_VR_RENDER_LOOP_FACTORY_H_
#define CHROME_BROWSER_ANDROID_VR_RENDER_LOOP_FACTORY_H_
#include <memory>
#include "base/callback.h"
#include "chrome/browser/vr/ui_initial_state.h"
#include "chrome/browser/vr/vr_export.h"
#include "ui/gfx/native_widget_types.h"
namespace gvr {
class GvrApi;
}
namespace base {
class WaitableEvent;
}
namespace vr {
class VrGLThread;
class VrShellGl;
class VR_EXPORT RenderLoopFactory {
public:
struct VR_EXPORT Params {
Params(gvr::GvrApi* gvr_api,
const UiInitialState& ui_initial_state,
bool reprojected_rendering,
bool daydream_support,
bool pause_content,
bool low_density,
base::WaitableEvent* gl_surface_created_event,
base::OnceCallback<gfx::AcceleratedWidget()> surface_callback);
~Params();
gvr::GvrApi* gvr_api;
UiInitialState ui_initial_state;
bool reprojected_rendering;
bool daydream_support;
bool pause_content;
bool low_density;
base::WaitableEvent* gl_surface_created_event;
base::OnceCallback<gfx::AcceleratedWidget()> surface_callback;
};
// TODO(acondor): Build an instance of RenderLoop owning VrShellGl.
static std::unique_ptr<VrShellGl> Create(VrGLThread* vr_gl_thread,
std::unique_ptr<Params> params);
};
} // namespace vr
#endif // CHROME_BROWSER_ANDROID_VR_RENDER_LOOP_FACTORY_H_
...@@ -52,13 +52,11 @@ gvr::ControllerButton PlatformToGvrButton(PlatformController::ButtonType type) { ...@@ -52,13 +52,11 @@ gvr::ControllerButton PlatformToGvrButton(PlatformController::ButtonType type) {
} // namespace } // namespace
VrController::VrController(gvr_context* gvr_context) VrController::VrController(gvr::GvrApi* gvr_api)
: previous_button_states_{0} { : gvr_api_(gvr_api), previous_button_states_{0} {
DVLOG(1) << __FUNCTION__ << "=" << this; DVLOG(1) << __FUNCTION__ << "=" << this;
CHECK(gvr_context != nullptr) << "invalid gvr_context";
controller_api_ = std::make_unique<gvr::ControllerApi>(); controller_api_ = std::make_unique<gvr::ControllerApi>();
controller_state_ = std::make_unique<gvr::ControllerState>(); controller_state_ = std::make_unique<gvr::ControllerState>();
gvr_api_ = gvr::GvrApi::WrapNonOwned(gvr_context);
int32_t options = gvr::ControllerApi::DefaultOptions(); int32_t options = gvr::ControllerApi::DefaultOptions();
...@@ -69,7 +67,7 @@ VrController::VrController(gvr_context* gvr_context) ...@@ -69,7 +67,7 @@ VrController::VrController(gvr_context* gvr_context)
options |= GVR_CONTROLLER_ENABLE_GYRO; options |= GVR_CONTROLLER_ENABLE_GYRO;
options |= GVR_CONTROLLER_ENABLE_ACCEL; options |= GVR_CONTROLLER_ENABLE_ACCEL;
CHECK(controller_api_->Init(options, gvr_context)); CHECK(controller_api_->Init(options, gvr_api_->cobj()));
controller_api_->Resume(); controller_api_->Resume();
handedness_ = gvr_api_->GetUserPrefs().GetControllerHandedness(); handedness_ = gvr_api_->GetUserPrefs().GetControllerHandedness();
......
...@@ -27,6 +27,7 @@ class Transform; ...@@ -27,6 +27,7 @@ class Transform;
namespace gvr { namespace gvr {
class ControllerState; class ControllerState;
class GvrApi;
} }
namespace vr { namespace vr {
...@@ -37,7 +38,7 @@ constexpr float kErgoAngleOffset = 0.26f; ...@@ -37,7 +38,7 @@ constexpr float kErgoAngleOffset = 0.26f;
class VrController : public PlatformController { class VrController : public PlatformController {
public: public:
// Controller API entry point. // Controller API entry point.
explicit VrController(gvr_context* gvr_context); explicit VrController(gvr::GvrApi* gvr_api);
~VrController() override; ~VrController() override;
// Must be called when the Activity gets OnResume(). // Must be called when the Activity gets OnResume().
...@@ -97,7 +98,7 @@ class VrController : public PlatformController { ...@@ -97,7 +98,7 @@ class VrController : public PlatformController {
// The last controller state (updated once per frame). // The last controller state (updated once per frame).
std::unique_ptr<gvr::ControllerState> controller_state_; std::unique_ptr<gvr::ControllerState> controller_state_;
std::unique_ptr<gvr::GvrApi> gvr_api_; gvr::GvrApi* gvr_api_;
std::unique_ptr<GestureDetector> gesture_detector_; std::unique_ptr<GestureDetector> gesture_detector_;
......
...@@ -27,25 +27,27 @@ namespace vr { ...@@ -27,25 +27,27 @@ namespace vr {
VrGLThread::VrGLThread( VrGLThread::VrGLThread(
const base::WeakPtr<VrShell>& weak_vr_shell, const base::WeakPtr<VrShell>& weak_vr_shell,
scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner, scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner,
base::WaitableEvent* gl_surface_created_event,
gvr_context* gvr_api, gvr_context* gvr_api,
const UiInitialState& ui_initial_state, const UiInitialState& ui_initial_state,
bool reprojected_rendering, bool reprojected_rendering,
bool daydream_support, bool daydream_support,
bool pause_content, bool pause_content,
bool low_density, bool low_density,
base::WaitableEvent* gl_surface_created_event,
base::OnceCallback<gfx::AcceleratedWidget()> surface_callback) base::OnceCallback<gfx::AcceleratedWidget()> surface_callback)
: base::android::JavaHandlerThread("VrShellGL"), : base::android::JavaHandlerThread("VrShellGL"),
weak_vr_shell_(weak_vr_shell), weak_vr_shell_(weak_vr_shell),
main_thread_task_runner_(std::move(main_thread_task_runner)), main_thread_task_runner_(std::move(main_thread_task_runner)),
gl_surface_created_event_(gl_surface_created_event), gvr_api_(gvr::GvrApi::WrapNonOwned(gvr_api)),
gvr_api_(gvr_api), factory_params_(std::make_unique<RenderLoopFactory::Params>(
ui_initial_state_(ui_initial_state), gvr_api_.get(),
reprojected_rendering_(reprojected_rendering), ui_initial_state,
daydream_support_(daydream_support), reprojected_rendering,
pause_content_(pause_content), daydream_support,
low_density_(low_density), pause_content,
surface_callback_(std::move(surface_callback)) {} low_density,
gl_surface_created_event,
std::move(surface_callback))) {}
VrGLThread::~VrGLThread() { VrGLThread::~VrGLThread() {
Stop(); Stop();
...@@ -61,40 +63,11 @@ void VrGLThread::SetInputConnection(VrInputConnection* input_connection) { ...@@ -61,40 +63,11 @@ void VrGLThread::SetInputConnection(VrInputConnection* input_connection) {
} }
void VrGLThread::Init() { void VrGLThread::Init() {
keyboard_delegate_ = GvrKeyboardDelegate::Create(); vr_shell_gl_ = RenderLoopFactory::Create(this, std::move(factory_params_));
text_input_delegate_ = std::make_unique<TextInputDelegate>();
if (!keyboard_delegate_.get())
ui_initial_state_.needs_keyboard_update = true;
audio_delegate_ = std::make_unique<SoundsManagerAudioDelegate>();
auto ui = UiFactory::Create(this, this, keyboard_delegate_.get(),
text_input_delegate_.get(), audio_delegate_.get(),
ui_initial_state_);
text_input_delegate_->SetRequestFocusCallback(base::BindRepeating(
&UiInterface::RequestFocus, base::Unretained(ui.get())));
text_input_delegate_->SetRequestUnfocusCallback(base::BindRepeating(
&UiInterface::RequestUnfocus, base::Unretained(ui.get())));
if (keyboard_delegate_.get()) {
keyboard_delegate_->SetUiInterface(ui.get());
text_input_delegate_->SetUpdateInputCallback(
base::BindRepeating(&GvrKeyboardDelegate::UpdateInput,
base::Unretained(keyboard_delegate_.get())));
}
vr_shell_gl_ = std::make_unique<VrShellGl>(
this, std::move(ui), gvr_api_, reprojected_rendering_, daydream_support_,
ui_initial_state_.in_web_vr, pause_content_, low_density_);
weak_browser_ui_ = vr_shell_gl_->GetBrowserUiWeakPtr(); weak_browser_ui_ = vr_shell_gl_->GetBrowserUiWeakPtr();
task_runner()->PostTask(
FROM_HERE, base::BindOnce(&VrShellGl::Init, vr_shell_gl_->GetWeakPtr(),
base::Unretained(gl_surface_created_event_),
base::Passed(std::move(surface_callback_))));
} }
void VrGLThread::CleanUp() { void VrGLThread::CleanUp() {
audio_delegate_.reset();
vr_shell_gl_.reset(); vr_shell_gl_.reset();
} }
......
...@@ -13,25 +13,27 @@ ...@@ -13,25 +13,27 @@
#include "base/single_thread_task_runner.h" #include "base/single_thread_task_runner.h"
#include "chrome/browser/android/vr/gl_browser_interface.h" #include "chrome/browser/android/vr/gl_browser_interface.h"
#include "chrome/browser/android/vr/gvr_keyboard_delegate.h" #include "chrome/browser/android/vr/gvr_keyboard_delegate.h"
#include "chrome/browser/android/vr/render_loop_factory.h"
#include "chrome/browser/vr/browser_ui_interface.h" #include "chrome/browser/vr/browser_ui_interface.h"
#include "chrome/browser/vr/model/omnibox_suggestions.h" #include "chrome/browser/vr/model/omnibox_suggestions.h"
#include "chrome/browser/vr/model/sound_id.h" #include "chrome/browser/vr/model/sound_id.h"
#include "chrome/browser/vr/platform_input_handler.h" #include "chrome/browser/vr/platform_input_handler.h"
#include "chrome/browser/vr/text_input_delegate.h" #include "chrome/browser/vr/text_input_delegate.h"
#include "chrome/browser/vr/ui_browser_interface.h" #include "chrome/browser/vr/ui_browser_interface.h"
#include "chrome/browser/vr/ui_initial_state.h"
#include "chrome/browser/vr/ui_test_input.h" #include "chrome/browser/vr/ui_test_input.h"
#include "third_party/gvr-android-sdk/src/libraries/headers/vr/gvr/capi/include/gvr_types.h" #include "third_party/gvr-android-sdk/src/libraries/headers/vr/gvr/capi/include/gvr_types.h"
#include "ui/gfx/native_widget_types.h"
namespace base { namespace base {
class Version; class Version;
class WaitableEvent; class WaitableEvent;
} // namespace base } // namespace base
namespace gvr {
class GvrApi;
}
namespace vr { namespace vr {
class AudioDelegate;
class VrInputConnection; class VrInputConnection;
class VrShell; class VrShell;
class VrShellGl; class VrShellGl;
...@@ -45,13 +47,13 @@ class VrGLThread : public base::android::JavaHandlerThread, ...@@ -45,13 +47,13 @@ class VrGLThread : public base::android::JavaHandlerThread,
VrGLThread( VrGLThread(
const base::WeakPtr<VrShell>& weak_vr_shell, const base::WeakPtr<VrShell>& weak_vr_shell,
scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner, scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner,
base::WaitableEvent* gl_surface_created_event,
gvr_context* gvr_api, gvr_context* gvr_api,
const UiInitialState& ui_initial_state, const UiInitialState& ui_initial_state,
bool reprojected_rendering, bool reprojected_rendering,
bool daydream_support, bool daydream_support,
bool pause_content, bool pause_content,
bool low_density, bool low_density,
base::WaitableEvent* gl_surface_created_event,
base::OnceCallback<gfx::AcceleratedWidget()> surface_callback); base::OnceCallback<gfx::AcceleratedWidget()> surface_callback);
~VrGLThread() override; ~VrGLThread() override;
...@@ -156,12 +158,6 @@ class VrGLThread : public base::android::JavaHandlerThread, ...@@ -156,12 +158,6 @@ class VrGLThread : public base::android::JavaHandlerThread,
bool OnMainThread() const; bool OnMainThread() const;
bool OnGlThread() const; bool OnGlThread() const;
// Created on GL thread.
std::unique_ptr<VrShellGl> vr_shell_gl_;
std::unique_ptr<GvrKeyboardDelegate> keyboard_delegate_;
std::unique_ptr<TextInputDelegate> text_input_delegate_;
std::unique_ptr<AudioDelegate> audio_delegate_;
base::WeakPtr<VrShell> weak_vr_shell_; base::WeakPtr<VrShell> weak_vr_shell_;
base::WeakPtr<BrowserUiInterface> weak_browser_ui_; base::WeakPtr<BrowserUiInterface> weak_browser_ui_;
base::WeakPtr<VrInputConnection> weak_input_connection_; base::WeakPtr<VrInputConnection> weak_input_connection_;
...@@ -170,16 +166,14 @@ class VrGLThread : public base::android::JavaHandlerThread, ...@@ -170,16 +166,14 @@ class VrGLThread : public base::android::JavaHandlerThread,
// VrGlThread. So it is safe to use raw pointer here. // VrGlThread. So it is safe to use raw pointer here.
VrInputConnection* input_connection_ = nullptr; VrInputConnection* input_connection_ = nullptr;
// This state is used for initializing vr_shell_gl_.
scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_;
base::WaitableEvent* gl_surface_created_event_;
gvr_context* gvr_api_; // Created on GL thread.
UiInitialState ui_initial_state_; std::unique_ptr<VrShellGl> vr_shell_gl_;
bool reprojected_rendering_; std::unique_ptr<gvr::GvrApi> gvr_api_;
bool daydream_support_;
bool pause_content_; // This state is used for initializing the RenderLoop.
bool low_density_; std::unique_ptr<RenderLoopFactory::Params> factory_params_;
base::OnceCallback<gfx::AcceleratedWidget()> surface_callback_;
DISALLOW_COPY_AND_ASSIGN(VrGLThread); DISALLOW_COPY_AND_ASSIGN(VrGLThread);
}; };
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <android/native_window_jni.h> #include <android/native_window_jni.h>
#include <algorithm>
#include <string> #include <string>
#include <utility> #include <utility>
...@@ -168,10 +169,10 @@ VrShell::VrShell(JNIEnv* env, ...@@ -168,10 +169,10 @@ VrShell::VrShell(JNIEnv* env,
base::BindOnce(&VrShell::GetRenderSurface, base::Unretained(this)); base::BindOnce(&VrShell::GetRenderSurface, base::Unretained(this));
gl_thread_ = std::make_unique<VrGLThread>( gl_thread_ = std::make_unique<VrGLThread>(
weak_ptr_factory_.GetWeakPtr(), main_thread_task_runner_, weak_ptr_factory_.GetWeakPtr(), main_thread_task_runner_, gvr_api,
&gl_surface_created_event_, gvr_api, ui_initial_state, ui_initial_state, reprojected_rendering_, HasDaydreamSupport(env),
reprojected_rendering_, HasDaydreamSupport(env), pause_content, pause_content, low_density, &gl_surface_created_event_,
low_density, std::move(surface_callback)); std::move(surface_callback));
ui_ = gl_thread_.get(); ui_ = gl_thread_.get();
toolbar_ = std::make_unique<ToolbarHelper>(ui_, this); toolbar_ = std::make_unique<ToolbarHelper>(ui_, this);
autocomplete_controller_ = autocomplete_controller_ =
...@@ -331,8 +332,7 @@ VrShell::~VrShell() { ...@@ -331,8 +332,7 @@ VrShell::~VrShell() {
void VrShell::PostToGlThread(const base::Location& from_here, void VrShell::PostToGlThread(const base::Location& from_here,
base::OnceClosure task) { base::OnceClosure task) {
gl_thread_->message_loop()->task_runner()->PostTask(from_here, gl_thread_->task_runner()->PostTask(from_here, std::move(task));
std::move(task));
} }
void VrShell::Navigate(GURL url, NavigationMethod method) { void VrShell::Navigate(GURL url, NavigationMethod method) {
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
#include "base/android/android_hardware_buffer_compat.h" #include "base/android/android_hardware_buffer_compat.h"
#include "base/android/jni_android.h" #include "base/android/jni_android.h"
#include "base/bind_helpers.h"
#include "base/callback_helpers.h" #include "base/callback_helpers.h"
#include "base/containers/queue.h" #include "base/containers/queue.h"
#include "base/metrics/field_trial_params.h" #include "base/metrics/field_trial_params.h"
...@@ -21,7 +20,6 @@ ...@@ -21,7 +20,6 @@
#include "base/time/time.h" #include "base/time/time.h"
#include "base/trace_event/trace_event_argument.h" #include "base/trace_event/trace_event_argument.h"
#include "chrome/browser/android/vr/gl_browser_interface.h" #include "chrome/browser/android/vr/gl_browser_interface.h"
#include "chrome/browser/android/vr/gvr_controller_delegate.h"
#include "chrome/browser/android/vr/gvr_util.h" #include "chrome/browser/android/vr/gvr_util.h"
#include "chrome/browser/android/vr/mailbox_to_surface_bridge.h" #include "chrome/browser/android/vr/mailbox_to_surface_bridge.h"
#include "chrome/browser/android/vr/metrics_util_android.h" #include "chrome/browser/android/vr/metrics_util_android.h"
...@@ -29,6 +27,7 @@ ...@@ -29,6 +27,7 @@
#include "chrome/browser/android/vr/vr_controller.h" #include "chrome/browser/android/vr/vr_controller.h"
#include "chrome/browser/android/vr/vr_shell.h" #include "chrome/browser/android/vr/vr_shell.h"
#include "chrome/browser/vr/assets_loader.h" #include "chrome/browser/vr/assets_loader.h"
#include "chrome/browser/vr/controller_delegate.h"
#include "chrome/browser/vr/gl_texture_location.h" #include "chrome/browser/vr/gl_texture_location.h"
#include "chrome/browser/vr/metrics/session_metrics_helper.h" #include "chrome/browser/vr/metrics/session_metrics_helper.h"
#include "chrome/browser/vr/model/assets.h" #include "chrome/browser/vr/model/assets.h"
...@@ -186,15 +185,21 @@ UiInterface::FovRectangle ToUiFovRect(const gvr::Rectf& rect) { ...@@ -186,15 +185,21 @@ UiInterface::FovRectangle ToUiFovRect(const gvr::Rectf& rect) {
VrShellGl::VrShellGl(GlBrowserInterface* browser, VrShellGl::VrShellGl(GlBrowserInterface* browser,
std::unique_ptr<UiInterface> ui, std::unique_ptr<UiInterface> ui,
gvr_context* gvr_api, std::unique_ptr<ControllerDelegate> controller_delegate,
gvr::GvrApi* gvr_api,
bool reprojected_rendering, bool reprojected_rendering,
bool daydream_support, bool daydream_support,
bool start_in_web_vr_mode, bool start_in_web_vr_mode,
bool pause_content, bool pause_content,
bool low_density) bool low_density)
: RenderLoop(std::move(ui), browser, this, kWebVRSlidingAverageSize), : RenderLoop(std::move(ui),
this,
std::move(controller_delegate),
browser,
kWebVRSlidingAverageSize),
webvr_vsync_align_( webvr_vsync_align_(
base::FeatureList::IsEnabled(features::kWebVrVsyncAlign)), base::FeatureList::IsEnabled(features::kWebVrVsyncAlign)),
gvr_api_(gvr_api),
low_density_(low_density), low_density_(low_density),
web_vr_mode_(start_in_web_vr_mode), web_vr_mode_(start_in_web_vr_mode),
surfaceless_rendering_(reprojected_rendering), surfaceless_rendering_(reprojected_rendering),
...@@ -212,9 +217,7 @@ VrShellGl::VrShellGl(GlBrowserInterface* browser, ...@@ -212,9 +217,7 @@ VrShellGl::VrShellGl(GlBrowserInterface* browser,
webvr_acquire_time_(kWebVRSlidingAverageSize), webvr_acquire_time_(kWebVRSlidingAverageSize),
webvr_submit_time_(kWebVRSlidingAverageSize), webvr_submit_time_(kWebVRSlidingAverageSize),
weak_ptr_factory_(this) { weak_ptr_factory_(this) {
GvrInit(gvr_api); GvrInit();
set_controller_delegate(std::make_unique<GvrControllerDelegate>(
std::make_unique<VrController>(gvr_api), browser_));
} }
VrShellGl::~VrShellGl() { VrShellGl::~VrShellGl() {
...@@ -239,20 +242,21 @@ void VrShellGl::InitializeGl(gfx::AcceleratedWidget window) { ...@@ -239,20 +242,21 @@ void VrShellGl::InitializeGl(gfx::AcceleratedWidget window) {
ForceExitVr(); ForceExitVr();
return; return;
} }
scoped_refptr<gl::GLSurface> surface;
if (window) { if (window) {
DCHECK(!surfaceless_rendering_); DCHECK(!surfaceless_rendering_);
surface_ = gl::init::CreateViewGLSurface(window); surface = gl::init::CreateViewGLSurface(window);
} else { } else {
DCHECK(surfaceless_rendering_); DCHECK(surfaceless_rendering_);
surface_ = gl::init::CreateOffscreenGLSurface(gfx::Size()); surface = gl::init::CreateOffscreenGLSurface(gfx::Size());
} }
if (!surface_.get()) { if (!surface.get()) {
LOG(ERROR) << "gl::init::CreateOffscreenGLSurface failed"; LOG(ERROR) << "gl::init::CreateOffscreenGLSurface failed";
ForceExitVr(); ForceExitVr();
return; return;
} }
if (!BaseCompositorDelegate::Initialize(surface_)) { if (!BaseCompositorDelegate::Initialize(surface)) {
ForceExitVr(); ForceExitVr();
return; return;
} }
...@@ -865,9 +869,7 @@ void VrShellGl::OnWebVrTimeoutImminent() { ...@@ -865,9 +869,7 @@ void VrShellGl::OnWebVrTimeoutImminent() {
ui_->OnWebVrTimeoutImminent(); ui_->OnWebVrTimeoutImminent();
} }
void VrShellGl::GvrInit(gvr_context* gvr_api) { void VrShellGl::GvrInit() {
gvr_api_ = gvr::GvrApi::WrapNonOwned(gvr_api);
MetricsUtilAndroid::LogVrViewerType(gvr_api_->GetViewerType()); MetricsUtilAndroid::LogVrViewerType(gvr_api_->GetViewerType());
cardboard_ = cardboard_ =
...@@ -1180,7 +1182,7 @@ void VrShellGl::DrawFrame(int16_t frame_index, base::TimeTicks current_time) { ...@@ -1180,7 +1182,7 @@ void VrShellGl::DrawFrame(int16_t frame_index, base::TimeTicks current_time) {
WebXrFrame* frame = webxr_.GetProcessingFrame(); WebXrFrame* frame = webxr_.GetProcessingFrame();
render_info_.head_pose = frame->head_pose; render_info_.head_pose = frame->head_pose;
} else { } else {
device::GvrDelegate::GetGvrPoseWithNeckModel(gvr_api_.get(), device::GvrDelegate::GetGvrPoseWithNeckModel(gvr_api_,
&render_info_.head_pose); &render_info_.head_pose);
} }
...@@ -1534,8 +1536,7 @@ void VrShellGl::DrawFrameSubmitNow(int16_t frame_index, ...@@ -1534,8 +1536,7 @@ void VrShellGl::DrawFrameSubmitNow(int16_t frame_index,
// No need to swap buffers for surfaceless rendering. // No need to swap buffers for surfaceless rendering.
if (!surfaceless_rendering_) { if (!surfaceless_rendering_) {
// TODO(mthiesse): Support asynchronous SwapBuffers. // TODO(mthiesse): Support asynchronous SwapBuffers.
TRACE_EVENT0("gpu", "VrShellGl::SwapBuffers"); SwapSurfaceBuffers();
surface_->SwapBuffers(base::DoNothing());
} }
// At this point, ShouldDrawWebVr and webvr_frame_processing_ may have become // At this point, ShouldDrawWebVr and webvr_frame_processing_ may have become
...@@ -1859,7 +1860,7 @@ void VrShellGl::OnVSync(base::TimeTicks frame_time) { ...@@ -1859,7 +1860,7 @@ void VrShellGl::OnVSync(base::TimeTicks frame_time) {
// When drawing WebVR, controller input doesn't need to be synchronized with // When drawing WebVR, controller input doesn't need to be synchronized with
// rendering as WebVR uses the gamepad api. To ensure we always handle input // rendering as WebVR uses the gamepad api. To ensure we always handle input
// like app button presses, process the controller here. // like app button presses, process the controller here.
device::GvrDelegate::GetGvrPoseWithNeckModel(gvr_api_.get(), device::GvrDelegate::GetGvrPoseWithNeckModel(gvr_api_,
&render_info_.head_pose); &render_info_.head_pose);
input_states_.push_back( input_states_.push_back(
ProcessControllerInputForWebXr(render_info_, frame_time)); ProcessControllerInputForWebXr(render_info_, frame_time));
...@@ -2040,7 +2041,7 @@ void VrShellGl::SendVSync() { ...@@ -2040,7 +2041,7 @@ void VrShellGl::SendVSync() {
gfx::Transform head_mat; gfx::Transform head_mat;
TRACE_EVENT_BEGIN0("gpu", "VrShellGl::GetVRPosePtrWithNeckModel"); TRACE_EVENT_BEGIN0("gpu", "VrShellGl::GetVRPosePtrWithNeckModel");
device::mojom::VRPosePtr pose = device::mojom::VRPosePtr pose =
device::GvrDelegate::GetVRPosePtrWithNeckModel(gvr_api_.get(), &head_mat, device::GvrDelegate::GetVRPosePtrWithNeckModel(gvr_api_, &head_mat,
prediction_nanos); prediction_nanos);
TRACE_EVENT_END0("gpu", "VrShellGl::GetVRPosePtrWithNeckModel"); TRACE_EVENT_END0("gpu", "VrShellGl::GetVRPosePtrWithNeckModel");
......
...@@ -59,6 +59,7 @@ struct SyncToken; ...@@ -59,6 +59,7 @@ struct SyncToken;
namespace vr { namespace vr {
class BrowserUiInterface; class BrowserUiInterface;
class ControllerDelegate;
class FPSMeter; class FPSMeter;
class GlBrowserInterface; class GlBrowserInterface;
class MailboxToSurfaceBridge; class MailboxToSurfaceBridge;
...@@ -103,7 +104,8 @@ class VrShellGl : public RenderLoop, ...@@ -103,7 +104,8 @@ class VrShellGl : public RenderLoop,
public: public:
VrShellGl(GlBrowserInterface* browser, VrShellGl(GlBrowserInterface* browser,
std::unique_ptr<UiInterface> ui, std::unique_ptr<UiInterface> ui,
gvr_context* gvr_api, std::unique_ptr<ControllerDelegate> controller_delegate,
gvr::GvrApi* gvr_api,
bool reprojected_rendering, bool reprojected_rendering,
bool daydream_support, bool daydream_support,
bool start_in_web_vr_mode, bool start_in_web_vr_mode,
...@@ -163,7 +165,7 @@ class VrShellGl : public RenderLoop, ...@@ -163,7 +165,7 @@ class VrShellGl : public RenderLoop,
private: private:
void InitializeGl(gfx::AcceleratedWidget surface); void InitializeGl(gfx::AcceleratedWidget surface);
void GvrInit(gvr_context* gvr_api); void GvrInit();
device::mojom::XRPresentationTransportOptionsPtr device::mojom::XRPresentationTransportOptionsPtr
GetWebVrFrameTransportOptions( GetWebVrFrameTransportOptions(
...@@ -284,7 +286,7 @@ class VrShellGl : public RenderLoop, ...@@ -284,7 +286,7 @@ class VrShellGl : public RenderLoop,
std::unique_ptr<gl::ScopedJavaSurface> ui_surface_; std::unique_ptr<gl::ScopedJavaSurface> ui_surface_;
std::unique_ptr<gl::ScopedJavaSurface> content_overlay_surface_; std::unique_ptr<gl::ScopedJavaSurface> content_overlay_surface_;
std::unique_ptr<gvr::GvrApi> gvr_api_; gvr::GvrApi* gvr_api_;
gvr::BufferViewportList viewport_list_; gvr::BufferViewportList viewport_list_;
Viewport main_viewport_; Viewport main_viewport_;
Viewport webvr_viewport_; Viewport webvr_viewport_;
......
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
#include <utility> #include <utility>
#include "base/bind_helpers.h"
#include "base/trace_event/trace_event.h"
#include "ui/gl/gl_context.h" #include "ui/gl/gl_context.h"
#include "ui/gl/gl_share_group.h" #include "ui/gl/gl_share_group.h"
#include "ui/gl/gl_surface.h" #include "ui/gl/gl_surface.h"
...@@ -43,6 +45,12 @@ bool BaseCompositorDelegate::RunInSkiaContext(SkiaContextCallback callback) { ...@@ -43,6 +45,12 @@ bool BaseCompositorDelegate::RunInSkiaContext(SkiaContextCallback callback) {
return MakeContextCurrent(kMainContext); return MakeContextCurrent(kMainContext);
} }
void BaseCompositorDelegate::SwapSurfaceBuffers() {
TRACE_EVENT0("gpu", __func__);
DCHECK(surface_);
surface_->SwapBuffers(base::DoNothing());
}
bool BaseCompositorDelegate::MakeContextCurrent(ContextId context_id) { bool BaseCompositorDelegate::MakeContextCurrent(ContextId context_id) {
DCHECK(context_id > kNone && context_id < kNumContexts); DCHECK(context_id > kNone && context_id < kNumContexts);
if (curr_context_id_ == context_id) if (curr_context_id_ == context_id)
......
...@@ -26,6 +26,9 @@ class VR_EXPORT BaseCompositorDelegate : public CompositorDelegate { ...@@ -26,6 +26,9 @@ class VR_EXPORT BaseCompositorDelegate : public CompositorDelegate {
bool Initialize(const scoped_refptr<gl::GLSurface>& surface) override; bool Initialize(const scoped_refptr<gl::GLSurface>& surface) override;
bool RunInSkiaContext(SkiaContextCallback callback) override; bool RunInSkiaContext(SkiaContextCallback callback) override;
protected:
void SwapSurfaceBuffers();
private: private:
enum ContextId { kNone = -1, kMainContext, kSkiaContext, kNumContexts }; enum ContextId { kNone = -1, kMainContext, kSkiaContext, kNumContexts };
......
...@@ -16,12 +16,15 @@ class Transform; ...@@ -16,12 +16,15 @@ class Transform;
namespace vr { namespace vr {
class KeyboardUiInterface;
struct CameraModel; struct CameraModel;
struct TextInputInfo;
class VR_EXPORT KeyboardDelegate { class VR_EXPORT KeyboardDelegate {
public: public:
virtual ~KeyboardDelegate() {} virtual ~KeyboardDelegate() {}
virtual void SetUiInterface(KeyboardUiInterface* ui) {}
virtual void ShowKeyboard() = 0; virtual void ShowKeyboard() = 0;
virtual void HideKeyboard() = 0; virtual void HideKeyboard() = 0;
virtual void SetTransform(const gfx::Transform&) = 0; virtual void SetTransform(const gfx::Transform&) = 0;
...@@ -39,6 +42,9 @@ class VR_EXPORT KeyboardDelegate { ...@@ -39,6 +42,9 @@ class VR_EXPORT KeyboardDelegate {
virtual void OnHoverMove(const gfx::PointF& position) {} virtual void OnHoverMove(const gfx::PointF& position) {}
virtual void OnButtonDown(const gfx::PointF& position) {} virtual void OnButtonDown(const gfx::PointF& position) {}
virtual void OnButtonUp(const gfx::PointF& position) {} virtual void OnButtonUp(const gfx::PointF& position) {}
// Called to update GVR keyboard with the given text input info.
virtual void UpdateInput(const TextInputInfo& info) {}
}; };
} // namespace vr } // namespace vr
......
...@@ -21,12 +21,14 @@ ...@@ -21,12 +21,14 @@
namespace vr { namespace vr {
RenderLoop::RenderLoop(std::unique_ptr<UiInterface> ui, RenderLoop::RenderLoop(std::unique_ptr<UiInterface> ui,
RenderLoopBrowserInterface* browser,
CompositorDelegate* compositor_delegate, CompositorDelegate* compositor_delegate,
std::unique_ptr<ControllerDelegate> controller_delegate,
RenderLoopBrowserInterface* browser,
size_t sliding_time_size) size_t sliding_time_size)
: ui_(std::move(ui)), : ui_(std::move(ui)),
browser_(browser),
compositor_delegate_(compositor_delegate), compositor_delegate_(compositor_delegate),
controller_delegate_(std::move(controller_delegate)),
browser_(browser),
ui_processing_time_(sliding_time_size), ui_processing_time_(sliding_time_size),
ui_controller_update_time_(sliding_time_size) {} ui_controller_update_time_(sliding_time_size) {}
RenderLoop::~RenderLoop() = default; RenderLoop::~RenderLoop() = default;
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include <memory> #include <memory>
#include "base/macros.h" #include "base/macros.h"
#include "chrome/browser/vr/controller_delegate.h"
#include "chrome/browser/vr/sliding_average.h" #include "chrome/browser/vr/sliding_average.h"
#include "chrome/browser/vr/vr_export.h" #include "chrome/browser/vr/vr_export.h"
#include "device/vr/public/mojom/vr_service.mojom.h" #include "device/vr/public/mojom/vr_service.mojom.h"
...@@ -22,6 +21,7 @@ namespace vr { ...@@ -22,6 +21,7 @@ namespace vr {
enum class VrUiTestActivityResult; enum class VrUiTestActivityResult;
class CompositorDelegate; class CompositorDelegate;
class ControllerDelegate;
class RenderLoopBrowserInterface; class RenderLoopBrowserInterface;
class UiInterface; class UiInterface;
struct ControllerTestInput; struct ControllerTestInput;
...@@ -38,9 +38,10 @@ class VR_EXPORT RenderLoop { ...@@ -38,9 +38,10 @@ class VR_EXPORT RenderLoop {
public: public:
enum FrameType { kUiFrame, kWebXrFrame }; enum FrameType { kUiFrame, kWebXrFrame };
explicit RenderLoop(std::unique_ptr<UiInterface> ui, RenderLoop(std::unique_ptr<UiInterface> ui,
RenderLoopBrowserInterface* browser,
CompositorDelegate* compositor_delegate, CompositorDelegate* compositor_delegate,
std::unique_ptr<ControllerDelegate> controller_delegate,
RenderLoopBrowserInterface* browser,
size_t sliding_time_size); size_t sliding_time_size);
virtual ~RenderLoop(); virtual ~RenderLoop();
...@@ -52,10 +53,6 @@ class VR_EXPORT RenderLoop { ...@@ -52,10 +53,6 @@ class VR_EXPORT RenderLoop {
UiTestActivityExpectation ui_expectation); UiTestActivityExpectation ui_expectation);
protected: protected:
void set_controller_delegate(std::unique_ptr<ControllerDelegate> delegate) {
controller_delegate_ = std::move(delegate);
}
// Position, hide and/or show UI elements, process input and update textures. // Position, hide and/or show UI elements, process input and update textures.
// Returns true if the scene changed. // Returns true if the scene changed.
void UpdateUi(const RenderInfo& render_info, void UpdateUi(const RenderInfo& render_info,
...@@ -83,13 +80,13 @@ class VR_EXPORT RenderLoop { ...@@ -83,13 +80,13 @@ class VR_EXPORT RenderLoop {
bool ui_updated); bool ui_updated);
void ReportUiActivityResultForTesting(VrUiTestActivityResult result); void ReportUiActivityResultForTesting(VrUiTestActivityResult result);
RenderLoopBrowserInterface* browser_;
CompositorDelegate* compositor_delegate_; CompositorDelegate* compositor_delegate_;
std::unique_ptr<ControllerDelegate> controller_delegate_; std::unique_ptr<ControllerDelegate> controller_delegate_;
std::unique_ptr<ControllerDelegate> controller_delegate_for_testing_; std::unique_ptr<ControllerDelegate> controller_delegate_for_testing_;
bool using_controller_delegate_for_testing_ = false; bool using_controller_delegate_for_testing_ = false;
RenderLoopBrowserInterface* browser_;
std::unique_ptr<UiTestState> ui_test_state_; std::unique_ptr<UiTestState> ui_test_state_;
SlidingTimeDeltaAverage ui_processing_time_; SlidingTimeDeltaAverage ui_processing_time_;
SlidingTimeDeltaAverage ui_controller_update_time_; SlidingTimeDeltaAverage ui_controller_update_time_;
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "chrome/browser/vr/render_info.h" #include "chrome/browser/vr/render_info.h"
#include "chrome/browser/vr/test/animation_utils.h" #include "chrome/browser/vr/test/animation_utils.h"
#include "chrome/browser/vr/test/constants.h" #include "chrome/browser/vr/test/constants.h"
#include "chrome/browser/vr/text_input_delegate.h"
#include "third_party/skia/include/core/SkImageEncoder.h" #include "third_party/skia/include/core/SkImageEncoder.h"
#include "third_party/skia/include/core/SkStream.h" #include "third_party/skia/include/core/SkStream.h"
#include "ui/gl/gl_bindings.h" #include "ui/gl/gl_bindings.h"
......
...@@ -20,10 +20,6 @@ namespace vr { ...@@ -20,10 +20,6 @@ namespace vr {
namespace { namespace {
void OnPresentedFrame(const gfx::PresentationFeedback& feedback) {
// Do nothing for now.
}
bool ClearGlErrors() { bool ClearGlErrors() {
bool errors = false; bool errors = false;
while (glGetError() != GL_NO_ERROR) while (glGetError() != GL_NO_ERROR)
...@@ -33,22 +29,14 @@ bool ClearGlErrors() { ...@@ -33,22 +29,14 @@ bool ClearGlErrors() {
} // namespace } // namespace
GlRenderer::GlRenderer(const scoped_refptr<gl::GLSurface>& surface, GlRenderer::GlRenderer() : weak_ptr_factory_(this) {}
vr::VrTestContext* vr)
: surface_(surface), vr_(vr), weak_ptr_factory_(this) {}
GlRenderer::~GlRenderer() {} GlRenderer::~GlRenderer() {}
bool GlRenderer::Initialize() { bool GlRenderer::Initialize(const scoped_refptr<gl::GLSurface>& surface) {
std::unique_ptr<CompositorDelegate> compositor_delegate = if (!BaseCompositorDelegate::Initialize(surface))
std::make_unique<BaseCompositorDelegate>();
if (!compositor_delegate->Initialize(surface_)) {
return false; return false;
} PostRenderFrameTask();
vr_->OnGlInitialized(std::move(compositor_delegate));
PostRenderFrameTask(gfx::SwapResult::SWAP_ACK);
return true; return true;
} }
...@@ -61,15 +49,15 @@ void GlRenderer::RenderFrame() { ...@@ -61,15 +49,15 @@ void GlRenderer::RenderFrame() {
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
vr_->DrawFrame(); vr_context_->DrawFrame();
DCHECK(!ClearGlErrors()); DCHECK(!ClearGlErrors());
PostRenderFrameTask( SwapSurfaceBuffers();
surface_->SwapBuffers(base::BindRepeating(&OnPresentedFrame))); PostRenderFrameTask();
} }
void GlRenderer::PostRenderFrameTask(gfx::SwapResult result) { void GlRenderer::PostRenderFrameTask() {
base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE, FROM_HERE,
base::BindOnce(&GlRenderer::RenderFrame, weak_ptr_factory_.GetWeakPtr()), base::BindOnce(&GlRenderer::RenderFrame, weak_ptr_factory_.GetWeakPtr()),
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "chrome/browser/vr/base_compositor_delegate.h"
#include "ui/gfx/swap_result.h" #include "ui/gfx/swap_result.h"
namespace gl { namespace gl {
...@@ -19,20 +20,18 @@ namespace vr { ...@@ -19,20 +20,18 @@ namespace vr {
class VrTestContext; class VrTestContext;
// This class manages an OpenGL context and initiates per-frame rendering. // This class manages an OpenGL context and initiates per-frame rendering.
class GlRenderer { class GlRenderer : public BaseCompositorDelegate {
public: public:
GlRenderer(const scoped_refptr<gl::GLSurface>& surface, GlRenderer();
vr::VrTestContext* vr); ~GlRenderer() override;
virtual ~GlRenderer(); bool Initialize(const scoped_refptr<gl::GLSurface>& surface) override;
bool Initialize();
void RenderFrame(); void RenderFrame();
void PostRenderFrameTask(gfx::SwapResult result); void PostRenderFrameTask();
void set_vr_context(VrTestContext* vr_context) { vr_context_ = vr_context; }
private: private:
scoped_refptr<gl::GLSurface> surface_; VrTestContext* vr_context_;
vr::VrTestContext* vr_;
base::WeakPtrFactory<GlRenderer> weak_ptr_factory_; base::WeakPtrFactory<GlRenderer> weak_ptr_factory_;
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "chrome/browser/vr/testapp/test_keyboard_delegate.h" #include "chrome/browser/vr/testapp/test_keyboard_delegate.h"
#include <memory> #include <memory>
#include <string>
#include "base/strings/utf_string_conversion_utils.h" #include "base/strings/utf_string_conversion_utils.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
...@@ -25,6 +26,10 @@ TestKeyboardDelegate::TestKeyboardDelegate() ...@@ -25,6 +26,10 @@ TestKeyboardDelegate::TestKeyboardDelegate()
TestKeyboardDelegate::~TestKeyboardDelegate() {} TestKeyboardDelegate::~TestKeyboardDelegate() {}
void TestKeyboardDelegate::SetUiInterface(KeyboardUiInterface* ui) {
ui_interface_ = ui;
}
void TestKeyboardDelegate::ShowKeyboard() { void TestKeyboardDelegate::ShowKeyboard() {
editing_ = true; editing_ = true;
} }
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#ifndef CHROME_BROWSER_VR_TESTAPP_TEST_KEYBOARD_DELEGATE_H_ #ifndef CHROME_BROWSER_VR_TESTAPP_TEST_KEYBOARD_DELEGATE_H_
#define CHROME_BROWSER_VR_TESTAPP_TEST_KEYBOARD_DELEGATE_H_ #define CHROME_BROWSER_VR_TESTAPP_TEST_KEYBOARD_DELEGATE_H_
#include <memory>
#include "base/macros.h" #include "base/macros.h"
#include "chrome/browser/vr/keyboard_delegate.h" #include "chrome/browser/vr/keyboard_delegate.h"
#include "chrome/browser/vr/keyboard_ui_interface.h" #include "chrome/browser/vr/keyboard_ui_interface.h"
...@@ -30,6 +32,7 @@ class TestKeyboardDelegate : public KeyboardDelegate { ...@@ -30,6 +32,7 @@ class TestKeyboardDelegate : public KeyboardDelegate {
TestKeyboardDelegate(); TestKeyboardDelegate();
~TestKeyboardDelegate() override; ~TestKeyboardDelegate() override;
void SetUiInterface(KeyboardUiInterface* ui) override;
void ShowKeyboard() override; void ShowKeyboard() override;
void HideKeyboard() override; void HideKeyboard() override;
void SetTransform(const gfx::Transform& transform) override; void SetTransform(const gfx::Transform& transform) override;
...@@ -38,12 +41,9 @@ class TestKeyboardDelegate : public KeyboardDelegate { ...@@ -38,12 +41,9 @@ class TestKeyboardDelegate : public KeyboardDelegate {
gfx::Point3F* hit_position) override; gfx::Point3F* hit_position) override;
void Draw(const CameraModel& model) override; void Draw(const CameraModel& model) override;
bool SupportsSelection() override; bool SupportsSelection() override;
void UpdateInput(const vr::TextInputInfo& info) override;
void Initialize(SkiaSurfaceProvider* provider, UiElementRenderer* renderer); void Initialize(SkiaSurfaceProvider* provider, UiElementRenderer* renderer);
void SetUiInterface(KeyboardUiInterface* keyboard) {
ui_interface_ = keyboard;
}
void UpdateInput(const vr::TextInputInfo& info);
bool HandleInput(ui::Event* e); bool HandleInput(ui::Event* e);
private: private:
......
...@@ -101,7 +101,9 @@ InputEventList CreateScrollGestureEventList(InputEvent::Type type, ...@@ -101,7 +101,9 @@ InputEventList CreateScrollGestureEventList(InputEvent::Type type,
} // namespace } // namespace
VrTestContext::VrTestContext() : view_scale_factor_(kDefaultViewScaleFactor) { VrTestContext::VrTestContext(CompositorDelegate* compositor_delegate)
: view_scale_factor_(kDefaultViewScaleFactor),
compositor_delegate_(compositor_delegate) {
base::FilePath pak_path; base::FilePath pak_path;
base::PathService::Get(base::DIR_MODULE, &pak_path); base::PathService::Get(base::DIR_MODULE, &pak_path);
ui::ResourceBundle::InitSharedInstanceWithPakPath( ui::ResourceBundle::InitSharedInstanceWithPakPath(
...@@ -109,27 +111,22 @@ VrTestContext::VrTestContext() : view_scale_factor_(kDefaultViewScaleFactor) { ...@@ -109,27 +111,22 @@ VrTestContext::VrTestContext() : view_scale_factor_(kDefaultViewScaleFactor) {
base::i18n::InitializeICU(); base::i18n::InitializeICU();
text_input_delegate_ = std::make_unique<TextInputDelegate>(); auto text_input_delegate = std::make_unique<TextInputDelegate>();
keyboard_delegate_ = std::make_unique<TestKeyboardDelegate>(); auto keyboard_delegate = std::make_unique<TestKeyboardDelegate>();
keyboard_delegate_ = keyboard_delegate.get();
text_input_delegate->SetUpdateInputCallback(
base::BindRepeating(&TestKeyboardDelegate::UpdateInput,
base::Unretained(keyboard_delegate.get())));
UiInitialState ui_initial_state; UiInitialState ui_initial_state;
ui_initial_state.create_tabs_view = true; ui_initial_state.create_tabs_view = true;
ui_instance_ = std::make_unique<Ui>(this, nullptr, keyboard_delegate_.get(), ui_instance_ = std::make_unique<Ui>(
text_input_delegate_.get(), nullptr, this, nullptr, std::move(keyboard_delegate),
ui_initial_state); std::move(text_input_delegate), nullptr, ui_initial_state);
ui_ = ui_instance_.get(); ui_ = ui_instance_.get();
LoadAssets(); LoadAssets();
text_input_delegate_->SetRequestFocusCallback(base::BindRepeating(
&vr::UiInterface::RequestFocus, base::Unretained(ui_)));
text_input_delegate_->SetRequestUnfocusCallback(base::BindRepeating(
&vr::UiInterface::RequestUnfocus, base::Unretained(ui_)));
text_input_delegate_->SetUpdateInputCallback(
base::BindRepeating(&TestKeyboardDelegate::UpdateInput,
base::Unretained(keyboard_delegate_.get())));
keyboard_delegate_->SetUiInterface(ui_instance_.get());
touchpad_touch_position_ = kInitialTouchPosition; touchpad_touch_position_ = kInitialTouchPosition;
model_ = ui_instance_->model_for_test(); model_ = ui_instance_->model_for_test();
...@@ -158,10 +155,23 @@ VrTestContext::VrTestContext() : view_scale_factor_(kDefaultViewScaleFactor) { ...@@ -158,10 +155,23 @@ VrTestContext::VrTestContext() : view_scale_factor_(kDefaultViewScaleFactor) {
ui_->AddOrUpdateTab(tab_id_++, true, ui_->AddOrUpdateTab(tab_id_++, true,
base::UTF8ToUTF16("VR - Google Search")); base::UTF8ToUTF16("VR - Google Search"));
} }
InitializeGl();
} }
VrTestContext::~VrTestContext() = default; VrTestContext::~VrTestContext() = default;
void VrTestContext::InitializeGl() {
unsigned int content_texture_id = CreateTexture(0xFF000080);
unsigned int ui_texture_id = CreateTexture(0xFF008000);
ui_->OnGlInitialized(content_texture_id, kGlTextureLocationLocal,
content_texture_id, kGlTextureLocationLocal,
ui_texture_id);
keyboard_delegate_->Initialize(
ui_instance_->scene()->SurfaceProviderForTesting(),
ui_instance_->ui_element_renderer());
}
void VrTestContext::DrawFrame() { void VrTestContext::DrawFrame() {
base::TimeTicks current_time = base::TimeTicks::Now(); base::TimeTicks current_time = base::TimeTicks::Now();
...@@ -455,21 +465,6 @@ ControllerModel VrTestContext::UpdateController(const RenderInfo& render_info, ...@@ -455,21 +465,6 @@ ControllerModel VrTestContext::UpdateController(const RenderInfo& render_info,
return controller_model; return controller_model;
} }
void VrTestContext::OnGlInitialized(
std::unique_ptr<CompositorDelegate> compositor_delegate) {
compositor_delegate_ = std::move(compositor_delegate);
unsigned int content_texture_id = CreateTexture(0xFF000080);
unsigned int ui_texture_id = CreateTexture(0xFF008000);
ui_->OnGlInitialized(content_texture_id, kGlTextureLocationLocal,
content_texture_id, kGlTextureLocationLocal,
ui_texture_id);
keyboard_delegate_->Initialize(
ui_instance_->scene()->SurfaceProviderForTesting(),
ui_instance_->ui_element_renderer());
}
unsigned int VrTestContext::CreateTexture(SkColor color) { unsigned int VrTestContext::CreateTexture(SkColor color) {
sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul(1, 1); sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul(1, 1);
SkCanvas* canvas = surface->getCanvas(); SkCanvas* canvas = surface->getCanvas();
......
...@@ -24,7 +24,6 @@ class Event; ...@@ -24,7 +24,6 @@ class Event;
namespace vr { namespace vr {
class CompositorDelegate; class CompositorDelegate;
class TextInputDelegate;
class TestKeyboardDelegate; class TestKeyboardDelegate;
class Ui; class Ui;
struct Model; struct Model;
...@@ -33,10 +32,9 @@ struct Model; ...@@ -33,10 +32,9 @@ struct Model;
// manipulates the UI according to user input. // manipulates the UI according to user input.
class VrTestContext : public vr::UiBrowserInterface { class VrTestContext : public vr::UiBrowserInterface {
public: public:
VrTestContext(); explicit VrTestContext(CompositorDelegate* compositor_delgate);
~VrTestContext() override; ~VrTestContext() override;
void OnGlInitialized(std::unique_ptr<CompositorDelegate> compositor_delegate);
// TODO(vollick): we should refactor VrShellGl's rendering logic and use it // TODO(vollick): we should refactor VrShellGl's rendering logic and use it
// directly. crbug.com/767282 // directly. crbug.com/767282
void DrawFrame(); void DrawFrame();
...@@ -74,6 +72,7 @@ class VrTestContext : public vr::UiBrowserInterface { ...@@ -74,6 +72,7 @@ class VrTestContext : public vr::UiBrowserInterface {
void set_window_size(const gfx::Size& size) { window_size_ = size; } void set_window_size(const gfx::Size& size) { window_size_ = size; }
private: private:
void InitializeGl();
unsigned int CreateTexture(SkColor color); unsigned int CreateTexture(SkColor color);
void CreateFakeVoiceSearchResult(); void CreateFakeVoiceSearchResult();
void CycleWebVrModes(); void CycleWebVrModes();
...@@ -118,9 +117,8 @@ class VrTestContext : public vr::UiBrowserInterface { ...@@ -118,9 +117,8 @@ class VrTestContext : public vr::UiBrowserInterface {
int tab_id_ = 0; int tab_id_ = 0;
bool hosted_ui_enabled_ = false; bool hosted_ui_enabled_ = false;
std::unique_ptr<TextInputDelegate> text_input_delegate_; CompositorDelegate* compositor_delegate_;
std::unique_ptr<TestKeyboardDelegate> keyboard_delegate_; TestKeyboardDelegate* keyboard_delegate_;
std::unique_ptr<CompositorDelegate> compositor_delegate_;
PlatformController::Handedness handedness_ = PlatformController::kRightHanded; PlatformController::Handedness handedness_ = PlatformController::kRightHanded;
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/task/task_scheduler/task_scheduler.h" #include "base/task/task_scheduler/task_scheduler.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "base/trace_event/trace_event.h" #include "base/trace_event/trace_event.h"
#include "chrome/browser/vr/base_compositor_delegate.h"
#include "chrome/browser/vr/testapp/gl_renderer.h" #include "chrome/browser/vr/testapp/gl_renderer.h"
#include "chrome/browser/vr/testapp/vr_test_context.h" #include "chrome/browser/vr/testapp/vr_test_context.h"
#include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkBitmap.h"
...@@ -45,8 +46,7 @@ class RendererFactory { ...@@ -45,8 +46,7 @@ class RendererFactory {
~RendererFactory(); ~RendererFactory();
bool Initialize(); bool Initialize();
std::unique_ptr<vr::GlRenderer> CreateRenderer(gfx::AcceleratedWidget widget, std::unique_ptr<vr::GlRenderer> CreateRenderer(gfx::AcceleratedWidget widget);
vr::VrTestContext* vr);
private: private:
// Helper for applications that do GL on main thread. // Helper for applications that do GL on main thread.
...@@ -100,7 +100,6 @@ class AppWindow : public ui::PlatformWindowDelegate { ...@@ -100,7 +100,6 @@ class AppWindow : public ui::PlatformWindowDelegate {
const gfx::Rect& bounds) const gfx::Rect& bounds)
: window_manager_(window_manager), : window_manager_(window_manager),
renderer_factory_(renderer_factory), renderer_factory_(renderer_factory),
vr_(std::make_unique<vr::VrTestContext>()),
weak_ptr_factory_(this) { weak_ptr_factory_(this) {
ui::PlatformWindowInitProperties properties; ui::PlatformWindowInitProperties properties;
properties.bounds = gfx::Rect(1024, 768); properties.bounds = gfx::Rect(1024, 768);
...@@ -131,10 +130,12 @@ class AppWindow : public ui::PlatformWindowDelegate { ...@@ -131,10 +130,12 @@ class AppWindow : public ui::PlatformWindowDelegate {
// PlatformWindowDelegate: // PlatformWindowDelegate:
void OnBoundsChanged(const gfx::Rect& new_bounds) override { void OnBoundsChanged(const gfx::Rect& new_bounds) override {
vr_->set_window_size(new_bounds.size()); vr_context_->set_window_size(new_bounds.size());
} }
void OnDamageRect(const gfx::Rect& damaged_region) override {} void OnDamageRect(const gfx::Rect& damaged_region) override {}
void DispatchEvent(ui::Event* event) override { vr_->HandleInput(event); } void DispatchEvent(ui::Event* event) override {
vr_context_->HandleInput(event);
}
void OnCloseRequest() override { Quit(); } void OnCloseRequest() override { Quit(); }
void OnClosed() override {} void OnClosed() override {}
void OnWindowStateChanged(ui::PlatformWindowState new_state) override {} void OnWindowStateChanged(ui::PlatformWindowState new_state) override {}
...@@ -150,15 +151,15 @@ class AppWindow : public ui::PlatformWindowDelegate { ...@@ -150,15 +151,15 @@ class AppWindow : public ui::PlatformWindowDelegate {
// Since we pretend to have a GPU process, we should also pretend to // Since we pretend to have a GPU process, we should also pretend to
// initialize the GPU resources via a posted task. // initialize the GPU resources via a posted task.
void StartOnGpu() { void StartOnGpu() {
renderer_ = renderer_ = renderer_factory_->CreateRenderer(GetAcceleratedWidget());
renderer_factory_->CreateRenderer(GetAcceleratedWidget(), vr_.get()); vr_context_ = std::make_unique<vr::VrTestContext>(renderer_.get());
renderer_->Initialize(); renderer_->set_vr_context(vr_context_.get());
} }
WindowManager* window_manager_; // Not owned. WindowManager* window_manager_; // Not owned.
RendererFactory* renderer_factory_; // Not owned. RendererFactory* renderer_factory_; // Not owned.
std::unique_ptr<vr::VrTestContext> vr_; std::unique_ptr<vr::VrTestContext> vr_context_;
std::unique_ptr<vr::GlRenderer> renderer_; std::unique_ptr<vr::GlRenderer> renderer_;
// Window-related state. // Window-related state.
...@@ -187,14 +188,15 @@ bool RendererFactory::Initialize() { ...@@ -187,14 +188,15 @@ bool RendererFactory::Initialize() {
} }
std::unique_ptr<vr::GlRenderer> RendererFactory::CreateRenderer( std::unique_ptr<vr::GlRenderer> RendererFactory::CreateRenderer(
gfx::AcceleratedWidget widget, gfx::AcceleratedWidget widget) {
vr::VrTestContext* vr) {
scoped_refptr<gl::GLSurface> surface = gl::init::CreateViewGLSurface(widget); scoped_refptr<gl::GLSurface> surface = gl::init::CreateViewGLSurface(widget);
if (!surface) { if (!surface) {
LOG(FATAL) << "Failed to create GL surface"; LOG(FATAL) << "Failed to create GL surface";
return nullptr; return nullptr;
} }
return std::make_unique<vr::GlRenderer>(surface, vr); auto renderer = std::make_unique<vr::GlRenderer>();
CHECK(renderer->Initialize(surface));
return renderer;
} }
WindowManager::WindowManager(const base::Closure& quit_closure) WindowManager::WindowManager(const base::Closure& quit_closure)
......
...@@ -77,38 +77,48 @@ UiElementName UserFriendlyElementNameToUiElementName( ...@@ -77,38 +77,48 @@ UiElementName UserFriendlyElementNameToUiElementName(
Ui::Ui(UiBrowserInterface* browser, Ui::Ui(UiBrowserInterface* browser,
PlatformInputHandler* content_input_forwarder, PlatformInputHandler* content_input_forwarder,
KeyboardDelegate* keyboard_delegate, std::unique_ptr<KeyboardDelegate> keyboard_delegate,
TextInputDelegate* text_input_delegate, std::unique_ptr<TextInputDelegate> text_input_delegate,
AudioDelegate* audio_delegate, std::unique_ptr<AudioDelegate> audio_delegate,
const UiInitialState& ui_initial_state) const UiInitialState& ui_initial_state)
: Ui(browser, : Ui(browser,
std::make_unique<ContentInputDelegate>(content_input_forwarder), std::make_unique<ContentInputDelegate>(content_input_forwarder),
keyboard_delegate, std::move(keyboard_delegate),
text_input_delegate, std::move(text_input_delegate),
audio_delegate, std::move(audio_delegate),
ui_initial_state) {} ui_initial_state) {}
Ui::Ui(UiBrowserInterface* browser, Ui::Ui(UiBrowserInterface* browser,
std::unique_ptr<ContentInputDelegate> content_input_delegate, std::unique_ptr<ContentInputDelegate> content_input_delegate,
KeyboardDelegate* keyboard_delegate, std::unique_ptr<KeyboardDelegate> keyboard_delegate,
TextInputDelegate* text_input_delegate, std::unique_ptr<TextInputDelegate> text_input_delegate,
AudioDelegate* audio_delegate, std::unique_ptr<AudioDelegate> audio_delegate,
const UiInitialState& ui_initial_state) const UiInitialState& ui_initial_state)
: browser_(browser), : browser_(browser),
scene_(std::make_unique<UiScene>()), scene_(std::make_unique<UiScene>()),
model_(std::make_unique<Model>()), model_(std::make_unique<Model>()),
content_input_delegate_(std::move(content_input_delegate)), content_input_delegate_(std::move(content_input_delegate)),
input_manager_(std::make_unique<UiInputManager>(scene_.get())), input_manager_(std::make_unique<UiInputManager>(scene_.get())),
audio_delegate_(audio_delegate), keyboard_delegate_(std::move(keyboard_delegate)),
text_input_delegate_(std::move(text_input_delegate)),
audio_delegate_(std::move(audio_delegate)),
weak_ptr_factory_(this) { weak_ptr_factory_(this) {
UiInitialState state = ui_initial_state; UiInitialState state = ui_initial_state;
if (keyboard_delegate != nullptr) if (text_input_delegate_) {
state.supports_selection = keyboard_delegate->SupportsSelection(); text_input_delegate_->SetRequestFocusCallback(
base::BindRepeating(&Ui::RequestFocus, base::Unretained(this)));
text_input_delegate_->SetRequestUnfocusCallback(
base::BindRepeating(&Ui::RequestUnfocus, base::Unretained(this)));
}
if (keyboard_delegate_) {
keyboard_delegate_->SetUiInterface(this);
state.supports_selection = keyboard_delegate_->SupportsSelection();
}
InitializeModel(state); InitializeModel(state);
UiSceneCreator(browser, scene_.get(), this, content_input_delegate_.get(), UiSceneCreator(browser, scene_.get(), this, content_input_delegate_.get(),
keyboard_delegate, text_input_delegate, audio_delegate, keyboard_delegate_.get(), text_input_delegate_.get(),
model_.get()) audio_delegate_.get(), model_.get())
.CreateScene(); .CreateScene();
} }
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <memory> #include <memory>
#include <queue> #include <queue>
#include <utility>
#include <vector> #include <vector>
#include "base/macros.h" #include "base/macros.h"
...@@ -50,16 +51,16 @@ class VR_UI_EXPORT Ui : public UiInterface { ...@@ -50,16 +51,16 @@ class VR_UI_EXPORT Ui : public UiInterface {
public: public:
Ui(UiBrowserInterface* browser, Ui(UiBrowserInterface* browser,
PlatformInputHandler* content_input_forwarder, PlatformInputHandler* content_input_forwarder,
KeyboardDelegate* keyboard_delegate, std::unique_ptr<KeyboardDelegate> keyboard_delegate,
TextInputDelegate* text_input_delegate, std::unique_ptr<TextInputDelegate> text_input_delegate,
AudioDelegate* audio_delegate, std::unique_ptr<AudioDelegate> audio_delegate,
const UiInitialState& ui_initial_state); const UiInitialState& ui_initial_state);
Ui(UiBrowserInterface* browser, Ui(UiBrowserInterface* browser,
std::unique_ptr<ContentInputDelegate> content_input_delegate, std::unique_ptr<ContentInputDelegate> content_input_delegate,
KeyboardDelegate* keyboard_delegate, std::unique_ptr<KeyboardDelegate> keyboard_delegate,
TextInputDelegate* text_input_delegate, std::unique_ptr<TextInputDelegate> text_input_delegate,
AudioDelegate* audio_delegate, std::unique_ptr<AudioDelegate> audio_delegate,
const UiInitialState& ui_initial_state); const UiInitialState& ui_initial_state);
~Ui() override; ~Ui() override;
...@@ -189,15 +190,14 @@ class VR_UI_EXPORT Ui : public UiInterface { ...@@ -189,15 +190,14 @@ class VR_UI_EXPORT Ui : public UiInterface {
const FovRectangle& fov_recommended_right, const FovRectangle& fov_recommended_right,
float z_near) override; float z_near) override;
void RequestFocus(int element_id) override;
void RequestUnfocus(int element_id) override;
// KeyboardUiInterface // KeyboardUiInterface
void OnInputEdited(const EditedText& info) override; void OnInputEdited(const EditedText& info) override;
void OnInputCommitted(const EditedText& info) override; void OnInputCommitted(const EditedText& info) override;
void OnKeyboardHidden() override; void OnKeyboardHidden() override;
private: private:
void RequestFocus(int element_id);
void RequestUnfocus(int element_id);
void OnMenuButtonClicked(); void OnMenuButtonClicked();
void OnSpeechRecognitionEnded(); void OnSpeechRecognitionEnded();
void InitializeModel(const UiInitialState& ui_initial_state); void InitializeModel(const UiInitialState& ui_initial_state);
...@@ -222,7 +222,9 @@ class VR_UI_EXPORT Ui : public UiInterface { ...@@ -222,7 +222,9 @@ class VR_UI_EXPORT Ui : public UiInterface {
// frame. // frame.
ContentElement* content_element_ = nullptr; ContentElement* content_element_ = nullptr;
AudioDelegate* audio_delegate_ = nullptr; std::unique_ptr<KeyboardDelegate> keyboard_delegate_;
std::unique_ptr<TextInputDelegate> text_input_delegate_;
std::unique_ptr<AudioDelegate> audio_delegate_;
base::WeakPtrFactory<Ui> weak_ptr_factory_; base::WeakPtrFactory<Ui> weak_ptr_factory_;
......
...@@ -4,7 +4,12 @@ ...@@ -4,7 +4,12 @@
#include "chrome/browser/vr/ui_factory.h" #include "chrome/browser/vr/ui_factory.h"
#include <utility>
#include "chrome/browser/vr/audio_delegate.h"
#include "chrome/browser/vr/content_input_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" #include "chrome/browser/vr/ui.h"
namespace vr { namespace vr {
...@@ -12,13 +17,14 @@ namespace vr { ...@@ -12,13 +17,14 @@ namespace vr {
std::unique_ptr<UiInterface> UiFactory::Create( std::unique_ptr<UiInterface> UiFactory::Create(
UiBrowserInterface* browser, UiBrowserInterface* browser,
PlatformInputHandler* content_input_forwarder, PlatformInputHandler* content_input_forwarder,
KeyboardDelegate* keyboard_delegate, std::unique_ptr<KeyboardDelegate> keyboard_delegate,
TextInputDelegate* text_input_delegate, std::unique_ptr<TextInputDelegate> text_input_delegate,
AudioDelegate* audio_delegate, std::unique_ptr<AudioDelegate> audio_delegate,
const UiInitialState& ui_initial_state) { const UiInitialState& ui_initial_state) {
return std::make_unique<Ui>(browser, content_input_forwarder, return std::make_unique<Ui>(browser, content_input_forwarder,
keyboard_delegate, text_input_delegate, std::move(keyboard_delegate),
audio_delegate, ui_initial_state); std::move(text_input_delegate),
std::move(audio_delegate), ui_initial_state);
} }
} // namespace vr } // namespace vr
...@@ -24,9 +24,9 @@ class VR_EXPORT UiFactory { ...@@ -24,9 +24,9 @@ class VR_EXPORT UiFactory {
static std::unique_ptr<UiInterface> Create( static std::unique_ptr<UiInterface> Create(
UiBrowserInterface* browser, UiBrowserInterface* browser,
PlatformInputHandler* content_input_forwarder, PlatformInputHandler* content_input_forwarder,
KeyboardDelegate* keyboard_delegate, std::unique_ptr<KeyboardDelegate> keyboard_delegate,
TextInputDelegate* text_input_delegate, std::unique_ptr<TextInputDelegate> text_input_delegate,
AudioDelegate* audio_delegate, std::unique_ptr<AudioDelegate> audio_delegate,
const UiInitialState& ui_initial_state); const UiInitialState& ui_initial_state);
}; };
......
...@@ -105,8 +105,6 @@ class UiInterface : public BrowserUiInterface, public KeyboardUiInterface { ...@@ -105,8 +105,6 @@ class UiInterface : public BrowserUiInterface, public KeyboardUiInterface {
ReticleModel* reticle_model, ReticleModel* reticle_model,
InputEventList* input_event_list) = 0; InputEventList* input_event_list) = 0;
virtual void HandleMenuButtonEvents(InputEventList* input_event_list) = 0; virtual void HandleMenuButtonEvents(InputEventList* input_event_list) = 0;
virtual void RequestFocus(int element_id) = 0;
virtual void RequestUnfocus(int element_id) = 0;
// This function calculates the minimal FOV (in degrees) which covers all // This function calculates the minimal FOV (in degrees) which covers all
// visible overflow elements as if it was viewing from fov_recommended. For // visible overflow elements as if it was viewing from fov_recommended. For
......
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