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

Side by Side Diff: chrome/browser/android/vr_shell/vr_shell.cc

Issue 2308683004: Added WebVR Render path to VrShell (Closed)
Patch Set: Addressed feedback Created 4 years, 3 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 #include "chrome/browser/android/vr_shell/vr_shell.h" 5 #include "chrome/browser/android/vr_shell/vr_shell.h"
6 6
7 #include "chrome/browser/android/vr_shell/vr_shell_renderer.h" 7 #include "chrome/browser/android/vr_shell/vr_shell_renderer.h"
8 #include "chrome/browser/android/vr_shell/vr_util.h" 8 #include "chrome/browser/android/vr_shell/vr_util.h"
9 #include "jni/VrShell_jni.h" 9 #include "jni/VrShell_jni.h"
10 #include "ui/gl/gl_bindings.h" 10 #include "ui/gl/gl_bindings.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 transfrom_to_world.m[3][2] = 0; 49 transfrom_to_world.m[3][2] = 0;
50 transfrom_to_world.m[3][3] = 1; 50 transfrom_to_world.m[3][3] = 1;
51 } 51 }
52 52
53 void ContentRect::Translate(float x, float y, float z) { 53 void ContentRect::Translate(float x, float y, float z) {
54 transfrom_to_world.m[0][3] += x; 54 transfrom_to_world.m[0][3] += x;
55 transfrom_to_world.m[1][3] += y; 55 transfrom_to_world.m[1][3] += y;
56 transfrom_to_world.m[2][3] += z; 56 transfrom_to_world.m[2][3] += z;
57 } 57 }
58 58
59 VrShell::VrShell(JNIEnv* env, jobject obj) { 59 VrShell::VrShell(JNIEnv* env, jobject obj) :
60 webvr_mode_(false) {
60 j_vr_shell_.Reset(env, obj); 61 j_vr_shell_.Reset(env, obj);
61 } 62 }
62 63
63 void VrShell::Destroy(JNIEnv* env, 64 void VrShell::Destroy(JNIEnv* env,
64 const base::android::JavaParamRef<jobject>& obj) { 65 const base::android::JavaParamRef<jobject>& obj) {
65 delete this; 66 delete this;
66 } 67 }
67 68
68 bool RegisterVrShell(JNIEnv* env) { 69 bool RegisterVrShell(JNIEnv* env) {
69 return RegisterNativesImpl(env); 70 return RegisterNativesImpl(env);
70 } 71 }
71 72
72 VrShell::~VrShell() {} 73 VrShell::~VrShell() {
74 device::GvrDelegateManager::GetInstance()->Shutdown();
75 }
73 76
74 void VrShell::GvrInit(JNIEnv* env, 77 void VrShell::GvrInit(JNIEnv* env,
75 const base::android::JavaParamRef<jobject>& obj, 78 const base::android::JavaParamRef<jobject>& obj,
76 jlong native_gvr_api) { 79 jlong native_gvr_api) {
77 gvr_api_ = 80 gvr_api_ =
78 gvr::GvrApi::WrapNonOwned(reinterpret_cast<gvr_context*>(native_gvr_api)); 81 gvr::GvrApi::WrapNonOwned(reinterpret_cast<gvr_context*>(native_gvr_api));
82
83 device::GvrDelegateManager::GetInstance()->Initialize(this);
79 } 84 }
80 85
81 void VrShell::InitializeGl(JNIEnv* env, 86 void VrShell::InitializeGl(JNIEnv* env,
82 const base::android::JavaParamRef<jobject>& obj, 87 const base::android::JavaParamRef<jobject>& obj,
83 jint texture_data_handle) { 88 jint texture_data_handle) {
84 gl::init::InitializeGLOneOff(); 89 gl::init::InitializeGLOneOff();
85 gvr_api_->InitializeGl(); 90 gvr_api_->InitializeGl();
86 std::vector<gvr::BufferSpec> specs; 91 std::vector<gvr::BufferSpec> specs;
87 specs.push_back(gvr_api_->CreateBufferSpec()); 92 specs.push_back(gvr_api_->CreateBufferSpec());
88 render_size_ = specs[0].GetSize(); 93 render_size_ = specs[0].GetSize();
89 swap_chain_.reset(new gvr::SwapChain(gvr_api_->CreateSwapchain(specs))); 94 swap_chain_.reset(new gvr::SwapChain(gvr_api_->CreateSwapchain(specs)));
90 content_rect_.reset(new ContentRect()); 95 content_rect_.reset(new ContentRect());
91 content_rect_->content_texture_handle = 96 content_rect_->content_texture_handle =
92 reinterpret_cast<int>(texture_data_handle); 97 reinterpret_cast<int>(texture_data_handle);
93 vr_shell_renderer_.reset(new VrShellRenderer()); 98 vr_shell_renderer_.reset(new VrShellRenderer());
94 buffer_viewport_list_.reset( 99 buffer_viewport_list_.reset(
95 new gvr::BufferViewportList(gvr_api_->CreateEmptyBufferViewportList())); 100 new gvr::BufferViewportList(gvr_api_->CreateEmptyBufferViewportList()));
96 buffer_viewport_.reset( 101 buffer_viewport_.reset(
97 new gvr::BufferViewport(gvr_api_->CreateBufferViewport())); 102 new gvr::BufferViewport(gvr_api_->CreateBufferViewport()));
98 } 103 }
99 104
100 void VrShell::DrawFrame(JNIEnv* env, 105 void VrShell::DrawFrame(JNIEnv* env,
101 const base::android::JavaParamRef<jobject>& obj) { 106 const base::android::JavaParamRef<jobject>& obj) {
102 buffer_viewport_list_->SetToRecommendedBufferViewports(); 107 buffer_viewport_list_->SetToRecommendedBufferViewports();
103 gvr::Frame frame = swap_chain_->AcquireFrame(); 108 gvr::Frame frame = swap_chain_->AcquireFrame();
104 gvr::ClockTimePoint target_time = gvr::GvrApi::GetTimePointNow(); 109 gvr::ClockTimePoint target_time = gvr::GvrApi::GetTimePointNow();
105 target_time.monotonic_system_time_nanos += kPredictionTimeWithoutVsyncNanos; 110 target_time.monotonic_system_time_nanos += kPredictionTimeWithoutVsyncNanos;
106 head_pose_ = gvr_api_->GetHeadPoseInStartSpace(target_time); 111 head_pose_ = gvr_api_->GetHeadPoseInStartSpace(target_time);
107 112
113 // Bind back to the default framebuffer.
114 frame.BindBuffer(0);
115
116 if (webvr_mode_) {
117 DrawWebVr();
118 } else {
119 DrawVrShell();
120 }
121
122 frame.Unbind();
123 frame.Submit(*buffer_viewport_list_, head_pose_);
124 }
125
126 void VrShell::DrawVrShell() {
108 // Content area positioning. 127 // Content area positioning.
109 content_rect_->SetIdentity(); 128 content_rect_->SetIdentity();
110 content_rect_->Translate(kContentRectPositionDefault.x, 129 content_rect_->Translate(kContentRectPositionDefault.x,
111 kContentRectPositionDefault.y, 130 kContentRectPositionDefault.y,
112 kContentRectPositionDefault.z); 131 kContentRectPositionDefault.z);
113 132
114 gvr::Mat4f left_eye_view_matrix = 133 gvr::Mat4f left_eye_view_matrix =
115 MatrixMul(gvr_api_->GetEyeFromHeadMatrix(GVR_LEFT_EYE), head_pose_); 134 MatrixMul(gvr_api_->GetEyeFromHeadMatrix(GVR_LEFT_EYE), head_pose_);
116 gvr::Mat4f right_eye_view_matrix = 135 gvr::Mat4f right_eye_view_matrix =
117 MatrixMul(gvr_api_->GetEyeFromHeadMatrix(GVR_RIGHT_EYE), head_pose_); 136 MatrixMul(gvr_api_->GetEyeFromHeadMatrix(GVR_RIGHT_EYE), head_pose_);
118 137
119 // Bind back to the default framebuffer.
120 frame.BindBuffer(0);
121
122 // Use culling to remove back faces. 138 // Use culling to remove back faces.
123 glEnable(GL_CULL_FACE); 139 glEnable(GL_CULL_FACE);
124 140
125 // Enable depth testing. 141 // Enable depth testing.
126 glEnable(GL_DEPTH_TEST); 142 glEnable(GL_DEPTH_TEST);
127 glEnable(GL_SCISSOR_TEST); 143 glEnable(GL_SCISSOR_TEST);
128 144
129 glClearColor(0.1f, 0.1f, 0.1f, 1.0f); 145 glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
130 146
131 // Enable transparency. 147 // Enable transparency.
132 glEnable(GL_BLEND); 148 glEnable(GL_BLEND);
133 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 149 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
134 150
135 buffer_viewport_list_->GetBufferViewport(GVR_LEFT_EYE, 151 buffer_viewport_list_->GetBufferViewport(GVR_LEFT_EYE,
136 buffer_viewport_.get()); 152 buffer_viewport_.get());
137 DrawEye(left_eye_view_matrix, *buffer_viewport_); 153 DrawEye(left_eye_view_matrix, *buffer_viewport_);
138 buffer_viewport_list_->GetBufferViewport(GVR_RIGHT_EYE, 154 buffer_viewport_list_->GetBufferViewport(GVR_RIGHT_EYE,
139 buffer_viewport_.get()); 155 buffer_viewport_.get());
140 DrawEye(right_eye_view_matrix, *buffer_viewport_); 156 DrawEye(right_eye_view_matrix, *buffer_viewport_);
141
142 frame.Unbind();
143 frame.Submit(*buffer_viewport_list_, head_pose_);
144 } 157 }
145 158
146 void VrShell::DrawEye(const gvr::Mat4f& view_matrix, 159 void VrShell::DrawEye(const gvr::Mat4f& view_matrix,
147 const gvr::BufferViewport& params) { 160 const gvr::BufferViewport& params) {
148 gvr::Recti pixel_rect = 161 gvr::Recti pixel_rect =
149 CalculatePixelSpaceRect(render_size_, params.GetSourceUv()); 162 CalculatePixelSpaceRect(render_size_, params.GetSourceUv());
150 glViewport(pixel_rect.left, pixel_rect.bottom, 163 glViewport(pixel_rect.left, pixel_rect.bottom,
151 pixel_rect.right - pixel_rect.left, 164 pixel_rect.right - pixel_rect.left,
152 pixel_rect.top - pixel_rect.bottom); 165 pixel_rect.top - pixel_rect.bottom);
153 glScissor(pixel_rect.left, pixel_rect.bottom, 166 glScissor(pixel_rect.left, pixel_rect.bottom,
(...skipping 11 matching lines...) Expand all
165 178
166 void VrShell::DrawContentRect() { 179 void VrShell::DrawContentRect() {
167 gvr::Mat4f content_rect_combined_matrix = 180 gvr::Mat4f content_rect_combined_matrix =
168 MatrixMul(view_matrix_, content_rect_->transfrom_to_world); 181 MatrixMul(view_matrix_, content_rect_->transfrom_to_world);
169 content_rect_combined_matrix = 182 content_rect_combined_matrix =
170 MatrixMul(projection_matrix_, content_rect_combined_matrix); 183 MatrixMul(projection_matrix_, content_rect_combined_matrix);
171 vr_shell_renderer_->GetTexturedQuadRenderer()->Draw( 184 vr_shell_renderer_->GetTexturedQuadRenderer()->Draw(
172 content_rect_->content_texture_handle, content_rect_combined_matrix); 185 content_rect_->content_texture_handle, content_rect_combined_matrix);
173 } 186 }
174 187
188 void VrShell::DrawWebVr() {
189 // Don't need face culling, depth testing, blending, etc. Turn it all off.
190 glDisable(GL_CULL_FACE);
191 glDepthMask(GL_FALSE);
192 glDisable(GL_DEPTH_TEST);
193 glDisable(GL_SCISSOR_TEST);
194 glDisable(GL_BLEND);
195 glDisable(GL_POLYGON_OFFSET_FILL);
196
197 // Don't need to clear, since we're drawing over the entire render target.
198
199 glViewport(0, 0, render_size_.width, render_size_.height);
200 vr_shell_renderer_->GetWebVrRenderer()->Draw(
201 reinterpret_cast<int>(content_rect_->content_texture_handle));
202 }
203
175 void VrShell::OnPause(JNIEnv* env, 204 void VrShell::OnPause(JNIEnv* env,
176 const base::android::JavaParamRef<jobject>& obj) { 205 const base::android::JavaParamRef<jobject>& obj) {
177 if (gvr_api_ == nullptr) 206 if (gvr_api_ == nullptr)
178 return; 207 return;
179 gvr_api_->PauseTracking(); 208 gvr_api_->PauseTracking();
180 } 209 }
181 210
182 void VrShell::OnResume(JNIEnv* env, 211 void VrShell::OnResume(JNIEnv* env,
183 const base::android::JavaParamRef<jobject>& obj) { 212 const base::android::JavaParamRef<jobject>& obj) {
184 if (gvr_api_ == nullptr) 213 if (gvr_api_ == nullptr)
185 return; 214 return;
186 gvr_api_->RefreshViewerProfile(); 215 gvr_api_->RefreshViewerProfile();
187 gvr_api_->ResumeTracking(); 216 gvr_api_->ResumeTracking();
188 } 217 }
189 218
219 void VrShell::RequestWebVRPresent() {
220 webvr_mode_ = true;
221 }
222
223 void VrShell::ExitWebVRPresent() {
224 webvr_mode_ = false;
225 }
226
227 void VrShell::SubmitWebVRFrame() {
228 }
229
230 void VrShell::UpdateWebVRTextureBounds(
231 int eye, float left, float top, float width, float height) {
232 gvr::Rectf bounds = { left, top, width, height };
233 vr_shell_renderer_->GetWebVrRenderer()->UpdateTextureBounds(eye, bounds);
234 }
235
236 gvr::GvrApi* VrShell::gvr_api() {
237 return gvr_api_.get();
238 }
239
190 // ---------------------------------------------------------------------------- 240 // ----------------------------------------------------------------------------
191 // Native JNI methods 241 // Native JNI methods
192 // ---------------------------------------------------------------------------- 242 // ----------------------------------------------------------------------------
193 243
194 jlong Init(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj) { 244 jlong Init(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj) {
195 VrShell* vrShell = new VrShell(env, obj); 245 VrShell* vrShell = new VrShell(env, obj);
196 return reinterpret_cast<intptr_t>(vrShell); 246 return reinterpret_cast<intptr_t>(vrShell);
197 } 247 }
198 248
199 } // namespace vr_shell 249 } // namespace vr_shell
OLDNEW
« no previous file with comments | « chrome/browser/android/vr_shell/vr_shell.h ('k') | chrome/browser/android/vr_shell/vr_shell_renderer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698