blob: dec99a75a0ce4b49913a2fe9f4593bb25f6957dc [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"
Aldo Culquicondorb8985eb2018-09-06 22:27:4414#include "chrome/browser/vr/fov_rectangle.h"
Aldo Culquicondor3c315ea02018-08-13 20:45:0915#include "chrome/browser/vr/gl_texture_location.h"
Aldo Culquicondorcc004c72018-08-02 14:50:0216
17namespace gfx {
18class Point3F;
Aldo Culquicondor3c315ea02018-08-13 20:45:0919class PointF;
20class Transform;
Aldo Culquicondorcc004c72018-08-02 14:50:0221}
Christopher Grant6cb4f2432018-07-19 15:29:1322
23namespace vr {
24
25class BrowserUiInterface;
Aldo Culquicondor3c315ea02018-08-13 20:45:0926class InputEvent;
Christopher Grant6cb4f2432018-07-19 15:29:1327class PlatformUiInputDelegate;
Aldo Culquicondor9122f39b2018-09-10 17:19:1628class SchedulerUiInterface;
Christopher Grant6cb4f2432018-07-19 15:29:1329struct 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.
Aldo Culquicondor9122f39b2018-09-10 17:19:1639class UiInterface {
Christopher Grant6cb4f2432018-07-19 15:29:1340 public:
Aldo Culquicondor9122f39b2018-09-10 17:19:1641 virtual ~UiInterface() = default;
Christopher Grant6cb4f2432018-07-19 15:29:1342
43 virtual base::WeakPtr<BrowserUiInterface> GetBrowserUiWeakPtr() = 0;
Aldo Culquicondor9122f39b2018-09-10 17:19:1644 virtual SchedulerUiInterface* GetSchedulerUiPtr() = 0;
Christopher Grant6cb4f2432018-07-19 15:29:1345
Aldo Culquicondorb8985eb2018-09-06 22:27:4446 // 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 Grant6cb4f2432018-07-19 15:29:1356 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 Grant6cb4f2432018-07-19 15:29:1365 virtual void OnPause() = 0;
Brandon Jones6e4b5ec2018-11-30 20:57:3766 virtual void OnControllersUpdated(
67 const std::vector<ControllerModel>& controller_models,
68 const ReticleModel& reticle_model) = 0;
Christopher Grant6cb4f2432018-07-19 15:29:1369 virtual void OnProjMatrixChanged(const gfx::Transform& proj_matrix) = 0;
Christopher Grant6cb4f2432018-07-19 15:29:1370 virtual void AcceptDoffPromptForTesting() = 0;
Aldo Culquicondorcc004c72018-08-02 14:50:0271 virtual gfx::Point3F GetTargetPointForTesting(
72 UserFriendlyElementName element_name,
73 const gfx::PointF& position) = 0;
bsheedya2ff3432018-10-02 18:16:5874 virtual bool GetElementVisibilityForTesting(
75 UserFriendlyElementName element_name) = 0;
bsheedyb3cc34d82018-11-15 22:20:4076 virtual void SetUiInputManagerForTesting(bool enabled) = 0;
Christopher Grant6cb4f2432018-07-19 15:29:1377 virtual bool IsContentVisibleAndOpaque() = 0;
Christopher Grant6cb4f2432018-07-19 15:29:1378 virtual void SetContentUsesQuadLayer(bool uses_quad_buffers) = 0;
79 virtual gfx::Transform GetContentWorldSpaceTransform() = 0;
Aldo Culquicondor4836b79e2018-09-13 18:52:2780 virtual bool OnBeginFrame(base::TimeTicks current_time,
81 const gfx::Transform& head_pose) = 0;
Christopher Grant6cb4f2432018-07-19 15:29:1382 virtual bool SceneHasDirtyTextures() const = 0;
83 virtual void UpdateSceneTextures() = 0;
Aldo Culquicondor4836b79e2018-09-13 18:52:2784 virtual void Draw(const RenderInfo& render_info) = 0;
Aldo Culquicondor4ca61bf2018-08-14 00:08:0585 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 Grant6cb4f2432018-07-19 15:29:1390 virtual void DrawWebVrOverlayForeground(const RenderInfo&) = 0;
Aldo Culquicondor3c315ea02018-08-13 20:45:0991 virtual bool HasWebXrOverlayElementsToDraw() = 0;
Christopher Grant6cb4f2432018-07-19 15:29:1392 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 Culquicondor570c3232018-07-23 16:46:4797 virtual void HandleMenuButtonEvents(InputEventList* input_event_list) = 0;
Christopher Grant6cb4f2432018-07-19 15:29:1398
99 // This function calculates the minimal FOV (in degrees) which covers all
Aldo Culquicondor3c315ea02018-08-13 20:45:09100 // 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 Grant6cb4f2432018-07-19 15:29:13108 // Using a smaller FOV could improve the performance a lot while we are
109 // showing UIs on top of WebVR content.
Aldo Culquicondor5dc384bf2018-08-22 23:42:36110 virtual FovRectangles GetMinimalFovForWebXrOverlayElements(
Aldo Culquicondor3c315ea02018-08-13 20:45:09111 const gfx::Transform& left_view,
112 const FovRectangle& fov_recommended_left,
113 const gfx::Transform& right_view,
114 const FovRectangle& fov_recommended_right,
Christopher Grant6cb4f2432018-07-19 15:29:13115 float z_near) = 0;
116};
117
118} // namespace vr
119
120#endif // CHROME_BROWSER_VR_UI_INTERFACE_H_