| 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 9f1bb69260ffe0abdcdd3bbe6189d19fcd743a16..34a0811ca4995f40829c22bbf65c82498eee98e6 100644
|
| --- a/chrome/browser/android/vr_shell/vr_shell.cc
|
| +++ b/chrome/browser/android/vr_shell/vr_shell.cc
|
| @@ -25,10 +25,14 @@
|
| #include "ui/android/view_android.h"
|
| #include "ui/android/window_android.h"
|
| #include "ui/base/page_transition_types.h"
|
| +#include "ui/display/android/screen_android.h"
|
| +#include "ui/display/display.h"
|
| +#include "ui/gfx/android/device_display_info.h"
|
| #include "ui/gl/gl_bindings.h"
|
| #include "ui/gl/init/gl_factory.h"
|
|
|
| using base::android::JavaParamRef;
|
| +using base::android::ScopedJavaLocalRef;
|
|
|
| namespace {
|
| // Constant taken from treasure_hunt demo.
|
| @@ -89,6 +93,9 @@ static constexpr float kWebVrWarningPermanentAngle = 16.3f; // degrees up
|
| // How long the transient warning needs to be displayed.
|
| static constexpr int64_t kWebVrWarningSeconds = 30;
|
|
|
| +static constexpr int kContentDisplayId = 1;
|
| +static constexpr int kUiDisplayId = 2;
|
| +
|
| vr_shell::VrShell* g_instance;
|
|
|
| static const char kVrShellUIURL[] = "chrome://vr-shell-ui";
|
| @@ -124,6 +131,16 @@ gvr::Quatf GetRotationFromZAxis(gvr::Vec3f vec) {
|
| return quat;
|
| }
|
|
|
| +void populateDisplayWithDefaults(display::Display& display, float dpr,
|
| + gfx::Rect bounds) {
|
| + gfx::DeviceDisplayInfo device_info;
|
| + display.SetScaleAndBounds(dpr, bounds);
|
| + display.SetRotationAsDegree(device_info.GetRotationDegrees());
|
| + display.set_color_depth(device_info.GetBitsPerPixel());
|
| + display.set_depth_per_component(device_info.GetBitsPerComponent());
|
| + display.set_is_monochrome(device_info.GetBitsPerComponent() == 0);
|
| +}
|
| +
|
| } // namespace
|
|
|
| namespace vr_shell {
|
| @@ -164,6 +181,11 @@ void VrShell::UpdateCompositorLayers(JNIEnv* env,
|
| const JavaParamRef<jobject>& obj) {
|
| content_compositor_->SetLayer(main_contents_);
|
| ui_compositor_->SetLayer(ui_contents_);
|
| +
|
| + // TODO(mthiesse): These are temporary placeholders until the UI js is
|
| + // updated to call these functions.
|
| + SetUiCssSize(1920, 1080, 1.0);
|
| + SetContentCssSize(1280, 720, 1.0);
|
| }
|
|
|
| void VrShell::Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj) {
|
| @@ -182,6 +204,10 @@ bool RegisterVrShell(JNIEnv* env) {
|
| }
|
|
|
| VrShell::~VrShell() {
|
| + display::ScreenAndroid* screen = reinterpret_cast<display::ScreenAndroid*>(
|
| + display::Screen::GetScreen());
|
| + screen->ClearDisplayForWindow(ui_contents_->GetNativeView());
|
| + screen->ClearDisplayForWindow(main_contents_->GetNativeView());
|
| g_instance = nullptr;
|
| gl::init::ClearGLBindings();
|
| }
|
| @@ -781,31 +807,28 @@ gvr::GvrApi* VrShell::gvr_api() {
|
| return gvr_api_.get();
|
| }
|
|
|
| -void VrShell::ContentSurfaceChanged(JNIEnv* env,
|
| - const JavaParamRef<jobject>& object,
|
| - jint width,
|
| - jint height,
|
| - const JavaParamRef<jobject>& surface) {
|
| - content_compositor_->SurfaceChanged((int)width, (int)height, surface);
|
| - content::ScreenInfo result;
|
| - main_contents_->GetRenderWidgetHostView()->GetRenderWidgetHost()->
|
| - GetScreenInfo(&result);
|
| - float dpr = result.device_scale_factor;
|
| - scene_->GetUiElementById(kBrowserUiElementId)->copy_rect =
|
| - { 0, 0, width / dpr, height / dpr };
|
| +void VrShell::SurfacesChanged(JNIEnv* env,
|
| + const JavaParamRef<jobject>& object,
|
| + const JavaParamRef<jobject>& content_surface,
|
| + const JavaParamRef<jobject>& ui_surface) {
|
| + content_compositor_->SurfaceChanged(content_surface);
|
| + ui_compositor_->SurfaceChanged(ui_surface);
|
| }
|
|
|
| -void VrShell::UiSurfaceChanged(JNIEnv* env,
|
| - const JavaParamRef<jobject>& object,
|
| - jint width,
|
| - jint height,
|
| - const JavaParamRef<jobject>& surface) {
|
| - ui_compositor_->SurfaceChanged((int)width, (int)height, surface);
|
| - content::ScreenInfo result;
|
| - ui_contents_->GetRenderWidgetHostView()->GetRenderWidgetHost()->GetScreenInfo(
|
| - &result);
|
| - ui_tex_width_ = width / result.device_scale_factor;
|
| - ui_tex_height_ = height / result.device_scale_factor;
|
| +void VrShell::ContentBoundsChanged(JNIEnv* env,
|
| + const JavaParamRef<jobject>& object,
|
| + jint width, jint height) {
|
| + content_compositor_->SetWindowBounds(width, height);
|
| + main_contents_->GetRenderWidgetHostView()->GetRenderWidgetHost()
|
| + ->WasResized();
|
| +}
|
| +
|
| +void VrShell::UIBoundsChanged(JNIEnv* env,
|
| + const JavaParamRef<jobject>& object,
|
| + jint width,
|
| + jint height) {
|
| + ui_compositor_->SetWindowBounds(width, height);
|
| + ui_contents_->GetRenderWidgetHostView()->GetRenderWidgetHost()->WasResized();
|
| }
|
|
|
| UiScene* VrShell::GetScene() {
|
| @@ -856,6 +879,43 @@ void VrShell::DoUiAction(const UiAction action) {
|
| }
|
| }
|
|
|
| +void VrShell::SetContentCssSize(float width, float height, float dpr) {
|
| + const gfx::Rect bounds_in_pixels = gfx::Rect(gfx::ScaleToCeiledSize(
|
| + gfx::Size(width, height), dpr));
|
| + display::Display display(kContentDisplayId);
|
| +
|
| + populateDisplayWithDefaults(display, dpr, bounds_in_pixels);
|
| +
|
| + display::ScreenAndroid* screen = reinterpret_cast<display::ScreenAndroid*>(
|
| + display::Screen::GetScreen());
|
| + screen->SetDisplayForWindow(main_contents_->GetNativeView(), display);
|
| +
|
| + JNIEnv* env = base::android::AttachCurrentThread();
|
| + Java_VrShellImpl_setContentCssSize(env, j_vr_shell_.obj(), width, height,
|
| + dpr);
|
| +
|
| + scene_->GetUiElementById(kBrowserUiElementId)->copy_rect =
|
| + { 0, 0, width, height };
|
| +}
|
| +
|
| +void VrShell::SetUiCssSize(float width, float height, float dpr) {
|
| + const gfx::Rect bounds_in_pixels = gfx::Rect(gfx::ScaleToCeiledSize(
|
| + gfx::Size(width, height), dpr));
|
| + display::Display display(kUiDisplayId);
|
| +
|
| + populateDisplayWithDefaults(display, dpr, bounds_in_pixels);
|
| +
|
| + display::ScreenAndroid* screen = reinterpret_cast<display::ScreenAndroid*>(
|
| + display::Screen::GetScreen());
|
| + screen->SetDisplayForWindow(ui_contents_->GetNativeView(), display);
|
| +
|
| + JNIEnv* env = base::android::AttachCurrentThread();
|
| + Java_VrShellImpl_setUiCssSize(env, j_vr_shell_.obj(), width, height, dpr);
|
| +
|
| + ui_tex_width_ = width;
|
| + ui_tex_height_ = height;
|
| +}
|
| +
|
| // ----------------------------------------------------------------------------
|
| // Native JNI methods
|
| // ----------------------------------------------------------------------------
|
|
|