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> |
| 10 | |
| 11 | #include "base/memory/weak_ptr.h" |
| 12 | #include "chrome/browser/vr/browser_ui_interface.h" |
Ian Vollick | 3d25962 | 2018-07-30 20:07:14 | [diff] [blame] | 13 | #include "chrome/browser/vr/keyboard_ui_interface.h" |
Christopher Grant | 6cb4f243 | 2018-07-19 15:29:13 | [diff] [blame] | 14 | #include "chrome/browser/vr/platform_controller.h" |
| 15 | #include "chrome/browser/vr/ui_element_renderer.h" |
| 16 | #include "chrome/browser/vr/ui_input_manager.h" |
| 17 | #include "chrome/browser/vr/ui_scene.h" |
| 18 | #include "chrome/browser/vr/ui_test_input.h" |
| 19 | |
| 20 | namespace vr { |
| 21 | |
| 22 | class BrowserUiInterface; |
| 23 | class PlatformUiInputDelegate; |
| 24 | struct ControllerModel; |
| 25 | struct RenderInfo; |
| 26 | struct ReticleModel; |
| 27 | |
| 28 | // This interface represents the methods that should be called by its owner, and |
| 29 | // also serves to make all such methods virtual for the sake of separating a UI |
| 30 | // feature module. |
Ian Vollick | 3d25962 | 2018-07-30 20:07:14 | [diff] [blame] | 31 | class UiInterface : public BrowserUiInterface, public KeyboardUiInterface { |
Christopher Grant | 6cb4f243 | 2018-07-19 15:29:13 | [diff] [blame] | 32 | public: |
| 33 | ~UiInterface() override {} |
| 34 | |
| 35 | virtual base::WeakPtr<BrowserUiInterface> GetBrowserUiWeakPtr() = 0; |
| 36 | |
| 37 | // TODO(ymalik): We expose this to stop sending VSync to the WebVR page until |
| 38 | // the splash screen has been visible for its minimum duration. The visibility |
| 39 | // logic currently lives in the UI, and it'd be much cleaner if the UI didn't |
| 40 | // have to worry about this, and if it were told to hide the splash screen |
| 41 | // like other WebVR phases (e.g. OnWebVrFrameAvailable below). |
| 42 | virtual bool CanSendWebVrVSync() = 0; |
| 43 | virtual void SetAlertDialogEnabled(bool enabled, |
| 44 | PlatformUiInputDelegate* delegate, |
| 45 | float width, |
| 46 | float height) = 0; |
| 47 | virtual void SetContentOverlayAlertDialogEnabled( |
| 48 | bool enabled, |
| 49 | PlatformUiInputDelegate* delegate, |
| 50 | float width_percentage, |
| 51 | float height_percentage) = 0; |
| 52 | virtual void SetAlertDialogSize(float width, float height) = 0; |
| 53 | virtual void SetContentOverlayAlertDialogSize(float width_percentage, |
| 54 | float height_percentage) = 0; |
| 55 | virtual void SetDialogLocation(float x, float y) = 0; |
| 56 | virtual void SetDialogFloating(bool floating) = 0; |
| 57 | virtual void ShowPlatformToast(const base::string16& text) = 0; |
| 58 | virtual void CancelPlatformToast() = 0; |
| 59 | virtual bool ShouldRenderWebVr() = 0; |
| 60 | virtual void OnGlInitialized( |
| 61 | unsigned int content_texture_id, |
| 62 | UiElementRenderer::TextureLocation content_location, |
| 63 | unsigned int content_overlay_texture_id, |
| 64 | UiElementRenderer::TextureLocation content_overlay_location, |
| 65 | unsigned int ui_texture_id) = 0; |
| 66 | virtual void OnPause() = 0; |
Christopher Grant | 6cb4f243 | 2018-07-19 15:29:13 | [diff] [blame] | 67 | virtual void OnControllerUpdated(const ControllerModel& controller_model, |
| 68 | const ReticleModel& reticle_model) = 0; |
| 69 | virtual void OnProjMatrixChanged(const gfx::Transform& proj_matrix) = 0; |
| 70 | virtual void OnWebVrFrameAvailable() = 0; |
| 71 | virtual void OnWebVrTimedOut() = 0; |
| 72 | virtual void OnWebVrTimeoutImminent() = 0; |
| 73 | virtual bool IsControllerVisible() const = 0; |
Christopher Grant | 6cb4f243 | 2018-07-19 15:29:13 | [diff] [blame] | 74 | virtual bool SkipsRedrawWhenNotDirty() const = 0; |
| 75 | virtual void OnSwapContents(int new_content_id) = 0; |
| 76 | virtual void OnContentBoundsChanged(int width, int height) = 0; |
| 77 | virtual void AcceptDoffPromptForTesting() = 0; |
| 78 | virtual void PerformControllerActionForTesting( |
| 79 | ControllerTestInput controller_input, |
| 80 | std::queue<ControllerModel>& controller_model_queue) = 0; |
| 81 | virtual bool IsContentVisibleAndOpaque() = 0; |
| 82 | virtual bool IsContentOverlayTextureEmpty() = 0; |
| 83 | virtual void SetContentUsesQuadLayer(bool uses_quad_buffers) = 0; |
| 84 | virtual gfx::Transform GetContentWorldSpaceTransform() = 0; |
| 85 | virtual bool OnBeginFrame(const base::TimeTicks&, const gfx::Transform&) = 0; |
| 86 | virtual bool SceneHasDirtyTextures() const = 0; |
| 87 | virtual void UpdateSceneTextures() = 0; |
| 88 | virtual void Draw(const RenderInfo&) = 0; |
| 89 | virtual void DrawWebVr(int texture_data_handle, |
| 90 | const float (&uv_transform)[16], |
| 91 | float xborder, |
| 92 | float yborder) = 0; |
| 93 | virtual void DrawWebVrOverlayForeground(const RenderInfo&) = 0; |
| 94 | virtual UiScene::Elements GetWebVrOverlayElementsToDraw() = 0; |
Christopher Grant | 6cb4f243 | 2018-07-19 15:29:13 | [diff] [blame] | 95 | virtual void HandleInput(base::TimeTicks current_time, |
| 96 | const RenderInfo& render_info, |
| 97 | const ControllerModel& controller_model, |
| 98 | ReticleModel* reticle_model, |
| 99 | InputEventList* input_event_list) = 0; |
Aldo Culquicondor | 570c323 | 2018-07-23 16:46:47 | [diff] [blame] | 100 | virtual void HandleMenuButtonEvents(InputEventList* input_event_list) = 0; |
Christopher Grant | 6cb4f243 | 2018-07-19 15:29:13 | [diff] [blame] | 101 | virtual void RequestFocus(int element_id) = 0; |
| 102 | virtual void RequestUnfocus(int element_id) = 0; |
| 103 | |
| 104 | // This function calculates the minimal FOV (in degrees) which covers all |
| 105 | // visible |elements| as if it was viewing from fov_recommended. For example, |
| 106 | // if fov_recommended is {20.f, 20.f, 20.f, 20.f}. And all elements appear on |
| 107 | // screen within a FOV of {-11.f, 19.f, 9.f, 9.f} if we use fov_recommended. |
| 108 | // Ideally, the calculated minimal FOV should be the same. In practice, the |
| 109 | // elements might get clipped near the edge sometimes due to float precison. |
| 110 | // To fix this, we add a small margin (1 degree) to all directions. So the |
| 111 | // |out_fov| set by this function should be {-10.f, 20.f, 10.f, 10.f} in the |
| 112 | // example case. |
| 113 | // Using a smaller FOV could improve the performance a lot while we are |
| 114 | // showing UIs on top of WebVR content. |
| 115 | struct FovRectangle { |
| 116 | float left; |
| 117 | float right; |
| 118 | float bottom; |
| 119 | float top; |
| 120 | }; |
| 121 | virtual FovRectangle GetMinimalFov( |
| 122 | const gfx::Transform& view_matrix, |
| 123 | const std::vector<const UiElement*>& elements, |
| 124 | const FovRectangle& fov_recommended, |
| 125 | float z_near) = 0; |
| 126 | }; |
| 127 | |
| 128 | } // namespace vr |
| 129 | |
| 130 | #endif // CHROME_BROWSER_VR_UI_INTERFACE_H_ |