| Index: chrome/browser/android/vr_shell/vr_shell.cc
|
| diff --git a/chrome/browser/android/vr_shell/vr_shell.cc b/chrome/browser/android/vr_shell/vr_shell.cc
|
| index 4416da93a63b0f6e05bb76957de9c43796284bf2..e64dc01e70ca52c99b02f8910bc9974739187f3d 100644
|
| --- a/chrome/browser/android/vr_shell/vr_shell.cc
|
| +++ b/chrome/browser/android/vr_shell/vr_shell.cc
|
| @@ -22,6 +22,7 @@
|
| #include "content/public/browser/web_contents.h"
|
| #include "content/public/common/referrer.h"
|
| #include "content/public/common/screen_info.h"
|
| +#include "device/vr/android/gvr/gvr_device_provider.h"
|
| #include "jni/VrShellImpl_jni.h"
|
| #include "ui/android/view_android.h"
|
| #include "ui/android/window_android.h"
|
| @@ -186,8 +187,7 @@ void VrShell::SetDelegate(JNIEnv* env,
|
| delegate_ = VrShellDelegate::getNativeDelegate(env, delegate);
|
| }
|
|
|
| -enum class ViewerType
|
| -{
|
| +enum class ViewerType {
|
| UNKNOWN_TYPE = 0,
|
| CARDBOARD = 1,
|
| DAYDREAM = 2,
|
| @@ -208,8 +208,7 @@ void VrShell::GvrInit(JNIEnv* env,
|
| ui_input_manager_ = new VrInputManager(ui_contents_);
|
|
|
| ViewerType viewerType;
|
| - switch (gvr_api_->GetViewerType())
|
| - {
|
| + switch (gvr_api_->GetViewerType()) {
|
| case gvr::ViewerType::GVR_VIEWER_TYPE_DAYDREAM:
|
| viewerType = ViewerType::DAYDREAM;
|
| break;
|
| @@ -271,7 +270,32 @@ void VrShell::InitializeGl(JNIEnv* env,
|
| void VrShell::UpdateController(const gvr::Vec3f& forward_vector) {
|
| controller_->UpdateState();
|
| std::unique_ptr<WebGestureEvent> gesture = controller_->DetectGesture();
|
| -
|
| +#if defined(ENABLE_VR_SHELL)
|
| + // Note that button up/down state is transient, so IsButtonUp only returns
|
| + // true for a single frame (and we're guaranteed not to miss it).
|
| + if (controller_->IsButtonUp(
|
| + gvr::ControllerButton::GVR_CONTROLLER_BUTTON_APP)) {
|
| + if (html_interface_->GetMode() == UiInterface::Mode::MENU) {
|
| + // Temporary: Hit app button a second time to exit menu mode.
|
| + if (webvr_mode_) {
|
| + html_interface_->SetMode(UiInterface::Mode::WEB_VR);
|
| + delegate_->GetDeviceProvider()->OnDisplayFocus();
|
| + } else {
|
| + html_interface_->SetMode(UiInterface::Mode::STANDARD);
|
| + }
|
| + } else {
|
| + if (html_interface_->GetMode() == UiInterface::Mode::WEB_VR) {
|
| + delegate_->GetDeviceProvider()->OnDisplayBlur();
|
| + }
|
| + html_interface_->SetMode(UiInterface::Mode::MENU);
|
| + // TODO(mthiesse): The page is no longer visible here. We should unfocus
|
| + // or otherwise let it know it's hidden.
|
| + }
|
| + }
|
| +#endif
|
| + if (html_interface_->GetMode() == UiInterface::Mode::WEB_VR) {
|
| + return;
|
| + }
|
| // TODO(asimjour) for now, scroll is sent to the main content.
|
| if (gesture->type == WebInputEvent::GestureScrollBegin ||
|
| gesture->type == WebInputEvent::GestureScrollUpdate ||
|
| @@ -411,7 +435,7 @@ uint32_t GetPixelEncodedPoseIndex() {
|
| // encodes the pose index, and device/vr/android/gvr/gvr_device.cc
|
| // which tracks poses.
|
| uint8_t pixels[4];
|
| - // Assume we're reading from the frambebuffer we just wrote to.
|
| + // Assume we're reading from the framebuffer we just wrote to.
|
| // That's true currently, we may need to use glReadBuffer(GL_BACK)
|
| // or equivalent if the rendering setup changes in the future.
|
| glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
|
| @@ -449,7 +473,7 @@ void VrShell::DrawFrame(JNIEnv* env, const JavaParamRef<jobject>& obj) {
|
|
|
| UpdateController(GetForwardVector(head_pose));
|
|
|
| - if (webvr_mode_) {
|
| + if (html_interface_->GetMode() == UiInterface::Mode::WEB_VR) {
|
| DrawWebVr();
|
|
|
| // When using async reprojection, we need to know which pose was used in
|
| @@ -486,16 +510,16 @@ void VrShell::DrawVrShell(const gvr::Mat4f& head_pose,
|
| }
|
| }
|
|
|
| - if (!webvr_mode_) {
|
| + bool not_web_vr = html_interface_->GetMode() != UiInterface::Mode::WEB_VR;
|
| +
|
| + if (not_web_vr) {
|
| glEnable(GL_CULL_FACE);
|
| glEnable(GL_DEPTH_TEST);
|
| glEnable(GL_SCISSOR_TEST);
|
| glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
|
| }
|
|
|
| - if (!world_elements.empty()) {
|
| - DrawUiView(&head_pose, world_elements);
|
| - }
|
| + DrawUiView(&head_pose, world_elements, not_web_vr);
|
|
|
| if (!head_locked_elements.empty()) {
|
| // Switch to head-locked viewports.
|
| @@ -507,14 +531,14 @@ void VrShell::DrawVrShell(const gvr::Mat4f& head_pose,
|
|
|
| // Bind the headlocked framebuffer.
|
| frame.BindBuffer(kFrameHeadlockedBuffer);
|
| - glClear(GL_COLOR_BUFFER_BIT);
|
| -
|
| - DrawUiView(nullptr, head_locked_elements);
|
| + glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
| + DrawUiView(nullptr, head_locked_elements, true);
|
| }
|
| }
|
|
|
| void VrShell::DrawUiView(const gvr::Mat4f* head_pose,
|
| - const std::vector<const ContentRectangle*>& elements) {
|
| + const std::vector<const ContentRectangle*>& elements,
|
| + bool clear) {
|
| for (auto eye : {GVR_LEFT_EYE, GVR_RIGHT_EYE}) {
|
| buffer_viewport_list_->GetBufferViewport(eye, buffer_viewport_.get());
|
|
|
| @@ -532,7 +556,7 @@ void VrShell::DrawUiView(const gvr::Mat4f* head_pose,
|
| pixel_rect.right - pixel_rect.left,
|
| pixel_rect.top - pixel_rect.bottom);
|
|
|
| - if (!webvr_mode_) {
|
| + if (clear) {
|
| glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
| }
|
|
|
| @@ -655,9 +679,6 @@ void VrShell::DrawWebVr() {
|
| glDisable(GL_BLEND);
|
| glDisable(GL_POLYGON_OFFSET_FILL);
|
|
|
| - // Don't need to clear, since we're drawing over the entire render target.
|
| - glClear(GL_COLOR_BUFFER_BIT);
|
| -
|
| glViewport(0, 0, render_size_.width, render_size_.height);
|
| vr_shell_renderer_->GetWebVrRenderer()->Draw(content_texture_id_);
|
| }
|
|
|