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