Chromium Code Reviews| OLD | NEW |
|---|---|
| (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_ | |
|
cjgrant
2016/12/08 17:02:49
Should vr_gl_util's contents move into these new f
mthiesse
2016/12/09 01:28:42
No preference. Feel free to move address this in a
| |
| 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 // samplerExternalOES texture data for UI content image. | |
| 106 int ui_texture_id_ = 0; | |
| 107 // samplerExternalOES texture data for main content image. | |
| 108 int content_texture_id_ = 0; | |
| 109 | |
| 110 std::unique_ptr<UiScene> scene_; | |
| 111 | |
| 112 scoped_refptr<gl::GLSurface> surface_; | |
| 113 scoped_refptr<gl::GLContext> context_; | |
| 114 scoped_refptr<gl::SurfaceTexture> ui_surface_texture_; | |
| 115 scoped_refptr<gl::SurfaceTexture> content_surface_texture_; | |
| 116 | |
| 117 std::unique_ptr<gl::ScopedJavaSurface> ui_surface_; | |
| 118 std::unique_ptr<gl::ScopedJavaSurface> content_surface_; | |
| 119 | |
| 120 std::unique_ptr<gvr::GvrApi> gvr_api_; | |
| 121 std::unique_ptr<gvr::BufferViewportList> buffer_viewport_list_; | |
| 122 std::unique_ptr<gvr::BufferViewport> buffer_viewport_; | |
| 123 std::unique_ptr<gvr::BufferViewport> headlocked_left_viewport_; | |
| 124 std::unique_ptr<gvr::BufferViewport> headlocked_right_viewport_; | |
| 125 std::unique_ptr<gvr::BufferViewport> webvr_left_viewport_; | |
| 126 std::unique_ptr<gvr::BufferViewport> webvr_right_viewport_; | |
| 127 std::unique_ptr<gvr::SwapChain> swap_chain_; | |
| 128 | |
| 129 // Current sizes for the render buffers. | |
| 130 gvr::Sizei render_size_primary_; | |
| 131 gvr::Sizei render_size_headlocked_; | |
| 132 | |
| 133 // Intended size for the primary render buffer by UI mode. | |
| 134 // For WebVR, a size of 0x0 is used to indicate "not yet ready" | |
| 135 // to suppress rendering while still initializing. | |
| 136 gvr::Sizei render_size_primary_webvr_ = device::kInvalidRenderTargetSize; | |
| 137 gvr::Sizei render_size_primary_vrshell_; | |
| 138 | |
| 139 std::unique_ptr<VrShellRenderer> vr_shell_renderer_; | |
| 140 | |
| 141 bool touch_pending_ = false; | |
| 142 gvr::Quatf controller_quat_; | |
| 143 | |
| 144 gvr::Vec3f target_point_; | |
| 145 const ContentRectangle* target_element_ = nullptr; | |
| 146 InputTarget current_input_target_ = NONE; | |
| 147 int ui_tex_css_width_ = 0; | |
| 148 int ui_tex_css_height_ = 0; | |
| 149 int content_tex_css_width_ = 0; | |
| 150 int content_tex_css_height_ = 0; | |
| 151 gvr::Sizei content_tex_physical_size_ = {0, 0}; | |
| 152 gvr::Sizei ui_tex_physical_size_ = {0, 0}; | |
| 153 | |
| 154 // The pose ring buffer size must be a power of two to avoid glitches when | |
| 155 // the pose index wraps around. It should be large enough to handle the | |
| 156 // current backlog of poses which is 2-3 frames. | |
| 157 static constexpr int kPoseRingBufferSize = 8; | |
| 158 std::vector<gvr::Mat4f> webvr_head_pose_; | |
| 159 std::vector<bool> webvr_head_pose_valid_; | |
| 160 jint webvr_texture_id_ = 0; | |
| 161 | |
| 162 std::unique_ptr<VrController> controller_; | |
| 163 | |
| 164 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | |
| 165 base::CancelableClosure draw_task_; | |
| 166 base::TimeTicks vsync_timebase_; | |
| 167 base::TimeDelta vsync_interval_; | |
| 168 | |
| 169 // TODO(mthiesse): Remove thread-unsafe VrShell usage. | |
| 170 VrShell* vr_shell_; | |
| 171 base::WeakPtr<VrShell> weak_vr_shell_; | |
| 172 base::WeakPtr<VrInputManager> content_input_manager_; | |
| 173 base::WeakPtr<VrInputManager> ui_input_manager_; | |
| 174 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; | |
| 175 | |
| 176 base::WeakPtrFactory<VrShellGl> weak_ptr_factory_; | |
| 177 | |
| 178 DISALLOW_COPY_AND_ASSIGN(VrShellGl); | |
| 179 }; | |
| 180 | |
| 181 } // namespace vr_shell | |
| 182 | |
| 183 #endif // CHROME_BROWSER_ANDROID_VR_SHELL_VR_SHELL_GL_H_ | |
| OLD | NEW |