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> |
(...skipping 19 matching lines...) Expand all Loading... |
30 class WebInputEvent; | 30 class WebInputEvent; |
31 } | 31 } |
32 | 32 |
33 namespace gl { | 33 namespace gl { |
34 class GLContext; | 34 class GLContext; |
35 class GLSurface; | 35 class GLSurface; |
36 class ScopedJavaSurface; | 36 class ScopedJavaSurface; |
37 class SurfaceTexture; | 37 class SurfaceTexture; |
38 } | 38 } |
39 | 39 |
| 40 namespace gpu { |
| 41 struct MailboxHolder; |
| 42 } |
| 43 |
40 namespace vr_shell { | 44 namespace vr_shell { |
41 | 45 |
| 46 class MailboxToSurfaceBridge; |
42 class UiScene; | 47 class UiScene; |
43 class VrController; | 48 class VrController; |
44 class VrShell; | 49 class VrShell; |
45 class VrShellDelegate; | 50 class VrShellDelegate; |
46 class VrShellRenderer; | 51 class VrShellRenderer; |
47 struct ContentRectangle; | 52 struct ContentRectangle; |
48 | 53 |
| 54 struct WebVrBounds { |
| 55 WebVrBounds(gvr::Rectf left, gvr::Rectf right, gvr::Sizei size) |
| 56 : left_bounds(left), right_bounds(right), source_size(size) {} |
| 57 gvr::Rectf left_bounds; |
| 58 gvr::Rectf right_bounds; |
| 59 gvr::Sizei source_size; |
| 60 }; |
| 61 |
49 // This class manages all GLThread owned objects and GL rendering for VrShell. | 62 // This class manages all GLThread owned objects and GL rendering for VrShell. |
50 // It is not threadsafe and must only be used on the GL thread. | 63 // It is not threadsafe and must only be used on the GL thread. |
51 class VrShellGl : public device::mojom::VRVSyncProvider { | 64 class VrShellGl : public device::mojom::VRVSyncProvider { |
52 public: | 65 public: |
53 enum class InputTarget { | 66 enum class InputTarget { |
54 NONE = 0, | 67 NONE = 0, |
55 CONTENT, | 68 CONTENT, |
56 UI, | 69 UI, |
57 }; | 70 }; |
58 | 71 |
59 VrShellGl(const base::WeakPtr<VrShell>& weak_vr_shell, | 72 VrShellGl(const base::WeakPtr<VrShell>& weak_vr_shell, |
60 const base::WeakPtr<VrShellDelegate>& delegate_provider, | 73 const base::WeakPtr<VrShellDelegate>& delegate_provider, |
61 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner, | 74 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner, |
62 gvr_context* gvr_api, | 75 gvr_context* gvr_api, |
63 bool initially_web_vr, | 76 bool initially_web_vr, |
64 bool reprojected_rendering); | 77 bool reprojected_rendering); |
65 ~VrShellGl() override; | 78 ~VrShellGl() override; |
66 | 79 |
67 void Initialize(); | 80 void Initialize(); |
68 void InitializeGl(gfx::AcceleratedWidget window); | 81 void InitializeGl(gfx::AcceleratedWidget window); |
69 | 82 |
70 void OnTriggerEvent(); | 83 void OnTriggerEvent(); |
71 void OnPause(); | 84 void OnPause(); |
72 void OnResume(); | 85 void OnResume(); |
73 | 86 |
74 void SetWebVrMode(bool enabled); | 87 void SetWebVrMode(bool enabled); |
| 88 void CreateOrResizeWebVRSurface(const gvr::Sizei& size); |
75 void CreateContentSurface(); | 89 void CreateContentSurface(); |
76 void ContentBoundsChanged(int width, int height); | 90 void ContentBoundsChanged(int width, int height); |
77 void ContentPhysicalBoundsChanged(int width, int height); | 91 void ContentPhysicalBoundsChanged(int width, int height); |
78 void UIBoundsChanged(int width, int height); | 92 void UIBoundsChanged(int width, int height); |
79 void UIPhysicalBoundsChanged(int width, int height); | 93 void UIPhysicalBoundsChanged(int width, int height); |
80 base::WeakPtr<VrShellGl> GetWeakPtr(); | 94 base::WeakPtr<VrShellGl> GetWeakPtr(); |
81 | 95 |
82 void UpdateWebVRTextureBounds(int16_t frame_index, | 96 void UpdateWebVRTextureBounds(int16_t frame_index, |
83 const gvr::Rectf& left_bounds, | 97 const gvr::Rectf& left_bounds, |
84 const gvr::Rectf& right_bounds); | 98 const gvr::Rectf& right_bounds, |
85 gvr::Sizei GetWebVRCompositorSurfaceSize(); | 99 const gvr::Sizei& source_size); |
86 | 100 |
87 void UpdateScene(std::unique_ptr<base::ListValue> commands); | 101 void UpdateScene(std::unique_ptr<base::ListValue> commands); |
88 | 102 |
89 void UpdateVSyncInterval(int64_t timebase_nanos, double interval_seconds); | 103 void UpdateVSyncInterval(int64_t timebase_nanos, double interval_seconds); |
90 | 104 |
91 void OnRequest(device::mojom::VRVSyncProviderRequest request); | 105 void OnRequest(device::mojom::VRVSyncProviderRequest request); |
92 void ResetPose(); | 106 void ResetPose(); |
93 void CreateVRDisplayInfo( | 107 void CreateVRDisplayInfo( |
94 const base::Callback<void(device::mojom::VRDisplayInfoPtr)>& callback, | 108 const base::Callback<void(device::mojom::VRDisplayInfoPtr)>& callback, |
95 uint32_t device_id); | 109 uint32_t device_id); |
| 110 void SubmitWebVRFrame(int16_t frame_index, const gpu::MailboxHolder& mailbox); |
| 111 void SetSubmitClient( |
| 112 device::mojom::VRSubmitFrameClientPtrInfo submit_client_info); |
96 | 113 |
97 private: | 114 private: |
98 void GvrInit(gvr_context* gvr_api); | 115 void GvrInit(gvr_context* gvr_api); |
99 void InitializeRenderer(); | 116 void InitializeRenderer(); |
100 void DrawFrame(); | 117 void DrawFrame(int16_t frame_index); |
101 void DrawVrShell(const gvr::Mat4f& head_pose, gvr::Frame& frame); | 118 void DrawVrShellAndUnbind(const gvr::Mat4f& head_pose, gvr::Frame& frame); |
102 void DrawUiView(const gvr::Mat4f* head_pose, | 119 void DrawUiView(const gvr::Mat4f* head_pose, |
103 const std::vector<const ContentRectangle*>& elements, | 120 const std::vector<const ContentRectangle*>& elements, |
104 const gvr::Sizei& render_size, | 121 const gvr::Sizei& render_size, |
105 int viewport_offset); | 122 int viewport_offset); |
106 void DrawElements(const gvr::Mat4f& view_proj_matrix, | 123 void DrawElements(const gvr::Mat4f& view_proj_matrix, |
107 const gvr::Mat4f& view_matrix, | 124 const gvr::Mat4f& view_matrix, |
108 const std::vector<const ContentRectangle*>& elements); | 125 const std::vector<const ContentRectangle*>& elements); |
109 std::vector<const ContentRectangle*> GetElementsInDrawOrder( | 126 std::vector<const ContentRectangle*> GetElementsInDrawOrder( |
110 const gvr::Mat4f& view_matrix, | 127 const gvr::Mat4f& view_matrix, |
111 const std::vector<const ContentRectangle*>& elements); | 128 const std::vector<const ContentRectangle*>& elements); |
112 void DrawCursor(const gvr::Mat4f& render_matrix); | 129 void DrawCursor(const gvr::Mat4f& render_matrix); |
113 void DrawWebVr(); | 130 void DrawWebVr(); |
114 bool WebVrPoseByteIsValid(int pose_index_byte); | 131 bool WebVrPoseByteIsValid(int pose_index_byte); |
115 | 132 |
116 void UpdateController(const gvr::Vec3f& forward_vector); | 133 void UpdateController(const gvr::Vec3f& forward_vector); |
117 void SendEventsToTarget(InputTarget input_target, int pixel_x, int pixel_y); | 134 void SendEventsToTarget(InputTarget input_target, int pixel_x, int pixel_y); |
118 void SendGesture(InputTarget input_target, | 135 void SendGesture(InputTarget input_target, |
119 std::unique_ptr<blink::WebInputEvent> event); | 136 std::unique_ptr<blink::WebInputEvent> event); |
120 void CreateUiSurface(); | 137 void CreateUiSurface(); |
121 void OnUIFrameAvailable(); | 138 void OnUIFrameAvailable(); |
122 void OnContentFrameAvailable(); | 139 void OnContentFrameAvailable(); |
| 140 void OnWebVRFrameAvailable(); |
123 bool GetPixelEncodedFrameIndex(uint16_t* frame_index); | 141 bool GetPixelEncodedFrameIndex(uint16_t* frame_index); |
124 | 142 |
125 void OnVSync(); | 143 void OnVSync(); |
126 | 144 |
127 // VRVSyncProvider | 145 // VRVSyncProvider |
128 void GetVSync(const GetVSyncCallback& callback) override; | 146 void GetVSync(const GetVSyncCallback& callback) override; |
129 | 147 |
130 void ForceExitVr(); | 148 void ForceExitVr(); |
131 | 149 |
132 void SendVSync(base::TimeDelta time, const GetVSyncCallback& callback); | 150 void SendVSync(base::TimeDelta time, const GetVSyncCallback& callback); |
133 | 151 |
134 // samplerExternalOES texture data for UI content image. | 152 // samplerExternalOES texture data for UI content image. |
135 int ui_texture_id_ = 0; | 153 int ui_texture_id_ = 0; |
136 // samplerExternalOES texture data for main content image. | 154 // samplerExternalOES texture data for main content image. |
137 int content_texture_id_ = 0; | 155 int content_texture_id_ = 0; |
| 156 // samplerExternalOES texture data for WebVR content image. |
| 157 int webvr_texture_id_ = 0; |
138 | 158 |
139 std::unique_ptr<UiScene> scene_; | 159 std::unique_ptr<UiScene> scene_; |
140 | 160 |
141 scoped_refptr<gl::GLSurface> surface_; | 161 scoped_refptr<gl::GLSurface> surface_; |
142 scoped_refptr<gl::GLContext> context_; | 162 scoped_refptr<gl::GLContext> context_; |
143 scoped_refptr<gl::SurfaceTexture> ui_surface_texture_; | 163 scoped_refptr<gl::SurfaceTexture> ui_surface_texture_; |
144 scoped_refptr<gl::SurfaceTexture> content_surface_texture_; | 164 scoped_refptr<gl::SurfaceTexture> content_surface_texture_; |
| 165 scoped_refptr<gl::SurfaceTexture> webvr_surface_texture_; |
145 | 166 |
146 std::unique_ptr<gl::ScopedJavaSurface> ui_surface_; | 167 std::unique_ptr<gl::ScopedJavaSurface> ui_surface_; |
147 std::unique_ptr<gl::ScopedJavaSurface> content_surface_; | 168 std::unique_ptr<gl::ScopedJavaSurface> content_surface_; |
148 | 169 |
149 std::unique_ptr<gvr::GvrApi> gvr_api_; | 170 std::unique_ptr<gvr::GvrApi> gvr_api_; |
150 std::unique_ptr<gvr::BufferViewportList> buffer_viewport_list_; | 171 std::unique_ptr<gvr::BufferViewportList> buffer_viewport_list_; |
151 std::unique_ptr<gvr::BufferViewport> buffer_viewport_; | 172 std::unique_ptr<gvr::BufferViewport> buffer_viewport_; |
152 std::unique_ptr<gvr::BufferViewport> headlocked_left_viewport_; | 173 std::unique_ptr<gvr::BufferViewport> headlocked_left_viewport_; |
153 std::unique_ptr<gvr::BufferViewport> headlocked_right_viewport_; | 174 std::unique_ptr<gvr::BufferViewport> headlocked_right_viewport_; |
154 std::unique_ptr<gvr::BufferViewport> webvr_left_viewport_; | 175 std::unique_ptr<gvr::BufferViewport> webvr_left_viewport_; |
155 std::unique_ptr<gvr::BufferViewport> webvr_right_viewport_; | 176 std::unique_ptr<gvr::BufferViewport> webvr_right_viewport_; |
156 std::unique_ptr<gvr::SwapChain> swap_chain_; | 177 std::unique_ptr<gvr::SwapChain> swap_chain_; |
157 using BoundsPair = std::pair<gvr::Rectf, gvr::Rectf>; | 178 std::queue<std::pair<uint8_t, WebVrBounds>> pending_bounds_; |
158 std::queue<std::pair<uint8_t, BoundsPair>> pending_bounds_; | 179 int premature_received_frames_ = 0; |
| 180 std::queue<uint16_t> pending_frames_; |
| 181 std::unique_ptr<MailboxToSurfaceBridge> mailbox_bridge_; |
159 | 182 |
160 // Current sizes for the render buffers. | 183 // Current sizes for the render buffers. |
161 gvr::Sizei render_size_primary_; | 184 gvr::Sizei render_size_primary_; |
162 gvr::Sizei render_size_headlocked_; | 185 gvr::Sizei render_size_headlocked_; |
163 | 186 |
| 187 // Intended render_size_primary_ for use by VrShell, so that it |
| 188 // can be restored after exiting WebVR mode. |
| 189 gvr::Sizei render_size_vrshell_; |
| 190 |
164 std::unique_ptr<VrShellRenderer> vr_shell_renderer_; | 191 std::unique_ptr<VrShellRenderer> vr_shell_renderer_; |
165 | 192 |
166 bool touch_pending_ = false; | 193 bool touch_pending_ = false; |
167 gvr::Quatf controller_quat_; | 194 gvr::Quatf controller_quat_; |
168 | 195 |
169 gvr::Vec3f target_point_; | 196 gvr::Vec3f target_point_; |
170 const ContentRectangle* target_element_ = nullptr; | 197 const ContentRectangle* target_element_ = nullptr; |
171 InputTarget current_input_target_ = InputTarget::NONE; | 198 InputTarget current_input_target_ = InputTarget::NONE; |
172 InputTarget current_scroll_target = InputTarget::NONE; | 199 InputTarget current_scroll_target = InputTarget::NONE; |
173 int ui_tex_css_width_ = 0; | 200 int ui_tex_css_width_ = 0; |
174 int ui_tex_css_height_ = 0; | 201 int ui_tex_css_height_ = 0; |
175 int content_tex_css_width_ = 0; | 202 int content_tex_css_width_ = 0; |
176 int content_tex_css_height_ = 0; | 203 int content_tex_css_height_ = 0; |
177 gvr::Sizei content_tex_physical_size_ = {0, 0}; | 204 gvr::Sizei content_tex_physical_size_ = {0, 0}; |
| 205 gvr::Sizei webvr_surface_size_ = {0, 0}; |
178 gvr::Sizei ui_tex_physical_size_ = {0, 0}; | 206 gvr::Sizei ui_tex_physical_size_ = {0, 0}; |
179 | 207 |
180 std::vector<gvr::Mat4f> webvr_head_pose_; | 208 std::vector<gvr::Mat4f> webvr_head_pose_; |
181 int webvr_texture_id_ = 0; | |
182 bool web_vr_mode_; | 209 bool web_vr_mode_; |
183 bool ready_to_draw_ = false; | 210 bool ready_to_draw_ = false; |
184 bool surfaceless_rendering_; | 211 bool surfaceless_rendering_; |
185 | 212 |
186 std::unique_ptr<VrController> controller_; | 213 std::unique_ptr<VrController> controller_; |
187 | 214 |
188 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 215 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
189 base::CancelableClosure vsync_task_; | 216 base::CancelableClosure vsync_task_; |
190 base::TimeTicks vsync_timebase_; | 217 base::TimeTicks vsync_timebase_; |
191 base::TimeDelta vsync_interval_; | 218 base::TimeDelta vsync_interval_; |
192 | 219 |
193 base::TimeDelta pending_time_; | 220 base::TimeDelta pending_time_; |
194 bool pending_vsync_ = false; | 221 bool pending_vsync_ = false; |
195 GetVSyncCallback callback_; | 222 GetVSyncCallback callback_; |
196 bool received_frame_ = false; | 223 bool received_frame_ = false; |
197 mojo::Binding<device::mojom::VRVSyncProvider> binding_; | 224 mojo::Binding<device::mojom::VRVSyncProvider> binding_; |
| 225 device::mojom::VRSubmitFrameClientPtr submit_client_; |
198 | 226 |
199 base::WeakPtr<VrShell> weak_vr_shell_; | 227 base::WeakPtr<VrShell> weak_vr_shell_; |
200 base::WeakPtr<VrShellDelegate> delegate_provider_; | 228 base::WeakPtr<VrShellDelegate> delegate_provider_; |
201 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; | 229 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; |
202 | 230 |
203 uint8_t frame_index_ = 0; | 231 uint8_t frame_index_ = 0; |
204 // larger than frame_index_ so it can be initialized out-of-band. | 232 // larger than frame_index_ so it can be initialized out-of-band. |
205 uint16_t last_frame_index_ = -1; | 233 uint16_t last_frame_index_ = -1; |
206 | 234 |
207 base::WeakPtrFactory<VrShellGl> weak_ptr_factory_; | 235 base::WeakPtrFactory<VrShellGl> weak_ptr_factory_; |
208 | 236 |
209 DISALLOW_COPY_AND_ASSIGN(VrShellGl); | 237 DISALLOW_COPY_AND_ASSIGN(VrShellGl); |
210 }; | 238 }; |
211 | 239 |
212 } // namespace vr_shell | 240 } // namespace vr_shell |
213 | 241 |
214 #endif // CHROME_BROWSER_ANDROID_VR_SHELL_VR_SHELL_GL_H_ | 242 #endif // CHROME_BROWSER_ANDROID_VR_SHELL_VR_SHELL_GL_H_ |
OLD | NEW |