blob: e9218880fc3d117a677bc535acdd64f350c6a297 [file] [log] [blame]
Christopher Grant6cb4f2432018-07-19 15:29:131// Copyright 2018 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CHROME_BROWSER_VR_UI_INTERFACE_H_
6#define CHROME_BROWSER_VR_UI_INTERFACE_H_
7
8#include <memory>
9#include <queue>
Aldo Culquicondor3c315ea02018-08-13 20:45:0910#include <utility>
Aldo Culquicondorcc004c72018-08-02 14:50:0211#include <vector>
Christopher Grant6cb4f2432018-07-19 15:29:1312
13#include "base/memory/weak_ptr.h"
Aldo Culquicondorb8985eb2018-09-06 22:27:4414#include "chrome/browser/vr/fov_rectangle.h"
Aldo Culquicondor3c315ea02018-08-13 20:45:0915#include "chrome/browser/vr/gl_texture_location.h"
Aldo Culquicondorcc004c72018-08-02 14:50:0216
17namespace gfx {
18class Point3F;
Aldo Culquicondor3c315ea02018-08-13 20:45:0919class PointF;
20class Transform;
Aldo Culquicondorcc004c72018-08-02 14:50:0221}
Christopher Grant6cb4f2432018-07-19 15:29:1322
23namespace vr {
24
Christopher Grant50c0e2c2019-03-04 22:46:0725class AudioDelegate;
Christopher Grant6cb4f2432018-07-19 15:29:1326class BrowserUiInterface;
Aldo Culquicondor3c315ea02018-08-13 20:45:0927class InputEvent;
Christopher Grant50c0e2c2019-03-04 22:46:0728class KeyboardDelegate;
29class PlatformInputHandler;
Christopher Grant6cb4f2432018-07-19 15:29:1330class PlatformUiInputDelegate;
Aldo Culquicondor9122f39b2018-09-10 17:19:1631class SchedulerUiInterface;
Christopher Grant50c0e2c2019-03-04 22:46:0732class TextInputDelegate;
33class UiBrowserInterface;
Christopher Grant6cb4f2432018-07-19 15:29:1334struct ControllerModel;
35struct RenderInfo;
36struct ReticleModel;
Christopher Grant50c0e2c2019-03-04 22:46:0737struct UiInitialState;
Aldo Culquicondorcc004c72018-08-02 14:50:0238enum class UserFriendlyElementName;
Christopher Grant6cb4f2432018-07-19 15:29:1339
Aldo Culquicondor3c315ea02018-08-13 20:45:0940using InputEventList = std::vector<std::unique_ptr<InputEvent>>;
41
Christopher Grant6cb4f2432018-07-19 15:29:1342// This interface represents the methods that should be called by its owner, and
43// also serves to make all such methods virtual for the sake of separating a UI
44// feature module.
Aldo Culquicondor9122f39b2018-09-10 17:19:1645class UiInterface {
Christopher Grant6cb4f2432018-07-19 15:29:1346 public:
Aldo Culquicondor9122f39b2018-09-10 17:19:1647 virtual ~UiInterface() = default;
Christopher Grant6cb4f2432018-07-19 15:29:1348
49 virtual base::WeakPtr<BrowserUiInterface> GetBrowserUiWeakPtr() = 0;
Aldo Culquicondor9122f39b2018-09-10 17:19:1650 virtual SchedulerUiInterface* GetSchedulerUiPtr() = 0;
Christopher Grant6cb4f2432018-07-19 15:29:1351
Aldo Culquicondorb8985eb2018-09-06 22:27:4452 // Textures from 2D UI that are positioned in the 3D scene.
53 // Content refers to the web contents, as coming from the Chrome compositor.
54 // Content Overlay refers to UI drawn in the same view hierarchy as the
55 // contents.
56 // Platform UI refers to popups, which are rendered in a different window.
57 virtual void OnGlInitialized(GlTextureLocation textures_location,
58 unsigned int content_texture_id,
59 unsigned int content_overlay_texture_id,
60 unsigned int platform_ui_texture_id) = 0;
61
Christopher Grant6cb4f2432018-07-19 15:29:1362 virtual void SetAlertDialogEnabled(bool enabled,
63 PlatformUiInputDelegate* delegate,
64 float width,
65 float height) = 0;
66 virtual void SetContentOverlayAlertDialogEnabled(
67 bool enabled,
68 PlatformUiInputDelegate* delegate,
69 float width_percentage,
70 float height_percentage) = 0;
Christopher Grant6cb4f2432018-07-19 15:29:1371 virtual void OnPause() = 0;
Brandon Jones6e4b5ec2018-11-30 20:57:3772 virtual void OnControllersUpdated(
73 const std::vector<ControllerModel>& controller_models,
74 const ReticleModel& reticle_model) = 0;
Christopher Grant6cb4f2432018-07-19 15:29:1375 virtual void OnProjMatrixChanged(const gfx::Transform& proj_matrix) = 0;
Christopher Grant6cb4f2432018-07-19 15:29:1376 virtual void AcceptDoffPromptForTesting() = 0;
Aldo Culquicondorcc004c72018-08-02 14:50:0277 virtual gfx::Point3F GetTargetPointForTesting(
78 UserFriendlyElementName element_name,
79 const gfx::PointF& position) = 0;
bsheedya2ff3432018-10-02 18:16:5880 virtual bool GetElementVisibilityForTesting(
81 UserFriendlyElementName element_name) = 0;
bsheedyb3cc34d82018-11-15 22:20:4082 virtual void SetUiInputManagerForTesting(bool enabled) = 0;
Christopher Grant6cb4f2432018-07-19 15:29:1383 virtual bool IsContentVisibleAndOpaque() = 0;
Christopher Grant6cb4f2432018-07-19 15:29:1384 virtual void SetContentUsesQuadLayer(bool uses_quad_buffers) = 0;
85 virtual gfx::Transform GetContentWorldSpaceTransform() = 0;
Aldo Culquicondor4836b79e2018-09-13 18:52:2786 virtual bool OnBeginFrame(base::TimeTicks current_time,
87 const gfx::Transform& head_pose) = 0;
Christopher Grant6cb4f2432018-07-19 15:29:1388 virtual bool SceneHasDirtyTextures() const = 0;
89 virtual void UpdateSceneTextures() = 0;
Aldo Culquicondor4836b79e2018-09-13 18:52:2790 virtual void Draw(const RenderInfo& render_info) = 0;
Aldo Culquicondor4ca61bf2018-08-14 00:08:0591 virtual void DrawContent(const float (&uv_transform)[16],
92 float xborder,
93 float yborder) = 0;
94 virtual void DrawWebXr(int texture_data_handle,
95 const float (&uv_transform)[16]) = 0;
Christopher Grant6cb4f2432018-07-19 15:29:1396 virtual void DrawWebVrOverlayForeground(const RenderInfo&) = 0;
Aldo Culquicondor3c315ea02018-08-13 20:45:0997 virtual bool HasWebXrOverlayElementsToDraw() = 0;
Christopher Grant6cb4f2432018-07-19 15:29:1398 virtual void HandleInput(base::TimeTicks current_time,
99 const RenderInfo& render_info,
100 const ControllerModel& controller_model,
101 ReticleModel* reticle_model,
102 InputEventList* input_event_list) = 0;
Aldo Culquicondor570c3232018-07-23 16:46:47103 virtual void HandleMenuButtonEvents(InputEventList* input_event_list) = 0;
Christopher Grant6cb4f2432018-07-19 15:29:13104
105 // This function calculates the minimal FOV (in degrees) which covers all
Aldo Culquicondor3c315ea02018-08-13 20:45:09106 // visible overflow elements as if it was viewing from fov_recommended. For
107 // example, if fov_recommended is {20.f, 20.f, 20.f, 20.f}. And all elements
108 // appear on screen within a FOV of {-11.f, 19.f, 9.f, 9.f} if we use
109 // fov_recommended. Ideally, the calculated minimal FOV should be the same. In
110 // practice, the elements might get clipped near the edge sometimes due to
111 // float precision. To fix this, we add a small margin (1 degree) to all
112 // directions. So the |out_fov| set by this function should be {-10.f, 20.f,
113 // 10.f, 10.f} in the example case.
Christopher Grant6cb4f2432018-07-19 15:29:13114 // Using a smaller FOV could improve the performance a lot while we are
115 // showing UIs on top of WebVR content.
Aldo Culquicondor5dc384bf2018-08-22 23:42:36116 virtual FovRectangles GetMinimalFovForWebXrOverlayElements(
Aldo Culquicondor3c315ea02018-08-13 20:45:09117 const gfx::Transform& left_view,
118 const FovRectangle& fov_recommended_left,
119 const gfx::Transform& right_view,
120 const FovRectangle& fov_recommended_right,
Christopher Grant6cb4f2432018-07-19 15:29:13121 float z_near) = 0;
122};
123
Christopher Grant50c0e2c2019-03-04 22:46:07124// After obtaining a void pointer to CreateUi() via dlsym, the resulting pointer
125// should be cast to this type. Hence, the arguments in this type must exactly
126// match the actual CreateUi method.
127typedef UiInterface* CreateUiFunction(
128 UiBrowserInterface* browser,
129 PlatformInputHandler* content_input_forwarder,
130 std::unique_ptr<KeyboardDelegate> keyboard_delegate,
131 std::unique_ptr<TextInputDelegate> text_input_delegate,
132 std::unique_ptr<AudioDelegate> audio_delegate,
133 const UiInitialState& ui_initial_state);
134
Christopher Grant6cb4f2432018-07-19 15:29:13135} // namespace vr
136
137#endif // CHROME_BROWSER_VR_UI_INTERFACE_H_