Christopher Grant | 6cb4f243 | 2018-07-19 15:29:13 | [diff] [blame] | 1 | // 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 Culquicondor | 3c315ea0 | 2018-08-13 20:45:09 | [diff] [blame] | 10 | #include <utility> |
Aldo Culquicondor | cc004c7 | 2018-08-02 14:50:02 | [diff] [blame] | 11 | #include <vector> |
Christopher Grant | 6cb4f243 | 2018-07-19 15:29:13 | [diff] [blame] | 12 | |
| 13 | #include "base/memory/weak_ptr.h" |
Aldo Culquicondor | b8985eb | 2018-09-06 22:27:44 | [diff] [blame] | 14 | #include "chrome/browser/vr/fov_rectangle.h" |
Aldo Culquicondor | 3c315ea0 | 2018-08-13 20:45:09 | [diff] [blame] | 15 | #include "chrome/browser/vr/gl_texture_location.h" |
Aldo Culquicondor | cc004c7 | 2018-08-02 14:50:02 | [diff] [blame] | 16 | |
| 17 | namespace gfx { |
| 18 | class Point3F; |
Aldo Culquicondor | 3c315ea0 | 2018-08-13 20:45:09 | [diff] [blame] | 19 | class PointF; |
| 20 | class Transform; |
Aldo Culquicondor | cc004c7 | 2018-08-02 14:50:02 | [diff] [blame] | 21 | } |
Christopher Grant | 6cb4f243 | 2018-07-19 15:29:13 | [diff] [blame] | 22 | |
| 23 | namespace vr { |
| 24 | |
Christopher Grant | 50c0e2c | 2019-03-04 22:46:07 | [diff] [blame] | 25 | class AudioDelegate; |
Christopher Grant | 6cb4f243 | 2018-07-19 15:29:13 | [diff] [blame] | 26 | class BrowserUiInterface; |
Aldo Culquicondor | 3c315ea0 | 2018-08-13 20:45:09 | [diff] [blame] | 27 | class InputEvent; |
Christopher Grant | 50c0e2c | 2019-03-04 22:46:07 | [diff] [blame] | 28 | class KeyboardDelegate; |
| 29 | class PlatformInputHandler; |
Christopher Grant | 6cb4f243 | 2018-07-19 15:29:13 | [diff] [blame] | 30 | class PlatformUiInputDelegate; |
Aldo Culquicondor | 9122f39b | 2018-09-10 17:19:16 | [diff] [blame] | 31 | class SchedulerUiInterface; |
Christopher Grant | 50c0e2c | 2019-03-04 22:46:07 | [diff] [blame] | 32 | class TextInputDelegate; |
| 33 | class UiBrowserInterface; |
Christopher Grant | 6cb4f243 | 2018-07-19 15:29:13 | [diff] [blame] | 34 | struct ControllerModel; |
| 35 | struct RenderInfo; |
| 36 | struct ReticleModel; |
Christopher Grant | 50c0e2c | 2019-03-04 22:46:07 | [diff] [blame] | 37 | struct UiInitialState; |
Aldo Culquicondor | cc004c7 | 2018-08-02 14:50:02 | [diff] [blame] | 38 | enum class UserFriendlyElementName; |
Christopher Grant | 6cb4f243 | 2018-07-19 15:29:13 | [diff] [blame] | 39 | |
Aldo Culquicondor | 3c315ea0 | 2018-08-13 20:45:09 | [diff] [blame] | 40 | using InputEventList = std::vector<std::unique_ptr<InputEvent>>; |
| 41 | |
Christopher Grant | 6cb4f243 | 2018-07-19 15:29:13 | [diff] [blame] | 42 | // 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 Culquicondor | 9122f39b | 2018-09-10 17:19:16 | [diff] [blame] | 45 | class UiInterface { |
Christopher Grant | 6cb4f243 | 2018-07-19 15:29:13 | [diff] [blame] | 46 | public: |
Aldo Culquicondor | 9122f39b | 2018-09-10 17:19:16 | [diff] [blame] | 47 | virtual ~UiInterface() = default; |
Christopher Grant | 6cb4f243 | 2018-07-19 15:29:13 | [diff] [blame] | 48 | |
| 49 | virtual base::WeakPtr<BrowserUiInterface> GetBrowserUiWeakPtr() = 0; |
Aldo Culquicondor | 9122f39b | 2018-09-10 17:19:16 | [diff] [blame] | 50 | virtual SchedulerUiInterface* GetSchedulerUiPtr() = 0; |
Christopher Grant | 6cb4f243 | 2018-07-19 15:29:13 | [diff] [blame] | 51 | |
Aldo Culquicondor | b8985eb | 2018-09-06 22:27:44 | [diff] [blame] | 52 | // 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 Grant | 6cb4f243 | 2018-07-19 15:29:13 | [diff] [blame] | 62 | 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 Grant | 6cb4f243 | 2018-07-19 15:29:13 | [diff] [blame] | 71 | virtual void OnPause() = 0; |
Brandon Jones | 6e4b5ec | 2018-11-30 20:57:37 | [diff] [blame] | 72 | virtual void OnControllersUpdated( |
| 73 | const std::vector<ControllerModel>& controller_models, |
| 74 | const ReticleModel& reticle_model) = 0; |
Christopher Grant | 6cb4f243 | 2018-07-19 15:29:13 | [diff] [blame] | 75 | virtual void OnProjMatrixChanged(const gfx::Transform& proj_matrix) = 0; |
Christopher Grant | 6cb4f243 | 2018-07-19 15:29:13 | [diff] [blame] | 76 | virtual void AcceptDoffPromptForTesting() = 0; |
Aldo Culquicondor | cc004c7 | 2018-08-02 14:50:02 | [diff] [blame] | 77 | virtual gfx::Point3F GetTargetPointForTesting( |
| 78 | UserFriendlyElementName element_name, |
| 79 | const gfx::PointF& position) = 0; |
bsheedy | a2ff343 | 2018-10-02 18:16:58 | [diff] [blame] | 80 | virtual bool GetElementVisibilityForTesting( |
| 81 | UserFriendlyElementName element_name) = 0; |
bsheedy | b3cc34d8 | 2018-11-15 22:20:40 | [diff] [blame] | 82 | virtual void SetUiInputManagerForTesting(bool enabled) = 0; |
Christopher Grant | 6cb4f243 | 2018-07-19 15:29:13 | [diff] [blame] | 83 | virtual bool IsContentVisibleAndOpaque() = 0; |
Christopher Grant | 6cb4f243 | 2018-07-19 15:29:13 | [diff] [blame] | 84 | virtual void SetContentUsesQuadLayer(bool uses_quad_buffers) = 0; |
| 85 | virtual gfx::Transform GetContentWorldSpaceTransform() = 0; |
Aldo Culquicondor | 4836b79e | 2018-09-13 18:52:27 | [diff] [blame] | 86 | virtual bool OnBeginFrame(base::TimeTicks current_time, |
| 87 | const gfx::Transform& head_pose) = 0; |
Christopher Grant | 6cb4f243 | 2018-07-19 15:29:13 | [diff] [blame] | 88 | virtual bool SceneHasDirtyTextures() const = 0; |
| 89 | virtual void UpdateSceneTextures() = 0; |
Aldo Culquicondor | 4836b79e | 2018-09-13 18:52:27 | [diff] [blame] | 90 | virtual void Draw(const RenderInfo& render_info) = 0; |
Aldo Culquicondor | 4ca61bf | 2018-08-14 00:08:05 | [diff] [blame] | 91 | 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 Grant | 6cb4f243 | 2018-07-19 15:29:13 | [diff] [blame] | 96 | virtual void DrawWebVrOverlayForeground(const RenderInfo&) = 0; |
Aldo Culquicondor | 3c315ea0 | 2018-08-13 20:45:09 | [diff] [blame] | 97 | virtual bool HasWebXrOverlayElementsToDraw() = 0; |
Christopher Grant | 6cb4f243 | 2018-07-19 15:29:13 | [diff] [blame] | 98 | 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 Culquicondor | 570c323 | 2018-07-23 16:46:47 | [diff] [blame] | 103 | virtual void HandleMenuButtonEvents(InputEventList* input_event_list) = 0; |
Christopher Grant | 6cb4f243 | 2018-07-19 15:29:13 | [diff] [blame] | 104 | |
| 105 | // This function calculates the minimal FOV (in degrees) which covers all |
Aldo Culquicondor | 3c315ea0 | 2018-08-13 20:45:09 | [diff] [blame] | 106 | // 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 Grant | 6cb4f243 | 2018-07-19 15:29:13 | [diff] [blame] | 114 | // Using a smaller FOV could improve the performance a lot while we are |
| 115 | // showing UIs on top of WebVR content. |
Aldo Culquicondor | 5dc384bf | 2018-08-22 23:42:36 | [diff] [blame] | 116 | virtual FovRectangles GetMinimalFovForWebXrOverlayElements( |
Aldo Culquicondor | 3c315ea0 | 2018-08-13 20:45:09 | [diff] [blame] | 117 | const gfx::Transform& left_view, |
| 118 | const FovRectangle& fov_recommended_left, |
| 119 | const gfx::Transform& right_view, |
| 120 | const FovRectangle& fov_recommended_right, |
Christopher Grant | 6cb4f243 | 2018-07-19 15:29:13 | [diff] [blame] | 121 | float z_near) = 0; |
| 122 | }; |
| 123 | |
Christopher Grant | 50c0e2c | 2019-03-04 22:46:07 | [diff] [blame] | 124 | // 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. |
| 127 | typedef 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 Grant | 6cb4f243 | 2018-07-19 15:29:13 | [diff] [blame] | 135 | } // namespace vr |
| 136 | |
| 137 | #endif // CHROME_BROWSER_VR_UI_INTERFACE_H_ |