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