Commit 3e140f29 authored by Michael Thiessen's avatar Michael Thiessen Committed by Commit Bot

VR: Update recommended WebVR resolution when density changes.

Bug: 767589
Change-Id: If3127d75eb4b7645979e478c0e5ce82916a27feb
Reviewed-on: https://chromium-review.googlesource.com/677958
Commit-Queue: Michael Thiessen <mthiesse@chromium.org>
Reviewed-by: default avatarBo <boliu@chromium.org>
Reviewed-by: default avatarBrandon Jones <bajones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#504411}
parent d77a1d01
......@@ -47,6 +47,9 @@ shared_library("libcontent_shell_content_view") {
"//device/sensors",
"//media/midi",
]
if (enable_vr) {
deps += [ "//device/vr" ]
}
}
sources = [
"shell_library_loader.cc",
......@@ -297,6 +300,9 @@ if (current_cpu != "x64") {
"//device/sensors",
"//media/midi",
]
if (enable_vr) {
deps += [ "//device/vr" ]
}
}
}
......
......@@ -131,6 +131,7 @@ if (is_android && (current_cpu == "arm" || current_cpu == "arm64")) {
deps = [
"//base:base_java",
"//third_party/gvr-android-sdk:gvr_common_java",
"//ui/android:ui_java",
]
}
}
......
......@@ -22,6 +22,8 @@
#include "ui/gfx/transform.h"
#include "ui/gfx/transform_util.h"
using base::android::JavaRef;
namespace device {
namespace {
......@@ -126,7 +128,8 @@ std::unique_ptr<GvrDevice> GvrDevice::Create() {
GvrDevice::GvrDevice() : VRDevice() {
GetGvrDelegateProvider();
JNIEnv* env = base::android::AttachCurrentThread();
non_presenting_context_.Reset(Java_NonPresentingGvrContext_create(env));
non_presenting_context_.Reset(
Java_NonPresentingGvrContext_create(env, reinterpret_cast<jlong>(this)));
if (!non_presenting_context_.obj())
return;
jlong context = Java_NonPresentingGvrContext_getNativeGvrContext(
......@@ -218,4 +221,10 @@ GvrDelegateProvider* GvrDevice::GetGvrDelegateProvider() {
return delegate_provider;
}
void GvrDevice::OnDIPScaleChanged(JNIEnv* env, const JavaRef<jobject>& obj) {
display_info_ = CreateVRDisplayInfo(
gvr_api_.get(), GetRecommendedWebVrSize(gvr_api_.get()), id());
OnChanged();
}
} // namespace device
......@@ -5,6 +5,8 @@
#ifndef DEVICE_VR_ANDROID_GVR_DEVICE_H
#define DEVICE_VR_ANDROID_GVR_DEVICE_H
#include <jni.h>
#include <memory>
#include "base/android/scoped_java_ref.h"
......@@ -37,6 +39,9 @@ class DEVICE_VR_EXPORT GvrDevice : public VRDevice {
void PauseTracking() override;
void ResumeTracking() override;
void OnDIPScaleChanged(JNIEnv* env,
const base::android::JavaRef<jobject>& obj);
private:
GvrDevice();
GvrDelegateProvider* GetGvrDelegateProvider();
......
include_rules = [
"+ui/android/java",
]
\ No newline at end of file
......@@ -15,6 +15,7 @@ import com.google.vr.ndk.base.GvrApi;
import org.chromium.base.ContextUtils;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace;
import org.chromium.ui.display.DisplayAndroid;
/**
* Creates an active GvrContext from a GvrApi created from the Application Context. This GvrContext
......@@ -22,10 +23,14 @@ import org.chromium.base.annotations.JNINamespace;
* parameters.
*/
@JNINamespace("device")
public class NonPresentingGvrContext {
public class NonPresentingGvrContext implements DisplayAndroid.DisplayAndroidObserver {
private GvrApi mGvrApi;
private DisplayAndroid mDisplayAndroid;
private NonPresentingGvrContext() {
private long mNativeGvrDevice;
private NonPresentingGvrContext(long nativeGvrDevice) {
mNativeGvrDevice = nativeGvrDevice;
Context context = ContextUtils.getApplicationContext();
WindowManager windowManager =
(WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
......@@ -39,12 +44,14 @@ public class NonPresentingGvrContext {
} finally {
StrictMode.setThreadPolicy(oldPolicy);
}
mDisplayAndroid = DisplayAndroid.getNonMultiDisplay(context);
mDisplayAndroid.addObserver(this);
}
@CalledByNative
private static NonPresentingGvrContext create() {
private static NonPresentingGvrContext create(long nativeNonPresentingGvrContext) {
try {
return new NonPresentingGvrContext();
return new NonPresentingGvrContext(nativeNonPresentingGvrContext);
} catch (IllegalStateException | UnsatisfiedLinkError e) {
return null;
}
......@@ -58,5 +65,18 @@ public class NonPresentingGvrContext {
@CalledByNative
private void shutdown() {
mGvrApi.shutdown();
mDisplayAndroid.removeObserver(this);
mNativeGvrDevice = 0;
}
public void onRotationChanged(int rotation) {}
public void onDIPScaleChanged(float dipScale) {
mGvrApi.refreshDisplayMetrics();
if (mNativeGvrDevice != 0) {
nativeOnDIPScaleChanged(mNativeGvrDevice);
}
}
private native void nativeOnDIPScaleChanged(long nativeGvrDevice);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment