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

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

Issue 2878543002: Refactor VR Shell Input. Locks input to click/scroll targets. (Closed)
Patch Set: Created 3 years, 7 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>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/cancelable_callback.h" 13 #include "base/cancelable_callback.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
16 #include "base/memory/weak_ptr.h" 16 #include "base/memory/weak_ptr.h"
17 #include "base/single_thread_task_runner.h" 17 #include "base/single_thread_task_runner.h"
18 #include "chrome/browser/android/vr_shell/vr_controller.h"
18 #include "chrome/browser/android/vr_shell/vr_controller_model.h" 19 #include "chrome/browser/android/vr_shell/vr_controller_model.h"
19 #include "device/vr/vr_service.mojom.h" 20 #include "device/vr/vr_service.mojom.h"
20 #include "device/vr/vr_types.h" 21 #include "device/vr/vr_types.h"
21 #include "mojo/public/cpp/bindings/binding.h" 22 #include "mojo/public/cpp/bindings/binding.h"
22 #include "third_party/gvr-android-sdk/src/libraries/headers/vr/gvr/capi/include/ gvr.h" 23 #include "third_party/gvr-android-sdk/src/libraries/headers/vr/gvr/capi/include/ gvr.h"
23 #include "third_party/gvr-android-sdk/src/libraries/headers/vr/gvr/capi/include/ gvr_types.h" 24 #include "third_party/gvr-android-sdk/src/libraries/headers/vr/gvr/capi/include/ gvr_types.h"
24 #include "ui/gfx/native_widget_types.h" 25 #include "ui/gfx/native_widget_types.h"
25 26
26 namespace blink { 27 namespace blink {
27 class WebInputEvent; 28 class WebInputEvent;
(...skipping 28 matching lines...) Expand all
56 : left_bounds(left), right_bounds(right), source_size(size) {} 57 : left_bounds(left), right_bounds(right), source_size(size) {}
57 gfx::RectF left_bounds; 58 gfx::RectF left_bounds;
58 gfx::RectF right_bounds; 59 gfx::RectF right_bounds;
59 gfx::Size source_size; 60 gfx::Size source_size;
60 }; 61 };
61 62
62 // 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.
63 // 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.
64 class VrShellGl : public device::mojom::VRVSyncProvider { 65 class VrShellGl : public device::mojom::VRVSyncProvider {
65 public: 66 public:
66 enum class InputTarget {
67 NONE = 0,
68 CONTENT,
69 };
70
71 VrShellGl(VrBrowserInterface* browser, 67 VrShellGl(VrBrowserInterface* browser,
72 gvr_context* gvr_api, 68 gvr_context* gvr_api,
73 bool initially_web_vr, 69 bool initially_web_vr,
74 bool reprojected_rendering, 70 bool reprojected_rendering,
75 UiScene* scene); 71 UiScene* scene);
76 ~VrShellGl() override; 72 ~VrShellGl() override;
77 73
78 void Initialize(); 74 void Initialize();
79 void InitializeGl(gfx::AcceleratedWidget window); 75 void InitializeGl(gfx::AcceleratedWidget window);
80 76
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 std::vector<const UiElement*> GetElementsInDrawOrder( 124 std::vector<const UiElement*> GetElementsInDrawOrder(
129 const vr::Mat4f& view_matrix, 125 const vr::Mat4f& view_matrix,
130 const std::vector<const UiElement*>& elements); 126 const std::vector<const UiElement*>& elements);
131 void DrawCursor(const vr::Mat4f& render_matrix); 127 void DrawCursor(const vr::Mat4f& render_matrix);
132 void DrawController(const vr::Mat4f& view_proj_matrix); 128 void DrawController(const vr::Mat4f& view_proj_matrix);
133 bool ShouldDrawWebVr(); 129 bool ShouldDrawWebVr();
134 void DrawWebVr(); 130 void DrawWebVr();
135 bool WebVrPoseByteIsValid(int pose_index_byte); 131 bool WebVrPoseByteIsValid(int pose_index_byte);
136 132
137 void UpdateController(const gfx::Vector3dF& head_direction); 133 void UpdateController(const gfx::Vector3dF& head_direction);
134 void HandleWebVrCompatClick();
135 void SendFlingCancel(GestureList& gesture_list);
136 void SendScrollEnd(GestureList& gesture_list);
137 bool SendScrollBegin(UiElement* target, GestureList& gesture_list);
138 void SendScrollUpdate(GestureList& gesture_list);
139 void SendHoverLeave(UiElement* target);
140 bool SendHoverEnter(UiElement* target,
141 const gfx::PointF& target_point,
142 const gfx::Point& local_point_pixels);
143 void SendHoverMove(const gfx::PointF& target_point,
144 const gfx::Point& local_point_pixels);
145 void SendButtonDown(UiElement* target, const gfx::PointF& target_point);
146 bool SendButtonUp(UiElement* target, const gfx::PointF& target_point);
147 void SendTap(UiElement* target,
148 const gfx::PointF& target_point,
149 const gfx::Point& local_point_pixels);
150 void GetVisualTargetElement(const gfx::Vector3dF& controller_direction,
151 gfx::Vector3dF& eye_to_target,
152 gfx::Point3F& target_point,
153 UiElement** target_element,
154 gfx::PointF& target_local_point) const;
155 bool GetTargetLocalPoint(const gfx::Vector3dF& eye_to_target,
156 const UiElement& element,
157 float max_distance_to_plane,
158 gfx::PointF& target_local_point,
159 gfx::Point3F& target_point,
160 float& distance_to_plane) const;
138 void HandleControllerInput(const gfx::Vector3dF& head_direction); 161 void HandleControllerInput(const gfx::Vector3dF& head_direction);
139 void HandleControllerAppButtonActivity( 162 void HandleControllerAppButtonActivity(
140 const gfx::Vector3dF& controller_direction); 163 const gfx::Vector3dF& controller_direction);
141 void SendInputToContent(InputTarget input_target, int pixel_x, int pixel_y);
142 void SendInputToUiElements(UiElement* target_element);
143 void SendGestureToContent(std::unique_ptr<blink::WebInputEvent> event); 164 void SendGestureToContent(std::unique_ptr<blink::WebInputEvent> event);
144 void CreateUiSurface(); 165 void CreateUiSurface();
145 void OnContentFrameAvailable(); 166 void OnContentFrameAvailable();
146 void OnWebVRFrameAvailable(); 167 void OnWebVRFrameAvailable();
147 bool GetPixelEncodedFrameIndex(uint16_t* frame_index); 168 bool GetPixelEncodedFrameIndex(uint16_t* frame_index);
148 169
149 void OnVSync(); 170 void OnVSync();
150 171
151 // VRVSyncProvider 172 // VRVSyncProvider
152 void GetVSync(const GetVSyncCallback& callback) override; 173 void GetVSync(const GetVSyncCallback& callback) override;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 // can be restored after exiting WebVR mode. 209 // can be restored after exiting WebVR mode.
189 gfx::Size render_size_vrshell_; 210 gfx::Size render_size_vrshell_;
190 211
191 std::unique_ptr<VrShellRenderer> vr_shell_renderer_; 212 std::unique_ptr<VrShellRenderer> vr_shell_renderer_;
192 213
193 bool touch_pending_ = false; 214 bool touch_pending_ = false;
194 vr::Quatf controller_quat_; 215 vr::Quatf controller_quat_;
195 216
196 gfx::Point3F target_point_; 217 gfx::Point3F target_point_;
197 218
198 // Input targeting for non-content elements. 219 UiElement* cursor_render_target_ = nullptr;
cjgrant 2017/05/10 20:16:26 Now might be a good time to TODO the fact that we
mthiesse 2017/05/10 21:09:08 Done.
199 UiElement* target_element_ = nullptr; 220 UiElement* hover_target_ = nullptr;
200 UiElement* previous_target_element_ = nullptr; 221 // TODO(mthiesse): Whether a target is flinging should be a property on the
asimjour1 2017/05/11 12:31:12 I don't get this comment. If you mean "whether a t
mthiesse 2017/05/11 14:12:00 You're right, changed the TODO.
201 UiElement* click_target_element_ = nullptr; 222 // element, so we can fling multiple things at once.
202 223 UiElement* fling_target_ = nullptr;
203 // Input targeting for the content element. 224 UiElement* input_locked_element_ = nullptr;
204 InputTarget current_input_target_ = InputTarget::NONE; 225 bool in_scroll_ = false;
205 InputTarget current_scroll_target_ = InputTarget::NONE; 226 bool in_click_ = false;
206 InputTarget current_fling_target_ = InputTarget::NONE;
207 227
208 int content_tex_css_width_ = 0; 228 int content_tex_css_width_ = 0;
209 int content_tex_css_height_ = 0; 229 int content_tex_css_height_ = 0;
210 gfx::Size content_tex_physical_size_ = {0, 0}; 230 gfx::Size content_tex_physical_size_ = {0, 0};
211 gfx::Size webvr_surface_size_ = {0, 0}; 231 gfx::Size webvr_surface_size_ = {0, 0};
212 232
213 std::vector<vr::Mat4f> webvr_head_pose_; 233 std::vector<vr::Mat4f> webvr_head_pose_;
214 bool web_vr_mode_; 234 bool web_vr_mode_;
215 bool ready_to_draw_ = false; 235 bool ready_to_draw_ = false;
216 bool surfaceless_rendering_; 236 bool surfaceless_rendering_;
(...skipping 28 matching lines...) Expand all
245 gfx::Point3F pointer_start_; 265 gfx::Point3F pointer_start_;
246 266
247 base::WeakPtrFactory<VrShellGl> weak_ptr_factory_; 267 base::WeakPtrFactory<VrShellGl> weak_ptr_factory_;
248 268
249 DISALLOW_COPY_AND_ASSIGN(VrShellGl); 269 DISALLOW_COPY_AND_ASSIGN(VrShellGl);
250 }; 270 };
251 271
252 } // namespace vr_shell 272 } // namespace vr_shell
253 273
254 #endif // CHROME_BROWSER_ANDROID_VR_SHELL_VR_SHELL_GL_H_ 274 #endif // CHROME_BROWSER_ANDROID_VR_SHELL_VR_SHELL_GL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698