Index: ui/gfx/android/shared_device_display_info.cc |
diff --git a/ui/gfx/android/shared_device_display_info.cc b/ui/gfx/android/shared_device_display_info.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..8e887121ed02fffd8a9aa27fff2596a404b10c4b |
--- /dev/null |
+++ b/ui/gfx/android/shared_device_display_info.cc |
@@ -0,0 +1,112 @@ |
+// Copyright (c) 2012 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. |
+ |
+#include "ui/gfx/android/shared_device_display_info.h" |
+ |
+#include "base/android/jni_android.h" |
+#include "base/android/jni_string.h" |
+#include "base/logging.h" |
+#include "jni/DeviceDisplayInfo_jni.h" |
+ |
+using base::android::AttachCurrentThread; |
Alexei Svitkine (slow)
2013/10/22 19:15:24
Nit: You only use this once below, just inline it.
ostap
2013/10/22 20:48:03
Done.
|
+using base::android::ScopedJavaLocalRef; |
Alexei Svitkine (slow)
2013/10/22 19:15:24
Nit: You don't seem to be using this, remove it.
ostap
2013/10/22 20:48:03
Done.
|
+ |
+namespace gfx { |
Alexei Svitkine (slow)
2013/10/22 19:15:24
Nit: Add a blank line after this.
ostap
2013/10/22 20:48:03
Done.
|
+void UpdateSharedDeviceDisplayInfo(JNIEnv* env, |
+ jobject obj, |
+ jint display_height, |
+ jint display_width, |
+ jint bits_per_pixel, |
+ jint bits_per_component, |
+ jdouble dip_scale, |
+ jint smallest_dip_width) { |
+ SharedDeviceDisplayInfo::GetInstance()->InvokeUpdate(env, obj, |
+ display_height, display_width, bits_per_pixel, bits_per_component, |
+ dip_scale, smallest_dip_width); |
+} |
+ |
+int SharedDeviceDisplayInfo::GetDisplayHeight() { |
+ base::AutoLock(lock()); |
+ return display_height_; |
+} |
+ |
+int SharedDeviceDisplayInfo::GetDisplayWidth() { |
+ base::AutoLock(lock()); |
+ return display_width_; |
+} |
+ |
+int SharedDeviceDisplayInfo::GetBitsPerPixel() { |
+ base::AutoLock(lock()); |
+ return bits_per_pixel_; |
+} |
+ |
+int SharedDeviceDisplayInfo::GetBitsPerComponent() { |
+ base::AutoLock(lock()); |
+ return bits_per_component_; |
+} |
+ |
+double SharedDeviceDisplayInfo::GetDIPScale() { |
+ base::AutoLock(lock()); |
+ return dip_scale_; |
+} |
+ |
+int SharedDeviceDisplayInfo::GetSmallestDIPWidth() { |
+ base::AutoLock(lock()); |
+ return smallest_dip_width_; |
+} |
+ |
+void SharedDeviceDisplayInfo::InvokeUpdate(JNIEnv* env, |
+ jobject obj, |
+ jint display_height, |
+ jint display_width, |
+ jint bits_per_pixel, |
+ jint bits_per_component, |
+ jdouble dip_scale, |
+ jint smallest_dip_width) { |
+ base::AutoLock(lock()); |
+ |
+ UpdateDisplayInfo(env, obj, display_height, |
+ display_width, bits_per_pixel, bits_per_component, dip_scale, |
+ smallest_dip_width); |
+} |
+ |
+void SharedDeviceDisplayInfo::UpdateDisplayInfo(JNIEnv* env, |
+ jobject jobj, |
+ jint display_height, |
+ jint display_width, |
+ jint bits_per_pixel, |
+ jint bits_per_component, |
+ jdouble dip_scale, |
+ jint smallest_dip_width) { |
+ display_height_ = static_cast<int>(display_height); |
+ display_width_ = static_cast<int>(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); |
+} |
+ |
+SharedDeviceDisplayInfo* SharedDeviceDisplayInfo::GetInstance() { |
Alexei Svitkine (slow)
2013/10/22 19:15:24
Order this consistently between .cc and .h file (i
ostap
2013/10/22 20:48:03
Done.
|
+ return Singleton<SharedDeviceDisplayInfo>::get(); |
+} |
+ |
+SharedDeviceDisplayInfo::SharedDeviceDisplayInfo() { |
Alexei Svitkine (slow)
2013/10/22 19:15:24
Please init all the instance variables to default
ostap
2013/10/22 20:48:03
Done.
ostap
2013/10/22 20:48:03
Done.
|
+ JNIEnv* env = AttachCurrentThread(); |
+ j_device_info_.Reset( |
+ Java_DeviceDisplayInfo_createWithListener(env, |
+ base::android::GetApplicationContext())); |
+ UpdateDisplayInfo(env, j_device_info_.obj(), |
+ Java_DeviceDisplayInfo_getDisplayHeight(env, j_device_info_.obj()), |
+ Java_DeviceDisplayInfo_getDisplayWidth(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())); |
+} |
+ |
+bool SharedDeviceDisplayInfo::RegisterSharedDeviceDisplayInfo(JNIEnv* env) { |
+ return RegisterNativesImpl(env); |
+} |
+ |
+} // namespace gfx |