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