| 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 ~VrShellGl() override; | 65 ~VrShellGl() override; |
| 66 | 66 |
| 67 void Initialize(); | 67 void Initialize(); |
| 68 void InitializeGl(gfx::AcceleratedWidget window); | 68 void InitializeGl(gfx::AcceleratedWidget window); |
| 69 | 69 |
| 70 void OnTriggerEvent(); | 70 void OnTriggerEvent(); |
| 71 void OnPause(); | 71 void OnPause(); |
| 72 void OnResume(); | 72 void OnResume(); |
| 73 | 73 |
| 74 void SetWebVrMode(bool enabled); | 74 void SetWebVrMode(bool enabled); |
| 75 void CreateWebVRSurface(); |
| 75 void CreateContentSurface(); | 76 void CreateContentSurface(); |
| 76 void ContentBoundsChanged(int width, int height); | 77 void ContentBoundsChanged(int width, int height); |
| 77 void ContentPhysicalBoundsChanged(int width, int height); | 78 void ContentPhysicalBoundsChanged(int width, int height); |
| 78 void UIBoundsChanged(int width, int height); | 79 void UIBoundsChanged(int width, int height); |
| 79 void UIPhysicalBoundsChanged(int width, int height); | 80 void UIPhysicalBoundsChanged(int width, int height); |
| 80 base::WeakPtr<VrShellGl> GetWeakPtr(); | 81 base::WeakPtr<VrShellGl> GetWeakPtr(); |
| 81 | 82 |
| 82 void UpdateWebVRTextureBounds(int16_t frame_index, | 83 void UpdateWebVRTextureBounds(int16_t frame_index, |
| 83 const gvr::Rectf& left_bounds, | 84 const gvr::Rectf& left_bounds, |
| 84 const gvr::Rectf& right_bounds); | 85 const gvr::Rectf& right_bounds); |
| 85 void SetGvrPoseForWebVr(const gvr::Mat4f& pose, uint32_t pose_num); | 86 void SetGvrPoseForWebVr(const gvr::Mat4f& pose, uint32_t pose_num); |
| 86 gvr::Sizei GetWebVRCompositorSurfaceSize(); | 87 gvr::Sizei GetWebVRCompositorSurfaceSize(); |
| 87 | 88 |
| 88 void UpdateScene(std::unique_ptr<base::ListValue> commands); | 89 void UpdateScene(std::unique_ptr<base::ListValue> commands); |
| 89 | 90 |
| 90 void UpdateVSyncInterval(int64_t timebase_nanos, double interval_seconds); | 91 void UpdateVSyncInterval(int64_t timebase_nanos, double interval_seconds); |
| 91 | 92 |
| 92 void OnRequest(device::mojom::VRVSyncProviderRequest request); | 93 void OnRequest(device::mojom::VRVSyncProviderRequest request); |
| 93 void ResetPose(); | 94 void ResetPose(); |
| 94 void CreateVRDisplayInfo( | 95 void CreateVRDisplayInfo( |
| 95 const base::Callback<void(device::mojom::VRDisplayInfoPtr)>& callback, | 96 const base::Callback<void(device::mojom::VRDisplayInfoPtr)>& callback, |
| 96 uint32_t device_id); | 97 uint32_t device_id); |
| 98 void ScheduleWebVRFrame(int frame_index); |
| 99 void DropWebVRFrame(int frame_index); |
| 97 | 100 |
| 98 private: | 101 private: |
| 99 void GvrInit(gvr_context* gvr_api); | 102 void GvrInit(gvr_context* gvr_api); |
| 100 void InitializeRenderer(); | 103 void InitializeRenderer(); |
| 101 void DrawFrame(); | 104 void DrawFrame(int frame_index); |
| 102 void DrawVrShell(const gvr::Mat4f& head_pose, gvr::Frame& frame); | 105 void DrawVrShell(const gvr::Mat4f& head_pose, gvr::Frame& frame); |
| 103 void DrawUiView(const gvr::Mat4f* head_pose, | 106 void DrawUiView(const gvr::Mat4f* head_pose, |
| 104 const std::vector<const ContentRectangle*>& elements, | 107 const std::vector<const ContentRectangle*>& elements, |
| 105 const gvr::Sizei& render_size, | 108 const gvr::Sizei& render_size, |
| 106 int viewport_offset); | 109 int viewport_offset); |
| 107 void DrawElements(const gvr::Mat4f& view_proj_matrix, | 110 void DrawElements(const gvr::Mat4f& view_proj_matrix, |
| 108 const gvr::Mat4f& view_matrix, | 111 const gvr::Mat4f& view_matrix, |
| 109 const std::vector<const ContentRectangle*>& elements); | 112 const std::vector<const ContentRectangle*>& elements); |
| 110 std::vector<const ContentRectangle*> GetElementsInDrawOrder( | 113 std::vector<const ContentRectangle*> GetElementsInDrawOrder( |
| 111 const gvr::Mat4f& view_matrix, | 114 const gvr::Mat4f& view_matrix, |
| 112 const std::vector<const ContentRectangle*>& elements); | 115 const std::vector<const ContentRectangle*>& elements); |
| 113 void DrawCursor(const gvr::Mat4f& render_matrix); | 116 void DrawCursor(const gvr::Mat4f& render_matrix); |
| 114 void DrawWebVr(); | 117 void DrawWebVr(); |
| 115 bool WebVrPoseByteIsValid(int pose_index_byte); | 118 bool WebVrPoseByteIsValid(int pose_index_byte); |
| 116 | 119 |
| 117 void UpdateController(const gvr::Vec3f& forward_vector); | 120 void UpdateController(const gvr::Vec3f& forward_vector); |
| 118 void SendEventsToTarget(InputTarget input_target, int pixel_x, int pixel_y); | 121 void SendEventsToTarget(InputTarget input_target, int pixel_x, int pixel_y); |
| 119 void SendGesture(InputTarget input_target, | 122 void SendGesture(InputTarget input_target, |
| 120 std::unique_ptr<blink::WebInputEvent> event); | 123 std::unique_ptr<blink::WebInputEvent> event); |
| 121 void CreateUiSurface(); | 124 void CreateUiSurface(); |
| 122 void OnUIFrameAvailable(); | 125 void OnUIFrameAvailable(); |
| 123 void OnContentFrameAvailable(); | 126 void OnContentFrameAvailable(); |
| 127 void OnWebVRFrameAvailable(); |
| 124 bool GetPixelEncodedFrameIndex(uint16_t* frame_index); | 128 bool GetPixelEncodedFrameIndex(uint16_t* frame_index); |
| 125 | 129 |
| 126 void OnVSync(); | 130 void OnVSync(); |
| 127 | 131 |
| 128 // VRVSyncProvider | 132 // VRVSyncProvider |
| 129 void GetVSync(const GetVSyncCallback& callback) override; | 133 void GetVSync(const GetVSyncCallback& callback) override; |
| 130 | 134 |
| 131 void ForceExitVr(); | 135 void ForceExitVr(); |
| 132 | 136 |
| 133 void SendVSync(base::TimeDelta time, const GetVSyncCallback& callback); | 137 void SendVSync(base::TimeDelta time, const GetVSyncCallback& callback); |
| 134 | 138 |
| 135 // samplerExternalOES texture data for UI content image. | 139 // samplerExternalOES texture data for UI content image. |
| 136 int ui_texture_id_ = 0; | 140 int ui_texture_id_ = 0; |
| 137 // samplerExternalOES texture data for main content image. | 141 // samplerExternalOES texture data for main content image. |
| 138 int content_texture_id_ = 0; | 142 int content_texture_id_ = 0; |
| 143 // samplerExternalOES texture data for WebVR content image. |
| 144 int webvr_texture_id_ = 0; |
| 139 | 145 |
| 140 std::unique_ptr<UiScene> scene_; | 146 std::unique_ptr<UiScene> scene_; |
| 141 | 147 |
| 142 scoped_refptr<gl::GLSurface> surface_; | 148 scoped_refptr<gl::GLSurface> surface_; |
| 143 scoped_refptr<gl::GLContext> context_; | 149 scoped_refptr<gl::GLContext> context_; |
| 144 scoped_refptr<gl::SurfaceTexture> ui_surface_texture_; | 150 scoped_refptr<gl::SurfaceTexture> ui_surface_texture_; |
| 145 scoped_refptr<gl::SurfaceTexture> content_surface_texture_; | 151 scoped_refptr<gl::SurfaceTexture> content_surface_texture_; |
| 152 scoped_refptr<gl::SurfaceTexture> webvr_surface_texture_; |
| 146 | 153 |
| 147 std::unique_ptr<gl::ScopedJavaSurface> ui_surface_; | 154 std::unique_ptr<gl::ScopedJavaSurface> ui_surface_; |
| 148 std::unique_ptr<gl::ScopedJavaSurface> content_surface_; | 155 std::unique_ptr<gl::ScopedJavaSurface> content_surface_; |
| 156 std::unique_ptr<gl::ScopedJavaSurface> webvr_surface_; |
| 157 int webvr_surface_handle_; |
| 149 | 158 |
| 150 std::unique_ptr<gvr::GvrApi> gvr_api_; | 159 std::unique_ptr<gvr::GvrApi> gvr_api_; |
| 151 std::unique_ptr<gvr::BufferViewportList> buffer_viewport_list_; | 160 std::unique_ptr<gvr::BufferViewportList> buffer_viewport_list_; |
| 152 std::unique_ptr<gvr::BufferViewport> buffer_viewport_; | 161 std::unique_ptr<gvr::BufferViewport> buffer_viewport_; |
| 153 std::unique_ptr<gvr::BufferViewport> headlocked_left_viewport_; | 162 std::unique_ptr<gvr::BufferViewport> headlocked_left_viewport_; |
| 154 std::unique_ptr<gvr::BufferViewport> headlocked_right_viewport_; | 163 std::unique_ptr<gvr::BufferViewport> headlocked_right_viewport_; |
| 155 std::unique_ptr<gvr::BufferViewport> webvr_left_viewport_; | 164 std::unique_ptr<gvr::BufferViewport> webvr_left_viewport_; |
| 156 std::unique_ptr<gvr::BufferViewport> webvr_right_viewport_; | 165 std::unique_ptr<gvr::BufferViewport> webvr_right_viewport_; |
| 157 std::unique_ptr<gvr::SwapChain> swap_chain_; | 166 std::unique_ptr<gvr::SwapChain> swap_chain_; |
| 158 using BoundsPair = std::pair<gvr::Rectf, gvr::Rectf>; | 167 using BoundsPair = std::pair<gvr::Rectf, gvr::Rectf>; |
| 159 std::queue<std::pair<uint8_t, BoundsPair>> pending_bounds_; | 168 std::queue<std::pair<uint8_t, BoundsPair>> pending_bounds_; |
| 169 int requested_frames_ = 0; |
| 170 int premature_received_frames_ = 0; |
| 171 std::queue<uint16_t> pending_frames_; |
| 160 | 172 |
| 161 // Current sizes for the render buffers. | 173 // Current sizes for the render buffers. |
| 162 gvr::Sizei render_size_primary_; | 174 gvr::Sizei render_size_primary_; |
| 163 gvr::Sizei render_size_headlocked_; | 175 gvr::Sizei render_size_headlocked_; |
| 164 | 176 |
| 165 std::unique_ptr<VrShellRenderer> vr_shell_renderer_; | 177 std::unique_ptr<VrShellRenderer> vr_shell_renderer_; |
| 166 | 178 |
| 167 bool touch_pending_ = false; | 179 bool touch_pending_ = false; |
| 168 gvr::Quatf controller_quat_; | 180 gvr::Quatf controller_quat_; |
| 169 | 181 |
| 170 gvr::Vec3f target_point_; | 182 gvr::Vec3f target_point_; |
| 171 const ContentRectangle* target_element_ = nullptr; | 183 const ContentRectangle* target_element_ = nullptr; |
| 172 InputTarget current_input_target_ = InputTarget::NONE; | 184 InputTarget current_input_target_ = InputTarget::NONE; |
| 173 InputTarget current_scroll_target = InputTarget::NONE; | 185 InputTarget current_scroll_target = InputTarget::NONE; |
| 174 int ui_tex_css_width_ = 0; | 186 int ui_tex_css_width_ = 0; |
| 175 int ui_tex_css_height_ = 0; | 187 int ui_tex_css_height_ = 0; |
| 176 int content_tex_css_width_ = 0; | 188 int content_tex_css_width_ = 0; |
| 177 int content_tex_css_height_ = 0; | 189 int content_tex_css_height_ = 0; |
| 178 gvr::Sizei content_tex_physical_size_ = {0, 0}; | 190 gvr::Sizei content_tex_physical_size_ = {0, 0}; |
| 179 gvr::Sizei ui_tex_physical_size_ = {0, 0}; | 191 gvr::Sizei ui_tex_physical_size_ = {0, 0}; |
| 180 | 192 |
| 181 std::vector<gvr::Mat4f> webvr_head_pose_; | 193 std::vector<gvr::Mat4f> webvr_head_pose_; |
| 182 int webvr_texture_id_ = 0; | |
| 183 bool web_vr_mode_; | 194 bool web_vr_mode_; |
| 184 bool ready_to_draw_ = false; | 195 bool ready_to_draw_ = false; |
| 185 bool surfaceless_rendering_; | 196 bool surfaceless_rendering_; |
| 186 | 197 |
| 187 std::unique_ptr<VrController> controller_; | 198 std::unique_ptr<VrController> controller_; |
| 188 | 199 |
| 189 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 200 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 190 base::CancelableClosure vsync_task_; | 201 base::CancelableClosure vsync_task_; |
| 191 base::TimeTicks vsync_timebase_; | 202 base::TimeTicks vsync_timebase_; |
| 192 base::TimeDelta vsync_interval_; | 203 base::TimeDelta vsync_interval_; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 206 uint16_t last_frame_index_ = -1; | 217 uint16_t last_frame_index_ = -1; |
| 207 | 218 |
| 208 base::WeakPtrFactory<VrShellGl> weak_ptr_factory_; | 219 base::WeakPtrFactory<VrShellGl> weak_ptr_factory_; |
| 209 | 220 |
| 210 DISALLOW_COPY_AND_ASSIGN(VrShellGl); | 221 DISALLOW_COPY_AND_ASSIGN(VrShellGl); |
| 211 }; | 222 }; |
| 212 | 223 |
| 213 } // namespace vr_shell | 224 } // namespace vr_shell |
| 214 | 225 |
| 215 #endif // CHROME_BROWSER_ANDROID_VR_SHELL_VR_SHELL_GL_H_ | 226 #endif // CHROME_BROWSER_ANDROID_VR_SHELL_VR_SHELL_GL_H_ |
| OLD | NEW |