Index: ui/gfx/android/device_display_info.cc |
diff --git a/ui/gfx/android/device_display_info.cc b/ui/gfx/android/device_display_info.cc |
index 4d2c80c09d6c1d9c4c87102e0138901222943fb9..e55d67fa7d18d9cf38b2c7e853c9ac9f504c2d09 100644 |
--- a/ui/gfx/android/device_display_info.cc |
+++ b/ui/gfx/android/device_display_info.cc |
@@ -2,53 +2,104 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
+#include "jni/DeviceDisplayInfo_jni.h" |
#include "ui/gfx/android/device_display_info.h" |
-#include "base/logging.h" |
-#include "ui/gfx/android/shared_device_display_info.h" |
- |
namespace gfx { |
+DeviceDisplayInfo::DeviceDisplayInfo( |
jdduke (slow)
2015/06/16 15:01:28
So, there's an assumption currently that creating
gsennton
2015/06/17 11:40:36
Potentially stupid question from my part -- why is
jdduke (slow)
2015/06/17 15:56:04
Now we have to construct a new Java object, and ca
boliu
2015/06/17 16:02:20
The bigger issue is to avoid gc pauses. Eg during
gsennton
2015/06/18 11:37:22
Oh, right, I missed this entirely -- if jni calls
gsennton
2015/06/25 13:59:58
To answer the original question here,
Chrome:
Whe
|
+ base::android::ScopedJavaLocalRef<jobject> context) { |
+ JNIEnv* env = base::android::AttachCurrentThread(); |
+ j_device_info_.Reset( |
+ Java_DeviceDisplayInfo_create(env, context.obj())); |
+ FetchDisplayInfoFromJava(env); |
+} |
+ |
DeviceDisplayInfo::DeviceDisplayInfo() { |
+ JNIEnv* env = base::android::AttachCurrentThread(); |
+ j_device_info_.Reset( |
jdduke (slow)
2015/06/17 15:56:04
It's a shame to have to create a Java object here
gsennton
2015/06/18 11:37:22
We could cache the primary display info in some sh
|
+ Java_DeviceDisplayInfo_create(env, |
+ base::android::GetApplicationContext())); |
+ FetchDisplayInfoFromJava(env); |
} |
DeviceDisplayInfo::~DeviceDisplayInfo() { |
} |
+void DeviceDisplayInfo::FetchDisplayInfoFromJava(JNIEnv* env) { |
+ UpdateDisplayInfo( |
+ Java_DeviceDisplayInfo_getDisplayHeight(env, j_device_info_.obj()), |
+ Java_DeviceDisplayInfo_getDisplayWidth(env, j_device_info_.obj()), |
+ Java_DeviceDisplayInfo_getPhysicalDisplayHeight(env, |
+ j_device_info_.obj()), |
+ Java_DeviceDisplayInfo_getPhysicalDisplayWidth(env, j_device_info_.obj()), |
+ Java_DeviceDisplayInfo_getBitsPerPixel(env, j_device_info_.obj()), |
+ Java_DeviceDisplayInfo_getBitsPerComponent(env, j_device_info_.obj()), |
+ Java_DeviceDisplayInfo_getDIPScale(env, j_device_info_.obj()), |
+ Java_DeviceDisplayInfo_getSmallestDIPWidth(env, j_device_info_.obj()), |
+ Java_DeviceDisplayInfo_getRotationDegrees(env, j_device_info_.obj())); |
+} |
+ |
+void DeviceDisplayInfo::UpdateDisplayInfo(jint display_height, |
+ jint display_width, |
+ jint physical_display_height, |
+ jint physical_display_width, |
+ jint bits_per_pixel, |
+ jint bits_per_component, |
+ jdouble dip_scale, |
+ jint smallest_dip_width, |
+ jint rotation_degrees) { |
+ display_height_ = static_cast<int>(display_height); |
+ display_width_ = static_cast<int>(display_width); |
+ physical_display_height_ = static_cast<int>(physical_display_height); |
+ physical_display_width_ = static_cast<int>(physical_display_width); |
+ bits_per_pixel_ = static_cast<int>(bits_per_pixel); |
+ bits_per_component_ = static_cast<int>(bits_per_component); |
+ dip_scale_ = static_cast<double>(dip_scale); |
+ smallest_dip_width_ = static_cast<int>(smallest_dip_width); |
+ rotation_degrees_ = static_cast<int>(rotation_degrees); |
+} |
+ |
+// TODO all these can be const if we only return the stored values here |
int DeviceDisplayInfo::GetDisplayHeight() { |
- return SharedDeviceDisplayInfo::GetInstance()->GetDisplayHeight(); |
+ return display_height_; |
} |
int DeviceDisplayInfo::GetDisplayWidth() { |
- return SharedDeviceDisplayInfo::GetInstance()->GetDisplayWidth(); |
+ return display_width_; |
} |
int DeviceDisplayInfo::GetPhysicalDisplayHeight() { |
- return SharedDeviceDisplayInfo::GetInstance()->GetPhysicalDisplayHeight(); |
+ return physical_display_height_; |
} |
int DeviceDisplayInfo::GetPhysicalDisplayWidth() { |
- return SharedDeviceDisplayInfo::GetInstance()->GetPhysicalDisplayWidth(); |
+ return physical_display_width_; |
} |
int DeviceDisplayInfo::GetBitsPerPixel() { |
- return SharedDeviceDisplayInfo::GetInstance()->GetBitsPerPixel(); |
+ return bits_per_pixel_; |
} |
int DeviceDisplayInfo::GetBitsPerComponent() { |
- return SharedDeviceDisplayInfo::GetInstance()->GetBitsPerComponent(); |
+ return bits_per_component_; |
} |
double DeviceDisplayInfo::GetDIPScale() { |
- return SharedDeviceDisplayInfo::GetInstance()->GetDIPScale(); |
+ return dip_scale_; |
} |
int DeviceDisplayInfo::GetSmallestDIPWidth() { |
- return SharedDeviceDisplayInfo::GetInstance()->GetSmallestDIPWidth(); |
+ return smallest_dip_width_; |
} |
int DeviceDisplayInfo::GetRotationDegrees() { |
- return SharedDeviceDisplayInfo::GetInstance()->GetRotationDegrees(); |
+ return rotation_degrees_; |
+} |
+ |
+// static |
+bool DeviceDisplayInfo::RegisterDeviceDisplayInfo(JNIEnv* env) { |
+ return RegisterNativesImpl(env); |
} |
} // namespace gfx |