Commit b8985eb3 authored by Aldo Culquicondor's avatar Aldo Culquicondor Committed by Commit Bot

Split VrShellGl into a compositor and scheduler delegates

The delegates communicate through 2 channels in the android
implementation:
1. WebXrPresentationState, owned by the scheduler.
2. The public interface of VrShellGl. Ideally, this interface should
remain very small to ensure the task separation.

VrShellGl now only implements the CompositorDelegate, and it's soon to
be renamed. RenderLoop now owns the delegates.

Bug: 875291
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: Ia30e62ed249b5fc0682b8f2b943eef615408daa3
Reviewed-on: https://chromium-review.googlesource.com/1191864
Commit-Queue: Aldo Culquicondor <acondor@chromium.org>
Reviewed-by: default avatarKlaus Weidner <klausw@chromium.org>
Reviewed-by: default avatarMichael Thiessen <mthiesse@chromium.org>
Cr-Commit-Position: refs/heads/master@{#589342}
parent 8977b622
......@@ -25,6 +25,8 @@ static_library("vr_android") {
"gvr_keyboard_delegate.cc",
"gvr_keyboard_delegate.h",
"gvr_keyboard_shim.cc",
"gvr_scheduler_delegate.cc",
"gvr_scheduler_delegate.h",
"gvr_util.cc",
"gvr_util.h",
"mailbox_to_surface_bridge.cc",
......
......@@ -4,8 +4,9 @@
#include "chrome/browser/android/vr/android_vsync_helper.h"
#include <utility>
#include "base/android/jni_android.h"
#include "base/callback_helpers.h"
#include "base/logging.h"
#include "jni/AndroidVSyncHelper_jni.h"
......@@ -14,7 +15,8 @@ using base::android::JavaParamRef;
namespace vr {
AndroidVSyncHelper::AndroidVSyncHelper() {
AndroidVSyncHelper::AndroidVSyncHelper(Callback callback)
: callback_(std::move(callback)) {
JNIEnv* env = AttachCurrentThread();
j_object_.Reset(
Java_AndroidVSyncHelper_create(env, reinterpret_cast<jlong>(this)));
......@@ -31,33 +33,30 @@ void AndroidVSyncHelper::OnVSync(JNIEnv* env,
const JavaParamRef<jobject>& obj,
jlong time_nanos) {
// See WindowAndroid::OnVSync.
DCHECK(vsync_requested_);
vsync_requested_ = false;
DCHECK_EQ(base::TimeTicks::GetClock(),
base::TimeTicks::Clock::LINUX_CLOCK_MONOTONIC);
DCHECK(!callback_.is_null());
base::TimeTicks frame_time =
base::TimeTicks() +
base::TimeDelta::FromMicroseconds(time_nanos /
base::Time::kNanosecondsPerMicrosecond);
base::TimeTicks() + base::TimeDelta::FromNanoseconds(time_nanos);
last_interval_ = frame_time - last_vsync_;
last_vsync_ = frame_time;
base::ResetAndReturn(&callback_).Run(frame_time);
callback_.Run(frame_time);
}
void AndroidVSyncHelper::RequestVSync(
const base::RepeatingCallback<void(base::TimeTicks)>& callback) {
DCHECK(callback_.is_null());
DCHECK(!callback.is_null());
callback_ = callback;
void AndroidVSyncHelper::RequestVSync() {
DCHECK(!vsync_requested_);
vsync_requested_ = true;
JNIEnv* env = AttachCurrentThread();
Java_AndroidVSyncHelper_requestVSync(env, j_object_);
}
void AndroidVSyncHelper::CancelVSyncRequest() {
if (callback_.is_null())
if (!vsync_requested_)
return;
vsync_requested_ = false;
JNIEnv* env = AttachCurrentThread();
Java_AndroidVSyncHelper_cancelVSyncRequest(env, j_object_);
callback_.Reset();
}
} // namespace vr
......@@ -6,6 +6,7 @@
#define CHROME_BROWSER_ANDROID_VR_ANDROID_VSYNC_HELPER_H_
#include <jni.h>
#include <utility>
#include "base/android/jni_weak_ref.h"
#include "base/callback.h"
......@@ -16,14 +17,13 @@ namespace vr {
class AndroidVSyncHelper {
public:
AndroidVSyncHelper();
using Callback = base::RepeatingCallback<void(base::TimeTicks)>;
explicit AndroidVSyncHelper(Callback callback);
~AndroidVSyncHelper();
void OnVSync(JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj,
jlong time_nanos);
void RequestVSync(
const base::RepeatingCallback<void(base::TimeTicks)>& callback);
void RequestVSync();
void CancelVSyncRequest();
// The last interval will be a multiple of the actual refresh interval, use
......@@ -37,7 +37,8 @@ class AndroidVSyncHelper {
base::TimeTicks last_vsync_;
base::TimeDelta last_interval_;
base::TimeDelta display_vsync_interval_;
base::RepeatingCallback<void(base::TimeTicks)> callback_;
Callback callback_;
bool vsync_requested_ = false;
base::android::ScopedJavaGlobalRef<jobject> j_object_;
......
This diff is collapsed.
This diff is collapsed.
......@@ -6,8 +6,10 @@
#include <utility>
#include "base/threading/thread_task_runner_handle.h"
#include "chrome/browser/android/vr/gvr_controller_delegate.h"
#include "chrome/browser/android/vr/gvr_keyboard_delegate.h"
#include "chrome/browser/android/vr/gvr_scheduler_delegate.h"
#include "chrome/browser/android/vr/vr_gl_thread.h"
#include "chrome/browser/android/vr/vr_shell_gl.h"
#include "chrome/browser/vr/render_loop.h"
......@@ -27,7 +29,7 @@ RenderLoopFactory::Params::Params(
gvr::GvrApi* gvr_api,
const UiInitialState& ui_initial_state,
bool reprojected_rendering,
bool daydream_support,
bool cardboard_gamepad,
bool pause_content,
bool low_density,
base::WaitableEvent* gl_surface_created_event,
......@@ -35,7 +37,7 @@ RenderLoopFactory::Params::Params(
: gvr_api(gvr_api),
ui_initial_state(ui_initial_state),
reprojected_rendering(reprojected_rendering),
daydream_support(daydream_support),
cardboard_gamepad(cardboard_gamepad),
pause_content(pause_content),
low_density(low_density),
gl_surface_created_event(gl_surface_created_event),
......@@ -64,28 +66,27 @@ std::unique_ptr<RenderLoop> RenderLoopFactory::Create(
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, params->gvr_api, params->reprojected_rendering,
params->daydream_support, params->ui_initial_state.in_web_vr,
params->pause_content, params->low_density, kSlidingAverageSize);
vr_gl_thread->task_runner()->PostTask(
auto compositor_delegate = std::make_unique<VrShellGl>(
vr_gl_thread,
base::BindOnce(&UiInterface::OnGlInitialized, base::Unretained(ui.get())),
params->gvr_api, params->reprojected_rendering, params->pause_content,
params->low_density, kSlidingAverageSize);
auto scheduler_delegate = std::make_unique<GvrSchedulerDelegate>(
vr_gl_thread, ui.get(), params->gvr_api, compositor_delegate.get(),
params->ui_initial_state.in_web_vr, params->cardboard_gamepad,
kSlidingAverageSize);
compositor_delegate->set_webxr_presentation_state(
scheduler_delegate->webxr());
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE,
base::BindOnce(&VrShellGl::Init, vr_shell_gl->GetWeakPtr(),
base::BindOnce(&VrShellGl::Init, compositor_delegate->GetWeakPtr(),
base::Unretained(params->gl_surface_created_event),
base::Passed(std::move(params->surface_callback))));
SchedulerDelegate* scheduler_delegate = vr_shell_gl.get();
base::Passed(std::move(params->surface_callback)),
params->ui_initial_state.in_web_vr));
auto render_loop = std::make_unique<RenderLoop>(
std::move(ui), std::move(vr_shell_gl), scheduler_delegate,
std::move(controller_delegate), vr_gl_thread, kSlidingAverageSize);
scheduler_delegate->SetDrawWebXrCallback(base::BindRepeating(
&RenderLoop::Draw, base::Unretained(render_loop.get()),
CompositorDelegate::kWebXrFrame));
scheduler_delegate->SetDrawBrowserCallback(base::BindRepeating(
&RenderLoop::Draw, base::Unretained(render_loop.get()),
CompositorDelegate::kUiFrame));
scheduler_delegate->SetWebXrInputCallback(
base::BindRepeating(&RenderLoop::ProcessControllerInputForWebXr,
base::Unretained(render_loop.get())));
std::move(ui), std::move(scheduler_delegate),
std::move(compositor_delegate), std::move(controller_delegate),
vr_gl_thread, kSlidingAverageSize);
return render_loop;
}
......
......@@ -32,7 +32,7 @@ class VR_EXPORT RenderLoopFactory {
Params(gvr::GvrApi* gvr_api,
const UiInitialState& ui_initial_state,
bool reprojected_rendering,
bool daydream_support,
bool cardboard_gamepad,
bool pause_content,
bool low_density,
base::WaitableEvent* gl_surface_created_event,
......@@ -41,7 +41,7 @@ class VR_EXPORT RenderLoopFactory {
gvr::GvrApi* gvr_api;
UiInitialState ui_initial_state;
bool reprojected_rendering;
bool daydream_support;
bool cardboard_gamepad;
bool pause_content;
bool low_density;
base::WaitableEvent* gl_surface_created_event;
......
......@@ -8,18 +8,20 @@
#include "base/strings/string16.h"
#include "base/version.h"
#include "chrome/browser/android/vr/metrics_util_android.h"
#include "chrome/browser/android/vr/vr_input_connection.h"
#include "chrome/browser/android/vr/vr_shell.h"
#include "chrome/browser/android/vr/vr_shell_gl.h"
#include "chrome/browser/vr/assets_loader.h"
#include "chrome/browser/vr/browser_ui_interface.h"
#include "chrome/browser/vr/model/assets.h"
#include "chrome/browser/vr/model/omnibox_suggestions.h"
#include "chrome/browser/vr/model/toolbar_state.h"
#include "chrome/browser/vr/render_loop.h"
#include "chrome/browser/vr/sounds_manager_audio_delegate.h"
#include "chrome/browser/vr/ui_factory.h"
#include "chrome/browser/vr/ui_test_input.h"
#include "chrome/common/chrome_features.h"
#include "third_party/gvr-android-sdk/src/libraries/headers/vr/gvr/capi/include/gvr.h"
#include "third_party/skia/include/core/SkBitmap.h"
namespace vr {
......@@ -43,11 +45,14 @@ VrGLThread::VrGLThread(
gvr_api_.get(),
ui_initial_state,
reprojected_rendering,
daydream_support,
gvr_api_->GetViewerType() ==
gvr::ViewerType::GVR_VIEWER_TYPE_CARDBOARD,
pause_content,
low_density,
gl_surface_created_event,
std::move(surface_callback))) {}
std::move(surface_callback))) {
MetricsUtilAndroid::LogVrViewerType(gvr_api_->GetViewerType());
}
VrGLThread::~VrGLThread() {
Stop();
......
This diff is collapsed.
This diff is collapsed.
......@@ -4,7 +4,6 @@
#include "chrome/browser/android/vr/web_xr_presentation_state.h"
#include "base/callback_helpers.h"
#include "base/trace_event/trace_event.h"
#include "gpu/command_buffer/common/mailbox_holder.h"
#include "gpu/ipc/common/gpu_memory_buffer_impl_android_hardware_buffer.h"
......@@ -119,10 +118,6 @@ bool WebXrPresentationState::RecycleProcessingFrameIfPossible() {
void WebXrPresentationState::EndPresentation() {
TRACE_EVENT0("gpu", __FUNCTION__);
if (end_presentation_callback) {
base::ResetAndReturn(&end_presentation_callback).Run();
}
if (HaveRenderingFrame()) {
rendering_frame_->Recycle();
idle_frames_.push(rendering_frame_);
......@@ -155,7 +150,7 @@ void WebXrPresentationState::ProcessOrDefer(base::OnceClosure callback) {
DCHECK(animating_frame_ && !animating_frame_->deferred_start_processing);
if (CanProcessFrame()) {
TransitionFrameAnimatingToProcessing();
base::ResetAndReturn(&callback).Run();
std::move(callback).Run();
} else {
DVLOG(2) << "Deferring processing frame, not ready";
animating_frame_->deferred_start_processing = std::move(callback);
......@@ -171,7 +166,7 @@ void WebXrPresentationState::TryDeferredProcessing() {
// Run synchronously, not via PostTask, to ensure we don't
// get a new SendVSync scheduling in between.
TransitionFrameAnimatingToProcessing();
base::ResetAndReturn(&animating_frame_->deferred_start_processing).Run();
std::move(animating_frame_->deferred_start_processing).Run();
}
} // namespace vr
......@@ -6,8 +6,9 @@
#define CHROME_BROWSER_ANDROID_VR_WEB_XR_PRESENTATION_STATE_H_
#include <memory>
#include <utility>
#include "base/cancelable_callback.h"
#include "base/callback.h"
#include "base/containers/queue.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
......@@ -167,15 +168,15 @@ class WebXrPresentationState {
// becoming true.
void TryDeferredProcessing();
bool HaveAnimatingFrame() { return animating_frame_; }
bool HaveAnimatingFrame() const { return animating_frame_; }
WebXrFrame* GetAnimatingFrame();
bool HaveProcessingFrame() { return processing_frame_; }
bool HaveProcessingFrame() const { return processing_frame_; }
WebXrFrame* GetProcessingFrame();
bool HaveRenderingFrame() { return rendering_frame_; }
bool HaveRenderingFrame() const { return rendering_frame_; }
WebXrFrame* GetRenderingFrame();
void set_mailbox_bridge_ready(bool ready) { mailbox_bridge_ready_ = ready; }
bool mailbox_bridge_ready() const { return mailbox_bridge_ready_; }
bool mailbox_bridge_ready() { return mailbox_bridge_ready_; }
void NotifyMailboxBridgeReady() { mailbox_bridge_ready_ = true; }
// Used by WebVrCanAnimateFrame() to detect when ui_->CanSendWebVrVSync()
// transitions from false to true, as part of starting the incoming frame
......@@ -186,8 +187,6 @@ class WebXrPresentationState {
// this, but try to keep it unique to avoid confusion.
int next_memory_buffer_id = 0;
base::OnceClosure end_presentation_callback;
private:
// Checks if we're in a valid state for processing the current animating
// frame. Invalid states include mailbox_bridge_ready_ being false, or an
......
......@@ -213,6 +213,7 @@ component("vr_common") {
"sample_queue.cc",
"sample_queue.h",
"scheduler_delegate.h",
"scheduler_render_loop_interface.h",
"service/browser_xr_runtime.cc",
"service/browser_xr_runtime.h",
"service/isolated_device_provider.cc",
......@@ -278,8 +279,8 @@ source_set("vr_base") {
"assets_loader.cc",
"assets_loader.h",
"browser_ui_interface.h",
"compositor_ui_interface.h",
"exit_vr_prompt_choice.h",
"fov_rectangle.h",
"gl_texture_location.h",
"input_event.cc",
"input_event.h",
......@@ -314,6 +315,7 @@ source_set("vr_base") {
"pose_util.cc",
"pose_util.h",
"render_info.h",
"scheduler_ui_interface.h",
"speech_recognizer.cc",
"speech_recognizer.h",
"text_edit_action.cc",
......
......@@ -6,13 +6,12 @@
#define CHROME_BROWSER_VR_COMPOSITOR_DELEGATE_H_
#include "base/callback.h"
#include "chrome/browser/vr/compositor_ui_interface.h"
#include "chrome/browser/vr/fov_rectangle.h"
#include "chrome/browser/vr/gl_texture_location.h"
#include "chrome/browser/vr/vr_export.h"
#include "device/vr/public/mojom/isolated_xr_service.mojom.h"
#include "device/vr/public/mojom/vr_service.mojom.h"
namespace gfx {
class Size;
class Transform;
}
......@@ -24,16 +23,24 @@ namespace vr {
struct RenderInfo;
// The CompositorDelegate manages surfaces, buffers and viewports, preparing
// them for drawing browser UI. It provides projection and view matrices for the
// viewports.
class VR_EXPORT CompositorDelegate {
public:
using Transform = float[16];
enum FrameType { kUiFrame, kWebXrFrame };
using SkiaContextCallback = base::OnceCallback<void()>;
using TexturesInitializedCallback = base::OnceCallback<
void(GlTextureLocation, unsigned int, unsigned int, unsigned int)>;
virtual ~CompositorDelegate() {}
virtual void OnResume() = 0;
virtual FovRectangles GetRecommendedFovs() = 0;
virtual float GetZNear() = 0;
virtual RenderInfo GetRenderInfo(FrameType frame_type) = 0;
virtual RenderInfo GetRenderInfo(FrameType frame_type,
const gfx::Transform& head_pose) = 0;
virtual RenderInfo GetOptimizedRenderInfoForFovs(
const FovRectangles& fovs) = 0;
virtual void InitializeBuffers() = 0;
......@@ -51,16 +58,8 @@ class VR_EXPORT CompositorDelegate {
virtual void GetContentQuadDrawParams(Transform* uv_transform,
float* border_x,
float* border_y) = 0;
virtual void SubmitFrame(FrameType frame_type) = 0;
virtual void SetUiInterface(CompositorUiInterface* ui) = 0;
virtual void SetShowingVrDialog(bool showing) = 0;
virtual int GetContentBufferWidth() = 0;
virtual void ConnectPresentingService(
device::mojom::VRDisplayInfoPtr display_info,
device::mojom::XRRuntimeSessionOptionsPtr options) = 0;
// These methods return true when succeeded.
virtual bool Initialize(const scoped_refptr<gl::GLSurface>& surface) = 0;
virtual bool RunInSkiaContext(SkiaContextCallback callback) = 0;
......
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_VR_COMPOSITOR_UI_INTERFACE_H_
#define CHROME_BROWSER_VR_COMPOSITOR_UI_INTERFACE_H_
#ifndef CHROME_BROWSER_VR_FOV_RECTANGLE_H_
#define CHROME_BROWSER_VR_FOV_RECTANGLE_H_
#include <utility>
......@@ -21,21 +21,6 @@ struct FovRectangle {
using FovRectangles = std::pair<FovRectangle, FovRectangle>;
class VR_EXPORT CompositorUiInterface {
public:
virtual ~CompositorUiInterface() {}
virtual void OnGlInitialized(unsigned int content_texture_id,
GlTextureLocation content_location,
unsigned int content_overlay_texture_id,
GlTextureLocation content_overlay_location,
unsigned int ui_texture_id) = 0;
virtual void OnWebXrFrameAvailable() = 0;
virtual void OnWebXrTimedOut() = 0;
virtual void OnWebXrTimeoutImminent() = 0;
};
} // namespace vr
#endif // CHROME_BROWSER_VR_COMPOSITOR_UI_INTERFACE_H_
#endif // CHROME_BROWSER_VR_FOV_RECTANGLE_H_
......@@ -23,28 +23,37 @@
namespace vr {
RenderLoop::RenderLoop(std::unique_ptr<UiInterface> ui,
std::unique_ptr<SchedulerDelegate> scheduler_delegate,
std::unique_ptr<CompositorDelegate> compositor_delegate,
SchedulerDelegate* scheduler_delegate,
std::unique_ptr<ControllerDelegate> controller_delegate,
RenderLoopBrowserInterface* browser,
size_t sliding_time_size)
: ui_(std::move(ui)),
scheduler_delegate_(std::move(scheduler_delegate)),
compositor_delegate_(std::move(compositor_delegate)),
scheduler_delegate_(scheduler_delegate),
controller_delegate_(std::move(controller_delegate)),
browser_(browser),
ui_processing_time_(sliding_time_size),
ui_controller_update_time_(sliding_time_size),
weak_ptr_factory_(this) {
compositor_delegate_->SetUiInterface(ui_.get());
scheduler_delegate_->SetRenderLoop(this);
}
RenderLoop::~RenderLoop() = default;
void RenderLoop::DrawBrowserFrame(base::TimeTicks current_time) {
Draw(CompositorDelegate::kUiFrame, current_time);
}
void RenderLoop::DrawWebXrFrame(base::TimeTicks current_time) {
Draw(CompositorDelegate::kWebXrFrame, current_time);
}
void RenderLoop::Draw(CompositorDelegate::FrameType frame_type,
base::TimeTicks current_time) {
TRACE_EVENT1("gpu", __func__, "frame_type", frame_type);
const auto& render_info = compositor_delegate_->GetRenderInfo(frame_type);
const auto& render_info = compositor_delegate_->GetRenderInfo(
frame_type, scheduler_delegate_->GetHeadPose());
UpdateUi(render_info, current_time, frame_type);
ui_->OnProjMatrixChanged(render_info.left_eye_model.proj_matrix);
bool use_quad_layer = ui_->IsContentVisibleAndOpaque() &&
......@@ -67,7 +76,6 @@ void RenderLoop::Draw(CompositorDelegate::FrameType frame_type,
ui_processing_time_.GetAverage().InMicroseconds(),
"controller",
ui_controller_update_time_.GetAverage().InMicroseconds());
compositor_delegate_->SubmitFrame(frame_type);
}
void RenderLoop::DrawWebXr() {
......@@ -150,12 +158,13 @@ void RenderLoop::OnSwapContents(int new_content_id) {
void RenderLoop::EnableAlertDialog(PlatformInputHandler* input_handler,
float width,
float height) {
compositor_delegate_->SetShowingVrDialog(true);
scheduler_delegate_->SetShowingVrDialog(true);
vr_dialog_input_delegate_ =
std::make_unique<PlatformUiInputDelegate>(input_handler);
vr_dialog_input_delegate_->SetSize(width, height);
auto content_width = compositor_delegate_->GetContentBufferWidth();
if (content_width) {
if (ui_->IsContentVisibleAndOpaque()) {
auto content_width = compositor_delegate_->GetContentBufferWidth();
DCHECK(content_width);
ui_->SetContentOverlayAlertDialogEnabled(
true, vr_dialog_input_delegate_.get(), width / content_width,
height / content_width);
......@@ -168,7 +177,7 @@ void RenderLoop::EnableAlertDialog(PlatformInputHandler* input_handler,
void RenderLoop::DisableAlertDialog() {
ui_->SetAlertDialogEnabled(false, nullptr, 0, 0);
vr_dialog_input_delegate_ = nullptr;
compositor_delegate_->SetShowingVrDialog(false);
scheduler_delegate_->SetShowingVrDialog(false);
}
void RenderLoop::SetAlertDialogSize(float width, float height) {
......@@ -178,8 +187,9 @@ void RenderLoop::SetAlertDialogSize(float width, float height) {
// ratio matters. But, if they are floating, its size should be relative to
// the contents. During a WebXR presentation, the contents are not present
// but, in this case, the dialogs are never floating.
auto content_width = compositor_delegate_->GetContentBufferWidth();
if (content_width) {
if (ui_->IsContentVisibleAndOpaque()) {
auto content_width = compositor_delegate_->GetContentBufferWidth();
DCHECK(content_width);
ui_->SetContentOverlayAlertDialogEnabled(
true, vr_dialog_input_delegate_.get(), width / content_width,
height / content_width);
......@@ -266,14 +276,14 @@ void RenderLoop::UpdateUi(const RenderInfo& render_info,
ui_processing_time_.AddSample(scene_time - controller_time);
}
void RenderLoop::ProcessControllerInputForWebXr(const gfx::Transform& head_pose,
base::TimeTicks current_time) {
void RenderLoop::ProcessControllerInputForWebXr(base::TimeTicks current_time) {
TRACE_EVENT0("gpu", __func__);
DCHECK(controller_delegate_);
DCHECK(ui_);
base::TimeTicks timing_start = base::TimeTicks::Now();
controller_delegate_->UpdateController(head_pose, current_time, true);
controller_delegate_->UpdateController(scheduler_delegate_->GetHeadPose(),
current_time, true);
auto input_event_list = controller_delegate_->GetGestures(current_time);
ui_->HandleMenuButtonEvents(&input_event_list);
......@@ -286,8 +296,8 @@ void RenderLoop::ProcessControllerInputForWebXr(const gfx::Transform& head_pose,
void RenderLoop::ConnectPresentingService(
device::mojom::VRDisplayInfoPtr display_info,
device::mojom::XRRuntimeSessionOptionsPtr options) {
compositor_delegate_->ConnectPresentingService(std::move(display_info),
std::move(options));
scheduler_delegate_->ConnectPresentingService(std::move(display_info),
std::move(options));
}
base::TimeDelta RenderLoop::ProcessControllerInput(
......
......@@ -11,8 +11,11 @@
#include "base/memory/weak_ptr.h"
#include "chrome/browser/vr/compositor_delegate.h"
#include "chrome/browser/vr/gl_texture_location.h"
#include "chrome/browser/vr/scheduler_render_loop_interface.h"
#include "chrome/browser/vr/sliding_average.h"
#include "chrome/browser/vr/vr_export.h"
#include "device/vr/public/mojom/isolated_xr_service.mojom.h"
#include "device/vr/public/mojom/vr_service.mojom.h"
namespace base {
class TimeDelta;
......@@ -34,23 +37,19 @@ struct RenderInfo;
struct UiTestActivityExpectation;
struct UiTestState;
// This abstract class handles all input/output activities during a frame.
// The RenderLoop handles all input/output activities during a frame.
// This includes head movement, controller movement and input, audio output and
// rendering of the frame.
// TODO(acondor): Move more functionality cross platform functionality from
// VrShellGl and make this class concrete (http://crbug.com/767282).
class VR_EXPORT RenderLoop {
// TODO(acondor): Rename to BrowserRenderer.
class VR_EXPORT RenderLoop : public SchedulerRenderLoopInterface {
public:
RenderLoop(std::unique_ptr<UiInterface> ui,
std::unique_ptr<SchedulerDelegate> scheduler_delegate,
std::unique_ptr<CompositorDelegate> compositor_delegate,
SchedulerDelegate* scheduler_delegate,
std::unique_ptr<ControllerDelegate> controller_delegate,
RenderLoopBrowserInterface* browser,
size_t sliding_time_size);
virtual ~RenderLoop();
void Draw(CompositorDelegate::FrameType frame_type,
base::TimeTicks current_time);
~RenderLoop() override;
void OnPause();
void OnResume();
......@@ -80,13 +79,19 @@ class VR_EXPORT RenderLoop {
void SetUiExpectingActivityForTesting(
UiTestActivityExpectation ui_expectation);
void AcceptDoffPromptForTesting();
void ProcessControllerInputForWebXr(const gfx::Transform& head_pose,
base::TimeTicks current_time);
void ConnectPresentingService(
device::mojom::VRDisplayInfoPtr display_info,
device::mojom::XRRuntimeSessionOptionsPtr options);
// SchedulerRenderLoopInterface implementation.
void DrawBrowserFrame(base::TimeTicks current_time) override;
void DrawWebXrFrame(base::TimeTicks current_time) override;
void ProcessControllerInputForWebXr(base::TimeTicks current_time) override;
private:
void Draw(CompositorDelegate::FrameType frame_type,
base::TimeTicks current_time);
// Position, hide and/or show UI elements, process input and update textures.
// Returns true if the scene changed.
void UpdateUi(const RenderInfo& render_info,
......@@ -104,8 +109,8 @@ class VR_EXPORT RenderLoop {
void ReportUiActivityResultForTesting(VrUiTestActivityResult result);
std::unique_ptr<UiInterface> ui_;
std::unique_ptr<SchedulerDelegate> scheduler_delegate_;
std::unique_ptr<CompositorDelegate> compositor_delegate_;
SchedulerDelegate* scheduler_delegate_;
std::unique_ptr<ControllerDelegate> controller_delegate_;
std::unique_ptr<ControllerDelegate> controller_delegate_for_testing_;
bool using_controller_delegate_for_testing_ = false;
......
......@@ -8,6 +8,7 @@
#include "base/callback.h"
#include "base/time/time.h"
#include "chrome/browser/vr/vr_export.h"
#include "device/vr/public/mojom/isolated_xr_service.mojom.h"
#include "device/vr/public/mojom/vr_service.mojom.h"
namespace gfx {
......@@ -16,24 +17,30 @@ class Transform;
namespace vr {
class SchedulerRenderLoopInterface;
// The SchedulerDelegate is responsible for starting the draw calls of the
// RenderLoop, given different signals, such as WebXR frames submitted or VSync
// events. It also provides head poses, obtained from the underlaying platform.
// TODO(acondor): Move head pose logic to the ControllerDelegate.
class VR_EXPORT SchedulerDelegate {
public:
using DrawCallback = base::RepeatingCallback<void(base::TimeTicks)>;
using WebXrInputCallback =
base::RepeatingCallback<void(const gfx::Transform&, base::TimeTicks)>;
virtual ~SchedulerDelegate() {}
virtual void OnPause() = 0;
virtual void OnResume() = 0;
virtual gfx::Transform GetHeadPose() = 0;
virtual void OnExitPresent() = 0;
virtual void OnTriggerEvent(bool pressed) = 0;
virtual void SetWebXrMode(bool enabled) = 0;
virtual void SetDrawWebXrCallback(DrawCallback callback) = 0;
virtual void SetDrawBrowserCallback(DrawCallback callback) = 0;
virtual void SetWebXrInputCallback(WebXrInputCallback callback) = 0;
virtual void SetShowingVrDialog(bool showing) = 0;
virtual void SetRenderLoop(SchedulerRenderLoopInterface* render_loop) = 0;
virtual void AddInputSourceState(
device::mojom::XRInputSourceStatePtr state) = 0;
virtual void ConnectPresentingService(
device::mojom::VRDisplayInfoPtr display_info,
device::mojom::XRRuntimeSessionOptionsPtr transport_options) = 0;
};
} // 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_VR_SCHEDULER_RENDER_LOOP_INTERFACE_H_
#define CHROME_BROWSER_VR_SCHEDULER_RENDER_LOOP_INTERFACE_H_
namespace base {
class TimeTicks;
}
namespace vr {
class SchedulerRenderLoopInterface {
public:
virtual ~SchedulerRenderLoopInterface() {}
virtual void DrawBrowserFrame(base::TimeTicks current_time) = 0;
virtual void DrawWebXrFrame(base::TimeTicks current_time) = 0;
virtual void ProcessControllerInputForWebXr(base::TimeTicks current_time) = 0;
};
} // namespace vr
#endif // CHROME_BROWSER_VR_SCHEDULER_RENDER_LOOP_INTERFACE_H_
// 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_VR_SCHEDULER_UI_INTERFACE_H_
#define CHROME_BROWSER_VR_SCHEDULER_UI_INTERFACE_H_
#include <utility>
#include "chrome/browser/vr/gl_texture_location.h"
#include "chrome/browser/vr/vr_export.h"
namespace vr {
class VR_EXPORT SchedulerUiInterface {
public:
virtual ~SchedulerUiInterface() {}
virtual void OnWebXrFrameAvailable() = 0;
virtual void OnWebXrTimedOut() = 0;
virtual void OnWebXrTimeoutImminent() = 0;
};
} // namespace vr
#endif // CHROME_BROWSER_VR_SCHEDULER_UI_INTERFACE_H_
......@@ -56,8 +56,8 @@ void UiPixelTest::MakeUi(const UiInitialState& ui_initial_state,
const ToolbarState& toolbar_state) {
ui_ = std::make_unique<Ui>(browser_.get(), nullptr, nullptr, nullptr, nullptr,
ui_initial_state);
ui_->OnGlInitialized(content_texture_, kGlTextureLocationLocal,
content_overlay_texture_, kGlTextureLocationLocal, 0);
ui_->OnGlInitialized(kGlTextureLocationLocal, content_texture_,
content_overlay_texture_, 0);
ui_->GetBrowserUiWeakPtr()->SetToolbarState(toolbar_state);
}
......
......@@ -42,13 +42,15 @@ bool GlRenderer::Initialize(const scoped_refptr<gl::GLSurface>& surface) {
}
// TODO(acondor): Provide actual implementation for the methods.
void GlRenderer::OnResume() {}
FovRectangles GlRenderer::GetRecommendedFovs() {
return {{}, {}};
}
float GlRenderer::GetZNear() {
return 0;
}
RenderInfo GlRenderer::GetRenderInfo(FrameType frame_type) {
RenderInfo GlRenderer::GetRenderInfo(FrameType frame_type,
const gfx::Transform& head_pose) {
return {};
}
RenderInfo GlRenderer::GetOptimizedRenderInfoForFovs(
......@@ -72,15 +74,9 @@ void GlRenderer::BufferBoundsChanged(const gfx::Size& content_buffer_size,
void GlRenderer::GetContentQuadDrawParams(Transform* uv_transform,
float* border_x,
float* border_y) {}
void GlRenderer::SubmitFrame(FrameType frame_type) {}
void GlRenderer::SetUiInterface(CompositorUiInterface* ui) {}
void GlRenderer::SetShowingVrDialog(bool showing) {}
int GlRenderer::GetContentBufferWidth() {
return 0;
}
void GlRenderer::ConnectPresentingService(
device::mojom::VRDisplayInfoPtr display_info,
device::mojom::XRRuntimeSessionOptionsPtr options) {}
void GlRenderer::RenderFrame() {
// Checking and clearing GL errors can be expensive, but we can afford to do
......
......@@ -27,9 +27,11 @@ class GlRenderer : public BaseCompositorDelegate {
// CompositorDelegate implementation.
bool Initialize(const scoped_refptr<gl::GLSurface>& surface) override;
void OnResume() override;
FovRectangles GetRecommendedFovs() override;
float GetZNear() override;
RenderInfo GetRenderInfo(FrameType frame_type) override;
RenderInfo GetRenderInfo(FrameType frame_type,
const gfx::Transform& head_pose) override;
RenderInfo GetOptimizedRenderInfoForFovs(const FovRectangles& fovs) override;
void InitializeBuffers() override;
void PrepareBufferForWebXr() override;
......@@ -46,13 +48,7 @@ class GlRenderer : public BaseCompositorDelegate {
void GetContentQuadDrawParams(Transform* uv_transform,
float* border_x,
float* border_y) override;
void SubmitFrame(FrameType frame_type) override;
void SetUiInterface(CompositorUiInterface* ui) override;
void SetShowingVrDialog(bool showing) override;
int GetContentBufferWidth() override;
void ConnectPresentingService(
device::mojom::VRDisplayInfoPtr display_info,
device::mojom::XRRuntimeSessionOptionsPtr options) override;
void RenderFrame();
void PostRenderFrameTask();
......
......@@ -165,9 +165,8 @@ 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);
ui_->OnGlInitialized(kGlTextureLocationLocal, content_texture_id,
content_texture_id, ui_texture_id);
keyboard_delegate_->Initialize(
ui_instance_->scene()->SurfaceProviderForTesting(),
ui_instance_->ui_element_renderer());
......
......@@ -369,11 +369,10 @@ void Ui::CancelPlatformToast() {
model_->platform_toast.reset();
}
void Ui::OnGlInitialized(unsigned int content_texture_id,
GlTextureLocation content_location,
void Ui::OnGlInitialized(GlTextureLocation textures_location,
unsigned int content_texture_id,
unsigned int content_overlay_texture_id,
GlTextureLocation content_overlay_location,
unsigned int ui_texture_id) {
unsigned int platform_ui_texture_id) {
ui_element_renderer_ = std::make_unique<UiElementRenderer>();
ui_renderer_ =
std::make_unique<UiRenderer>(scene_.get(), ui_element_renderer_.get());
......@@ -381,9 +380,9 @@ void Ui::OnGlInitialized(unsigned int content_texture_id,
scene_->OnGlInitialized(provider_.get());
model_->content_texture_id = content_texture_id;
model_->content_overlay_texture_id = content_overlay_texture_id;
model_->content_location = content_location;
model_->content_overlay_location = content_overlay_location;
model_->hosted_platform_ui.texture_id = ui_texture_id;
model_->content_location = textures_location;
model_->content_overlay_location = textures_location;
model_->hosted_platform_ui.texture_id = platform_ui_texture_id;
}
void Ui::RequestFocus(int element_id) {
......
......@@ -119,6 +119,10 @@ class VR_UI_EXPORT Ui : public UiInterface {
void RemoveAllTabs() override;
// UiInterface
void OnGlInitialized(GlTextureLocation textures_location,
unsigned int content_texture_id,
unsigned int content_overlay_texture_id,
unsigned int platform_ui_texture_id) override;
base::WeakPtr<BrowserUiInterface> GetBrowserUiWeakPtr() override;
void SetAlertDialogEnabled(bool enabled,
PlatformUiInputDelegate* delegate,
......@@ -177,12 +181,7 @@ class VR_UI_EXPORT Ui : public UiInterface {
const FovRectangle& fov_recommended_right,
float z_near) override;
// CompositorUiInterface
void OnGlInitialized(unsigned int content_texture_id,
GlTextureLocation content_location,
unsigned int content_overlay_texture_id,
GlTextureLocation content_overlay_location,
unsigned int ui_texture_id) override;
// SchedulerUiInterface
void OnWebXrFrameAvailable() override;
void OnWebXrTimedOut() override;
void OnWebXrTimeoutImminent() override;
......
......@@ -12,9 +12,10 @@
#include "base/memory/weak_ptr.h"
#include "chrome/browser/vr/browser_ui_interface.h"
#include "chrome/browser/vr/compositor_ui_interface.h"
#include "chrome/browser/vr/fov_rectangle.h"
#include "chrome/browser/vr/gl_texture_location.h"
#include "chrome/browser/vr/keyboard_ui_interface.h"
#include "chrome/browser/vr/scheduler_ui_interface.h"
namespace gfx {
class Point3F;
......@@ -38,13 +39,23 @@ using InputEventList = std::vector<std::unique_ptr<InputEvent>>;
// also serves to make all such methods virtual for the sake of separating a UI
// feature module.
class UiInterface : public BrowserUiInterface,
public CompositorUiInterface,
public SchedulerUiInterface,
public KeyboardUiInterface {
public:
~UiInterface() override {}
virtual base::WeakPtr<BrowserUiInterface> GetBrowserUiWeakPtr() = 0;
// Textures from 2D UI that are positioned in the 3D scene.
// Content refers to the web contents, as coming from the Chrome compositor.
// Content Overlay refers to UI drawn in the same view hierarchy as the
// contents.
// Platform UI refers to popups, which are rendered in a different window.
virtual void OnGlInitialized(GlTextureLocation textures_location,
unsigned int content_texture_id,
unsigned int content_overlay_texture_id,
unsigned int platform_ui_texture_id) = 0;
virtual void SetAlertDialogEnabled(bool enabled,
PlatformUiInputDelegate* delegate,
float width,
......
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