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