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

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

Issue 2562733002: Implement our own GLThread for VR Shell. (Closed)
Patch Set: Rebase + Fix thread teardown + Address comments Created 4 years 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_ANDROID_VR_SHELL_VR_SHELL_GL_H_
6 #define CHROME_BROWSER_ANDROID_VR_SHELL_VR_SHELL_GL_H_
7
8 #include <memory>
9
10 #include "base/cancelable_callback.h"
11 #include "base/macros.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/single_thread_task_runner.h"
15 #include "device/vr/android/gvr/gvr_delegate.h"
16 #include "third_party/gvr-android-sdk/src/ndk/include/vr/gvr/capi/include/gvr.h"
17 #include "third_party/gvr-android-sdk/src/ndk/include/vr/gvr/capi/include/gvr_ty pes.h"
18 #include "ui/gfx/native_widget_types.h"
19
20 namespace blink {
21 class WebInputEvent;
22 }
23
24 namespace gl {
25 class GLContext;
26 class GLSurface;
27 class ScopedJavaSurface;
28 class SurfaceTexture;
29 }
30
31 namespace vr_shell {
32
33 class UiScene;
34 class VrController;
35 class VrInputManager;
36 class VrShell;
37 class VrShellRenderer;
38 struct ContentRectangle;
39
40 class VrShellGl {
41 public:
42 VrShellGl(
43 VrShell* vr_shell,
44 base::WeakPtr<VrShell> weak_vr_shell,
45 base::WeakPtr<VrInputManager> content_input_manager,
46 base::WeakPtr<VrInputManager> ui_input_manager,
47 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner,
48 gvr_context* gvr_api);
49 ~VrShellGl();
50
51 enum InputTarget {
52 NONE = 0,
53 CONTENT,
54 UI
55 };
56 void DrawFrame();
57
58 void OnTriggerEvent();
59 void OnPause();
60 void OnResume();
61
62 void SetWebVrMode(bool enabled);
63 void ContentBoundsChanged(int width, int height);
64 void ContentPhysicalBoundsChanged(int width, int height);
65 void UIBoundsChanged(int width, int height);
66 void UIPhysicalBoundsChanged(int width, int height);
67 base::WeakPtr<VrShellGl> GetWeakPtr();
68
69 void UpdateWebVRTextureBounds(const gvr::Rectf& left_bounds,
70 const gvr::Rectf& right_bounds);
71 gvr::GvrApi* gvr_api();
72 void SetGvrPoseForWebVr(const gvr::Mat4f& pose, uint32_t pose_num);
73 void SetWebVRRenderSurfaceSize(int width, int height);
74 gvr::Sizei GetWebVRCompositorSurfaceSize();
75
76 UiScene* GetScene() { return scene_.get(); }
77
78 private:
79 void InitializeGl();
80 void GvrInit(gvr_context* gvr_api);
81 void InitializeRenderer();
82 void DrawVrShell(const gvr::Mat4f& head_pose, gvr::Frame &frame);
83 void DrawUiView(const gvr::Mat4f* head_pose,
84 const std::vector<const ContentRectangle*>& elements,
85 const gvr::Sizei& render_size, int viewport_offset);
86 void DrawElements(const gvr::Mat4f& render_matrix,
87 const std::vector<const ContentRectangle*>& elements);
88 void DrawCursor(const gvr::Mat4f& render_matrix);
89 void DrawWebVr();
90 bool WebVrPoseByteIsValid(int pose_index_byte);
91
92 void UpdateController(const gvr::Vec3f& forward_vector);
93 void SendEventsToTarget(InputTarget input_target, int pixel_x,
94 int pixel_y);
95 void SendGesture(InputTarget input_target,
96 std::unique_ptr<blink::WebInputEvent> event);
97
98 void OnUIFrameAvailable();
99 void OnContentFrameAvailable();
100
101 void UpdateVSyncParameters(const base::TimeTicks timebase,
102 const base::TimeDelta interval);
103 void ScheduleNextDrawFrame();
104
105 void ForceExitVR();
106
107 // samplerExternalOES texture data for UI content image.
108 int ui_texture_id_ = 0;
109 // samplerExternalOES texture data for main content image.
110 int content_texture_id_ = 0;
111
112 std::unique_ptr<UiScene> scene_;
113
114 scoped_refptr<gl::GLSurface> surface_;
115 scoped_refptr<gl::GLContext> context_;
116 scoped_refptr<gl::SurfaceTexture> ui_surface_texture_;
117 scoped_refptr<gl::SurfaceTexture> content_surface_texture_;
118
119 std::unique_ptr<gl::ScopedJavaSurface> ui_surface_;
120 std::unique_ptr<gl::ScopedJavaSurface> content_surface_;
121
122 std::unique_ptr<gvr::GvrApi> gvr_api_;
123 std::unique_ptr<gvr::BufferViewportList> buffer_viewport_list_;
124 std::unique_ptr<gvr::BufferViewport> buffer_viewport_;
125 std::unique_ptr<gvr::BufferViewport> headlocked_left_viewport_;
126 std::unique_ptr<gvr::BufferViewport> headlocked_right_viewport_;
127 std::unique_ptr<gvr::BufferViewport> webvr_left_viewport_;
128 std::unique_ptr<gvr::BufferViewport> webvr_right_viewport_;
129 std::unique_ptr<gvr::SwapChain> swap_chain_;
130
131 // Current sizes for the render buffers.
132 gvr::Sizei render_size_primary_;
133 gvr::Sizei render_size_headlocked_;
134
135 // Intended size for the primary render buffer by UI mode.
136 // For WebVR, a size of 0x0 is used to indicate "not yet ready"
137 // to suppress rendering while still initializing.
138 gvr::Sizei render_size_primary_webvr_ = device::kInvalidRenderTargetSize;
139 gvr::Sizei render_size_primary_vrshell_;
140
141 std::unique_ptr<VrShellRenderer> vr_shell_renderer_;
142
143 bool touch_pending_ = false;
144 gvr::Quatf controller_quat_;
145
146 gvr::Vec3f target_point_;
147 const ContentRectangle* target_element_ = nullptr;
148 InputTarget current_input_target_ = NONE;
149 int ui_tex_css_width_ = 0;
150 int ui_tex_css_height_ = 0;
151 int content_tex_css_width_ = 0;
152 int content_tex_css_height_ = 0;
153 gvr::Sizei content_tex_physical_size_ = {0, 0};
154 gvr::Sizei ui_tex_physical_size_ = {0, 0};
155
156 // The pose ring buffer size must be a power of two to avoid glitches when
157 // the pose index wraps around. It should be large enough to handle the
158 // current backlog of poses which is 2-3 frames.
159 static constexpr int kPoseRingBufferSize = 8;
160 std::vector<gvr::Mat4f> webvr_head_pose_;
161 std::vector<bool> webvr_head_pose_valid_;
162 jint webvr_texture_id_ = 0;
163
164 std::unique_ptr<VrController> controller_;
165
166 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
167 base::CancelableClosure draw_task_;
168 base::TimeTicks vsync_timebase_;
169 base::TimeDelta vsync_interval_;
170
171 // TODO(mthiesse): Remove thread-unsafe VrShell usage.
172 VrShell* vr_shell_;
173 base::WeakPtr<VrShell> weak_vr_shell_;
174 base::WeakPtr<VrInputManager> content_input_manager_;
175 base::WeakPtr<VrInputManager> ui_input_manager_;
176 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_;
177
178 base::WeakPtrFactory<VrShellGl> weak_ptr_factory_;
179
180 DISALLOW_COPY_AND_ASSIGN(VrShellGl);
181 };
182
183 } // namespace vr_shell
184
185 #endif // CHROME_BROWSER_ANDROID_VR_SHELL_VR_SHELL_GL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698