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,
20 jint bits_per_component,
22 jint smallest_dip_width) {
23 SharedDeviceDisplayInfo::GetInstance()->InvokeUpdate(env, obj,
24 display_height, display_width, bits_per_pixel, bits_per_component,
25 dip_scale, smallest_dip_width);
29 SharedDeviceDisplayInfo* SharedDeviceDisplayInfo::GetInstance() {
30 return Singleton<SharedDeviceDisplayInfo>::get();
33 int SharedDeviceDisplayInfo::GetDisplayHeight() {
34 base::AutoLock autolock(lock_);
35 DCHECK_NE(0, display_height_);
36 return display_height_;
39 int SharedDeviceDisplayInfo::GetDisplayWidth() {
40 base::AutoLock autolock(lock_);
41 DCHECK_NE(0, display_width_);
42 return display_width_;
45 int SharedDeviceDisplayInfo::GetBitsPerPixel() {
46 base::AutoLock autolock(lock_);
47 DCHECK_NE(0, bits_per_pixel_);
48 return bits_per_pixel_;
51 int SharedDeviceDisplayInfo::GetBitsPerComponent() {
52 base::AutoLock autolock(lock_);
53 DCHECK_NE(0, bits_per_component_);
54 return bits_per_component_;
57 double SharedDeviceDisplayInfo::GetDIPScale() {
58 base::AutoLock autolock(lock_);
59 DCHECK_NE(0, dip_scale_);
63 int SharedDeviceDisplayInfo::GetSmallestDIPWidth() {
64 base::AutoLock autolock(lock_);
65 DCHECK_NE(0, smallest_dip_width_);
66 return smallest_dip_width_;
70 bool SharedDeviceDisplayInfo::RegisterSharedDeviceDisplayInfo(JNIEnv* env) {
71 return RegisterNativesImpl(env);
74 void SharedDeviceDisplayInfo::InvokeUpdate(JNIEnv* env,
79 jint bits_per_component,
81 jint smallest_dip_width) {
82 base::AutoLock autolock(lock_);
84 UpdateDisplayInfo(env, obj, display_height,
85 display_width, bits_per_pixel, bits_per_component, dip_scale,
89 SharedDeviceDisplayInfo::SharedDeviceDisplayInfo()
93 bits_per_component_(0),
95 smallest_dip_width_(0) {
96 JNIEnv* env = base::android::AttachCurrentThread();
98 Java_DeviceDisplayInfo_createWithListener(env,
99 base::android::GetApplicationContext()));
100 UpdateDisplayInfo(env, j_device_info_.obj(),
101 Java_DeviceDisplayInfo_getDisplayHeight(env, j_device_info_.obj()),
102 Java_DeviceDisplayInfo_getDisplayWidth(env, j_device_info_.obj()),
103 Java_DeviceDisplayInfo_getBitsPerPixel(env, j_device_info_.obj()),
104 Java_DeviceDisplayInfo_getBitsPerComponent(env, j_device_info_.obj()),
105 Java_DeviceDisplayInfo_getDIPScale(env, j_device_info_.obj()),
106 Java_DeviceDisplayInfo_getSmallestDIPWidth(env, j_device_info_.obj()));
109 SharedDeviceDisplayInfo::~SharedDeviceDisplayInfo() {
112 void SharedDeviceDisplayInfo::UpdateDisplayInfo(JNIEnv* env,
117 jint bits_per_component,
119 jint smallest_dip_width) {
120 display_height_ = static_cast<int>(display_height);
121 display_width_ = static_cast<int>(display_width);
122 bits_per_pixel_ = static_cast<int>(bits_per_pixel);
123 bits_per_component_ = static_cast<int>(bits_per_component);
124 dip_scale_ = static_cast<double>(dip_scale);
125 smallest_dip_width_ = static_cast<int>(smallest_dip_width);