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

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

Issue 2738683002: WebVR compositor bypass via BrowserMain context + mailbox (Closed)
Patch Set: Less hacked up version Created 3 years, 9 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 #include <queue> 9 #include <queue>
10 #include <utility> 10 #include <utility>
(...skipping 19 matching lines...) Expand all
30 class WebInputEvent; 30 class WebInputEvent;
31 } 31 }
32 32
33 namespace gl { 33 namespace gl {
34 class GLContext; 34 class GLContext;
35 class GLSurface; 35 class GLSurface;
36 class ScopedJavaSurface; 36 class ScopedJavaSurface;
37 class SurfaceTexture; 37 class SurfaceTexture;
38 } 38 }
39 39
40 namespace gpu {
41 struct MailboxHolder;
42 }
43
40 namespace vr_shell { 44 namespace vr_shell {
41 45
42 class UiScene; 46 class UiScene;
43 class VrController; 47 class VrController;
44 class VrShell; 48 class VrShell;
49 class VrShellCommandBufferGl;
45 class VrShellDelegate; 50 class VrShellDelegate;
46 class VrShellRenderer; 51 class VrShellRenderer;
47 struct ContentRectangle; 52 struct ContentRectangle;
48 53
54 class WebVrBounds {
55 public:
56 WebVrBounds(gvr::Rectf left, gvr::Rectf right, gvr::Sizei size)
57 : left_bounds(left), right_bounds(right), source_size(size) {}
58 gvr::Rectf left_bounds;
59 gvr::Rectf right_bounds;
60 gvr::Sizei source_size;
61 };
62
49 // This class manages all GLThread owned objects and GL rendering for VrShell. 63 // This class manages all GLThread owned objects and GL rendering for VrShell.
50 // It is not threadsafe and must only be used on the GL thread. 64 // It is not threadsafe and must only be used on the GL thread.
51 class VrShellGl : public device::mojom::VRVSyncProvider { 65 class VrShellGl : public device::mojom::VRVSyncProvider {
52 public: 66 public:
53 enum class InputTarget { 67 enum class InputTarget {
54 NONE = 0, 68 NONE = 0,
55 CONTENT, 69 CONTENT,
56 UI, 70 UI,
57 }; 71 };
58 72
59 VrShellGl(const base::WeakPtr<VrShell>& weak_vr_shell, 73 VrShellGl(const base::WeakPtr<VrShell>& weak_vr_shell,
60 const base::WeakPtr<VrShellDelegate>& delegate_provider, 74 const base::WeakPtr<VrShellDelegate>& delegate_provider,
61 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner, 75 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner,
62 gvr_context* gvr_api, 76 gvr_context* gvr_api,
63 bool initially_web_vr, 77 bool initially_web_vr,
64 bool reprojected_rendering); 78 bool reprojected_rendering);
65 ~VrShellGl() override; 79 ~VrShellGl() override;
66 80
67 void Initialize(); 81 void Initialize();
68 void InitializeGl(gfx::AcceleratedWidget window); 82 void InitializeGl(gfx::AcceleratedWidget window);
69 83
70 void OnTriggerEvent(); 84 void OnTriggerEvent();
71 void OnPause(); 85 void OnPause();
72 void OnResume(); 86 void OnResume();
73 87
74 void SetWebVrMode(bool enabled); 88 void SetWebVrMode(bool enabled);
89 void CreateOrResizeWebVRSurface(const gvr::Sizei& size);
75 void CreateContentSurface(); 90 void CreateContentSurface();
76 void ContentBoundsChanged(int width, int height); 91 void ContentBoundsChanged(int width, int height);
77 void ContentPhysicalBoundsChanged(int width, int height); 92 void ContentPhysicalBoundsChanged(int width, int height);
78 void UIBoundsChanged(int width, int height); 93 void UIBoundsChanged(int width, int height);
79 void UIPhysicalBoundsChanged(int width, int height); 94 void UIPhysicalBoundsChanged(int width, int height);
80 base::WeakPtr<VrShellGl> GetWeakPtr(); 95 base::WeakPtr<VrShellGl> GetWeakPtr();
81 96
82 void UpdateWebVRTextureBounds(int16_t frame_index, 97 void UpdateWebVRTextureBounds(int16_t frame_index,
83 const gvr::Rectf& left_bounds, 98 const gvr::Rectf& left_bounds,
84 const gvr::Rectf& right_bounds); 99 const gvr::Rectf& right_bounds,
85 gvr::Sizei GetWebVRCompositorSurfaceSize(); 100 const gvr::Sizei& source_size);
86 101
87 void UpdateScene(std::unique_ptr<base::ListValue> commands); 102 void UpdateScene(std::unique_ptr<base::ListValue> commands);
88 103
89 void UpdateVSyncInterval(int64_t timebase_nanos, double interval_seconds); 104 void UpdateVSyncInterval(int64_t timebase_nanos, double interval_seconds);
90 105
91 void OnRequest(device::mojom::VRVSyncProviderRequest request); 106 void OnRequest(device::mojom::VRVSyncProviderRequest request);
92 void ResetPose(); 107 void ResetPose();
93 void CreateVRDisplayInfo( 108 void CreateVRDisplayInfo(
94 const base::Callback<void(device::mojom::VRDisplayInfoPtr)>& callback, 109 const base::Callback<void(device::mojom::VRDisplayInfoPtr)>& callback,
95 uint32_t device_id); 110 uint32_t device_id);
111 void SubmitWebVRFrame(int16_t frame_index, const gpu::MailboxHolder& mailbox);
96 112
97 private: 113 private:
98 void GvrInit(gvr_context* gvr_api); 114 void GvrInit(gvr_context* gvr_api);
99 void InitializeRenderer(); 115 void InitializeRenderer();
100 void DrawFrame(); 116 void DrawFrame(int frame_index);
101 void DrawVrShell(const gvr::Mat4f& head_pose, gvr::Frame& frame); 117 void DrawVrShellAndUnbind(const gvr::Mat4f& head_pose, gvr::Frame& frame);
102 void DrawUiView(const gvr::Mat4f* head_pose, 118 void DrawUiView(const gvr::Mat4f* head_pose,
103 const std::vector<const ContentRectangle*>& elements, 119 const std::vector<const ContentRectangle*>& elements,
104 const gvr::Sizei& render_size, 120 const gvr::Sizei& render_size,
105 int viewport_offset); 121 int viewport_offset);
106 void DrawElements(const gvr::Mat4f& view_proj_matrix, 122 void DrawElements(const gvr::Mat4f& view_proj_matrix,
107 const gvr::Mat4f& view_matrix, 123 const gvr::Mat4f& view_matrix,
108 const std::vector<const ContentRectangle*>& elements); 124 const std::vector<const ContentRectangle*>& elements);
109 std::vector<const ContentRectangle*> GetElementsInDrawOrder( 125 std::vector<const ContentRectangle*> GetElementsInDrawOrder(
110 const gvr::Mat4f& view_matrix, 126 const gvr::Mat4f& view_matrix,
111 const std::vector<const ContentRectangle*>& elements); 127 const std::vector<const ContentRectangle*>& elements);
112 void DrawCursor(const gvr::Mat4f& render_matrix); 128 void DrawCursor(const gvr::Mat4f& render_matrix);
113 void DrawWebVr(); 129 void DrawWebVr();
114 bool WebVrPoseByteIsValid(int pose_index_byte); 130 bool WebVrPoseByteIsValid(int pose_index_byte);
115 131
116 void UpdateController(const gvr::Vec3f& forward_vector); 132 void UpdateController(const gvr::Vec3f& forward_vector);
117 void SendEventsToTarget(InputTarget input_target, int pixel_x, int pixel_y); 133 void SendEventsToTarget(InputTarget input_target, int pixel_x, int pixel_y);
118 void SendGesture(InputTarget input_target, 134 void SendGesture(InputTarget input_target,
119 std::unique_ptr<blink::WebInputEvent> event); 135 std::unique_ptr<blink::WebInputEvent> event);
120 void CreateUiSurface(); 136 void CreateUiSurface();
121 void OnUIFrameAvailable(); 137 void OnUIFrameAvailable();
122 void OnContentFrameAvailable(); 138 void OnContentFrameAvailable();
139 void OnWebVRFrameAvailable();
123 bool GetPixelEncodedFrameIndex(uint16_t* frame_index); 140 bool GetPixelEncodedFrameIndex(uint16_t* frame_index);
124 141
125 void OnVSync(); 142 void OnVSync();
126 143
127 // VRVSyncProvider 144 // VRVSyncProvider
128 void GetVSync(const GetVSyncCallback& callback) override; 145 void GetVSync(const GetVSyncCallback& callback) override;
129 146
130 void ForceExitVr(); 147 void ForceExitVr();
131 148
132 void SendVSync(base::TimeDelta time, const GetVSyncCallback& callback); 149 void SendVSync(base::TimeDelta time, const GetVSyncCallback& callback);
133 150
134 // samplerExternalOES texture data for UI content image. 151 // samplerExternalOES texture data for UI content image.
135 int ui_texture_id_ = 0; 152 int ui_texture_id_ = 0;
136 // samplerExternalOES texture data for main content image. 153 // samplerExternalOES texture data for main content image.
137 int content_texture_id_ = 0; 154 int content_texture_id_ = 0;
155 // samplerExternalOES texture data for WebVR content image.
156 int webvr_texture_id_ = 0;
138 157
139 std::unique_ptr<UiScene> scene_; 158 std::unique_ptr<UiScene> scene_;
140 159
141 scoped_refptr<gl::GLSurface> surface_; 160 scoped_refptr<gl::GLSurface> surface_;
142 scoped_refptr<gl::GLContext> context_; 161 scoped_refptr<gl::GLContext> context_;
143 scoped_refptr<gl::SurfaceTexture> ui_surface_texture_; 162 scoped_refptr<gl::SurfaceTexture> ui_surface_texture_;
144 scoped_refptr<gl::SurfaceTexture> content_surface_texture_; 163 scoped_refptr<gl::SurfaceTexture> content_surface_texture_;
164 scoped_refptr<gl::SurfaceTexture> webvr_surface_texture_;
145 165
146 std::unique_ptr<gl::ScopedJavaSurface> ui_surface_; 166 std::unique_ptr<gl::ScopedJavaSurface> ui_surface_;
147 std::unique_ptr<gl::ScopedJavaSurface> content_surface_; 167 std::unique_ptr<gl::ScopedJavaSurface> content_surface_;
168 std::unique_ptr<gl::ScopedJavaSurface> webvr_surface_;
148 169
149 std::unique_ptr<gvr::GvrApi> gvr_api_; 170 std::unique_ptr<gvr::GvrApi> gvr_api_;
150 std::unique_ptr<gvr::BufferViewportList> buffer_viewport_list_; 171 std::unique_ptr<gvr::BufferViewportList> buffer_viewport_list_;
151 std::unique_ptr<gvr::BufferViewport> buffer_viewport_; 172 std::unique_ptr<gvr::BufferViewport> buffer_viewport_;
152 std::unique_ptr<gvr::BufferViewport> headlocked_left_viewport_; 173 std::unique_ptr<gvr::BufferViewport> headlocked_left_viewport_;
153 std::unique_ptr<gvr::BufferViewport> headlocked_right_viewport_; 174 std::unique_ptr<gvr::BufferViewport> headlocked_right_viewport_;
154 std::unique_ptr<gvr::BufferViewport> webvr_left_viewport_; 175 std::unique_ptr<gvr::BufferViewport> webvr_left_viewport_;
155 std::unique_ptr<gvr::BufferViewport> webvr_right_viewport_; 176 std::unique_ptr<gvr::BufferViewport> webvr_right_viewport_;
156 std::unique_ptr<gvr::SwapChain> swap_chain_; 177 std::unique_ptr<gvr::SwapChain> swap_chain_;
157 using BoundsPair = std::pair<gvr::Rectf, gvr::Rectf>; 178 std::queue<std::pair<uint8_t, WebVrBounds>> pending_bounds_;
158 std::queue<std::pair<uint8_t, BoundsPair>> pending_bounds_; 179 int premature_received_frames_ = 0;
180 std::queue<uint16_t> pending_frames_;
181 std::unique_ptr<VrShellCommandBufferGl> command_buffer_gl_;
159 182
160 // Current sizes for the render buffers. 183 // Current sizes for the render buffers.
161 gvr::Sizei render_size_primary_; 184 gvr::Sizei render_size_primary_;
162 gvr::Sizei render_size_headlocked_; 185 gvr::Sizei render_size_headlocked_;
163 186
187 // Intended render_size_primary_ for use by VrShell, so that it
188 // can be restored after exiting WebVR mode.
189 gvr::Sizei render_size_vrshell_;
190
164 std::unique_ptr<VrShellRenderer> vr_shell_renderer_; 191 std::unique_ptr<VrShellRenderer> vr_shell_renderer_;
165 192
166 bool touch_pending_ = false; 193 bool touch_pending_ = false;
167 gvr::Quatf controller_quat_; 194 gvr::Quatf controller_quat_;
168 195
169 gvr::Vec3f target_point_; 196 gvr::Vec3f target_point_;
170 const ContentRectangle* target_element_ = nullptr; 197 const ContentRectangle* target_element_ = nullptr;
171 InputTarget current_input_target_ = InputTarget::NONE; 198 InputTarget current_input_target_ = InputTarget::NONE;
172 InputTarget current_scroll_target = InputTarget::NONE; 199 InputTarget current_scroll_target = InputTarget::NONE;
173 int ui_tex_css_width_ = 0; 200 int ui_tex_css_width_ = 0;
174 int ui_tex_css_height_ = 0; 201 int ui_tex_css_height_ = 0;
175 int content_tex_css_width_ = 0; 202 int content_tex_css_width_ = 0;
176 int content_tex_css_height_ = 0; 203 int content_tex_css_height_ = 0;
177 gvr::Sizei content_tex_physical_size_ = {0, 0}; 204 gvr::Sizei content_tex_physical_size_ = {0, 0};
205 gvr::Sizei webvr_surface_size_ = {0, 0};
178 gvr::Sizei ui_tex_physical_size_ = {0, 0}; 206 gvr::Sizei ui_tex_physical_size_ = {0, 0};
179 207
180 std::vector<gvr::Mat4f> webvr_head_pose_; 208 std::vector<gvr::Mat4f> webvr_head_pose_;
181 int webvr_texture_id_ = 0;
182 bool web_vr_mode_; 209 bool web_vr_mode_;
183 bool ready_to_draw_ = false; 210 bool ready_to_draw_ = false;
184 bool surfaceless_rendering_; 211 bool surfaceless_rendering_;
185 212
186 std::unique_ptr<VrController> controller_; 213 std::unique_ptr<VrController> controller_;
187 214
188 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 215 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
189 base::CancelableClosure vsync_task_; 216 base::CancelableClosure vsync_task_;
190 base::TimeTicks vsync_timebase_; 217 base::TimeTicks vsync_timebase_;
191 base::TimeDelta vsync_interval_; 218 base::TimeDelta vsync_interval_;
(...skipping 13 matching lines...) Expand all
205 uint16_t last_frame_index_ = -1; 232 uint16_t last_frame_index_ = -1;
206 233
207 base::WeakPtrFactory<VrShellGl> weak_ptr_factory_; 234 base::WeakPtrFactory<VrShellGl> weak_ptr_factory_;
208 235
209 DISALLOW_COPY_AND_ASSIGN(VrShellGl); 236 DISALLOW_COPY_AND_ASSIGN(VrShellGl);
210 }; 237 };
211 238
212 } // namespace vr_shell 239 } // namespace vr_shell
213 240
214 #endif // CHROME_BROWSER_ANDROID_VR_SHELL_VR_SHELL_GL_H_ 241 #endif // CHROME_BROWSER_ANDROID_VR_SHELL_VR_SHELL_GL_H_
OLDNEW
« no previous file with comments | « chrome/browser/android/vr_shell/vr_shell_command_buffer_gl.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