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 | |
| 25 | class BrowserUiInterface; |
Aldo Culquicondor | 3c315ea0 | 2018-08-13 20:45:09 | [diff] [blame] | 26 | class InputEvent; |
Christopher Grant | 6cb4f243 | 2018-07-19 15:29:13 | [diff] [blame] | 27 | class PlatformUiInputDelegate; |
Aldo Culquicondor | 9122f39b | 2018-09-10 17:19:16 | [diff] [blame] | 28 | class SchedulerUiInterface; |
Christopher Grant | 6cb4f243 | 2018-07-19 15:29:13 | [diff] [blame] | 29 | struct ControllerModel; |
| 30 | struct RenderInfo; |
| 31 | struct ReticleModel; |
Aldo Culquicondor | cc004c7 | 2018-08-02 14:50:02 | [diff] [blame] | 32 | enum class UserFriendlyElementName; |
Christopher Grant | 6cb4f243 | 2018-07-19 15:29:13 | [diff] [blame] | 33 | |
Aldo Culquicondor | 3c315ea0 | 2018-08-13 20:45:09 | [diff] [blame] | 34 | using InputEventList = std::vector<std::unique_ptr<InputEvent>>; |
| 35 | |
Christopher Grant | 6cb4f243 | 2018-07-19 15:29:13 | [diff] [blame] | 36 | // This interface represents the methods that should be called by its owner, and |
| 37 | // also serves to make all such methods virtual for the sake of separating a UI |
| 38 | // feature module. |
Aldo Culquicondor | 9122f39b | 2018-09-10 17:19:16 | [diff] [blame] | 39 | class UiInterface { |
Christopher Grant | 6cb4f243 | 2018-07-19 15:29:13 | [diff] [blame] | 40 | public: |
Aldo Culquicondor | 9122f39b | 2018-09-10 17:19:16 | [diff] [blame] | 41 | virtual ~UiInterface() = default; |
Christopher Grant | 6cb4f243 | 2018-07-19 15:29:13 | [diff] [blame] | 42 | |
| 43 | virtual base::WeakPtr<BrowserUiInterface> GetBrowserUiWeakPtr() = 0; |
Aldo Culquicondor | 9122f39b | 2018-09-10 17:19:16 | [diff] [blame] | 44 | virtual SchedulerUiInterface* GetSchedulerUiPtr() = 0; |
Christopher Grant | 6cb4f243 | 2018-07-19 15:29:13 | [diff] [blame] | 45 | |
Aldo Culquicondor | b8985eb | 2018-09-06 22:27:44 | [diff] [blame] | 46 | // Textures from 2D UI that are positioned in the 3D scene. |
| 47 | // Content refers to the web contents, as coming from the Chrome compositor. |
| 48 | // Content Overlay refers to UI drawn in the same view hierarchy as the |
| 49 | // contents. |
| 50 | // Platform UI refers to popups, which are rendered in a different window. |
| 51 | virtual void OnGlInitialized(GlTextureLocation textures_location, |
| 52 | unsigned int content_texture_id, |
| 53 | unsigned int content_overlay_texture_id, |
| 54 | unsigned int platform_ui_texture_id) = 0; |
| 55 | |
Christopher Grant | 6cb4f243 | 2018-07-19 15:29:13 | [diff] [blame] | 56 | virtual void SetAlertDialogEnabled(bool enabled, |
| 57 | PlatformUiInputDelegate* delegate, |
| 58 | float width, |
| 59 | float height) = 0; |
| 60 | virtual void SetContentOverlayAlertDialogEnabled( |
| 61 | bool enabled, |
| 62 | PlatformUiInputDelegate* delegate, |
| 63 | float width_percentage, |
| 64 | float height_percentage) = 0; |
Christopher Grant | 6cb4f243 | 2018-07-19 15:29:13 | [diff] [blame] | 65 | virtual void OnPause() = 0; |
Brandon Jones | 6e4b5ec | 2018-11-30 20:57:37 | [diff] [blame^] | 66 | virtual void OnControllersUpdated( |
| 67 | const std::vector<ControllerModel>& controller_models, |
| 68 | const ReticleModel& reticle_model) = 0; |
Christopher Grant | 6cb4f243 | 2018-07-19 15:29:13 | [diff] [blame] | 69 | virtual void OnProjMatrixChanged(const gfx::Transform& proj_matrix) = 0; |
Christopher Grant | 6cb4f243 | 2018-07-19 15:29:13 | [diff] [blame] | 70 | virtual void AcceptDoffPromptForTesting() = 0; |
Aldo Culquicondor | cc004c7 | 2018-08-02 14:50:02 | [diff] [blame] | 71 | virtual gfx::Point3F GetTargetPointForTesting( |
| 72 | UserFriendlyElementName element_name, |
| 73 | const gfx::PointF& position) = 0; |
bsheedy | a2ff343 | 2018-10-02 18:16:58 | [diff] [blame] | 74 | virtual bool GetElementVisibilityForTesting( |
| 75 | UserFriendlyElementName element_name) = 0; |
bsheedy | b3cc34d8 | 2018-11-15 22:20:40 | [diff] [blame] | 76 | virtual void SetUiInputManagerForTesting(bool enabled) = 0; |
Christopher Grant | 6cb4f243 | 2018-07-19 15:29:13 | [diff] [blame] | 77 | virtual bool IsContentVisibleAndOpaque() = 0; |
Christopher Grant | 6cb4f243 | 2018-07-19 15:29:13 | [diff] [blame] | 78 | virtual void SetContentUsesQuadLayer(bool uses_quad_buffers) = 0; |
| 79 | virtual gfx::Transform GetContentWorldSpaceTransform() = 0; |
Aldo Culquicondor | 4836b79e | 2018-09-13 18:52:27 | [diff] [blame] | 80 | virtual bool OnBeginFrame(base::TimeTicks current_time, |
| 81 | const gfx::Transform& head_pose) = 0; |
Christopher Grant | 6cb4f243 | 2018-07-19 15:29:13 | [diff] [blame] | 82 | virtual bool SceneHasDirtyTextures() const = 0; |
| 83 | virtual void UpdateSceneTextures() = 0; |
Aldo Culquicondor | 4836b79e | 2018-09-13 18:52:27 | [diff] [blame] | 84 | virtual void Draw(const RenderInfo& render_info) = 0; |
Aldo Culquicondor | 4ca61bf | 2018-08-14 00:08:05 | [diff] [blame] | 85 | virtual void DrawContent(const float (&uv_transform)[16], |
| 86 | float xborder, |
| 87 | float yborder) = 0; |
| 88 | virtual void DrawWebXr(int texture_data_handle, |
| 89 | const float (&uv_transform)[16]) = 0; |
Christopher Grant | 6cb4f243 | 2018-07-19 15:29:13 | [diff] [blame] | 90 | virtual void DrawWebVrOverlayForeground(const RenderInfo&) = 0; |
Aldo Culquicondor | 3c315ea0 | 2018-08-13 20:45:09 | [diff] [blame] | 91 | virtual bool HasWebXrOverlayElementsToDraw() = 0; |
Christopher Grant | 6cb4f243 | 2018-07-19 15:29:13 | [diff] [blame] | 92 | virtual void HandleInput(base::TimeTicks current_time, |
| 93 | const RenderInfo& render_info, |
| 94 | const ControllerModel& controller_model, |
| 95 | ReticleModel* reticle_model, |
| 96 | InputEventList* input_event_list) = 0; |
Aldo Culquicondor | 570c323 | 2018-07-23 16:46:47 | [diff] [blame] | 97 | virtual void HandleMenuButtonEvents(InputEventList* input_event_list) = 0; |
Christopher Grant | 6cb4f243 | 2018-07-19 15:29:13 | [diff] [blame] | 98 | |
| 99 | // This function calculates the minimal FOV (in degrees) which covers all |
Aldo Culquicondor | 3c315ea0 | 2018-08-13 20:45:09 | [diff] [blame] | 100 | // visible overflow elements as if it was viewing from fov_recommended. For |
| 101 | // example, if fov_recommended is {20.f, 20.f, 20.f, 20.f}. And all elements |
| 102 | // appear on screen within a FOV of {-11.f, 19.f, 9.f, 9.f} if we use |
| 103 | // fov_recommended. Ideally, the calculated minimal FOV should be the same. In |
| 104 | // practice, the elements might get clipped near the edge sometimes due to |
| 105 | // float precision. To fix this, we add a small margin (1 degree) to all |
| 106 | // directions. So the |out_fov| set by this function should be {-10.f, 20.f, |
| 107 | // 10.f, 10.f} in the example case. |
Christopher Grant | 6cb4f243 | 2018-07-19 15:29:13 | [diff] [blame] | 108 | // Using a smaller FOV could improve the performance a lot while we are |
| 109 | // showing UIs on top of WebVR content. |
Aldo Culquicondor | 5dc384bf | 2018-08-22 23:42:36 | [diff] [blame] | 110 | virtual FovRectangles GetMinimalFovForWebXrOverlayElements( |
Aldo Culquicondor | 3c315ea0 | 2018-08-13 20:45:09 | [diff] [blame] | 111 | const gfx::Transform& left_view, |
| 112 | const FovRectangle& fov_recommended_left, |
| 113 | const gfx::Transform& right_view, |
| 114 | const FovRectangle& fov_recommended_right, |
Christopher Grant | 6cb4f243 | 2018-07-19 15:29:13 | [diff] [blame] | 115 | float z_near) = 0; |
| 116 | }; |
| 117 | |
| 118 | } // namespace vr |
| 119 | |
| 120 | #endif // CHROME_BROWSER_VR_UI_INTERFACE_H_ |