| 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 | 9 |
| 10 #include "base/cancelable_callback.h" | 10 #include "base/cancelable_callback.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
| 15 #include "device/vr/android/gvr/gvr_delegate.h" | 15 #include "device/vr/android/gvr/gvr_delegate.h" |
| 16 #include "device/vr/vr_service.mojom.h" |
| 17 #include "mojo/public/cpp/bindings/binding.h" |
| 16 #include "third_party/gvr-android-sdk/src/libraries/headers/vr/gvr/capi/include/
gvr.h" | 18 #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" | 19 #include "third_party/gvr-android-sdk/src/libraries/headers/vr/gvr/capi/include/
gvr_types.h" |
| 18 #include "ui/gfx/native_widget_types.h" | 20 #include "ui/gfx/native_widget_types.h" |
| 19 | 21 |
| 20 namespace base { | 22 namespace base { |
| 21 class ListValue; | 23 class ListValue; |
| 22 } | 24 } |
| 23 | 25 |
| 24 namespace blink { | 26 namespace blink { |
| 25 class WebInputEvent; | 27 class WebInputEvent; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 36 | 38 |
| 37 class UiScene; | 39 class UiScene; |
| 38 class VrController; | 40 class VrController; |
| 39 class VrInputManager; | 41 class VrInputManager; |
| 40 class VrShell; | 42 class VrShell; |
| 41 class VrShellRenderer; | 43 class VrShellRenderer; |
| 42 struct ContentRectangle; | 44 struct ContentRectangle; |
| 43 | 45 |
| 44 // This class manages all GLThread owned objects and GL rendering for VrShell. | 46 // This class manages all GLThread owned objects and GL rendering for VrShell. |
| 45 // It is not threadsafe and must only be used on the GL thread. | 47 // It is not threadsafe and must only be used on the GL thread. |
| 46 class VrShellGl { | 48 class VrShellGl : public device::mojom::VRVSyncProvider { |
| 47 public: | 49 public: |
| 48 enum class InputTarget { | 50 enum class InputTarget { |
| 49 NONE = 0, | 51 NONE = 0, |
| 50 CONTENT, | 52 CONTENT, |
| 51 UI | 53 UI |
| 52 }; | 54 }; |
| 53 | 55 |
| 54 VrShellGl( | 56 VrShellGl( |
| 55 const base::WeakPtr<VrShell>& weak_vr_shell, | 57 const base::WeakPtr<VrShell>& weak_vr_shell, |
| 56 const base::WeakPtr<VrInputManager>& content_input_manager, | 58 const base::WeakPtr<VrInputManager>& content_input_manager, |
| 57 const base::WeakPtr<VrInputManager>& ui_input_manager, | 59 const base::WeakPtr<VrInputManager>& ui_input_manager, |
| 58 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner, | 60 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner, |
| 59 gvr_context* gvr_api, | 61 gvr_context* gvr_api, |
| 60 bool initially_web_vr, | 62 bool initially_web_vr, |
| 61 bool reprojected_rendering); | 63 bool reprojected_rendering); |
| 62 ~VrShellGl(); | 64 ~VrShellGl(); |
| 63 | 65 |
| 64 void Initialize(); | 66 void Initialize(); |
| 65 void InitializeGl(gfx::AcceleratedWidget window); | 67 void InitializeGl(gfx::AcceleratedWidget window); |
| 66 | 68 |
| 67 void DrawFrame(); | |
| 68 | |
| 69 void OnTriggerEvent(); | 69 void OnTriggerEvent(); |
| 70 void OnPause(); | 70 void OnPause(); |
| 71 void OnResume(); | 71 void OnResume(); |
| 72 | 72 |
| 73 void SetWebVrMode(bool enabled); | 73 void SetWebVrMode(bool enabled); |
| 74 void ContentBoundsChanged(int width, int height); | 74 void ContentBoundsChanged(int width, int height); |
| 75 void ContentPhysicalBoundsChanged(int width, int height); | 75 void ContentPhysicalBoundsChanged(int width, int height); |
| 76 void UIBoundsChanged(int width, int height); | 76 void UIBoundsChanged(int width, int height); |
| 77 void UIPhysicalBoundsChanged(int width, int height); | 77 void UIPhysicalBoundsChanged(int width, int height); |
| 78 base::WeakPtr<VrShellGl> GetWeakPtr(); | 78 base::WeakPtr<VrShellGl> GetWeakPtr(); |
| 79 | 79 |
| 80 void UpdateWebVRTextureBounds(const gvr::Rectf& left_bounds, | 80 void UpdateWebVRTextureBounds(const gvr::Rectf& left_bounds, |
| 81 const gvr::Rectf& right_bounds); | 81 const gvr::Rectf& right_bounds); |
| 82 gvr::GvrApi* gvr_api(); | 82 gvr::GvrApi* gvr_api(); |
| 83 void SetGvrPoseForWebVr(const gvr::Mat4f& pose, uint32_t pose_num); | 83 void SetGvrPoseForWebVr(const gvr::Mat4f& pose, uint32_t pose_num); |
| 84 gvr::Sizei GetWebVRCompositorSurfaceSize(); | 84 gvr::Sizei GetWebVRCompositorSurfaceSize(); |
| 85 | 85 |
| 86 void UpdateScene(std::unique_ptr<base::ListValue> commands); | 86 void UpdateScene(std::unique_ptr<base::ListValue> commands); |
| 87 | 87 |
| 88 void UpdateVSyncInterval(long timebase_nanos, double interval_seconds); |
| 89 |
| 90 void OnRequest(device::mojom::VRVSyncProviderRequest request); |
| 91 |
| 88 private: | 92 private: |
| 89 void GvrInit(gvr_context* gvr_api); | 93 void GvrInit(gvr_context* gvr_api); |
| 90 void InitializeRenderer(); | 94 void InitializeRenderer(); |
| 95 void DrawFrame(); |
| 91 void DrawVrShell(const gvr::Mat4f& head_pose, gvr::Frame &frame); | 96 void DrawVrShell(const gvr::Mat4f& head_pose, gvr::Frame &frame); |
| 92 void DrawUiView(const gvr::Mat4f* head_pose, | 97 void DrawUiView(const gvr::Mat4f* head_pose, |
| 93 const std::vector<const ContentRectangle*>& elements, | 98 const std::vector<const ContentRectangle*>& elements, |
| 94 const gvr::Sizei& render_size, int viewport_offset); | 99 const gvr::Sizei& render_size, int viewport_offset); |
| 95 void DrawElements(const gvr::Mat4f& render_matrix, | 100 void DrawElements(const gvr::Mat4f& render_matrix, |
| 96 const std::vector<const ContentRectangle*>& elements); | 101 const std::vector<const ContentRectangle*>& elements); |
| 97 void DrawCursor(const gvr::Mat4f& render_matrix); | 102 void DrawCursor(const gvr::Mat4f& render_matrix); |
| 98 void DrawWebVr(); | 103 void DrawWebVr(); |
| 99 bool WebVrPoseByteIsValid(int pose_index_byte); | 104 bool WebVrPoseByteIsValid(int pose_index_byte); |
| 100 | 105 |
| 101 void UpdateController(const gvr::Vec3f& forward_vector); | 106 void UpdateController(const gvr::Vec3f& forward_vector); |
| 102 void SendEventsToTarget(InputTarget input_target, int pixel_x, | 107 void SendEventsToTarget(InputTarget input_target, int pixel_x, |
| 103 int pixel_y); | 108 int pixel_y); |
| 104 void SendGesture(InputTarget input_target, | 109 void SendGesture(InputTarget input_target, |
| 105 std::unique_ptr<blink::WebInputEvent> event); | 110 std::unique_ptr<blink::WebInputEvent> event); |
| 106 | 111 |
| 107 void OnUIFrameAvailable(); | 112 void OnUIFrameAvailable(); |
| 108 void OnContentFrameAvailable(); | 113 void OnContentFrameAvailable(); |
| 114 bool GetPixelEncodedPoseIndexByte(int* pose_index); |
| 109 | 115 |
| 110 void UpdateVSyncParameters(const base::TimeTicks timebase, | 116 void OnVSync(); |
| 111 const base::TimeDelta interval); | 117 |
| 112 void ScheduleNextDrawFrame(); | 118 // VRVSyncProvider |
| 119 void GetVSync(const GetVSyncCallback& callback) override; |
| 113 | 120 |
| 114 void ForceExitVr(); | 121 void ForceExitVr(); |
| 115 | 122 |
| 123 device::mojom::VRPosePtr GetPose(); |
| 124 |
| 116 // samplerExternalOES texture data for UI content image. | 125 // samplerExternalOES texture data for UI content image. |
| 117 int ui_texture_id_ = 0; | 126 int ui_texture_id_ = 0; |
| 118 // samplerExternalOES texture data for main content image. | 127 // samplerExternalOES texture data for main content image. |
| 119 int content_texture_id_ = 0; | 128 int content_texture_id_ = 0; |
| 120 | 129 |
| 121 std::unique_ptr<UiScene> scene_; | 130 std::unique_ptr<UiScene> scene_; |
| 122 | 131 |
| 123 scoped_refptr<gl::GLSurface> surface_; | 132 scoped_refptr<gl::GLSurface> surface_; |
| 124 scoped_refptr<gl::GLContext> context_; | 133 scoped_refptr<gl::GLContext> context_; |
| 125 scoped_refptr<gl::SurfaceTexture> ui_surface_texture_; | 134 scoped_refptr<gl::SurfaceTexture> ui_surface_texture_; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 154 int content_tex_css_width_ = 0; | 163 int content_tex_css_width_ = 0; |
| 155 int content_tex_css_height_ = 0; | 164 int content_tex_css_height_ = 0; |
| 156 gvr::Sizei content_tex_physical_size_ = {0, 0}; | 165 gvr::Sizei content_tex_physical_size_ = {0, 0}; |
| 157 gvr::Sizei ui_tex_physical_size_ = {0, 0}; | 166 gvr::Sizei ui_tex_physical_size_ = {0, 0}; |
| 158 | 167 |
| 159 // The pose ring buffer size must be a power of two to avoid glitches when | 168 // The pose ring buffer size must be a power of two to avoid glitches when |
| 160 // the pose index wraps around. It should be large enough to handle the | 169 // the pose index wraps around. It should be large enough to handle the |
| 161 // current backlog of poses which is 2-3 frames. | 170 // current backlog of poses which is 2-3 frames. |
| 162 static constexpr int kPoseRingBufferSize = 8; | 171 static constexpr int kPoseRingBufferSize = 8; |
| 163 std::vector<gvr::Mat4f> webvr_head_pose_; | 172 std::vector<gvr::Mat4f> webvr_head_pose_; |
| 164 std::vector<bool> webvr_head_pose_valid_; | |
| 165 int webvr_texture_id_ = 0; | 173 int webvr_texture_id_ = 0; |
| 166 bool web_vr_mode_; | 174 bool web_vr_mode_; |
| 167 bool ready_to_draw_ = false; | 175 bool ready_to_draw_ = false; |
| 168 bool surfaceless_rendering_; | 176 bool surfaceless_rendering_; |
| 169 | 177 |
| 170 std::unique_ptr<VrController> controller_; | 178 std::unique_ptr<VrController> controller_; |
| 171 | 179 |
| 172 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 180 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 173 base::CancelableClosure draw_task_; | 181 base::CancelableClosure vsync_task_; |
| 174 base::TimeTicks vsync_timebase_; | 182 base::TimeTicks vsync_timebase_; |
| 175 base::TimeDelta vsync_interval_; | 183 base::TimeDelta vsync_interval_; |
| 176 | 184 |
| 185 double pending_time_ = 0; |
| 186 bool pending_vsync_ = false; |
| 187 GetVSyncCallback callback_; |
| 188 bool received_frame_ = false; |
| 189 mojo::Binding<device::mojom::VRVSyncProvider> binding_; |
| 190 |
| 177 base::WeakPtr<VrShell> weak_vr_shell_; | 191 base::WeakPtr<VrShell> weak_vr_shell_; |
| 178 base::WeakPtr<VrInputManager> content_input_manager_; | 192 base::WeakPtr<VrInputManager> content_input_manager_; |
| 179 base::WeakPtr<VrInputManager> ui_input_manager_; | 193 base::WeakPtr<VrInputManager> ui_input_manager_; |
| 180 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; | 194 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; |
| 181 | 195 |
| 196 uint32_t pose_index_ = 1; |
| 197 int last_pose_ = 0; |
| 198 |
| 182 base::WeakPtrFactory<VrShellGl> weak_ptr_factory_; | 199 base::WeakPtrFactory<VrShellGl> weak_ptr_factory_; |
| 183 | 200 |
| 184 DISALLOW_COPY_AND_ASSIGN(VrShellGl); | 201 DISALLOW_COPY_AND_ASSIGN(VrShellGl); |
| 185 }; | 202 }; |
| 186 | 203 |
| 187 } // namespace vr_shell | 204 } // namespace vr_shell |
| 188 | 205 |
| 189 #endif // CHROME_BROWSER_ANDROID_VR_SHELL_VR_SHELL_GL_H_ | 206 #endif // CHROME_BROWSER_ANDROID_VR_SHELL_VR_SHELL_GL_H_ |
| OLD | NEW |