| 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 | 10 |
| 10 #include "base/cancelable_callback.h" | 11 #include "base/cancelable_callback.h" |
| 11 #include "base/macros.h" | 12 #include "base/macros.h" |
| 12 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 14 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
| 15 #include "device/vr/android/gvr/gvr_delegate.h" | 16 #include "device/vr/android/gvr/gvr_delegate.h" |
| 16 #include "device/vr/vr_service.mojom.h" | 17 #include "device/vr/vr_service.mojom.h" |
| 17 #include "mojo/public/cpp/bindings/binding.h" | 18 #include "mojo/public/cpp/bindings/binding.h" |
| 18 #include "third_party/gvr-android-sdk/src/libraries/headers/vr/gvr/capi/include/
gvr.h" | 19 #include "third_party/gvr-android-sdk/src/libraries/headers/vr/gvr/capi/include/
gvr.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 void OnPause(); | 71 void OnPause(); |
| 71 void OnResume(); | 72 void OnResume(); |
| 72 | 73 |
| 73 void SetWebVrMode(bool enabled); | 74 void SetWebVrMode(bool enabled); |
| 74 void ContentBoundsChanged(int width, int height); | 75 void ContentBoundsChanged(int width, int height); |
| 75 void ContentPhysicalBoundsChanged(int width, int height); | 76 void ContentPhysicalBoundsChanged(int width, int height); |
| 76 void UIBoundsChanged(int width, int height); | 77 void UIBoundsChanged(int width, int height); |
| 77 void UIPhysicalBoundsChanged(int width, int height); | 78 void UIPhysicalBoundsChanged(int width, int height); |
| 78 base::WeakPtr<VrShellGl> GetWeakPtr(); | 79 base::WeakPtr<VrShellGl> GetWeakPtr(); |
| 79 | 80 |
| 80 void UpdateWebVRTextureBounds(const gvr::Rectf& left_bounds, | 81 void UpdateWebVRTextureBounds(int16_t frame_index, |
| 82 const gvr::Rectf& left_bounds, |
| 81 const gvr::Rectf& right_bounds); | 83 const gvr::Rectf& right_bounds); |
| 82 gvr::GvrApi* gvr_api(); | 84 gvr::GvrApi* gvr_api(); |
| 83 void SetGvrPoseForWebVr(const gvr::Mat4f& pose, uint32_t pose_num); | 85 void SetGvrPoseForWebVr(const gvr::Mat4f& pose, uint32_t pose_num); |
| 84 gvr::Sizei GetWebVRCompositorSurfaceSize(); | 86 gvr::Sizei GetWebVRCompositorSurfaceSize(); |
| 85 | 87 |
| 86 void UpdateScene(std::unique_ptr<base::ListValue> commands); | 88 void UpdateScene(std::unique_ptr<base::ListValue> commands); |
| 87 | 89 |
| 88 void UpdateVSyncInterval(long timebase_nanos, double interval_seconds); | 90 void UpdateVSyncInterval(long timebase_nanos, double interval_seconds); |
| 89 | 91 |
| 90 void OnRequest(device::mojom::VRVSyncProviderRequest request); | 92 void OnRequest(device::mojom::VRVSyncProviderRequest request); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 104 bool WebVrPoseByteIsValid(int pose_index_byte); | 106 bool WebVrPoseByteIsValid(int pose_index_byte); |
| 105 | 107 |
| 106 void UpdateController(const gvr::Vec3f& forward_vector); | 108 void UpdateController(const gvr::Vec3f& forward_vector); |
| 107 void SendEventsToTarget(InputTarget input_target, int pixel_x, | 109 void SendEventsToTarget(InputTarget input_target, int pixel_x, |
| 108 int pixel_y); | 110 int pixel_y); |
| 109 void SendGesture(InputTarget input_target, | 111 void SendGesture(InputTarget input_target, |
| 110 std::unique_ptr<blink::WebInputEvent> event); | 112 std::unique_ptr<blink::WebInputEvent> event); |
| 111 | 113 |
| 112 void OnUIFrameAvailable(); | 114 void OnUIFrameAvailable(); |
| 113 void OnContentFrameAvailable(); | 115 void OnContentFrameAvailable(); |
| 114 bool GetPixelEncodedPoseIndexByte(int* pose_index); | 116 bool GetPixelEncodedFrameIndex(uint8_t* frame_index); |
| 115 | 117 |
| 116 void OnVSync(); | 118 void OnVSync(); |
| 117 | 119 |
| 118 // VRVSyncProvider | 120 // VRVSyncProvider |
| 119 void GetVSync(const GetVSyncCallback& callback) override; | 121 void GetVSync(const GetVSyncCallback& callback) override; |
| 120 | 122 |
| 121 void ForceExitVr(); | 123 void ForceExitVr(); |
| 122 | 124 |
| 123 device::mojom::VRPosePtr GetPose(); | 125 void SendVSync(double time, GetVSyncCallback callback); |
| 124 | 126 |
| 125 // samplerExternalOES texture data for UI content image. | 127 // samplerExternalOES texture data for UI content image. |
| 126 int ui_texture_id_ = 0; | 128 int ui_texture_id_ = 0; |
| 127 // samplerExternalOES texture data for main content image. | 129 // samplerExternalOES texture data for main content image. |
| 128 int content_texture_id_ = 0; | 130 int content_texture_id_ = 0; |
| 129 | 131 |
| 130 std::unique_ptr<UiScene> scene_; | 132 std::unique_ptr<UiScene> scene_; |
| 131 | 133 |
| 132 scoped_refptr<gl::GLSurface> surface_; | 134 scoped_refptr<gl::GLSurface> surface_; |
| 133 scoped_refptr<gl::GLContext> context_; | 135 scoped_refptr<gl::GLContext> context_; |
| 134 scoped_refptr<gl::SurfaceTexture> ui_surface_texture_; | 136 scoped_refptr<gl::SurfaceTexture> ui_surface_texture_; |
| 135 scoped_refptr<gl::SurfaceTexture> content_surface_texture_; | 137 scoped_refptr<gl::SurfaceTexture> content_surface_texture_; |
| 136 | 138 |
| 137 std::unique_ptr<gl::ScopedJavaSurface> ui_surface_; | 139 std::unique_ptr<gl::ScopedJavaSurface> ui_surface_; |
| 138 std::unique_ptr<gl::ScopedJavaSurface> content_surface_; | 140 std::unique_ptr<gl::ScopedJavaSurface> content_surface_; |
| 139 | 141 |
| 140 std::unique_ptr<gvr::GvrApi> gvr_api_; | 142 std::unique_ptr<gvr::GvrApi> gvr_api_; |
| 141 std::unique_ptr<gvr::BufferViewportList> buffer_viewport_list_; | 143 std::unique_ptr<gvr::BufferViewportList> buffer_viewport_list_; |
| 142 std::unique_ptr<gvr::BufferViewport> buffer_viewport_; | 144 std::unique_ptr<gvr::BufferViewport> buffer_viewport_; |
| 143 std::unique_ptr<gvr::BufferViewport> headlocked_left_viewport_; | 145 std::unique_ptr<gvr::BufferViewport> headlocked_left_viewport_; |
| 144 std::unique_ptr<gvr::BufferViewport> headlocked_right_viewport_; | 146 std::unique_ptr<gvr::BufferViewport> headlocked_right_viewport_; |
| 145 std::unique_ptr<gvr::BufferViewport> webvr_left_viewport_; | 147 std::unique_ptr<gvr::BufferViewport> webvr_left_viewport_; |
| 146 std::unique_ptr<gvr::BufferViewport> webvr_right_viewport_; | 148 std::unique_ptr<gvr::BufferViewport> webvr_right_viewport_; |
| 147 std::unique_ptr<gvr::SwapChain> swap_chain_; | 149 std::unique_ptr<gvr::SwapChain> swap_chain_; |
| 150 typedef std::pair<gvr::Rectf, gvr::Rectf> BoundsPair; |
| 151 std::queue<std::pair<uint8_t, BoundsPair>> pending_bounds_; |
| 148 | 152 |
| 149 // Current sizes for the render buffers. | 153 // Current sizes for the render buffers. |
| 150 gvr::Sizei render_size_primary_; | 154 gvr::Sizei render_size_primary_; |
| 151 gvr::Sizei render_size_headlocked_; | 155 gvr::Sizei render_size_headlocked_; |
| 152 | 156 |
| 153 std::unique_ptr<VrShellRenderer> vr_shell_renderer_; | 157 std::unique_ptr<VrShellRenderer> vr_shell_renderer_; |
| 154 | 158 |
| 155 bool touch_pending_ = false; | 159 bool touch_pending_ = false; |
| 156 gvr::Quatf controller_quat_; | 160 gvr::Quatf controller_quat_; |
| 157 | 161 |
| 158 gvr::Vec3f target_point_; | 162 gvr::Vec3f target_point_; |
| 159 const ContentRectangle* target_element_ = nullptr; | 163 const ContentRectangle* target_element_ = nullptr; |
| 160 InputTarget current_input_target_ = InputTarget::NONE; | 164 InputTarget current_input_target_ = InputTarget::NONE; |
| 161 int ui_tex_css_width_ = 0; | 165 int ui_tex_css_width_ = 0; |
| 162 int ui_tex_css_height_ = 0; | 166 int ui_tex_css_height_ = 0; |
| 163 int content_tex_css_width_ = 0; | 167 int content_tex_css_width_ = 0; |
| 164 int content_tex_css_height_ = 0; | 168 int content_tex_css_height_ = 0; |
| 165 gvr::Sizei content_tex_physical_size_ = {0, 0}; | 169 gvr::Sizei content_tex_physical_size_ = {0, 0}; |
| 166 gvr::Sizei ui_tex_physical_size_ = {0, 0}; | 170 gvr::Sizei ui_tex_physical_size_ = {0, 0}; |
| 167 | 171 |
| 168 // The pose ring buffer size must be a power of two to avoid glitches when | 172 // Buffer size large enough to handle the current backlog of poses which is |
| 169 // the pose index wraps around. It should be large enough to handle the | 173 // 2-3 frames. |
| 170 // current backlog of poses which is 2-3 frames. | |
| 171 static constexpr int kPoseRingBufferSize = 8; | 174 static constexpr int kPoseRingBufferSize = 8; |
| 172 std::vector<gvr::Mat4f> webvr_head_pose_; | 175 std::vector<gvr::Mat4f> webvr_head_pose_; |
| 173 int webvr_texture_id_ = 0; | 176 int webvr_texture_id_ = 0; |
| 174 bool web_vr_mode_; | 177 bool web_vr_mode_; |
| 175 bool ready_to_draw_ = false; | 178 bool ready_to_draw_ = false; |
| 176 bool surfaceless_rendering_; | 179 bool surfaceless_rendering_; |
| 177 | 180 |
| 178 std::unique_ptr<VrController> controller_; | 181 std::unique_ptr<VrController> controller_; |
| 179 | 182 |
| 180 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 183 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 181 base::CancelableClosure vsync_task_; | 184 base::CancelableClosure vsync_task_; |
| 182 base::TimeTicks vsync_timebase_; | 185 base::TimeTicks vsync_timebase_; |
| 183 base::TimeDelta vsync_interval_; | 186 base::TimeDelta vsync_interval_; |
| 184 | 187 |
| 185 double pending_time_ = 0; | 188 double pending_time_ = 0; |
| 186 bool pending_vsync_ = false; | 189 bool pending_vsync_ = false; |
| 187 GetVSyncCallback callback_; | 190 GetVSyncCallback callback_; |
| 188 bool received_frame_ = false; | 191 bool received_frame_ = false; |
| 189 mojo::Binding<device::mojom::VRVSyncProvider> binding_; | 192 mojo::Binding<device::mojom::VRVSyncProvider> binding_; |
| 190 | 193 |
| 191 base::WeakPtr<VrShell> weak_vr_shell_; | 194 base::WeakPtr<VrShell> weak_vr_shell_; |
| 192 base::WeakPtr<VrInputManager> content_input_manager_; | 195 base::WeakPtr<VrInputManager> content_input_manager_; |
| 193 base::WeakPtr<VrInputManager> ui_input_manager_; | 196 base::WeakPtr<VrInputManager> ui_input_manager_; |
| 194 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; | 197 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; |
| 195 | 198 |
| 196 uint32_t pose_index_ = 1; | 199 uint8_t frame_index_ = 0; |
| 197 int last_pose_ = 0; | 200 uint8_t last_frame_index_ = 0; |
| 198 | 201 |
| 199 base::WeakPtrFactory<VrShellGl> weak_ptr_factory_; | 202 base::WeakPtrFactory<VrShellGl> weak_ptr_factory_; |
| 200 | 203 |
| 201 DISALLOW_COPY_AND_ASSIGN(VrShellGl); | 204 DISALLOW_COPY_AND_ASSIGN(VrShellGl); |
| 202 }; | 205 }; |
| 203 | 206 |
| 204 } // namespace vr_shell | 207 } // namespace vr_shell |
| 205 | 208 |
| 206 #endif // CHROME_BROWSER_ANDROID_VR_SHELL_VR_SHELL_GL_H_ | 209 #endif // CHROME_BROWSER_ANDROID_VR_SHELL_VR_SHELL_GL_H_ |
| OLD | NEW |