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