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; | |
Yaron
2013/10/22 22:58:30
Nit: remove
ostap
2013/10/22 23:06:55
Done.
| |
13 | |
14 namespace gfx { | |
15 | |
16 // static JNI call | |
17 static void UpdateSharedDeviceDisplayInfo(JNIEnv* env, | |
18 jobject obj, | |
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 // static | |
31 SharedDeviceDisplayInfo* SharedDeviceDisplayInfo::GetInstance() { | |
32 return Singleton<SharedDeviceDisplayInfo>::get(); | |
33 } | |
34 | |
35 int SharedDeviceDisplayInfo::GetDisplayHeight() { | |
36 base::AutoLock autolock(lock_); | |
37 DCHECK_NE(0, display_height_); | |
38 return display_height_; | |
39 } | |
40 | |
41 int SharedDeviceDisplayInfo::GetDisplayWidth() { | |
42 base::AutoLock autolock(lock_); | |
43 DCHECK_NE(0, display_width_); | |
44 return display_width_; | |
45 } | |
46 | |
47 int SharedDeviceDisplayInfo::GetBitsPerPixel() { | |
48 base::AutoLock autolock(lock_); | |
49 DCHECK_NE(0, bits_per_pixel_); | |
50 return bits_per_pixel_; | |
51 } | |
52 | |
53 int SharedDeviceDisplayInfo::GetBitsPerComponent() { | |
54 base::AutoLock autolock(lock_); | |
55 DCHECK_NE(0, bits_per_component_); | |
56 return bits_per_component_; | |
57 } | |
58 | |
59 double SharedDeviceDisplayInfo::GetDIPScale() { | |
60 base::AutoLock autolock(lock_); | |
61 DCHECK_NE(0, dip_scale_); | |
62 return dip_scale_; | |
63 } | |
64 | |
65 int SharedDeviceDisplayInfo::GetSmallestDIPWidth() { | |
66 base::AutoLock autolock(lock_); | |
67 DCHECK_NE(0, smallest_dip_width_); | |
68 return smallest_dip_width_; | |
69 } | |
70 | |
71 // static | |
72 bool SharedDeviceDisplayInfo::RegisterSharedDeviceDisplayInfo(JNIEnv* env) { | |
73 return RegisterNativesImpl(env); | |
74 } | |
75 | |
76 void SharedDeviceDisplayInfo::InvokeUpdate(JNIEnv* env, | |
77 jobject obj, | |
78 jint display_height, | |
79 jint display_width, | |
80 jint bits_per_pixel, | |
81 jint bits_per_component, | |
82 jdouble dip_scale, | |
83 jint smallest_dip_width) { | |
84 base::AutoLock autolock(lock_); | |
85 | |
86 UpdateDisplayInfo(env, obj, display_height, | |
87 display_width, bits_per_pixel, bits_per_component, dip_scale, | |
88 smallest_dip_width); | |
89 } | |
90 | |
91 SharedDeviceDisplayInfo::SharedDeviceDisplayInfo() | |
92 : display_height_(0), | |
93 display_width_(0), | |
94 bits_per_pixel_(0), | |
95 bits_per_component_(0), | |
96 dip_scale_(0), | |
97 smallest_dip_width_(0) { | |
98 JNIEnv* env = base::android::AttachCurrentThread(); | |
99 j_device_info_.Reset( | |
100 Java_DeviceDisplayInfo_createWithListener(env, | |
101 base::android::GetApplicationContext())); | |
102 UpdateDisplayInfo(env, j_device_info_.obj(), | |
103 Java_DeviceDisplayInfo_getDisplayHeight(env, j_device_info_.obj()), | |
104 Java_DeviceDisplayInfo_getDisplayWidth(env, j_device_info_.obj()), | |
105 Java_DeviceDisplayInfo_getBitsPerPixel(env, j_device_info_.obj()), | |
106 Java_DeviceDisplayInfo_getBitsPerComponent(env, j_device_info_.obj()), | |
107 Java_DeviceDisplayInfo_getDIPScale(env, j_device_info_.obj()), | |
108 Java_DeviceDisplayInfo_getSmallestDIPWidth(env, j_device_info_.obj())); | |
109 } | |
110 | |
111 void SharedDeviceDisplayInfo::UpdateDisplayInfo(JNIEnv* env, | |
112 jobject jobj, | |
113 jint display_height, | |
114 jint display_width, | |
115 jint bits_per_pixel, | |
116 jint bits_per_component, | |
117 jdouble dip_scale, | |
118 jint smallest_dip_width) { | |
119 display_height_ = static_cast<int>(display_height); | |
120 display_width_ = static_cast<int>(display_width); | |
121 bits_per_pixel_ = static_cast<int>(bits_per_pixel); | |
122 bits_per_component_ = static_cast<int>(bits_per_component); | |
123 dip_scale_ = static_cast<double>(dip_scale); | |
124 smallest_dip_width_ = static_cast<int>(smallest_dip_width); | |
125 } | |
126 | |
127 } // namespace gfx | |
OLD | NEW |