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 #include "chrome/browser/android/vr_shell/vr_shell.h" | 5 #include "chrome/browser/android/vr_shell/vr_shell.h" |
6 | 6 |
7 #include <thread> | 7 #include <thread> |
8 | 8 |
9 #include "chrome/browser/android/vr_shell/vr_gl_util.h" | 9 #include "chrome/browser/android/vr_shell/vr_gl_util.h" |
10 #include "chrome/browser/android/vr_shell/vr_math.h" | 10 #include "chrome/browser/android/vr_shell/vr_math.h" |
| 11 #include "chrome/browser/android/vr_shell/vr_shell_delegate.h" |
11 #include "chrome/browser/android/vr_shell/vr_shell_renderer.h" | 12 #include "chrome/browser/android/vr_shell/vr_shell_renderer.h" |
12 #include "jni/VrShell_jni.h" | 13 #include "jni/VrShell_jni.h" |
13 #include "ui/gl/gl_bindings.h" | 14 #include "ui/gl/gl_bindings.h" |
14 #include "ui/gl/init/gl_factory.h" | 15 #include "ui/gl/init/gl_factory.h" |
15 | 16 |
16 using base::android::JavaParamRef; | 17 using base::android::JavaParamRef; |
17 | 18 |
18 namespace { | 19 namespace { |
19 // Constant taken from treasure_hunt demo. | 20 // Constant taken from treasure_hunt demo. |
20 static constexpr long kPredictionTimeWithoutVsyncNanos = 50000000; | 21 static constexpr long kPredictionTimeWithoutVsyncNanos = 50000000; |
21 | 22 |
22 static constexpr float kZNear = 0.1f; | 23 static constexpr float kZNear = 0.1f; |
23 static constexpr float kZFar = 1000.0f; | 24 static constexpr float kZFar = 1000.0f; |
24 | 25 |
25 static constexpr gvr::Vec3f kDesktopPositionDefault = {0.0f, 0.0f, -2.0f}; | 26 static constexpr gvr::Vec3f kDesktopPositionDefault = {0.0f, 0.0f, -2.0f}; |
26 static constexpr float kDesktopHeightDefault = 1.6f; | 27 static constexpr float kDesktopHeightDefault = 1.6f; |
27 | 28 |
28 // Screen angle in degrees. 0 = vertical, positive = top closer. | 29 // Screen angle in degrees. 0 = vertical, positive = top closer. |
29 static constexpr float kDesktopScreenTiltDefault = 0; | 30 static constexpr float kDesktopScreenTiltDefault = 0; |
30 | 31 |
31 static constexpr float kScreenHeightMeters = 2.0f; | 32 static constexpr float kScreenHeightMeters = 2.0f; |
32 static constexpr float kScreenWidthMeters = 2.0f; | 33 static constexpr float kScreenWidthMeters = 2.0f; |
33 } // namespace | 34 } // namespace |
34 | 35 |
35 namespace vr_shell { | 36 namespace vr_shell { |
36 | 37 |
37 VrShell::VrShell(JNIEnv* env, jobject obj) | 38 VrShell::VrShell(JNIEnv* env, jobject obj) |
38 : desktop_screen_tilt_(kDesktopScreenTiltDefault), | 39 : desktop_screen_tilt_(kDesktopScreenTiltDefault), |
39 desktop_height_(kDesktopHeightDefault), | 40 desktop_height_(kDesktopHeightDefault), |
40 desktop_position_(kDesktopPositionDefault) { | 41 desktop_position_(kDesktopPositionDefault), |
| 42 delegate_(nullptr) { |
41 j_vr_shell_.Reset(env, obj); | 43 j_vr_shell_.Reset(env, obj); |
42 ui_rects_.emplace_back(new ContentRectangle()); | 44 ui_rects_.emplace_back(new ContentRectangle()); |
43 desktop_plane_ = ui_rects_.back().get(); | 45 desktop_plane_ = ui_rects_.back().get(); |
44 desktop_plane_->id = 0; | 46 desktop_plane_->id = 0; |
45 desktop_plane_->copy_rect = {0.0f, 0.0f, 1.0f, 1.0f}; | 47 desktop_plane_->copy_rect = {0.0f, 0.0f, 1.0f, 1.0f}; |
46 // TODO(cjgrant): If we use the native path for content clicks, fix this. | 48 // TODO(cjgrant): If we use the native path for content clicks, fix this. |
47 desktop_plane_->window_rect = {0, 0, 0, 0}; | 49 desktop_plane_->window_rect = {0, 0, 0, 0}; |
48 desktop_plane_->translation = {0.0f, 0.0f, 0.0f}; | 50 desktop_plane_->translation = {0.0f, 0.0f, 0.0f}; |
49 desktop_plane_->x_anchoring = XNONE; | 51 desktop_plane_->x_anchoring = XNONE; |
50 desktop_plane_->y_anchoring = YNONE; | 52 desktop_plane_->y_anchoring = YNONE; |
51 desktop_plane_->anchor_z = false; | 53 desktop_plane_->anchor_z = false; |
52 desktop_plane_->orientation_axis_angle = {{1.0f, 0.0f, 0.0f, 0.0f}}; | 54 desktop_plane_->orientation_axis_angle = {{1.0f, 0.0f, 0.0f, 0.0f}}; |
53 desktop_plane_->rotation_axis_angle = {{0.0f, 0.0f, 0.0f, 0.0f}}; | 55 desktop_plane_->rotation_axis_angle = {{0.0f, 0.0f, 0.0f, 0.0f}}; |
54 } | 56 } |
55 | 57 |
56 void VrShell::Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 58 void VrShell::Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
57 delete this; | 59 delete this; |
58 gl::init::ClearGLBindings(); | 60 gl::init::ClearGLBindings(); |
59 } | 61 } |
60 | 62 |
61 bool RegisterVrShell(JNIEnv* env) { | 63 bool RegisterVrShell(JNIEnv* env) { |
62 return RegisterNativesImpl(env); | 64 return RegisterNativesImpl(env); |
63 } | 65 } |
64 | 66 |
65 VrShell::~VrShell() { | 67 VrShell::~VrShell() { |
66 device::GvrDelegateManager::GetInstance()->Shutdown(); | 68 } |
| 69 |
| 70 void VrShell::SetDelegate(JNIEnv* env, |
| 71 const base::android::JavaParamRef<jobject>& obj, |
| 72 jlong native_delegate) { |
| 73 delegate_ = reinterpret_cast<VrShellDelegate*>(native_delegate); |
67 } | 74 } |
68 | 75 |
69 void VrShell::GvrInit(JNIEnv* env, | 76 void VrShell::GvrInit(JNIEnv* env, |
70 const JavaParamRef<jobject>& obj, | 77 const JavaParamRef<jobject>& obj, |
71 jlong native_gvr_api) { | 78 jlong native_gvr_api) { |
72 gvr_api_ = | 79 gvr_api_ = |
73 gvr::GvrApi::WrapNonOwned(reinterpret_cast<gvr_context*>(native_gvr_api)); | 80 gvr::GvrApi::WrapNonOwned(reinterpret_cast<gvr_context*>(native_gvr_api)); |
74 | 81 |
75 device::GvrDelegateManager::GetInstance()->Initialize(this); | 82 if (delegate_) |
| 83 delegate_->OnVrShellReady(this); |
76 } | 84 } |
77 | 85 |
78 void VrShell::InitializeGl(JNIEnv* env, | 86 void VrShell::InitializeGl(JNIEnv* env, |
79 const JavaParamRef<jobject>& obj, | 87 const JavaParamRef<jobject>& obj, |
80 jint texture_data_handle) { | 88 jint texture_data_handle) { |
81 CHECK(gl::GetGLImplementation() != gl::kGLImplementationNone || | 89 CHECK(gl::GetGLImplementation() != gl::kGLImplementationNone || |
82 gl::init::InitializeGLOneOff()); | 90 gl::init::InitializeGLOneOff()); |
83 | 91 |
84 content_texture_id_ = texture_data_handle; | 92 content_texture_id_ = texture_data_handle; |
85 gvr_api_->InitializeGl(); | 93 gvr_api_->InitializeGl(); |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 } | 252 } |
245 | 253 |
246 void VrShell::OnResume(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 254 void VrShell::OnResume(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
247 if (gvr_api_ == nullptr) | 255 if (gvr_api_ == nullptr) |
248 return; | 256 return; |
249 | 257 |
250 gvr_api_->RefreshViewerProfile(); | 258 gvr_api_->RefreshViewerProfile(); |
251 gvr_api_->ResumeTracking(); | 259 gvr_api_->ResumeTracking(); |
252 } | 260 } |
253 | 261 |
254 void VrShell::RequestWebVRPresent() { | 262 void VrShell::SetWebVrMode(JNIEnv* env, |
255 webvr_mode_ = true; | 263 const base::android::JavaParamRef<jobject>& obj, |
256 } | 264 bool enabled) { |
257 | 265 webvr_mode_ = enabled; |
258 void VrShell::ExitWebVRPresent() { | |
259 webvr_mode_ = false; | |
260 } | 266 } |
261 | 267 |
262 void VrShell::SubmitWebVRFrame() { | 268 void VrShell::SubmitWebVRFrame() { |
263 } | 269 } |
264 | 270 |
265 void VrShell::UpdateWebVRTextureBounds( | 271 void VrShell::UpdateWebVRTextureBounds( |
266 int eye, float left, float top, float width, float height) { | 272 int eye, float left, float top, float width, float height) { |
267 gvr::Rectf bounds = { left, top, width, height }; | 273 gvr::Rectf bounds = { left, top, width, height }; |
268 vr_shell_renderer_->GetWebVrRenderer()->UpdateTextureBounds(eye, bounds); | 274 vr_shell_renderer_->GetWebVrRenderer()->UpdateTextureBounds(eye, bounds); |
269 } | 275 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 | 326 |
321 // ---------------------------------------------------------------------------- | 327 // ---------------------------------------------------------------------------- |
322 // Native JNI methods | 328 // Native JNI methods |
323 // ---------------------------------------------------------------------------- | 329 // ---------------------------------------------------------------------------- |
324 | 330 |
325 jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 331 jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
326 return reinterpret_cast<intptr_t>(new VrShell(env, obj)); | 332 return reinterpret_cast<intptr_t>(new VrShell(env, obj)); |
327 } | 333 } |
328 | 334 |
329 } // namespace vr_shell | 335 } // namespace vr_shell |
OLD | NEW |