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.
5 #include "ui/gfx/android/shared_device_display_info.h"
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"
15 static void UpdateSharedDeviceDisplayInfo(JNIEnv
* env
,
19 jint physical_display_height
,
20 jint physical_display_width
,
22 jint bits_per_component
,
24 jint smallest_dip_width
,
25 jint rotation_degrees
) {
26 SharedDeviceDisplayInfo::GetInstance()->InvokeUpdate(env
, obj
,
27 display_height
, display_width
,
28 physical_display_height
, physical_display_width
,
29 bits_per_pixel
, bits_per_component
,
30 dip_scale
, smallest_dip_width
, rotation_degrees
);
34 SharedDeviceDisplayInfo
* SharedDeviceDisplayInfo::GetInstance() {
35 return Singleton
<SharedDeviceDisplayInfo
>::get();
38 int SharedDeviceDisplayInfo::GetDisplayHeight() {
39 base::AutoLock
autolock(lock_
);
40 DCHECK_NE(0, display_height_
);
41 return display_height_
;
44 int SharedDeviceDisplayInfo::GetDisplayWidth() {
45 base::AutoLock
autolock(lock_
);
46 DCHECK_NE(0, display_width_
);
47 return display_width_
;
50 int SharedDeviceDisplayInfo::GetPhysicalDisplayHeight() {
51 base::AutoLock
autolock(lock_
);
52 return physical_display_height_
;
55 int SharedDeviceDisplayInfo::GetPhysicalDisplayWidth() {
56 base::AutoLock
autolock(lock_
);
57 return physical_display_width_
;
60 int SharedDeviceDisplayInfo::GetBitsPerPixel() {
61 base::AutoLock
autolock(lock_
);
62 DCHECK_NE(0, bits_per_pixel_
);
63 return bits_per_pixel_
;
66 int SharedDeviceDisplayInfo::GetBitsPerComponent() {
67 base::AutoLock
autolock(lock_
);
68 DCHECK_NE(0, bits_per_component_
);
69 return bits_per_component_
;
72 double SharedDeviceDisplayInfo::GetDIPScale() {
73 base::AutoLock
autolock(lock_
);
74 DCHECK_NE(0, dip_scale_
);
78 int SharedDeviceDisplayInfo::GetSmallestDIPWidth() {
79 base::AutoLock
autolock(lock_
);
80 DCHECK_NE(0, smallest_dip_width_
);
81 return smallest_dip_width_
;
84 int SharedDeviceDisplayInfo::GetRotationDegrees() {
85 base::AutoLock
autolock(lock_
);
86 return rotation_degrees_
;
90 bool SharedDeviceDisplayInfo::RegisterSharedDeviceDisplayInfo(JNIEnv
* env
) {
91 return RegisterNativesImpl(env
);
94 void SharedDeviceDisplayInfo::InvokeUpdate(JNIEnv
* env
,
98 jint physical_display_height
,
99 jint physical_display_width
,
101 jint bits_per_component
,
103 jint smallest_dip_width
,
104 jint rotation_degrees
) {
105 base::AutoLock
autolock(lock_
);
107 UpdateDisplayInfo(env
, obj
,
108 display_height
, display_width
,
109 physical_display_height
, physical_display_width
,
110 bits_per_pixel
, bits_per_component
, dip_scale
,
111 smallest_dip_width
, rotation_degrees
);
114 SharedDeviceDisplayInfo::SharedDeviceDisplayInfo()
115 : display_height_(0),
118 bits_per_component_(0),
120 smallest_dip_width_(0) {
121 JNIEnv
* env
= base::android::AttachCurrentThread();
122 j_device_info_
.Reset(
123 Java_DeviceDisplayInfo_create(
124 env
, base::android::GetApplicationContext()));
125 UpdateDisplayInfo(env
, j_device_info_
.obj(),
126 Java_DeviceDisplayInfo_getDisplayHeight(env
, j_device_info_
.obj()),
127 Java_DeviceDisplayInfo_getDisplayWidth(env
, j_device_info_
.obj()),
128 Java_DeviceDisplayInfo_getPhysicalDisplayHeight(env
,
129 j_device_info_
.obj()),
130 Java_DeviceDisplayInfo_getPhysicalDisplayWidth(env
, j_device_info_
.obj()),
131 Java_DeviceDisplayInfo_getBitsPerPixel(env
, j_device_info_
.obj()),
132 Java_DeviceDisplayInfo_getBitsPerComponent(env
, j_device_info_
.obj()),
133 Java_DeviceDisplayInfo_getDIPScale(env
, j_device_info_
.obj()),
134 Java_DeviceDisplayInfo_getSmallestDIPWidth(env
, j_device_info_
.obj()),
135 Java_DeviceDisplayInfo_getRotationDegrees(env
, j_device_info_
.obj()));
138 SharedDeviceDisplayInfo::~SharedDeviceDisplayInfo() {
141 void SharedDeviceDisplayInfo::UpdateDisplayInfo(JNIEnv
* env
,
145 jint physical_display_height
,
146 jint physical_display_width
,
148 jint bits_per_component
,
150 jint smallest_dip_width
,
151 jint rotation_degrees
) {
152 display_height_
= static_cast<int>(display_height
);
153 display_width_
= static_cast<int>(display_width
);
154 physical_display_height_
= static_cast<int>(physical_display_height
);
155 physical_display_width_
= static_cast<int>(physical_display_width
);
156 bits_per_pixel_
= static_cast<int>(bits_per_pixel
);
157 bits_per_component_
= static_cast<int>(bits_per_component
);
158 dip_scale_
= static_cast<double>(dip_scale
);
159 smallest_dip_width_
= static_cast<int>(smallest_dip_width
);
160 rotation_degrees_
= static_cast<int>(rotation_degrees
);