blob: 30541911b1e431f3e003448f48d184380f3189bb [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"
14#include "chrome/browser/vr/browser_ui_interface.h"
Aldo Culquicondor3c315ea02018-08-13 20:45:0915#include "chrome/browser/vr/gl_texture_location.h"
Ian Vollick3d259622018-07-30 20:07:1416#include "chrome/browser/vr/keyboard_ui_interface.h"
Aldo Culquicondorcc004c72018-08-02 14:50:0217
18namespace gfx {
19class Point3F;
Aldo Culquicondor3c315ea02018-08-13 20:45:0920class PointF;
21class Transform;
Aldo Culquicondorcc004c72018-08-02 14:50:0222}
Christopher Grant6cb4f2432018-07-19 15:29:1323
24namespace vr {
25
26class BrowserUiInterface;
Aldo Culquicondor3c315ea02018-08-13 20:45:0927class InputEvent;
Christopher Grant6cb4f2432018-07-19 15:29:1328class PlatformUiInputDelegate;
29struct ControllerModel;
30struct RenderInfo;
31struct ReticleModel;
Aldo Culquicondorcc004c72018-08-02 14:50:0232enum class UserFriendlyElementName;
Christopher Grant6cb4f2432018-07-19 15:29:1333
Aldo Culquicondor3c315ea02018-08-13 20:45:0934using InputEventList = std::vector<std::unique_ptr<InputEvent>>;
35
Christopher Grant6cb4f2432018-07-19 15:29:1336// 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.
Ian Vollick3d259622018-07-30 20:07:1439class UiInterface : public BrowserUiInterface, public KeyboardUiInterface {
Christopher Grant6cb4f2432018-07-19 15:29:1340 public:
41 ~UiInterface() override {}
42
43 virtual base::WeakPtr<BrowserUiInterface> GetBrowserUiWeakPtr() = 0;
44
45 // TODO(ymalik): We expose this to stop sending VSync to the WebVR page until
46 // the splash screen has been visible for its minimum duration. The visibility
47 // logic currently lives in the UI, and it'd be much cleaner if the UI didn't
48 // have to worry about this, and if it were told to hide the splash screen
49 // like other WebVR phases (e.g. OnWebVrFrameAvailable below).
50 virtual bool CanSendWebVrVSync() = 0;
51 virtual void SetAlertDialogEnabled(bool enabled,
52 PlatformUiInputDelegate* delegate,
53 float width,
54 float height) = 0;
55 virtual void SetContentOverlayAlertDialogEnabled(
56 bool enabled,
57 PlatformUiInputDelegate* delegate,
58 float width_percentage,
59 float height_percentage) = 0;
60 virtual void SetAlertDialogSize(float width, float height) = 0;
61 virtual void SetContentOverlayAlertDialogSize(float width_percentage,
62 float height_percentage) = 0;
63 virtual void SetDialogLocation(float x, float y) = 0;
64 virtual void SetDialogFloating(bool floating) = 0;
65 virtual void ShowPlatformToast(const base::string16& text) = 0;
66 virtual void CancelPlatformToast() = 0;
67 virtual bool ShouldRenderWebVr() = 0;
Aldo Culquicondor3c315ea02018-08-13 20:45:0968 virtual void OnGlInitialized(unsigned int content_texture_id,
69 GlTextureLocation content_location,
70 unsigned int content_overlay_texture_id,
71 GlTextureLocation content_overlay_location,
72 unsigned int ui_texture_id) = 0;
Christopher Grant6cb4f2432018-07-19 15:29:1373 virtual void OnPause() = 0;
Christopher Grant6cb4f2432018-07-19 15:29:1374 virtual void OnControllerUpdated(const ControllerModel& controller_model,
75 const ReticleModel& reticle_model) = 0;
76 virtual void OnProjMatrixChanged(const gfx::Transform& proj_matrix) = 0;
77 virtual void OnWebVrFrameAvailable() = 0;
78 virtual void OnWebVrTimedOut() = 0;
79 virtual void OnWebVrTimeoutImminent() = 0;
80 virtual bool IsControllerVisible() const = 0;
Christopher Grant6cb4f2432018-07-19 15:29:1381 virtual bool SkipsRedrawWhenNotDirty() const = 0;
82 virtual void OnSwapContents(int new_content_id) = 0;
83 virtual void OnContentBoundsChanged(int width, int height) = 0;
84 virtual void AcceptDoffPromptForTesting() = 0;
Aldo Culquicondorcc004c72018-08-02 14:50:0285 virtual gfx::Point3F GetTargetPointForTesting(
86 UserFriendlyElementName element_name,
87 const gfx::PointF& position) = 0;
Christopher Grant6cb4f2432018-07-19 15:29:1388 virtual bool IsContentVisibleAndOpaque() = 0;
Christopher Grant6cb4f2432018-07-19 15:29:1389 virtual void SetContentUsesQuadLayer(bool uses_quad_buffers) = 0;
90 virtual gfx::Transform GetContentWorldSpaceTransform() = 0;
91 virtual bool OnBeginFrame(const base::TimeTicks&, const gfx::Transform&) = 0;
92 virtual bool SceneHasDirtyTextures() const = 0;
93 virtual void UpdateSceneTextures() = 0;
94 virtual void Draw(const RenderInfo&) = 0;
Aldo Culquicondor4ca61bf2018-08-14 00:08:0595 virtual void DrawContent(const float (&uv_transform)[16],
96 float xborder,
97 float yborder) = 0;
98 virtual void DrawWebXr(int texture_data_handle,
99 const float (&uv_transform)[16]) = 0;
Christopher Grant6cb4f2432018-07-19 15:29:13100 virtual void DrawWebVrOverlayForeground(const RenderInfo&) = 0;
Aldo Culquicondor3c315ea02018-08-13 20:45:09101 virtual bool HasWebXrOverlayElementsToDraw() = 0;
Christopher Grant6cb4f2432018-07-19 15:29:13102 virtual void HandleInput(base::TimeTicks current_time,
103 const RenderInfo& render_info,
104 const ControllerModel& controller_model,
105 ReticleModel* reticle_model,
106 InputEventList* input_event_list) = 0;
Aldo Culquicondor570c3232018-07-23 16:46:47107 virtual void HandleMenuButtonEvents(InputEventList* input_event_list) = 0;
Christopher Grant6cb4f2432018-07-19 15:29:13108 virtual void RequestFocus(int element_id) = 0;
109 virtual void RequestUnfocus(int element_id) = 0;
110
111 // This function calculates the minimal FOV (in degrees) which covers all
Aldo Culquicondor3c315ea02018-08-13 20:45:09112 // visible overflow elements as if it was viewing from fov_recommended. For
113 // example, if fov_recommended is {20.f, 20.f, 20.f, 20.f}. And all elements
114 // appear on screen within a FOV of {-11.f, 19.f, 9.f, 9.f} if we use
115 // fov_recommended. Ideally, the calculated minimal FOV should be the same. In
116 // practice, the elements might get clipped near the edge sometimes due to
117 // float precision. To fix this, we add a small margin (1 degree) to all
118 // directions. So the |out_fov| set by this function should be {-10.f, 20.f,
119 // 10.f, 10.f} in the example case.
Christopher Grant6cb4f2432018-07-19 15:29:13120 // Using a smaller FOV could improve the performance a lot while we are
121 // showing UIs on top of WebVR content.
122 struct FovRectangle {
123 float left;
124 float right;
125 float bottom;
126 float top;
127 };
Aldo Culquicondor3c315ea02018-08-13 20:45:09128 virtual std::pair<FovRectangle, FovRectangle>
129 GetMinimalFovForWebXrOverlayElements(
130 const gfx::Transform& left_view,
131 const FovRectangle& fov_recommended_left,
132 const gfx::Transform& right_view,
133 const FovRectangle& fov_recommended_right,
Christopher Grant6cb4f2432018-07-19 15:29:13134 float z_near) = 0;
135};
136
137} // namespace vr
138
139#endif // CHROME_BROWSER_VR_UI_INTERFACE_H_