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" |
| 14 | #include "chrome/browser/vr/browser_ui_interface.h" |
Aldo Culquicondor | 5dc384bf | 2018-08-22 23:42:36 | [diff] [blame^] | 15 | #include "chrome/browser/vr/compositor_ui_interface.h" |
Aldo Culquicondor | 3c315ea0 | 2018-08-13 20:45:09 | [diff] [blame] | 16 | #include "chrome/browser/vr/gl_texture_location.h" |
Ian Vollick | 3d25962 | 2018-07-30 20:07:14 | [diff] [blame] | 17 | #include "chrome/browser/vr/keyboard_ui_interface.h" |
Aldo Culquicondor | cc004c7 | 2018-08-02 14:50:02 | [diff] [blame] | 18 | |
| 19 | namespace gfx { |
| 20 | class Point3F; |
Aldo Culquicondor | 3c315ea0 | 2018-08-13 20:45:09 | [diff] [blame] | 21 | class PointF; |
| 22 | class Transform; |
Aldo Culquicondor | cc004c7 | 2018-08-02 14:50:02 | [diff] [blame] | 23 | } |
Christopher Grant | 6cb4f243 | 2018-07-19 15:29:13 | [diff] [blame] | 24 | |
| 25 | namespace vr { |
| 26 | |
| 27 | class BrowserUiInterface; |
Aldo Culquicondor | 3c315ea0 | 2018-08-13 20:45:09 | [diff] [blame] | 28 | class InputEvent; |
Christopher Grant | 6cb4f243 | 2018-07-19 15:29:13 | [diff] [blame] | 29 | class PlatformUiInputDelegate; |
| 30 | struct ControllerModel; |
| 31 | struct RenderInfo; |
| 32 | struct ReticleModel; |
Aldo Culquicondor | cc004c7 | 2018-08-02 14:50:02 | [diff] [blame] | 33 | enum class UserFriendlyElementName; |
Christopher Grant | 6cb4f243 | 2018-07-19 15:29:13 | [diff] [blame] | 34 | |
Aldo Culquicondor | 3c315ea0 | 2018-08-13 20:45:09 | [diff] [blame] | 35 | using InputEventList = std::vector<std::unique_ptr<InputEvent>>; |
| 36 | |
Christopher Grant | 6cb4f243 | 2018-07-19 15:29:13 | [diff] [blame] | 37 | // This interface represents the methods that should be called by its owner, and |
| 38 | // also serves to make all such methods virtual for the sake of separating a UI |
| 39 | // feature module. |
Aldo Culquicondor | 5dc384bf | 2018-08-22 23:42:36 | [diff] [blame^] | 40 | class UiInterface : public BrowserUiInterface, |
| 41 | public CompositorUiInterface, |
| 42 | public KeyboardUiInterface { |
Christopher Grant | 6cb4f243 | 2018-07-19 15:29:13 | [diff] [blame] | 43 | public: |
| 44 | ~UiInterface() override {} |
| 45 | |
| 46 | virtual base::WeakPtr<BrowserUiInterface> GetBrowserUiWeakPtr() = 0; |
| 47 | |
Christopher Grant | 6cb4f243 | 2018-07-19 15:29:13 | [diff] [blame] | 48 | virtual void SetAlertDialogEnabled(bool enabled, |
| 49 | PlatformUiInputDelegate* delegate, |
| 50 | float width, |
| 51 | float height) = 0; |
| 52 | virtual void SetContentOverlayAlertDialogEnabled( |
| 53 | bool enabled, |
| 54 | PlatformUiInputDelegate* delegate, |
| 55 | float width_percentage, |
| 56 | float height_percentage) = 0; |
| 57 | virtual void SetAlertDialogSize(float width, float height) = 0; |
| 58 | virtual void SetContentOverlayAlertDialogSize(float width_percentage, |
| 59 | float height_percentage) = 0; |
| 60 | virtual void SetDialogLocation(float x, float y) = 0; |
| 61 | virtual void SetDialogFloating(bool floating) = 0; |
| 62 | virtual void ShowPlatformToast(const base::string16& text) = 0; |
| 63 | virtual void CancelPlatformToast() = 0; |
| 64 | virtual bool ShouldRenderWebVr() = 0; |
Christopher Grant | 6cb4f243 | 2018-07-19 15:29:13 | [diff] [blame] | 65 | virtual void OnPause() = 0; |
Christopher Grant | 6cb4f243 | 2018-07-19 15:29:13 | [diff] [blame] | 66 | virtual void OnControllerUpdated(const ControllerModel& controller_model, |
| 67 | const ReticleModel& reticle_model) = 0; |
| 68 | virtual void OnProjMatrixChanged(const gfx::Transform& proj_matrix) = 0; |
Christopher Grant | 6cb4f243 | 2018-07-19 15:29:13 | [diff] [blame] | 69 | virtual bool IsControllerVisible() const = 0; |
Christopher Grant | 6cb4f243 | 2018-07-19 15:29:13 | [diff] [blame] | 70 | virtual bool SkipsRedrawWhenNotDirty() const = 0; |
| 71 | virtual void OnSwapContents(int new_content_id) = 0; |
| 72 | virtual void OnContentBoundsChanged(int width, int height) = 0; |
| 73 | virtual void AcceptDoffPromptForTesting() = 0; |
Aldo Culquicondor | cc004c7 | 2018-08-02 14:50:02 | [diff] [blame] | 74 | virtual gfx::Point3F GetTargetPointForTesting( |
| 75 | UserFriendlyElementName element_name, |
| 76 | const gfx::PointF& position) = 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; |
| 80 | virtual bool OnBeginFrame(const base::TimeTicks&, const gfx::Transform&) = 0; |
| 81 | virtual bool SceneHasDirtyTextures() const = 0; |
| 82 | virtual void UpdateSceneTextures() = 0; |
| 83 | virtual void Draw(const RenderInfo&) = 0; |
Aldo Culquicondor | 4ca61bf | 2018-08-14 00:08:05 | [diff] [blame] | 84 | virtual void DrawContent(const float (&uv_transform)[16], |
| 85 | float xborder, |
| 86 | float yborder) = 0; |
| 87 | virtual void DrawWebXr(int texture_data_handle, |
| 88 | const float (&uv_transform)[16]) = 0; |
Christopher Grant | 6cb4f243 | 2018-07-19 15:29:13 | [diff] [blame] | 89 | virtual void DrawWebVrOverlayForeground(const RenderInfo&) = 0; |
Aldo Culquicondor | 3c315ea0 | 2018-08-13 20:45:09 | [diff] [blame] | 90 | virtual bool HasWebXrOverlayElementsToDraw() = 0; |
Christopher Grant | 6cb4f243 | 2018-07-19 15:29:13 | [diff] [blame] | 91 | virtual void HandleInput(base::TimeTicks current_time, |
| 92 | const RenderInfo& render_info, |
| 93 | const ControllerModel& controller_model, |
| 94 | ReticleModel* reticle_model, |
| 95 | InputEventList* input_event_list) = 0; |
Aldo Culquicondor | 570c323 | 2018-07-23 16:46:47 | [diff] [blame] | 96 | virtual void HandleMenuButtonEvents(InputEventList* input_event_list) = 0; |
Christopher Grant | 6cb4f243 | 2018-07-19 15:29:13 | [diff] [blame] | 97 | |
| 98 | // This function calculates the minimal FOV (in degrees) which covers all |
Aldo Culquicondor | 3c315ea0 | 2018-08-13 20:45:09 | [diff] [blame] | 99 | // visible overflow elements as if it was viewing from fov_recommended. For |
| 100 | // example, if fov_recommended is {20.f, 20.f, 20.f, 20.f}. And all elements |
| 101 | // appear on screen within a FOV of {-11.f, 19.f, 9.f, 9.f} if we use |
| 102 | // fov_recommended. Ideally, the calculated minimal FOV should be the same. In |
| 103 | // practice, the elements might get clipped near the edge sometimes due to |
| 104 | // float precision. To fix this, we add a small margin (1 degree) to all |
| 105 | // directions. So the |out_fov| set by this function should be {-10.f, 20.f, |
| 106 | // 10.f, 10.f} in the example case. |
Christopher Grant | 6cb4f243 | 2018-07-19 15:29:13 | [diff] [blame] | 107 | // Using a smaller FOV could improve the performance a lot while we are |
| 108 | // showing UIs on top of WebVR content. |
Aldo Culquicondor | 5dc384bf | 2018-08-22 23:42:36 | [diff] [blame^] | 109 | virtual FovRectangles GetMinimalFovForWebXrOverlayElements( |
Aldo Culquicondor | 3c315ea0 | 2018-08-13 20:45:09 | [diff] [blame] | 110 | const gfx::Transform& left_view, |
| 111 | const FovRectangle& fov_recommended_left, |
| 112 | const gfx::Transform& right_view, |
| 113 | const FovRectangle& fov_recommended_right, |
Christopher Grant | 6cb4f243 | 2018-07-19 15:29:13 | [diff] [blame] | 114 | float z_near) = 0; |
| 115 | }; |
| 116 | |
| 117 | } // namespace vr |
| 118 | |
| 119 | #endif // CHROME_BROWSER_VR_UI_INTERFACE_H_ |