Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(569)

Side by Side Diff: chrome/browser/android/vr_shell/vr_shell_gl.h

Issue 2624633002: Remove Sync GetPose VRService call, implement VRVSyncProvider (Closed)
Patch Set: oops Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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;
26 } 28 }
27 29
28 namespace gl { 30 namespace gl {
29 class GLContext; 31 class GLContext;
30 class GLSurface; 32 class GLSurface;
31 class ScopedJavaSurface; 33 class ScopedJavaSurface;
32 class SurfaceTexture; 34 class SurfaceTexture;
33 } 35 }
34 36
35 namespace vr_shell { 37 namespace vr_shell {
36 38
37 class UiScene; 39 class UiScene;
38 class VrController; 40 class VrController;
39 class VrShell; 41 class VrShell;
42 class VrShellDelegate;
40 class VrShellRenderer; 43 class VrShellRenderer;
41 struct ContentRectangle; 44 struct ContentRectangle;
42 45
43 // 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.
44 // 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.
45 class VrShellGl { 48 class VrShellGl : public device::mojom::VRVSyncProvider {
46 public: 49 public:
47 enum class InputTarget { 50 enum class InputTarget {
48 NONE = 0, 51 NONE = 0,
49 CONTENT, 52 CONTENT,
50 UI 53 UI
51 }; 54 };
52 55
53 VrShellGl( 56 VrShellGl(
54 const base::WeakPtr<VrShell>& weak_vr_shell, 57 const base::WeakPtr<VrShell>& weak_vr_shell,
58 const base::WeakPtr<VrShellDelegate>& delegate_provider,
55 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner, 59 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner,
56 gvr_context* gvr_api, 60 gvr_context* gvr_api,
57 bool initially_web_vr, 61 bool initially_web_vr,
58 bool reprojected_rendering); 62 bool reprojected_rendering);
59 ~VrShellGl(); 63 ~VrShellGl() override;
60 64
61 void Initialize(); 65 void Initialize();
62 void InitializeGl(gfx::AcceleratedWidget window); 66 void InitializeGl(gfx::AcceleratedWidget window);
63 67
64 void DrawFrame();
65
66 void OnTriggerEvent(); 68 void OnTriggerEvent();
67 void OnPause(); 69 void OnPause();
68 void OnResume(); 70 void OnResume();
69 71
70 void SetWebVrMode(bool enabled); 72 void SetWebVrMode(bool enabled);
71 void ContentBoundsChanged(int width, int height); 73 void ContentBoundsChanged(int width, int height);
72 void ContentPhysicalBoundsChanged(int width, int height); 74 void ContentPhysicalBoundsChanged(int width, int height);
73 void UIBoundsChanged(int width, int height); 75 void UIBoundsChanged(int width, int height);
74 void UIPhysicalBoundsChanged(int width, int height); 76 void UIPhysicalBoundsChanged(int width, int height);
75 base::WeakPtr<VrShellGl> GetWeakPtr(); 77 base::WeakPtr<VrShellGl> GetWeakPtr();
76 78
77 void UpdateWebVRTextureBounds(const gvr::Rectf& left_bounds, 79 void UpdateWebVRTextureBounds(const gvr::Rectf& left_bounds,
78 const gvr::Rectf& right_bounds); 80 const gvr::Rectf& right_bounds);
79 gvr::GvrApi* gvr_api(); 81 gvr::GvrApi* gvr_api();
80 void SetGvrPoseForWebVr(const gvr::Mat4f& pose, uint32_t pose_num); 82 void SetGvrPoseForWebVr(const gvr::Mat4f& pose, uint32_t pose_num);
81 gvr::Sizei GetWebVRCompositorSurfaceSize(); 83 gvr::Sizei GetWebVRCompositorSurfaceSize();
82 84
83 void UpdateScene(std::unique_ptr<base::ListValue> commands); 85 void UpdateScene(std::unique_ptr<base::ListValue> commands);
84 86
87 void UpdateVSyncInterval(long timebase_nanos, double interval_seconds);
88
89 void OnRequest(device::mojom::VRVSyncProviderRequest request);
90
85 private: 91 private:
86 void GvrInit(gvr_context* gvr_api); 92 void GvrInit(gvr_context* gvr_api);
87 void InitializeRenderer(); 93 void InitializeRenderer();
94 void DrawFrame();
88 void DrawVrShell(const gvr::Mat4f& head_pose, gvr::Frame &frame); 95 void DrawVrShell(const gvr::Mat4f& head_pose, gvr::Frame &frame);
89 void DrawUiView(const gvr::Mat4f* head_pose, 96 void DrawUiView(const gvr::Mat4f* head_pose,
90 const std::vector<const ContentRectangle*>& elements, 97 const std::vector<const ContentRectangle*>& elements,
91 const gvr::Sizei& render_size, int viewport_offset); 98 const gvr::Sizei& render_size, int viewport_offset);
92 void DrawElements(const gvr::Mat4f& render_matrix, 99 void DrawElements(const gvr::Mat4f& render_matrix,
93 const std::vector<const ContentRectangle*>& elements); 100 const std::vector<const ContentRectangle*>& elements);
94 void DrawCursor(const gvr::Mat4f& render_matrix); 101 void DrawCursor(const gvr::Mat4f& render_matrix);
95 void DrawBackground(const gvr::Mat4f& render_matrix); 102 void DrawBackground(const gvr::Mat4f& render_matrix);
96 void DrawWebVr(); 103 void DrawWebVr();
97 bool WebVrPoseByteIsValid(int pose_index_byte); 104 bool WebVrPoseByteIsValid(int pose_index_byte);
98 105
99 void UpdateController(const gvr::Vec3f& forward_vector); 106 void UpdateController(const gvr::Vec3f& forward_vector);
100 void SendEventsToTarget(InputTarget input_target, int pixel_x, 107 void SendEventsToTarget(InputTarget input_target, int pixel_x,
101 int pixel_y); 108 int pixel_y);
102 void SendGesture(InputTarget input_target, 109 void SendGesture(InputTarget input_target,
103 std::unique_ptr<blink::WebInputEvent> event); 110 std::unique_ptr<blink::WebInputEvent> event);
104 111
105 void OnUIFrameAvailable(); 112 void OnUIFrameAvailable();
106 void OnContentFrameAvailable(); 113 void OnContentFrameAvailable();
114 bool GetPixelEncodedPoseIndexByte(int* pose_index);
107 115
108 void UpdateVSyncParameters(const base::TimeTicks timebase, 116 void OnVSync();
109 const base::TimeDelta interval); 117
110 void ScheduleNextDrawFrame(); 118 // VRVSyncProvider
119 void GetVSync(const GetVSyncCallback& callback) override;
111 120
112 void ForceExitVr(); 121 void ForceExitVr();
113 122
123 device::mojom::VRPosePtr GetPose();
124
114 // samplerExternalOES texture data for UI content image. 125 // samplerExternalOES texture data for UI content image.
115 int ui_texture_id_ = 0; 126 int ui_texture_id_ = 0;
116 // samplerExternalOES texture data for main content image. 127 // samplerExternalOES texture data for main content image.
117 int content_texture_id_ = 0; 128 int content_texture_id_ = 0;
118 129
119 std::unique_ptr<UiScene> scene_; 130 std::unique_ptr<UiScene> scene_;
120 131
121 scoped_refptr<gl::GLSurface> surface_; 132 scoped_refptr<gl::GLSurface> surface_;
122 scoped_refptr<gl::GLContext> context_; 133 scoped_refptr<gl::GLContext> context_;
123 scoped_refptr<gl::SurfaceTexture> ui_surface_texture_; 134 scoped_refptr<gl::SurfaceTexture> ui_surface_texture_;
(...skipping 28 matching lines...) Expand all
152 int content_tex_css_width_ = 0; 163 int content_tex_css_width_ = 0;
153 int content_tex_css_height_ = 0; 164 int content_tex_css_height_ = 0;
154 gvr::Sizei content_tex_physical_size_ = {0, 0}; 165 gvr::Sizei content_tex_physical_size_ = {0, 0};
155 gvr::Sizei ui_tex_physical_size_ = {0, 0}; 166 gvr::Sizei ui_tex_physical_size_ = {0, 0};
156 167
157 // 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
158 // 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
159 // current backlog of poses which is 2-3 frames. 170 // current backlog of poses which is 2-3 frames.
160 static constexpr int kPoseRingBufferSize = 8; 171 static constexpr int kPoseRingBufferSize = 8;
161 std::vector<gvr::Mat4f> webvr_head_pose_; 172 std::vector<gvr::Mat4f> webvr_head_pose_;
162 std::vector<bool> webvr_head_pose_valid_;
163 int webvr_texture_id_ = 0; 173 int webvr_texture_id_ = 0;
164 bool web_vr_mode_; 174 bool web_vr_mode_;
165 bool ready_to_draw_ = false; 175 bool ready_to_draw_ = false;
166 bool surfaceless_rendering_; 176 bool surfaceless_rendering_;
167 177
168 std::unique_ptr<VrController> controller_; 178 std::unique_ptr<VrController> controller_;
169 179
170 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 180 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
171 base::CancelableClosure draw_task_; 181 base::CancelableClosure vsync_task_;
172 base::TimeTicks vsync_timebase_; 182 base::TimeTicks vsync_timebase_;
173 base::TimeDelta vsync_interval_; 183 base::TimeDelta vsync_interval_;
174 184
185 base::TimeDelta pending_time_;
186 bool pending_vsync_ = false;
187 GetVSyncCallback callback_;
188 bool received_frame_ = false;
189 mojo::Binding<device::mojom::VRVSyncProvider> binding_;
190
175 base::WeakPtr<VrShell> weak_vr_shell_; 191 base::WeakPtr<VrShell> weak_vr_shell_;
192 base::WeakPtr<VrShellDelegate> delegate_provider_;
176 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; 193 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_;
177 194
195 uint32_t pose_index_ = 1;
196 int last_pose_ = 0;
197
178 base::WeakPtrFactory<VrShellGl> weak_ptr_factory_; 198 base::WeakPtrFactory<VrShellGl> weak_ptr_factory_;
179 199
180 DISALLOW_COPY_AND_ASSIGN(VrShellGl); 200 DISALLOW_COPY_AND_ASSIGN(VrShellGl);
181 }; 201 };
182 202
183 } // namespace vr_shell 203 } // namespace vr_shell
184 204
185 #endif // CHROME_BROWSER_ANDROID_VR_SHELL_VR_SHELL_GL_H_ 205 #endif // CHROME_BROWSER_ANDROID_VR_SHELL_VR_SHELL_GL_H_
OLDNEW
« no previous file with comments | « chrome/browser/android/vr_shell/vr_shell_delegate.cc ('k') | chrome/browser/android/vr_shell/vr_shell_gl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698