Commit 6234388d authored by Eric Karl's avatar Eric Karl Committed by Commit Bot

Add DeJellyUtils.java

Adds Android-specific customization of de-jelly effect based on display
properties.

Bug: 995965
Change-Id: Ie48ddf1e3f61d601e05522cf1f7b99a3dc25f012
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1837115
Commit-Queue: Eric Karl <ericrk@chromium.org>
Reviewed-by: default avatarAndrew Grieve <agrieve@chromium.org>
Reviewed-by: default avatarBo <boliu@chromium.org>
Reviewed-by: default avatarenne <enne@chromium.org>
Cr-Commit-Position: refs/heads/master@{#705760}
parent c880db15
......@@ -632,6 +632,7 @@ android_library("browser_java") {
"//components/variations:load_seed_result_enum_java",
"//components/variations/android:variations_java",
"//components/version_info/android:version_constants_java",
"//components/viz/common:common_java",
"//content/public/android:content_java",
"//device/gamepad:java",
"//mojo/public/java:system_java",
......
......@@ -325,6 +325,7 @@ android_library("chrome_java") {
"//components/url_formatter/android:url_formatter_java",
"//components/variations/android:variations_java",
"//components/version_info/android:version_constants_java",
"//components/viz/common:common_java",
"//components/viz/service:service_java",
"//content/public/android:content_java",
"//device/gamepad:java",
......
......@@ -278,7 +278,10 @@ viz_component("common") {
}
if (is_android) {
deps += [ "//gpu/config" ]
deps += [
":common_jni_headers",
"//gpu/config",
]
}
if (is_chromecast) {
......@@ -396,3 +399,20 @@ viz_source_set("perf_tests") {
"//testing/perf",
]
}
if (is_android) {
android_library("common_java") {
deps = [
"//base:base_java",
]
java_files = [
"java/src/org/chromium/components/viz/common/display/DeJellyUtils.java",
]
}
generate_jni("common_jni_headers") {
sources = [
"java/src/org/chromium/components/viz/common/display/DeJellyUtils.java",
]
}
}
......@@ -5,8 +5,16 @@
#include "components/viz/common/display/de_jelly.h"
#include "base/command_line.h"
#include "build/build_config.h"
#include "components/viz/common/switches.h"
#if defined(OS_ANDROID)
#include "base/android/jni_android.h"
#include "base/android/jni_string.h"
#include "base/time/time.h"
#include "components/viz/common/common_jni_headers/DeJellyUtils_jni.h"
#endif
namespace viz {
bool DeJellyEnabled() {
......@@ -15,8 +23,14 @@ bool DeJellyEnabled() {
}
bool DeJellyActive() {
// TODO(ericrk): Android specific bits to be added in a follow-up CL.
return DeJellyEnabled();
if (!DeJellyEnabled())
return false;
#if defined(OS_ANDROID)
return Java_DeJellyUtils_useDeJelly(base::android::AttachCurrentThread());
#endif
return true;
}
float DeJellyScreenWidth() {
......@@ -26,8 +40,10 @@ float DeJellyScreenWidth() {
if (!value.empty())
return std::atoi(value.c_str());
// TODO(ericrk): We can automatically handle this on Android. For now return
// a reasonable default.
#if defined(OS_ANDROID)
return Java_DeJellyUtils_screenWidth(base::android::AttachCurrentThread());
#endif
return 1440.0f;
}
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.components.viz.common.display;
import android.content.ComponentCallbacks;
import android.content.Context;
import android.content.res.Configuration;
import android.graphics.Point;
import android.hardware.display.DisplayManager;
import android.provider.Settings.Global;
import android.view.Display;
import android.view.Surface;
import org.chromium.base.ContextUtils;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.MainDex;
import java.lang.reflect.Field;
/**
* Provides static utility functions to query de-jelly settings.
*/
@JNINamespace("viz")
@MainDex
public class DeJellyUtils implements DisplayManager.DisplayListener, ComponentCallbacks {
/** Singleton DeJellyUtils instance */
private static DeJellyUtils sInstance;
/**
* @return The DeJellyUtils singleton.
*/
private static DeJellyUtils getInstance() {
if (sInstance == null) sInstance = new DeJellyUtils();
return sInstance;
}
/** Whether the last processed rotation should have de-jelly applied. */
private boolean mRotationOk;
/** Whether the last processed configuration should have de-jelly applied. */
private boolean mConfigurationOk;
/** The last processed screen width. */
private float mScreenWidth;
/** Cached DisplayManager. */
private DisplayManager mManager;
/** Field used to identify in-use screen on some devices. */
private Field mDisplayDeviceType;
/** Int representing the sub-display, used with mDisplayDeviceType. */
private static final int SEM_DISPLAY_DEVICE_TYPE_SUB = 5;
private DeJellyUtils() {
// TODO(ericrk): We should probably plumb display information from the
// browser process, rather than re-querying it here.
mManager = (DisplayManager) ContextUtils.getApplicationContext().getSystemService(
Context.DISPLAY_SERVICE);
// Register callbacks which will notify of future changes.
mManager.registerDisplayListener(this, null);
ContextUtils.getApplicationContext().registerComponentCallbacks(this);
// Get current state, as we may need these values and callbacks will not yet have fired.
onDisplayChanged(0);
onConfigurationChanged(
ContextUtils.getApplicationContext().getResources().getConfiguration());
// See if we have a display device type field to query.
try {
Class configurationClass = Configuration.class;
mDisplayDeviceType = configurationClass.getDeclaredField("semDisplayDeviceType");
} catch (Exception e) {
// We do not require mDisplayDeviceType to exist. Continue.
}
}
// DisplayManager.DisplayListener implementation.
@Override
public void onDisplayAdded(int displayId) {}
@Override
public void onDisplayChanged(int displayId) {
// Ignore non-default display.
if (displayId != Display.DEFAULT_DISPLAY) return;
Display display = mManager.getDisplay(displayId);
// For now only support ROTATION_0.
// TODO(ericrk): Allow this to be customized.
int rotation = display.getRotation();
mRotationOk = rotation == Surface.ROTATION_0;
Point realSize = new Point();
display.getRealSize(realSize);
mScreenWidth = realSize.x;
}
@Override
public void onDisplayRemoved(int displayId) {}
// ComponentCallbacks implementation.
@Override
public void onConfigurationChanged(Configuration configuration) {
if (mDisplayDeviceType != null) {
try {
mConfigurationOk =
mDisplayDeviceType.getInt(configuration) != SEM_DISPLAY_DEVICE_TYPE_SUB;
return;
} catch (Exception e) {
// We don't require that this field exists, continue.
}
}
// Configuration is always ok if we can't query mDisplayDeviceType.
mConfigurationOk = true;
}
@Override
public void onLowMemory() {}
/**
* @return Whether the current screen / configuration should use the de-jelly effect.
*/
@CalledByNative
private static boolean useDeJelly() {
DeJellyUtils utils = getInstance();
// Device specific flag which force-disables jelly scroll on a per-frame basis.
if (Global.getInt(ContextUtils.getApplicationContext().getContentResolver(),
"sem_support_scroll_filter", 1)
== 0) {
return false;
}
return utils.mRotationOk && utils.mConfigurationOk;
}
/**
* @return the current screen width.
*/
@CalledByNative
private static float screenWidth() {
return getInstance().mScreenWidth;
}
};
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