Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ui/gfx/android/shared_device_display_info.h" | |
| 6 | |
| 7 #include "base/android/jni_android.h" | |
| 8 #include "base/android/jni_string.h" | |
| 9 #include "base/logging.h" | |
| 10 #include "jni/DeviceDisplayInfo_jni.h" | |
| 11 | |
| 12 using base::android::AttachCurrentThread; | |
| 13 | |
| 14 namespace gfx { | |
| 15 | |
| 16 // static JNI call | |
| 17 static void UpdateSharedDeviceDisplayInfo(JNIEnv* env, | |
| 18 jobject obj, | |
|
Alexei Svitkine (slow)
2013/10/22 21:01:54
Nit: Align params.
ostap
2013/10/22 21:40:42
Done.
| |
| 19 jint display_height, | |
| 20 jint display_width, | |
| 21 jint bits_per_pixel, | |
| 22 jint bits_per_component, | |
| 23 jdouble dip_scale, | |
| 24 jint smallest_dip_width) { | |
| 25 SharedDeviceDisplayInfo::GetInstance()->InvokeUpdate(env, obj, | |
| 26 display_height, display_width, bits_per_pixel, bits_per_component, | |
| 27 dip_scale, smallest_dip_width); | |
| 28 } | |
| 29 | |
| 30 SharedDeviceDisplayInfo* SharedDeviceDisplayInfo::GetInstance() { | |
|
Alexei Svitkine (slow)
2013/10/22 21:01:54
Nit: Add "// static" above this.
ostap
2013/10/22 21:40:42
Done.
| |
| 31 return Singleton<SharedDeviceDisplayInfo>::get(); | |
| 32 } | |
| 33 | |
| 34 int SharedDeviceDisplayInfo::GetDisplayHeight() { | |
| 35 base::AutoLock autolock(lock_); | |
| 36 return display_height_; | |
| 37 } | |
| 38 | |
| 39 int SharedDeviceDisplayInfo::GetDisplayWidth() { | |
| 40 base::AutoLock autolock(lock_); | |
| 41 return display_width_; | |
| 42 } | |
| 43 | |
| 44 int SharedDeviceDisplayInfo::GetBitsPerPixel() { | |
| 45 base::AutoLock autolock(lock_); | |
| 46 return bits_per_pixel_; | |
| 47 } | |
| 48 | |
| 49 int SharedDeviceDisplayInfo::GetBitsPerComponent() { | |
| 50 base::AutoLock autolock(lock_); | |
| 51 return bits_per_component_; | |
| 52 } | |
| 53 | |
| 54 double SharedDeviceDisplayInfo::GetDIPScale() { | |
| 55 base::AutoLock autolock(lock_); | |
| 56 return dip_scale_; | |
| 57 } | |
| 58 | |
| 59 int SharedDeviceDisplayInfo::GetSmallestDIPWidth() { | |
| 60 base::AutoLock autolock(lock_); | |
| 61 return smallest_dip_width_; | |
|
Alexei Svitkine (slow)
2013/10/22 21:01:54
Can you add a DCHECK_NE(0, smallest_dip_width_); h
ostap
2013/10/22 21:40:42
Done.
| |
| 62 } | |
| 63 | |
| 64 bool SharedDeviceDisplayInfo::RegisterSharedDeviceDisplayInfo(JNIEnv* env) { | |
|
Alexei Svitkine (slow)
2013/10/22 21:01:54
Nit: Add "// static" above this.
ostap
2013/10/22 21:40:42
Done.
| |
| 65 return RegisterNativesImpl(env); | |
| 66 } | |
| 67 | |
| 68 void SharedDeviceDisplayInfo::InvokeUpdate(JNIEnv* env, | |
| 69 jobject obj, | |
| 70 jint display_height, | |
| 71 jint display_width, | |
| 72 jint bits_per_pixel, | |
| 73 jint bits_per_component, | |
| 74 jdouble dip_scale, | |
| 75 jint smallest_dip_width) { | |
| 76 base::AutoLock autolock(lock_); | |
| 77 | |
| 78 UpdateDisplayInfo(env, obj, display_height, | |
| 79 display_width, bits_per_pixel, bits_per_component, dip_scale, | |
| 80 smallest_dip_width); | |
| 81 } | |
| 82 | |
| 83 SharedDeviceDisplayInfo::SharedDeviceDisplayInfo() | |
| 84 : display_height_(0), | |
| 85 display_width_(0), | |
| 86 bits_per_pixel_(0), | |
| 87 bits_per_component_(0), | |
| 88 dip_scale_(0), | |
| 89 smallest_dip_width_(0) | |
| 90 | |
|
Alexei Svitkine (slow)
2013/10/22 21:01:54
Nit: Remove empty line.
ostap
2013/10/22 21:40:42
Done.
| |
| 91 { | |
| 92 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 93 j_device_info_.Reset( | |
| 94 Java_DeviceDisplayInfo_createWithListener(env, | |
| 95 base::android::GetApplicationContext())); | |
| 96 UpdateDisplayInfo(env, j_device_info_.obj(), | |
| 97 Java_DeviceDisplayInfo_getDisplayHeight(env, j_device_info_.obj()), | |
| 98 Java_DeviceDisplayInfo_getDisplayWidth(env, j_device_info_.obj()), | |
| 99 Java_DeviceDisplayInfo_getBitsPerPixel(env, j_device_info_.obj()), | |
| 100 Java_DeviceDisplayInfo_getBitsPerComponent(env, j_device_info_.obj()), | |
| 101 Java_DeviceDisplayInfo_getDIPScale(env, j_device_info_.obj()), | |
| 102 Java_DeviceDisplayInfo_getSmallestDIPWidth(env, j_device_info_.obj())); | |
| 103 } | |
| 104 | |
| 105 void SharedDeviceDisplayInfo::UpdateDisplayInfo(JNIEnv* env, | |
| 106 jobject jobj, | |
| 107 jint display_height, | |
| 108 jint display_width, | |
| 109 jint bits_per_pixel, | |
| 110 jint bits_per_component, | |
| 111 jdouble dip_scale, | |
| 112 jint smallest_dip_width) { | |
| 113 display_height_ = static_cast<int>(display_height); | |
| 114 display_width_ = static_cast<int>(display_width); | |
| 115 bits_per_pixel_ = static_cast<int>(bits_per_pixel); | |
| 116 bits_per_component_ = static_cast<int>(bits_per_component); | |
| 117 dip_scale_ = static_cast<double>(dip_scale); | |
| 118 smallest_dip_width_ = static_cast<int>(smallest_dip_width); | |
| 119 } | |
| 120 | |
| 121 } // namespace gfx | |
| OLD | NEW |