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