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