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..208a7bf7cdeba85d631a05b7f0cb7dfdce8f90c1 100644 |
--- a/ui/gfx/android/device_display_info.cc |
+++ b/ui/gfx/android/device_display_info.cc |
@@ -2,53 +2,108 @@ |
// 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() { |
+DeviceDisplayInfo::DeviceDisplayInfo(jobject windowAndroid) { |
+ JNIEnv* env = base::android::AttachCurrentThread(); |
+ j_device_info_.Reset( |
+ Java_DeviceDisplayInfo_createFromWindow(env, windowAndroid)); |
+ 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())); |
+} |
+ |
+DeviceDisplayInfo::DeviceDisplayInfo() { // TODO ugly? |
boliu
2015/06/01 15:30:18
c++11 allows just calling the other constructor no
gsennton
2015/06/04 14:10:29
I am not sure what you mean by this? The other con
boliu
2015/06/05 04:57:51
Oh good point. But you could factor out the body o
|
+ JNIEnv* env = base::android::AttachCurrentThread(); |
+ j_device_info_.Reset( |
+ Java_DeviceDisplayInfo_create(env, |
+ base::android::GetApplicationContext())); |
+ 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())); |
} |
DeviceDisplayInfo::~DeviceDisplayInfo() { |
} |
+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); |
+} |
+ |
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 |