Commit 2d67dc21 authored by boliu's avatar boliu Committed by Commit bot

android: Remove DeviceDisplayInfo from ResourceBundle

Instead, copy the logic to get the primary display density in
resource_bundle_android. Note this is not using Display to avoid
initializing Display backend in any child process.

BUG=625089

Review-Url: https://codereview.chromium.org/2616203002
Cr-Commit-Position: refs/heads/master@{#442615}
parent a52cc54f
...@@ -4,9 +4,14 @@ ...@@ -4,9 +4,14 @@
package org.chromium.ui.base; package org.chromium.ui.base;
import android.util.DisplayMetrics;
import android.view.Display;
import org.chromium.base.BuildConfig; import org.chromium.base.BuildConfig;
import org.chromium.base.ContextUtils;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace; import org.chromium.base.annotations.JNINamespace;
import org.chromium.ui.display.DisplayAndroidManager;
import java.util.Arrays; import java.util.Arrays;
...@@ -15,7 +20,9 @@ import java.util.Arrays; ...@@ -15,7 +20,9 @@ import java.util.Arrays;
* library. * library.
*/ */
@JNINamespace("ui") @JNINamespace("ui")
public class ResourceBundle { final class ResourceBundle {
private ResourceBundle() {}
@CalledByNative @CalledByNative
private static String getLocalePakResourcePath(String locale) { private static String getLocalePakResourcePath(String locale) {
if (Arrays.binarySearch(BuildConfig.UNCOMPRESSED_LOCALES, locale) >= 0) { if (Arrays.binarySearch(BuildConfig.UNCOMPRESSED_LOCALES, locale) >= 0) {
...@@ -23,4 +30,13 @@ public class ResourceBundle { ...@@ -23,4 +30,13 @@ public class ResourceBundle {
} }
return null; return null;
} }
@CalledByNative
private static float getPrimaryDisplayScale() {
Display primaryDisplay = DisplayAndroidManager.getDefaultDisplayForContext(
ContextUtils.getApplicationContext());
DisplayMetrics displayMetrics = new DisplayMetrics();
primaryDisplay.getMetrics(displayMetrics);
return displayMetrics.density;
}
} }
...@@ -26,7 +26,7 @@ import org.chromium.ui.gfx.DeviceDisplayInfo; ...@@ -26,7 +26,7 @@ import org.chromium.ui.gfx.DeviceDisplayInfo;
* DisplayAndroidManager is a class that informs its observers Display changes. * DisplayAndroidManager is a class that informs its observers Display changes.
*/ */
@JNINamespace("ui") @JNINamespace("ui")
/* package */ class DisplayAndroidManager { public class DisplayAndroidManager {
/** /**
* DisplayListenerBackend is an interface that abstract the mechanism used for the actual * DisplayListenerBackend is an interface that abstract the mechanism used for the actual
* display update listening. The reason being that from Android API Level 17 DisplayListener * display update listening. The reason being that from Android API Level 17 DisplayListener
...@@ -204,7 +204,7 @@ import org.chromium.ui.gfx.DeviceDisplayInfo; ...@@ -204,7 +204,7 @@ import org.chromium.ui.gfx.DeviceDisplayInfo;
return sDisplayAndroidManager; return sDisplayAndroidManager;
} }
/* package */ static Display getDefaultDisplayForContext(Context context) { public static Display getDefaultDisplayForContext(Context context) {
WindowManager windowManager = WindowManager windowManager =
(WindowManager) context.getSystemService(Context.WINDOW_SERVICE); (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
return windowManager.getDefaultDisplay(); return windowManager.getDefaultDisplay();
......
...@@ -44,7 +44,6 @@ ...@@ -44,7 +44,6 @@
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
#include "ui/base/resource/resource_bundle_android.h" #include "ui/base/resource/resource_bundle_android.h"
#include "ui/gfx/android/device_display_info.h"
#endif #endif
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
...@@ -693,8 +692,7 @@ void ResourceBundle::InitSharedInstance(Delegate* delegate) { ...@@ -693,8 +692,7 @@ void ResourceBundle::InitSharedInstance(Delegate* delegate) {
if (display::Display::HasForceDeviceScaleFactor()) { if (display::Display::HasForceDeviceScaleFactor()) {
display_density = display::Display::GetForcedDeviceScaleFactor(); display_density = display::Display::GetForcedDeviceScaleFactor();
} else { } else {
gfx::DeviceDisplayInfo device_info; display_density = GetPrimaryDisplayScale();
display_density = device_info.GetDIPScale();
} }
const ScaleFactor closest = FindClosestScaleFactorUnsafe(display_density); const ScaleFactor closest = FindClosestScaleFactorUnsafe(display_density);
if (closest != SCALE_FACTOR_100P) if (closest != SCALE_FACTOR_100P)
......
...@@ -166,4 +166,9 @@ std::string GetPathForAndroidLocalePakWithinApk(const std::string& locale) { ...@@ -166,4 +166,9 @@ std::string GetPathForAndroidLocalePakWithinApk(const std::string& locale) {
return base::android::ConvertJavaStringToUTF8(env, ret.obj()); return base::android::ConvertJavaStringToUTF8(env, ret.obj());
} }
float GetPrimaryDisplayScale() {
return Java_ResourceBundle_getPrimaryDisplayScale(
base::android::AttachCurrentThread());
}
} // namespace ui } // namespace ui
...@@ -41,6 +41,10 @@ UI_BASE_EXPORT void SetLocalePaksStoredInApk(bool value); ...@@ -41,6 +41,10 @@ UI_BASE_EXPORT void SetLocalePaksStoredInApk(bool value);
UI_BASE_EXPORT std::string GetPathForAndroidLocalePakWithinApk( UI_BASE_EXPORT std::string GetPathForAndroidLocalePakWithinApk(
const std::string& locale); const std::string& locale);
// Get the density of the primary display. Use this instead of using Display
// to avoid initializing Display in child processes.
float GetPrimaryDisplayScale();
} // namespace ui } // namespace ui
#endif // UI_BASE_RESOURCE_RESOURCE_BUNDLE_ANDROID_H_ #endif // UI_BASE_RESOURCE_RESOURCE_BUNDLE_ANDROID_H_
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