OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_ANDROID_VR_SHELL_VR_SHELL_GL_H_ | 5 #ifndef CHROME_BROWSER_ANDROID_VR_SHELL_VR_SHELL_GL_H_ |
6 #define CHROME_BROWSER_ANDROID_VR_SHELL_VR_SHELL_GL_H_ | 6 #define CHROME_BROWSER_ANDROID_VR_SHELL_VR_SHELL_GL_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <queue> | 9 #include <queue> |
10 #include <utility> | 10 #include <utility> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/cancelable_callback.h" | 13 #include "base/cancelable_callback.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
17 #include "base/single_thread_task_runner.h" | 17 #include "base/single_thread_task_runner.h" |
18 #include "chrome/browser/android/vr_shell/vr_controller_model.h" | 18 #include "chrome/browser/android/vr_shell/vr_controller_model.h" |
19 #include "device/vr/vr_service.mojom.h" | 19 #include "device/vr/vr_service.mojom.h" |
| 20 #include "device/vr/vr_types.h" |
20 #include "mojo/public/cpp/bindings/binding.h" | 21 #include "mojo/public/cpp/bindings/binding.h" |
21 #include "third_party/gvr-android-sdk/src/libraries/headers/vr/gvr/capi/include/
gvr.h" | 22 #include "third_party/gvr-android-sdk/src/libraries/headers/vr/gvr/capi/include/
gvr.h" |
22 #include "third_party/gvr-android-sdk/src/libraries/headers/vr/gvr/capi/include/
gvr_types.h" | 23 #include "third_party/gvr-android-sdk/src/libraries/headers/vr/gvr/capi/include/
gvr_types.h" |
23 #include "ui/gfx/native_widget_types.h" | 24 #include "ui/gfx/native_widget_types.h" |
24 | 25 |
25 namespace base { | 26 namespace base { |
26 class ListValue; | 27 class ListValue; |
27 } | 28 } |
28 | 29 |
29 namespace blink { | 30 namespace blink { |
(...skipping 14 matching lines...) Expand all Loading... |
44 namespace vr_shell { | 45 namespace vr_shell { |
45 | 46 |
46 class MailboxToSurfaceBridge; | 47 class MailboxToSurfaceBridge; |
47 class UiScene; | 48 class UiScene; |
48 class VrController; | 49 class VrController; |
49 class VrShell; | 50 class VrShell; |
50 class VrShellRenderer; | 51 class VrShellRenderer; |
51 struct ContentRectangle; | 52 struct ContentRectangle; |
52 | 53 |
53 struct WebVrBounds { | 54 struct WebVrBounds { |
54 WebVrBounds(gvr::Rectf left, gvr::Rectf right, gvr::Sizei size) | 55 WebVrBounds(const gfx::RectF& left, |
| 56 const gfx::RectF& right, |
| 57 const gfx::Size& size) |
55 : left_bounds(left), right_bounds(right), source_size(size) {} | 58 : left_bounds(left), right_bounds(right), source_size(size) {} |
56 gvr::Rectf left_bounds; | 59 gfx::RectF left_bounds; |
57 gvr::Rectf right_bounds; | 60 gfx::RectF right_bounds; |
58 gvr::Sizei source_size; | 61 gfx::Size source_size; |
59 }; | 62 }; |
60 | 63 |
61 // This class manages all GLThread owned objects and GL rendering for VrShell. | 64 // This class manages all GLThread owned objects and GL rendering for VrShell. |
62 // It is not threadsafe and must only be used on the GL thread. | 65 // It is not threadsafe and must only be used on the GL thread. |
63 class VrShellGl : public device::mojom::VRVSyncProvider { | 66 class VrShellGl : public device::mojom::VRVSyncProvider { |
64 public: | 67 public: |
65 enum class InputTarget { | 68 enum class InputTarget { |
66 NONE = 0, | 69 NONE = 0, |
67 CONTENT, | 70 CONTENT, |
68 UI, | 71 UI, |
69 }; | 72 }; |
70 | 73 |
71 VrShellGl(const base::WeakPtr<VrShell>& weak_vr_shell, | 74 VrShellGl(const base::WeakPtr<VrShell>& weak_vr_shell, |
72 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner, | 75 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner, |
73 gvr_context* gvr_api, | 76 gvr_context* gvr_api, |
74 bool initially_web_vr, | 77 bool initially_web_vr, |
75 bool reprojected_rendering); | 78 bool reprojected_rendering); |
76 ~VrShellGl() override; | 79 ~VrShellGl() override; |
77 | 80 |
78 void Initialize(); | 81 void Initialize(); |
79 void InitializeGl(gfx::AcceleratedWidget window); | 82 void InitializeGl(gfx::AcceleratedWidget window); |
80 | 83 |
81 void OnTriggerEvent(); | 84 void OnTriggerEvent(); |
82 void OnPause(); | 85 void OnPause(); |
83 void OnResume(); | 86 void OnResume(); |
84 | 87 |
85 void SetWebVrMode(bool enabled); | 88 void SetWebVrMode(bool enabled); |
86 void CreateOrResizeWebVRSurface(const gvr::Sizei& size); | 89 void CreateOrResizeWebVRSurface(const gfx::Size& size); |
87 void CreateContentSurface(); | 90 void CreateContentSurface(); |
88 void ContentBoundsChanged(int width, int height); | 91 void ContentBoundsChanged(int width, int height); |
89 void ContentPhysicalBoundsChanged(int width, int height); | 92 void ContentPhysicalBoundsChanged(int width, int height); |
90 void UIBoundsChanged(int width, int height); | 93 void UIBoundsChanged(int width, int height); |
91 void UIPhysicalBoundsChanged(int width, int height); | 94 void UIPhysicalBoundsChanged(int width, int height); |
92 base::WeakPtr<VrShellGl> GetWeakPtr(); | 95 base::WeakPtr<VrShellGl> GetWeakPtr(); |
93 | 96 |
94 void SetControllerModel(std::unique_ptr<VrControllerModel> model); | 97 void SetControllerModel(std::unique_ptr<VrControllerModel> model); |
95 | 98 |
96 void UpdateWebVRTextureBounds(int16_t frame_index, | 99 void UpdateWebVRTextureBounds(int16_t frame_index, |
97 const gvr::Rectf& left_bounds, | 100 const gfx::RectF& left_bounds, |
98 const gvr::Rectf& right_bounds, | 101 const gfx::RectF& right_bounds, |
99 const gvr::Sizei& source_size); | 102 const gfx::Size& source_size); |
100 | 103 |
101 void UpdateScene(std::unique_ptr<base::ListValue> commands); | 104 void UpdateScene(std::unique_ptr<base::ListValue> commands); |
102 | 105 |
103 void UpdateVSyncInterval(int64_t timebase_nanos, double interval_seconds); | 106 void UpdateVSyncInterval(int64_t timebase_nanos, double interval_seconds); |
104 | 107 |
105 void OnRequest(device::mojom::VRVSyncProviderRequest request); | 108 void OnRequest(device::mojom::VRVSyncProviderRequest request); |
106 void CreateVRDisplayInfo( | 109 void CreateVRDisplayInfo( |
107 const base::Callback<void(device::mojom::VRDisplayInfoPtr)>& callback, | 110 const base::Callback<void(device::mojom::VRDisplayInfoPtr)>& callback, |
108 uint32_t device_id); | 111 uint32_t device_id); |
109 void SubmitWebVRFrame(int16_t frame_index, const gpu::MailboxHolder& mailbox); | 112 void SubmitWebVRFrame(int16_t frame_index, const gpu::MailboxHolder& mailbox); |
110 void SetSubmitClient( | 113 void SetSubmitClient( |
111 device::mojom::VRSubmitFrameClientPtrInfo submit_client_info); | 114 device::mojom::VRSubmitFrameClientPtrInfo submit_client_info); |
112 | 115 |
113 private: | 116 private: |
114 void GvrInit(gvr_context* gvr_api); | 117 void GvrInit(gvr_context* gvr_api); |
115 void InitializeRenderer(); | 118 void InitializeRenderer(); |
116 void DrawFrame(int16_t frame_index); | 119 void DrawFrame(int16_t frame_index); |
117 void DrawWorldElements(const gvr::Mat4f& head_pose); | 120 void DrawWorldElements(const vr::Mat4f& head_pose); |
118 void DrawHeadLockedElements(); | 121 void DrawHeadLockedElements(); |
119 void DrawUiView(const gvr::Mat4f& head_pose, | 122 void DrawUiView(const vr::Mat4f& head_pose, |
120 const std::vector<const ContentRectangle*>& elements, | 123 const std::vector<const ContentRectangle*>& elements, |
121 const gvr::Sizei& render_size, | 124 const gfx::Size& render_size, |
122 int viewport_offset, | 125 int viewport_offset, |
123 bool draw_cursor); | 126 bool draw_cursor); |
124 void DrawElements(const gvr::Mat4f& view_proj_matrix, | 127 void DrawElements(const vr::Mat4f& view_proj_matrix, |
125 const std::vector<const ContentRectangle*>& elements); | 128 const std::vector<const ContentRectangle*>& elements); |
126 std::vector<const ContentRectangle*> GetElementsInDrawOrder( | 129 std::vector<const ContentRectangle*> GetElementsInDrawOrder( |
127 const gvr::Mat4f& view_matrix, | 130 const vr::Mat4f& view_matrix, |
128 const std::vector<const ContentRectangle*>& elements); | 131 const std::vector<const ContentRectangle*>& elements); |
129 void DrawCursor(const gvr::Mat4f& render_matrix); | 132 void DrawCursor(const vr::Mat4f& render_matrix); |
130 void DrawController(const gvr::Mat4f& view_proj_matrix); | 133 void DrawController(const vr::Mat4f& view_proj_matrix); |
131 bool ShouldDrawWebVr(); | 134 bool ShouldDrawWebVr(); |
132 void DrawWebVr(); | 135 void DrawWebVr(); |
133 bool WebVrPoseByteIsValid(int pose_index_byte); | 136 bool WebVrPoseByteIsValid(int pose_index_byte); |
134 | 137 |
135 void UpdateController(); | 138 void UpdateController(); |
136 void HandleControllerInput(const gvr::Vec3f& forward_vector); | 139 void HandleControllerInput(const gfx::Vector3dF& forward_vector); |
137 void HandleControllerAppButtonActivity( | 140 void HandleControllerAppButtonActivity( |
138 const gvr::Vec3f& controller_direction); | 141 const gfx::Vector3dF& controller_direction); |
139 void SendEventsToTarget(InputTarget input_target, int pixel_x, int pixel_y); | 142 void SendEventsToTarget(InputTarget input_target, int pixel_x, int pixel_y); |
140 void SendGesture(InputTarget input_target, | 143 void SendGesture(InputTarget input_target, |
141 std::unique_ptr<blink::WebInputEvent> event); | 144 std::unique_ptr<blink::WebInputEvent> event); |
142 void CreateUiSurface(); | 145 void CreateUiSurface(); |
143 void OnUIFrameAvailable(); | 146 void OnUIFrameAvailable(); |
144 void OnContentFrameAvailable(); | 147 void OnContentFrameAvailable(); |
145 void OnWebVRFrameAvailable(); | 148 void OnWebVRFrameAvailable(); |
146 bool GetPixelEncodedFrameIndex(uint16_t* frame_index); | 149 bool GetPixelEncodedFrameIndex(uint16_t* frame_index); |
147 | 150 |
148 void OnVSync(); | 151 void OnVSync(); |
(...skipping 30 matching lines...) Expand all Loading... |
179 std::unique_ptr<gvr::BufferViewport> headlocked_right_viewport_; | 182 std::unique_ptr<gvr::BufferViewport> headlocked_right_viewport_; |
180 std::unique_ptr<gvr::BufferViewport> webvr_left_viewport_; | 183 std::unique_ptr<gvr::BufferViewport> webvr_left_viewport_; |
181 std::unique_ptr<gvr::BufferViewport> webvr_right_viewport_; | 184 std::unique_ptr<gvr::BufferViewport> webvr_right_viewport_; |
182 std::unique_ptr<gvr::SwapChain> swap_chain_; | 185 std::unique_ptr<gvr::SwapChain> swap_chain_; |
183 std::queue<std::pair<uint8_t, WebVrBounds>> pending_bounds_; | 186 std::queue<std::pair<uint8_t, WebVrBounds>> pending_bounds_; |
184 int premature_received_frames_ = 0; | 187 int premature_received_frames_ = 0; |
185 std::queue<uint16_t> pending_frames_; | 188 std::queue<uint16_t> pending_frames_; |
186 std::unique_ptr<MailboxToSurfaceBridge> mailbox_bridge_; | 189 std::unique_ptr<MailboxToSurfaceBridge> mailbox_bridge_; |
187 | 190 |
188 // Current sizes for the render buffers. | 191 // Current sizes for the render buffers. |
189 gvr::Sizei render_size_primary_; | 192 gfx::Size render_size_primary_; |
190 gvr::Sizei render_size_headlocked_; | 193 gfx::Size render_size_headlocked_; |
191 | 194 |
192 // Intended render_size_primary_ for use by VrShell, so that it | 195 // Intended render_size_primary_ for use by VrShell, so that it |
193 // can be restored after exiting WebVR mode. | 196 // can be restored after exiting WebVR mode. |
194 gvr::Sizei render_size_vrshell_; | 197 gfx::Size render_size_vrshell_; |
195 | 198 |
196 std::unique_ptr<VrShellRenderer> vr_shell_renderer_; | 199 std::unique_ptr<VrShellRenderer> vr_shell_renderer_; |
197 | 200 |
198 bool touch_pending_ = false; | 201 bool touch_pending_ = false; |
199 gvr::Quatf controller_quat_; | 202 vr::Quatf controller_quat_; |
200 | 203 |
201 gvr::Vec3f target_point_; | 204 gfx::Point3F target_point_; |
202 const ContentRectangle* target_element_ = nullptr; | 205 const ContentRectangle* target_element_ = nullptr; |
203 InputTarget current_input_target_ = InputTarget::NONE; | 206 InputTarget current_input_target_ = InputTarget::NONE; |
204 InputTarget current_scroll_target = InputTarget::NONE; | 207 InputTarget current_scroll_target = InputTarget::NONE; |
205 int ui_tex_css_width_ = 0; | 208 int ui_tex_css_width_ = 0; |
206 int ui_tex_css_height_ = 0; | 209 int ui_tex_css_height_ = 0; |
207 int content_tex_css_width_ = 0; | 210 int content_tex_css_width_ = 0; |
208 int content_tex_css_height_ = 0; | 211 int content_tex_css_height_ = 0; |
209 gvr::Sizei content_tex_physical_size_ = {0, 0}; | 212 gfx::Size content_tex_physical_size_ = {0, 0}; |
210 gvr::Sizei webvr_surface_size_ = {0, 0}; | 213 gfx::Size webvr_surface_size_ = {0, 0}; |
211 gvr::Sizei ui_tex_physical_size_ = {0, 0}; | 214 gfx::Size ui_tex_physical_size_ = {0, 0}; |
212 | 215 |
213 std::vector<gvr::Mat4f> webvr_head_pose_; | 216 std::vector<vr::Mat4f> webvr_head_pose_; |
214 bool web_vr_mode_; | 217 bool web_vr_mode_; |
215 bool ready_to_draw_ = false; | 218 bool ready_to_draw_ = false; |
216 bool surfaceless_rendering_; | 219 bool surfaceless_rendering_; |
217 | 220 |
218 std::unique_ptr<VrController> controller_; | 221 std::unique_ptr<VrController> controller_; |
219 | 222 |
220 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 223 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
221 base::CancelableClosure vsync_task_; | 224 base::CancelableClosure vsync_task_; |
222 base::TimeTicks vsync_timebase_; | 225 base::TimeTicks vsync_timebase_; |
223 base::TimeDelta vsync_interval_; | 226 base::TimeDelta vsync_interval_; |
224 | 227 |
225 base::TimeDelta pending_time_; | 228 base::TimeDelta pending_time_; |
226 bool pending_vsync_ = false; | 229 bool pending_vsync_ = false; |
227 GetVSyncCallback callback_; | 230 GetVSyncCallback callback_; |
228 bool received_frame_ = false; | 231 bool received_frame_ = false; |
229 mojo::Binding<device::mojom::VRVSyncProvider> binding_; | 232 mojo::Binding<device::mojom::VRVSyncProvider> binding_; |
230 device::mojom::VRSubmitFrameClientPtr submit_client_; | 233 device::mojom::VRSubmitFrameClientPtr submit_client_; |
231 | 234 |
232 base::WeakPtr<VrShell> weak_vr_shell_; | 235 base::WeakPtr<VrShell> weak_vr_shell_; |
233 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; | 236 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; |
234 | 237 |
235 uint8_t frame_index_ = 0; | 238 uint8_t frame_index_ = 0; |
236 // Larger than frame_index_ so it can be initialized out-of-band. | 239 // Larger than frame_index_ so it can be initialized out-of-band. |
237 uint16_t last_frame_index_ = -1; | 240 uint16_t last_frame_index_ = -1; |
238 | 241 |
239 // Attributes for gesture detection while holding app button. | 242 // Attributes for gesture detection while holding app button. |
240 gvr::Vec3f controller_start_direction_; | 243 gfx::Vector3dF controller_start_direction_; |
241 | 244 |
242 base::WeakPtrFactory<VrShellGl> weak_ptr_factory_; | 245 base::WeakPtrFactory<VrShellGl> weak_ptr_factory_; |
243 | 246 |
244 DISALLOW_COPY_AND_ASSIGN(VrShellGl); | 247 DISALLOW_COPY_AND_ASSIGN(VrShellGl); |
245 }; | 248 }; |
246 | 249 |
247 } // namespace vr_shell | 250 } // namespace vr_shell |
248 | 251 |
249 #endif // CHROME_BROWSER_ANDROID_VR_SHELL_VR_SHELL_GL_H_ | 252 #endif // CHROME_BROWSER_ANDROID_VR_SHELL_VR_SHELL_GL_H_ |
OLD | NEW |