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 <deque> |
| 9 #include <iomanip> |
| 10 #include <list> |
8 #include <memory> | 11 #include <memory> |
9 | 12 |
10 #include "base/cancelable_callback.h" | 13 #include "base/cancelable_callback.h" |
11 #include "base/macros.h" | 14 #include "base/macros.h" |
12 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
13 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
14 #include "base/single_thread_task_runner.h" | 17 #include "base/single_thread_task_runner.h" |
15 #include "device/vr/android/gvr/gvr_delegate.h" | 18 #include "device/vr/android/gvr/gvr_delegate.h" |
| 19 #include "gpu/ipc/common/surface_handle.h" |
16 #include "third_party/gvr-android-sdk/src/libraries/headers/vr/gvr/capi/include/
gvr.h" | 20 #include "third_party/gvr-android-sdk/src/libraries/headers/vr/gvr/capi/include/
gvr.h" |
17 #include "third_party/gvr-android-sdk/src/libraries/headers/vr/gvr/capi/include/
gvr_types.h" | 21 #include "third_party/gvr-android-sdk/src/libraries/headers/vr/gvr/capi/include/
gvr_types.h" |
18 #include "ui/gfx/native_widget_types.h" | 22 #include "ui/gfx/native_widget_types.h" |
19 | 23 |
20 namespace base { | 24 namespace base { |
21 class ListValue; | 25 class ListValue; |
22 } | 26 } |
23 | 27 |
24 namespace blink { | 28 namespace blink { |
25 class WebInputEvent; | 29 class WebInputEvent; |
(...skipping 29 matching lines...) Expand all Loading... |
55 const base::WeakPtr<VrShell>& weak_vr_shell, | 59 const base::WeakPtr<VrShell>& weak_vr_shell, |
56 const base::WeakPtr<VrInputManager>& content_input_manager, | 60 const base::WeakPtr<VrInputManager>& content_input_manager, |
57 const base::WeakPtr<VrInputManager>& ui_input_manager, | 61 const base::WeakPtr<VrInputManager>& ui_input_manager, |
58 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner, | 62 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner, |
59 gvr_context* gvr_api, | 63 gvr_context* gvr_api, |
60 bool initially_web_vr); | 64 bool initially_web_vr); |
61 ~VrShellGl(); | 65 ~VrShellGl(); |
62 | 66 |
63 bool Initialize(); | 67 bool Initialize(); |
64 | 68 |
65 void DrawFrame(); | 69 void DrawFrame(uint32_t pose_index); |
66 | 70 |
67 void OnTriggerEvent(); | 71 void OnTriggerEvent(); |
68 void OnPause(); | 72 void OnPause(); |
69 void OnResume(); | 73 void OnResume(); |
70 | 74 |
71 void SetWebVrMode(bool enabled); | 75 void SetWebVrMode(bool enabled); |
72 void ContentBoundsChanged(int width, int height); | 76 void ContentBoundsChanged(int width, int height); |
73 void ContentPhysicalBoundsChanged(int width, int height); | 77 void ContentPhysicalBoundsChanged(int width, int height); |
74 void UIBoundsChanged(int width, int height); | 78 void UIBoundsChanged(int width, int height); |
75 void UIPhysicalBoundsChanged(int width, int height); | 79 void UIPhysicalBoundsChanged(int width, int height); |
76 base::WeakPtr<VrShellGl> GetWeakPtr(); | 80 base::WeakPtr<VrShellGl> GetWeakPtr(); |
77 | 81 |
78 void UpdateWebVRTextureBounds(const gvr::Rectf& left_bounds, | 82 void UpdateWebVRTextureBounds(uint32_t for_pose_index, |
| 83 const gvr::Rectf& left_bounds, |
79 const gvr::Rectf& right_bounds); | 84 const gvr::Rectf& right_bounds); |
| 85 void SubmitWebVRFrame(int32_t surface_handle, const device::mojom::VRPosePtr&
pose); |
80 gvr::GvrApi* gvr_api(); | 86 gvr::GvrApi* gvr_api(); |
81 void SetGvrPoseForWebVr(const gvr::Mat4f& pose, uint32_t pose_num); | 87 void SetWebVRGvrPose(const gvr::Mat4f& pose, uint32_t pose_index, |
82 gvr::Sizei GetWebVRCompositorSurfaceSize(); | 88 int64_t pose_time_nanos); |
| 89 void GetWebVRSurfaceHandle(int width, int height, const device::mojom::VRDispl
ay::GetSurfaceHandleCallback& callback); |
83 | 90 |
84 void UpdateScene(std::unique_ptr<base::ListValue> commands); | 91 void UpdateScene(std::unique_ptr<base::ListValue> commands); |
85 | 92 |
86 private: | 93 private: |
87 bool InitializeGl(); | 94 bool InitializeGl(); |
88 void GvrInit(gvr_context* gvr_api); | 95 void GvrInit(gvr_context* gvr_api); |
89 void InitializeRenderer(); | 96 void InitializeRenderer(); |
90 void DrawVrShell(const gvr::Mat4f& head_pose, gvr::Frame &frame); | 97 void DrawVrShell(const gvr::Mat4f& head_pose, gvr::Frame &frame); |
91 void DrawUiView(const gvr::Mat4f* head_pose, | 98 void DrawUiView(const gvr::Mat4f* head_pose, |
92 const std::vector<const ContentRectangle*>& elements, | 99 const std::vector<const ContentRectangle*>& elements, |
93 const gvr::Sizei& render_size, int viewport_offset); | 100 const gvr::Sizei& render_size, int viewport_offset); |
94 void DrawElements(const gvr::Mat4f& render_matrix, | 101 void DrawElements(const gvr::Mat4f& render_matrix, |
95 const std::vector<const ContentRectangle*>& elements); | 102 const std::vector<const ContentRectangle*>& elements); |
96 void DrawCursor(const gvr::Mat4f& render_matrix); | 103 void DrawCursor(const gvr::Mat4f& render_matrix); |
97 void DrawWebVr(); | 104 void DrawWebVr(uint32_t pose_index); |
98 bool WebVrPoseByteIsValid(int pose_index_byte); | 105 bool WebVrPoseByteIsValid(int pose_index_byte); |
99 | 106 |
100 void UpdateController(const gvr::Vec3f& forward_vector); | 107 void UpdateController(const gvr::Vec3f& forward_vector); |
101 void SendEventsToTarget(InputTarget input_target, int pixel_x, | 108 void SendEventsToTarget(InputTarget input_target, int pixel_x, |
102 int pixel_y); | 109 int pixel_y); |
103 void SendGesture(InputTarget input_target, | 110 void SendGesture(InputTarget input_target, |
104 std::unique_ptr<blink::WebInputEvent> event); | 111 std::unique_ptr<blink::WebInputEvent> event); |
105 | 112 |
106 void OnUIFrameAvailable(); | 113 void OnUIFrameAvailable(); |
107 void OnContentFrameAvailable(); | 114 void OnContentFrameAvailable(); |
| 115 void OnWebVrFrameAvailable(); |
| 116 void SetWebVrSurface(); |
108 | 117 |
109 void UpdateVSyncParameters(const base::TimeTicks timebase, | 118 void UpdateVSyncParameters(const base::TimeTicks timebase, |
110 const base::TimeDelta interval); | 119 const base::TimeDelta interval); |
111 void ScheduleNextDrawFrame(); | 120 void ScheduleNextDrawFrame(); |
112 | 121 |
113 void ForceExitVr(); | 122 void ForceExitVr(); |
114 | 123 |
115 // samplerExternalOES texture data for UI content image. | 124 // samplerExternalOES texture data for UI content image. |
116 int ui_texture_id_ = 0; | 125 int ui_texture_id_ = 0; |
117 // samplerExternalOES texture data for main content image. | 126 // samplerExternalOES texture data for main content image. |
118 int content_texture_id_ = 0; | 127 int content_texture_id_ = 0; |
| 128 // samplerExternalOES texture data for WebVR image. |
| 129 int webvr_texture_id_ = 0; |
119 | 130 |
120 std::unique_ptr<UiScene> scene_; | 131 std::unique_ptr<UiScene> scene_; |
121 | 132 |
122 scoped_refptr<gl::GLSurface> surface_; | 133 scoped_refptr<gl::GLSurface> surface_; |
123 scoped_refptr<gl::GLContext> context_; | 134 scoped_refptr<gl::GLContext> context_; |
124 scoped_refptr<gl::SurfaceTexture> ui_surface_texture_; | 135 scoped_refptr<gl::SurfaceTexture> ui_surface_texture_; |
125 scoped_refptr<gl::SurfaceTexture> content_surface_texture_; | 136 scoped_refptr<gl::SurfaceTexture> content_surface_texture_; |
| 137 scoped_refptr<gl::SurfaceTexture> webvr_surface_texture_; |
126 | 138 |
127 std::unique_ptr<gl::ScopedJavaSurface> ui_surface_; | 139 std::unique_ptr<gl::ScopedJavaSurface> ui_surface_; |
128 std::unique_ptr<gl::ScopedJavaSurface> content_surface_; | 140 std::unique_ptr<gl::ScopedJavaSurface> content_surface_; |
| 141 std::unique_ptr<gl::ScopedJavaSurface> webvr_surface_; |
129 | 142 |
130 std::unique_ptr<gvr::GvrApi> gvr_api_; | 143 std::unique_ptr<gvr::GvrApi> gvr_api_; |
131 std::unique_ptr<gvr::BufferViewportList> buffer_viewport_list_; | 144 std::unique_ptr<gvr::BufferViewportList> buffer_viewport_list_; |
132 std::unique_ptr<gvr::BufferViewport> buffer_viewport_; | 145 std::unique_ptr<gvr::BufferViewport> buffer_viewport_; |
133 std::unique_ptr<gvr::BufferViewport> headlocked_left_viewport_; | 146 std::unique_ptr<gvr::BufferViewport> headlocked_left_viewport_; |
134 std::unique_ptr<gvr::BufferViewport> headlocked_right_viewport_; | 147 std::unique_ptr<gvr::BufferViewport> headlocked_right_viewport_; |
135 std::unique_ptr<gvr::BufferViewport> webvr_left_viewport_; | 148 std::unique_ptr<gvr::BufferViewport> webvr_left_viewport_; |
136 std::unique_ptr<gvr::BufferViewport> webvr_right_viewport_; | 149 std::unique_ptr<gvr::BufferViewport> webvr_right_viewport_; |
137 std::unique_ptr<gvr::SwapChain> swap_chain_; | 150 std::unique_ptr<gvr::SwapChain> swap_chain_; |
138 | 151 |
139 // Current sizes for the render buffers. | 152 // Current sizes for the render buffers. |
140 gvr::Sizei render_size_primary_; | 153 gvr::Sizei render_size_primary_; |
141 gvr::Sizei render_size_headlocked_; | 154 gvr::Sizei render_size_headlocked_; |
142 | 155 |
| 156 // Expected sizes for the primary render buffer by mode. |
| 157 gvr::Sizei render_size_primary_vrshell_; |
| 158 gvr::Sizei render_size_primary_webvr_; |
| 159 |
143 std::unique_ptr<VrShellRenderer> vr_shell_renderer_; | 160 std::unique_ptr<VrShellRenderer> vr_shell_renderer_; |
144 | 161 |
145 bool touch_pending_ = false; | 162 bool touch_pending_ = false; |
146 gvr::Quatf controller_quat_; | 163 gvr::Quatf controller_quat_; |
147 | 164 |
148 gvr::Vec3f target_point_; | 165 gvr::Vec3f target_point_; |
149 const ContentRectangle* target_element_ = nullptr; | 166 const ContentRectangle* target_element_ = nullptr; |
150 InputTarget current_input_target_ = InputTarget::NONE; | 167 InputTarget current_input_target_ = InputTarget::NONE; |
151 int ui_tex_css_width_ = 0; | 168 int ui_tex_css_width_ = 0; |
152 int ui_tex_css_height_ = 0; | 169 int ui_tex_css_height_ = 0; |
153 int content_tex_css_width_ = 0; | 170 int content_tex_css_width_ = 0; |
154 int content_tex_css_height_ = 0; | 171 int content_tex_css_height_ = 0; |
155 gvr::Sizei content_tex_physical_size_ = {0, 0}; | 172 gvr::Sizei content_tex_physical_size_ = {0, 0}; |
156 gvr::Sizei ui_tex_physical_size_ = {0, 0}; | 173 gvr::Sizei ui_tex_physical_size_ = {0, 0}; |
157 | 174 |
158 // The pose ring buffer size must be a power of two to avoid glitches when | 175 // The pose ring buffer size must be a power of two to avoid glitches when |
159 // the pose index wraps around. It should be large enough to handle the | 176 // the pose index wraps around. It should be large enough to handle the |
160 // current backlog of poses which is 2-3 frames. | 177 // current backlog of poses which is 2-3 frames. |
161 static constexpr int kPoseRingBufferSize = 8; | 178 static constexpr int kPoseRingBufferSize = 8; |
162 std::vector<gvr::Mat4f> webvr_head_pose_; | 179 std::vector<gvr::Mat4f> webvr_head_pose_; |
163 std::vector<bool> webvr_head_pose_valid_; | 180 std::vector<double> webvr_time_frame_start_; |
164 int webvr_texture_id_ = 0; | 181 std::vector<double> webvr_time_service_start_; |
| 182 std::vector<double> webvr_time_get_pose_; |
| 183 std::vector<double> webvr_time_got_pose_; |
| 184 std::vector<double> webvr_time_submit_; |
| 185 std::vector<double> webvr_time_surfaced_; |
| 186 std::vector<double> webvr_time_acquired_; |
165 bool web_vr_mode_; | 187 bool web_vr_mode_; |
| 188 gpu::SurfaceHandle webvr_surface_handle_ = 0; |
| 189 uint32_t webvr_last_submitted_ = 0; |
| 190 std::list<uint32_t> webvr_texture_bounds_need_update_at_; |
| 191 std::list<gvr::Rectf> webvr_texture_bounds_left_; |
| 192 std::list<gvr::Rectf> webvr_texture_bounds_right_; |
| 193 std::deque<uint32_t> webvr_pending_poses_; |
| 194 int webvr_already_available_frames_ = 0; |
166 | 195 |
167 std::unique_ptr<VrController> controller_; | 196 std::unique_ptr<VrController> controller_; |
168 | 197 |
169 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 198 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
170 base::CancelableClosure draw_task_; | 199 base::CancelableClosure draw_task_; |
171 base::TimeTicks vsync_timebase_; | 200 base::TimeTicks vsync_timebase_; |
172 base::TimeDelta vsync_interval_; | 201 base::TimeDelta vsync_interval_; |
173 | 202 |
174 base::WeakPtr<VrShell> weak_vr_shell_; | 203 base::WeakPtr<VrShell> weak_vr_shell_; |
175 base::WeakPtr<VrInputManager> content_input_manager_; | 204 base::WeakPtr<VrInputManager> content_input_manager_; |
176 base::WeakPtr<VrInputManager> ui_input_manager_; | 205 base::WeakPtr<VrInputManager> ui_input_manager_; |
177 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; | 206 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; |
178 | 207 |
179 base::WeakPtrFactory<VrShellGl> weak_ptr_factory_; | 208 base::WeakPtrFactory<VrShellGl> weak_ptr_factory_; |
180 | 209 |
181 DISALLOW_COPY_AND_ASSIGN(VrShellGl); | 210 DISALLOW_COPY_AND_ASSIGN(VrShellGl); |
182 }; | 211 }; |
183 | 212 |
184 } // namespace vr_shell | 213 } // namespace vr_shell |
185 | 214 |
186 #endif // CHROME_BROWSER_ANDROID_VR_SHELL_VR_SHELL_GL_H_ | 215 #endif // CHROME_BROWSER_ANDROID_VR_SHELL_VR_SHELL_GL_H_ |
OLD | NEW |