| OLD | NEW |
| 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_H_ | 5 #ifndef CHROME_BROWSER_ANDROID_VR_SHELL_VR_SHELL_H_ |
| 6 #define CHROME_BROWSER_ANDROID_VR_SHELL_VR_SHELL_H_ | 6 #define CHROME_BROWSER_ANDROID_VR_SHELL_VR_SHELL_H_ |
| 7 | 7 |
| 8 #include <jni.h> | 8 #include <jni.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 | 65 |
| 66 class VrShell : public device::GvrDelegate, content::WebContentsObserver { | 66 class VrShell : public device::GvrDelegate, content::WebContentsObserver { |
| 67 public: | 67 public: |
| 68 VrShell(JNIEnv* env, jobject obj, | 68 VrShell(JNIEnv* env, jobject obj, |
| 69 content::WebContents* main_contents, | 69 content::WebContents* main_contents, |
| 70 ui::WindowAndroid* content_window, | 70 ui::WindowAndroid* content_window, |
| 71 content::WebContents* ui_contents, | 71 content::WebContents* ui_contents, |
| 72 ui::WindowAndroid* ui_window, | 72 ui::WindowAndroid* ui_window, |
| 73 bool for_web_vr); | 73 bool for_web_vr); |
| 74 | 74 |
| 75 void UpdateCompositorLayers(JNIEnv* env, | 75 void UpdateCompositorLayersOnUI( |
| 76 const base::android::JavaParamRef<jobject>& obj); | 76 JNIEnv* env, const base::android::JavaParamRef<jobject>& obj); |
| 77 void Destroy(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj); | 77 void DestroyOnUI(JNIEnv* env, |
| 78 void SetDelegate(JNIEnv* env, | 78 const base::android::JavaParamRef<jobject>& obj); |
| 79 void SetDelegateOnUI(JNIEnv* env, |
| 80 const base::android::JavaParamRef<jobject>& obj, |
| 81 const base::android::JavaParamRef<jobject>& delegate); |
| 82 void GvrInitOnGL(JNIEnv* env, |
| 79 const base::android::JavaParamRef<jobject>& obj, | 83 const base::android::JavaParamRef<jobject>& obj, |
| 80 const base::android::JavaParamRef<jobject>& delegate); | 84 jlong native_gvr_api); |
| 81 void GvrInit(JNIEnv* env, | 85 void InitializeGlOnGL(JNIEnv* env, |
| 82 const base::android::JavaParamRef<jobject>& obj, | 86 const base::android::JavaParamRef<jobject>& obj, |
| 83 jlong native_gvr_api); | 87 jint content_texture_handle, |
| 84 void InitializeGl(JNIEnv* env, | 88 jint ui_texture_handle); |
| 85 const base::android::JavaParamRef<jobject>& obj, | 89 void DrawFrameOnGL(JNIEnv* env, |
| 86 jint content_texture_handle, | 90 const base::android::JavaParamRef<jobject>& obj); |
| 87 jint ui_texture_handle); | 91 void OnTriggerEventOnUI(JNIEnv* env, |
| 88 void DrawFrame(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj); | |
| 89 void OnTriggerEvent(JNIEnv* env, | |
| 90 const base::android::JavaParamRef<jobject>& obj); | 92 const base::android::JavaParamRef<jobject>& obj); |
| 91 void OnPause(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj); | 93 void OnPauseOnUI(JNIEnv* env, |
| 92 void OnResume(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj); | 94 const base::android::JavaParamRef<jobject>& obj); |
| 93 void SetWebVrMode(JNIEnv* env, | 95 void OnResumeOnUI(JNIEnv* env, |
| 94 const base::android::JavaParamRef<jobject>& obj, | 96 const base::android::JavaParamRef<jobject>& obj); |
| 95 bool enabled); | 97 void SetWebVrModeOnUI(JNIEnv* env, |
| 98 const base::android::JavaParamRef<jobject>& obj, |
| 99 bool enabled); |
| 96 | 100 |
| 97 void ContentWebContentsDestroyed(); | 101 void ContentWebContentsDestroyedOnUI(); |
| 98 // Called when our WebContents have been hidden. Usually a sign that something | 102 // Called when our WebContents have been hidden. Usually a sign that something |
| 99 // like another tab placed in front of it. | 103 // like another tab placed in front of it. |
| 100 void ContentWasHidden(); | 104 void ContentWasHiddenOnUI(); |
| 101 | 105 |
| 102 // html/js UI hooks. | 106 // html/js UI hooks. |
| 103 static base::WeakPtr<VrShell> GetWeakPtr( | 107 static base::WeakPtr<VrShell> GetWeakPtrOnUI( |
| 104 const content::WebContents* web_contents); | 108 const content::WebContents* web_contents); |
| 105 UiScene* GetScene(); | 109 // TODO(mthiesse): Clean up threading around Scene. |
| 106 UiInterface* GetUiInterface(); | 110 UiScene* GetSceneOnGL(); |
| 107 void OnDomContentsLoaded(); | 111 // TODO(mthiesse): Clean up threading around UiInterface. |
| 112 UiInterface* GetUiInterfaceOnGL(); |
| 113 void OnDomContentsLoadedOnUI(); |
| 108 | 114 |
| 109 // device::GvrDelegate implementation | 115 // device::GvrDelegate implementation |
| 116 // TODO(mthiesse): Clean up threading around GVR API. These functions are |
| 117 // called on the UI thread, but use GL thread objects in a non-threadsafe way. |
| 110 void SetWebVRSecureOrigin(bool secure_origin) override; | 118 void SetWebVRSecureOrigin(bool secure_origin) override; |
| 111 void SubmitWebVRFrame() override; | 119 void SubmitWebVRFrame() override; |
| 112 void UpdateWebVRTextureBounds(const gvr::Rectf& left_bounds, | 120 void UpdateWebVRTextureBounds(const gvr::Rectf& left_bounds, |
| 113 const gvr::Rectf& right_bounds) override; | 121 const gvr::Rectf& right_bounds) override; |
| 114 gvr::GvrApi* gvr_api() override; | 122 gvr::GvrApi* gvr_api() override; |
| 115 void SetGvrPoseForWebVr(const gvr::Mat4f& pose, uint32_t pose_num) override; | 123 void SetGvrPoseForWebVr(const gvr::Mat4f& pose, uint32_t pose_num) override; |
| 116 void SetWebVRRenderSurfaceSize(int width, int height) override; | 124 void SetWebVRRenderSurfaceSize(int width, int height) override; |
| 117 gvr::Sizei GetWebVRCompositorSurfaceSize() override; | 125 gvr::Sizei GetWebVRCompositorSurfaceSize() override; |
| 118 | 126 |
| 119 void SurfacesChanged( | 127 void SurfacesChangedOnUI( |
| 120 JNIEnv* env, | 128 JNIEnv* env, |
| 121 const base::android::JavaParamRef<jobject>& object, | 129 const base::android::JavaParamRef<jobject>& object, |
| 122 const base::android::JavaParamRef<jobject>& content_surface, | 130 const base::android::JavaParamRef<jobject>& content_surface, |
| 123 const base::android::JavaParamRef<jobject>& ui_surface); | 131 const base::android::JavaParamRef<jobject>& ui_surface); |
| 124 | 132 |
| 125 void ContentBoundsChanged( | 133 void ContentBoundsChangedOnUI( |
| 126 JNIEnv* env, | 134 JNIEnv* env, |
| 127 const base::android::JavaParamRef<jobject>& object, | 135 const base::android::JavaParamRef<jobject>& object, |
| 128 jint width, jint height, jfloat dpr); | 136 jint width, jint height, jfloat dpr); |
| 129 | 137 |
| 130 void UIBoundsChanged( | 138 void UIBoundsChangedOnUI( |
| 131 JNIEnv* env, | 139 JNIEnv* env, |
| 132 const base::android::JavaParamRef<jobject>& object, | 140 const base::android::JavaParamRef<jobject>& object, |
| 133 jint width, jint height, jfloat dpr); | 141 jint width, jint height, jfloat dpr); |
| 134 | 142 |
| 135 // Called from non-render thread to queue a callback onto the render thread. | 143 // Called from non-render thread to queue a callback onto the render thread. |
| 136 // The render thread checks for callbacks and processes them between frames. | 144 // The render thread checks for callbacks and processes them between frames. |
| 137 void QueueTask(base::Callback<void()>& callback); | 145 void QueueTaskOnUI(base::Callback<void()>& callback); |
| 138 | 146 |
| 139 // Perform a UI action triggered by the javascript API. | 147 // Perform a UI action triggered by the javascript API. |
| 140 void DoUiAction(const UiAction action); | 148 void DoUiActionOnUI(const UiAction action); |
| 141 | 149 |
| 142 void SetContentCssSize(float width, float height, float dpr); | 150 void SetContentCssSizeOnUI(float width, float height, float dpr); |
| 143 void SetUiCssSize(float width, float height, float dpr); | 151 void SetUiCssSizeOnUI(float width, float height, float dpr); |
| 144 | 152 |
| 145 private: | 153 private: |
| 146 ~VrShell() override; | 154 ~VrShell() override; |
| 147 void LoadUIContent(); | 155 void LoadUIContentOnUI(); |
| 148 void DrawVrShell(const gvr::Mat4f& head_pose, gvr::Frame &frame); | 156 void DrawVrShellOnGL(const gvr::Mat4f& head_pose, gvr::Frame &frame); |
| 149 void DrawUiView(const gvr::Mat4f* head_pose, | 157 void DrawUiViewOnGL(const gvr::Mat4f* head_pose, |
| 150 const std::vector<const ContentRectangle*>& elements, | 158 const std::vector<const ContentRectangle*>& elements, |
| 151 const gvr::Sizei& render_size, int viewport_offset); | 159 const gvr::Sizei& render_size, int viewport_offset); |
| 152 void DrawElements(const gvr::Mat4f& render_matrix, | 160 void DrawElementsOnGL(const gvr::Mat4f& render_matrix, |
| 153 const std::vector<const ContentRectangle*>& elements); | 161 const std::vector<const ContentRectangle*>& elements); |
| 154 void DrawCursor(const gvr::Mat4f& render_matrix); | 162 void DrawCursorOnGL(const gvr::Mat4f& render_matrix); |
| 155 void DrawWebVr(); | 163 void DrawWebVrOnGL(); |
| 156 bool WebVrPoseByteIsValid(int pose_index_byte); | 164 bool WebVrPoseByteIsValidOnGL(int pose_index_byte); |
| 157 | 165 |
| 158 void UpdateController(const gvr::Vec3f& forward_vector); | 166 void UpdateControllerOnGL(const gvr::Vec3f& forward_vector); |
| 159 void SendEventsToTarget(InputTarget input_target, int pixel_x, int pixel_y); | 167 void SendEventsToTargetOnGL(InputTarget input_target, int pixel_x, |
| 160 // This function should only be called from the GL thread. | 168 int pixel_y); |
| 161 void SendGesture(InputTarget input_target, | 169 void SendGestureOnGL(InputTarget input_target, |
| 162 std::unique_ptr<blink::WebInputEvent> event); | 170 std::unique_ptr<blink::WebInputEvent> event); |
| 163 | 171 |
| 164 void HandleQueuedTasks(); | 172 void HandleQueuedTasksOnGL(); |
| 165 | 173 |
| 166 // content::WebContentsObserver implementation. | 174 // content::WebContentsObserver implementation. All called on UI thread. |
| 167 void RenderViewHostChanged(content::RenderViewHost* old_host, | 175 void RenderViewHostChanged(content::RenderViewHost* old_host, |
| 168 content::RenderViewHost* new_host) override; | 176 content::RenderViewHost* new_host) override; |
| 169 void MainFrameWasResized(bool width_changed) override; | 177 void MainFrameWasResized(bool width_changed) override; |
| 170 void WebContentsDestroyed() override; | 178 void WebContentsDestroyed() override; |
| 171 | 179 |
| 172 // samplerExternalOES texture data for UI content image. | 180 // samplerExternalOES texture data for UI content image. |
| 173 jint ui_texture_id_ = 0; | 181 jint ui_texture_id_ = 0; |
| 174 // samplerExternalOES texture data for main content image. | 182 // samplerExternalOES texture data for main content image. |
| 175 jint content_texture_id_ = 0; | 183 jint content_texture_id_ = 0; |
| 176 | 184 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 base::WeakPtrFactory<VrShell> weak_ptr_factory_; | 250 base::WeakPtrFactory<VrShell> weak_ptr_factory_; |
| 243 | 251 |
| 244 DISALLOW_COPY_AND_ASSIGN(VrShell); | 252 DISALLOW_COPY_AND_ASSIGN(VrShell); |
| 245 }; | 253 }; |
| 246 | 254 |
| 247 bool RegisterVrShell(JNIEnv* env); | 255 bool RegisterVrShell(JNIEnv* env); |
| 248 | 256 |
| 249 } // namespace vr_shell | 257 } // namespace vr_shell |
| 250 | 258 |
| 251 #endif // CHROME_BROWSER_ANDROID_VR_SHELL_VR_SHELL_H_ | 259 #endif // CHROME_BROWSER_ANDROID_VR_SHELL_VR_SHELL_H_ |
| OLD | NEW |