| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/gfx/android/shared_device_display_info.h" | 5 #include "ui/gfx/android/shared_device_display_info.h" |
| 6 | 6 |
| 7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
| 8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "jni/DeviceDisplayInfo_jni.h" | 10 #include "jni/DeviceDisplayInfo_jni.h" |
| 11 | 11 |
| 12 namespace gfx { | 12 namespace gfx { |
| 13 | 13 |
| 14 // static JNI call | 14 // static JNI call |
| 15 static void UpdateSharedDeviceDisplayInfo(JNIEnv* env, | 15 static void UpdateSharedDeviceDisplayInfo(JNIEnv* env, |
| 16 jobject obj, | 16 jobject obj, |
| 17 jint display_height, | 17 jint display_height, |
| 18 jint display_width, | 18 jint display_width, |
| 19 jint physical_display_height, |
| 20 jint physical_display_width, |
| 19 jint bits_per_pixel, | 21 jint bits_per_pixel, |
| 20 jint bits_per_component, | 22 jint bits_per_component, |
| 21 jdouble dip_scale, | 23 jdouble dip_scale, |
| 22 jint smallest_dip_width) { | 24 jint smallest_dip_width) { |
| 23 SharedDeviceDisplayInfo::GetInstance()->InvokeUpdate(env, obj, | 25 SharedDeviceDisplayInfo::GetInstance()->InvokeUpdate(env, obj, |
| 24 display_height, display_width, bits_per_pixel, bits_per_component, | 26 display_height, display_width, |
| 27 physical_display_height, physical_display_width, |
| 28 bits_per_pixel, bits_per_component, |
| 25 dip_scale, smallest_dip_width); | 29 dip_scale, smallest_dip_width); |
| 26 } | 30 } |
| 27 | 31 |
| 28 // static | 32 // static |
| 29 SharedDeviceDisplayInfo* SharedDeviceDisplayInfo::GetInstance() { | 33 SharedDeviceDisplayInfo* SharedDeviceDisplayInfo::GetInstance() { |
| 30 return Singleton<SharedDeviceDisplayInfo>::get(); | 34 return Singleton<SharedDeviceDisplayInfo>::get(); |
| 31 } | 35 } |
| 32 | 36 |
| 33 int SharedDeviceDisplayInfo::GetDisplayHeight() { | 37 int SharedDeviceDisplayInfo::GetDisplayHeight() { |
| 34 base::AutoLock autolock(lock_); | 38 base::AutoLock autolock(lock_); |
| 35 DCHECK_NE(0, display_height_); | 39 DCHECK_NE(0, display_height_); |
| 36 return display_height_; | 40 return display_height_; |
| 37 } | 41 } |
| 38 | 42 |
| 39 int SharedDeviceDisplayInfo::GetDisplayWidth() { | 43 int SharedDeviceDisplayInfo::GetDisplayWidth() { |
| 40 base::AutoLock autolock(lock_); | 44 base::AutoLock autolock(lock_); |
| 41 DCHECK_NE(0, display_width_); | 45 DCHECK_NE(0, display_width_); |
| 42 return display_width_; | 46 return display_width_; |
| 43 } | 47 } |
| 44 | 48 |
| 49 int SharedDeviceDisplayInfo::GetPhysicalDisplayHeight() { |
| 50 base::AutoLock autolock(lock_); |
| 51 return physical_display_height_; |
| 52 } |
| 53 |
| 54 int SharedDeviceDisplayInfo::GetPhysicalDisplayWidth() { |
| 55 base::AutoLock autolock(lock_); |
| 56 return physical_display_width_; |
| 57 } |
| 58 |
| 45 int SharedDeviceDisplayInfo::GetBitsPerPixel() { | 59 int SharedDeviceDisplayInfo::GetBitsPerPixel() { |
| 46 base::AutoLock autolock(lock_); | 60 base::AutoLock autolock(lock_); |
| 47 DCHECK_NE(0, bits_per_pixel_); | 61 DCHECK_NE(0, bits_per_pixel_); |
| 48 return bits_per_pixel_; | 62 return bits_per_pixel_; |
| 49 } | 63 } |
| 50 | 64 |
| 51 int SharedDeviceDisplayInfo::GetBitsPerComponent() { | 65 int SharedDeviceDisplayInfo::GetBitsPerComponent() { |
| 52 base::AutoLock autolock(lock_); | 66 base::AutoLock autolock(lock_); |
| 53 DCHECK_NE(0, bits_per_component_); | 67 DCHECK_NE(0, bits_per_component_); |
| 54 return bits_per_component_; | 68 return bits_per_component_; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 68 | 82 |
| 69 // static | 83 // static |
| 70 bool SharedDeviceDisplayInfo::RegisterSharedDeviceDisplayInfo(JNIEnv* env) { | 84 bool SharedDeviceDisplayInfo::RegisterSharedDeviceDisplayInfo(JNIEnv* env) { |
| 71 return RegisterNativesImpl(env); | 85 return RegisterNativesImpl(env); |
| 72 } | 86 } |
| 73 | 87 |
| 74 void SharedDeviceDisplayInfo::InvokeUpdate(JNIEnv* env, | 88 void SharedDeviceDisplayInfo::InvokeUpdate(JNIEnv* env, |
| 75 jobject obj, | 89 jobject obj, |
| 76 jint display_height, | 90 jint display_height, |
| 77 jint display_width, | 91 jint display_width, |
| 92 jint physical_display_height, |
| 93 jint physical_display_width, |
| 78 jint bits_per_pixel, | 94 jint bits_per_pixel, |
| 79 jint bits_per_component, | 95 jint bits_per_component, |
| 80 jdouble dip_scale, | 96 jdouble dip_scale, |
| 81 jint smallest_dip_width) { | 97 jint smallest_dip_width) { |
| 82 base::AutoLock autolock(lock_); | 98 base::AutoLock autolock(lock_); |
| 83 | 99 |
| 84 UpdateDisplayInfo(env, obj, display_height, | 100 UpdateDisplayInfo(env, obj, |
| 85 display_width, bits_per_pixel, bits_per_component, dip_scale, | 101 display_height, display_width, |
| 102 physical_display_height, physical_display_width, |
| 103 bits_per_pixel, bits_per_component, dip_scale, |
| 86 smallest_dip_width); | 104 smallest_dip_width); |
| 87 } | 105 } |
| 88 | 106 |
| 89 SharedDeviceDisplayInfo::SharedDeviceDisplayInfo() | 107 SharedDeviceDisplayInfo::SharedDeviceDisplayInfo() |
| 90 : display_height_(0), | 108 : display_height_(0), |
| 91 display_width_(0), | 109 display_width_(0), |
| 92 bits_per_pixel_(0), | 110 bits_per_pixel_(0), |
| 93 bits_per_component_(0), | 111 bits_per_component_(0), |
| 94 dip_scale_(0), | 112 dip_scale_(0), |
| 95 smallest_dip_width_(0) { | 113 smallest_dip_width_(0) { |
| 96 JNIEnv* env = base::android::AttachCurrentThread(); | 114 JNIEnv* env = base::android::AttachCurrentThread(); |
| 97 j_device_info_.Reset( | 115 j_device_info_.Reset( |
| 98 Java_DeviceDisplayInfo_createWithListener(env, | 116 Java_DeviceDisplayInfo_createWithListener(env, |
| 99 base::android::GetApplicationContext())); | 117 base::android::GetApplicationContext())); |
| 100 UpdateDisplayInfo(env, j_device_info_.obj(), | 118 UpdateDisplayInfo(env, j_device_info_.obj(), |
| 101 Java_DeviceDisplayInfo_getDisplayHeight(env, j_device_info_.obj()), | 119 Java_DeviceDisplayInfo_getDisplayHeight(env, j_device_info_.obj()), |
| 102 Java_DeviceDisplayInfo_getDisplayWidth(env, j_device_info_.obj()), | 120 Java_DeviceDisplayInfo_getDisplayWidth(env, j_device_info_.obj()), |
| 121 Java_DeviceDisplayInfo_getPhysicalDisplayHeight(env, |
| 122 j_device_info_.obj()), |
| 123 Java_DeviceDisplayInfo_getPhysicalDisplayWidth(env, j_device_info_.obj()), |
| 103 Java_DeviceDisplayInfo_getBitsPerPixel(env, j_device_info_.obj()), | 124 Java_DeviceDisplayInfo_getBitsPerPixel(env, j_device_info_.obj()), |
| 104 Java_DeviceDisplayInfo_getBitsPerComponent(env, j_device_info_.obj()), | 125 Java_DeviceDisplayInfo_getBitsPerComponent(env, j_device_info_.obj()), |
| 105 Java_DeviceDisplayInfo_getDIPScale(env, j_device_info_.obj()), | 126 Java_DeviceDisplayInfo_getDIPScale(env, j_device_info_.obj()), |
| 106 Java_DeviceDisplayInfo_getSmallestDIPWidth(env, j_device_info_.obj())); | 127 Java_DeviceDisplayInfo_getSmallestDIPWidth(env, j_device_info_.obj())); |
| 107 } | 128 } |
| 108 | 129 |
| 109 SharedDeviceDisplayInfo::~SharedDeviceDisplayInfo() { | 130 SharedDeviceDisplayInfo::~SharedDeviceDisplayInfo() { |
| 110 } | 131 } |
| 111 | 132 |
| 112 void SharedDeviceDisplayInfo::UpdateDisplayInfo(JNIEnv* env, | 133 void SharedDeviceDisplayInfo::UpdateDisplayInfo(JNIEnv* env, |
| 113 jobject jobj, | 134 jobject jobj, |
| 114 jint display_height, | 135 jint display_height, |
| 115 jint display_width, | 136 jint display_width, |
| 137 jint physical_display_height, |
| 138 jint physical_display_width, |
| 116 jint bits_per_pixel, | 139 jint bits_per_pixel, |
| 117 jint bits_per_component, | 140 jint bits_per_component, |
| 118 jdouble dip_scale, | 141 jdouble dip_scale, |
| 119 jint smallest_dip_width) { | 142 jint smallest_dip_width) { |
| 120 display_height_ = static_cast<int>(display_height); | 143 display_height_ = static_cast<int>(display_height); |
| 121 display_width_ = static_cast<int>(display_width); | 144 display_width_ = static_cast<int>(display_width); |
| 145 physical_display_height_ = static_cast<int>(physical_display_height); |
| 146 physical_display_width_ = static_cast<int>(physical_display_width); |
| 122 bits_per_pixel_ = static_cast<int>(bits_per_pixel); | 147 bits_per_pixel_ = static_cast<int>(bits_per_pixel); |
| 123 bits_per_component_ = static_cast<int>(bits_per_component); | 148 bits_per_component_ = static_cast<int>(bits_per_component); |
| 124 dip_scale_ = static_cast<double>(dip_scale); | 149 dip_scale_ = static_cast<double>(dip_scale); |
| 125 smallest_dip_width_ = static_cast<int>(smallest_dip_width); | 150 smallest_dip_width_ = static_cast<int>(smallest_dip_width); |
| 126 } | 151 } |
| 127 | 152 |
| 128 } // namespace gfx | 153 } // namespace gfx |
| OLD | NEW |