blob: ca91d5083feace475fff057eb8aabe24c6f2b79c [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 Culquicondor5dc384bf2018-08-22 23:42:3615#include "chrome/browser/vr/compositor_ui_interface.h"
Aldo Culquicondor3c315ea02018-08-13 20:45:0916#include "chrome/browser/vr/gl_texture_location.h"
Ian Vollick3d259622018-07-30 20:07:1417#include "chrome/browser/vr/keyboard_ui_interface.h"
Aldo Culquicondorcc004c72018-08-02 14:50:0218
19namespace gfx {
20class Point3F;
Aldo Culquicondor3c315ea02018-08-13 20:45:0921class PointF;
22class Transform;
Aldo Culquicondorcc004c72018-08-02 14:50:0223}
Christopher Grant6cb4f2432018-07-19 15:29:1324
25namespace vr {
26
27class BrowserUiInterface;
Aldo Culquicondor3c315ea02018-08-13 20:45:0928class InputEvent;
Christopher Grant6cb4f2432018-07-19 15:29:1329class PlatformUiInputDelegate;
30struct ControllerModel;
31struct RenderInfo;
32struct ReticleModel;
Aldo Culquicondorcc004c72018-08-02 14:50:0233enum class UserFriendlyElementName;
Christopher Grant6cb4f2432018-07-19 15:29:1334
Aldo Culquicondor3c315ea02018-08-13 20:45:0935using InputEventList = std::vector<std::unique_ptr<InputEvent>>;
36
Christopher Grant6cb4f2432018-07-19 15:29:1337// 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 Culquicondor5dc384bf2018-08-22 23:42:3640class UiInterface : public BrowserUiInterface,
41 public CompositorUiInterface,
42 public KeyboardUiInterface {
Christopher Grant6cb4f2432018-07-19 15:29:1343 public:
44 ~UiInterface() override {}
45
46 virtual base::WeakPtr<BrowserUiInterface> GetBrowserUiWeakPtr() = 0;
47
Christopher Grant6cb4f2432018-07-19 15:29:1348 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 Grant6cb4f2432018-07-19 15:29:1365 virtual void OnPause() = 0;
Christopher Grant6cb4f2432018-07-19 15:29:1366 virtual void OnControllerUpdated(const ControllerModel& controller_model,
67 const ReticleModel& reticle_model) = 0;
68 virtual void OnProjMatrixChanged(const gfx::Transform& proj_matrix) = 0;
Christopher Grant6cb4f2432018-07-19 15:29:1369 virtual bool IsControllerVisible() const = 0;
Christopher Grant6cb4f2432018-07-19 15:29:1370 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 Culquicondorcc004c72018-08-02 14:50:0274 virtual gfx::Point3F GetTargetPointForTesting(
75 UserFriendlyElementName element_name,
76 const gfx::PointF& position) = 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;
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 Culquicondor4ca61bf2018-08-14 00:08:0584 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 Grant6cb4f2432018-07-19 15:29:1389 virtual void DrawWebVrOverlayForeground(const RenderInfo&) = 0;
Aldo Culquicondor3c315ea02018-08-13 20:45:0990 virtual bool HasWebXrOverlayElementsToDraw() = 0;
Christopher Grant6cb4f2432018-07-19 15:29:1391 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 Culquicondor570c3232018-07-23 16:46:4796 virtual void HandleMenuButtonEvents(InputEventList* input_event_list) = 0;
Christopher Grant6cb4f2432018-07-19 15:29:1397
98 // This function calculates the minimal FOV (in degrees) which covers all
Aldo Culquicondor3c315ea02018-08-13 20:45:0999 // 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 Grant6cb4f2432018-07-19 15:29:13107 // Using a smaller FOV could improve the performance a lot while we are
108 // showing UIs on top of WebVR content.
Aldo Culquicondor5dc384bf2018-08-22 23:42:36109 virtual FovRectangles GetMinimalFovForWebXrOverlayElements(
Aldo Culquicondor3c315ea02018-08-13 20:45:09110 const gfx::Transform& left_view,
111 const FovRectangle& fov_recommended_left,
112 const gfx::Transform& right_view,
113 const FovRectangle& fov_recommended_right,
Christopher Grant6cb4f2432018-07-19 15:29:13114 float z_near) = 0;
115};
116
117} // namespace vr
118
119#endif // CHROME_BROWSER_VR_UI_INTERFACE_H_