Chromium Code Reviews| 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..ae2dd320a8f75217f621df0c78a726017f11e30b |
| --- /dev/null |
| +++ b/ui/gfx/android/shared_device_display_info.cc |
| @@ -0,0 +1,109 @@ |
| +// 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; |
| +using base::android::ScopedJavaLocalRef; |
| + |
| +namespace gfx { |
| + |
| +base::LazyInstance<SharedDeviceDisplayInfo> g_instance_; |
| + |
| +int SharedDeviceDisplayInfo::GetDisplayHeight() { |
| + SharedDeviceDisplayInfo* instance = Instance(); |
| + base::AutoLock(instance->lock_); |
| + return instance->display_height_; |
| +} |
| + |
| +int SharedDeviceDisplayInfo::GetDisplayWidth() { |
| + SharedDeviceDisplayInfo* instance = Instance(); |
| + base::AutoLock(instance->lock_); |
| + return instance->display_width_; |
| +} |
| + |
| +int SharedDeviceDisplayInfo::GetBitsPerPixel() { |
| + SharedDeviceDisplayInfo* instance = Instance(); |
| + base::AutoLock(instance->lock_); |
| + return instance->bits_per_pixel_; |
| +} |
| + |
| +int SharedDeviceDisplayInfo::GetBitsPerComponent() { |
| + SharedDeviceDisplayInfo* instance = Instance(); |
| + base::AutoLock(instance->lock_); |
| + return instance->bits_per_component_; |
| +} |
| + |
| +double SharedDeviceDisplayInfo::GetDIPScale() { |
| + SharedDeviceDisplayInfo* instance = Instance(); |
| + base::AutoLock(instance->lock_); |
| + return instance->dip_scale_; |
| +} |
| + |
| +void UpdateSharedDeviceDisplayInfo(JNIEnv* env, |
|
Alexei Svitkine (slow)
2013/10/11 14:13:06
This should be in anon namespace at the top of the
|
| + jobject obj, |
| + jint display_height, |
| + jint display_width, |
| + jint bits_per_pixel, |
| + jint bits_per_component, |
| + jdouble dip_scale) { |
| + SharedDeviceDisplayInfo::InvokeUpdate(env, obj, display_height, |
| + display_width, bits_per_pixel, bits_per_component, dip_scale); |
|
Alexei Svitkine (slow)
2013/10/11 14:13:06
Nit: Indent 2 more. Please fix throughout.
|
| +} |
| + |
| +void SharedDeviceDisplayInfo::InvokeUpdate(JNIEnv* env, |
| + jobject obj, |
| + jint display_height, |
| + jint display_width, |
| + jint bits_per_pixel, |
| + jint bits_per_component, |
| + jdouble dip_scale) { |
| + SharedDeviceDisplayInfo* instance = SharedDeviceDisplayInfo::Instance(); |
| + base::AutoLock(instance->lock()); |
| + |
| + instance->UpdateDisplayInfo(env, obj, display_height, |
| + display_width, bits_per_pixel, bits_per_component, dip_scale); |
| +} |
| + |
| +void SharedDeviceDisplayInfo::UpdateDisplayInfo(JNIEnv*, |
| + jobject, |
| + jint display_height, |
| + jint display_width, |
| + jint bits_per_pixel, |
| + jint bits_per_component, |
| + jdouble dip_scale) { |
| + 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); |
| +} |
| + |
| +SharedDeviceDisplayInfo* SharedDeviceDisplayInfo::Instance() { |
| + return g_instance_.Pointer(); |
| +} |
| + |
| +SharedDeviceDisplayInfo::SharedDeviceDisplayInfo() { |
| + 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())); |
| +} |
| + |
| +bool SharedDeviceDisplayInfo::RegisterSharedDeviceDisplayInfo(JNIEnv* env) { |
| + return RegisterNativesImpl(env); |
| +} |
| + |
| +} // namespace gfx |