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; | |
13 using base::android::ScopedJavaLocalRef; | |
14 | |
15 namespace gfx { | |
16 | |
17 base::LazyInstance<SharedDeviceDisplayInfo> | |
18 SharedDeviceDisplayInfo::g_instance_; | |
19 | |
20 int SharedDeviceDisplayInfo::GetDisplayHeight() { | |
21 SharedDeviceDisplayInfo* instance = Instance(); | |
22 base::AutoLock(instance->lock_); | |
23 return instance->display_height_; | |
24 } | |
25 | |
26 int SharedDeviceDisplayInfo::GetDisplayWidth() { | |
27 SharedDeviceDisplayInfo* instance = Instance(); | |
28 base::AutoLock(instance->lock_); | |
29 return instance->display_width_; | |
30 } | |
31 | |
32 int SharedDeviceDisplayInfo::GetBitsPerPixel() { | |
33 SharedDeviceDisplayInfo* instance = Instance(); | |
34 base::AutoLock(instance->lock_); | |
35 return instance->bits_per_pixel_; | |
36 } | |
37 | |
38 int SharedDeviceDisplayInfo::GetBitsPerComponent() { | |
39 SharedDeviceDisplayInfo* instance = Instance(); | |
40 base::AutoLock(instance->lock_); | |
41 return instance->bits_per_component_; | |
42 } | |
43 | |
44 double SharedDeviceDisplayInfo::GetDIPScale() { | |
45 SharedDeviceDisplayInfo* instance = Instance(); | |
46 base::AutoLock(instance->lock_); | |
47 return instance->dip_scale_; | |
48 } | |
49 | |
50 void UpdateSharedDeviceDisplayInfo(JNIEnv* env, | |
51 jobject obj, | |
52 jint display_height, | |
53 jint display_width, | |
54 jint bits_per_pixel, | |
55 jint bits_per_component, | |
56 jdouble dip_scale) { | |
57 SharedDeviceDisplayInfo* instance = SharedDeviceDisplayInfo::Instance(); | |
58 base::AutoLock(instance->lock()); | |
59 | |
60 instance->UpdateDisplayInfo(env, obj, display_height, | |
61 display_width, bits_per_pixel, bits_per_component, dip_scale); | |
62 } | |
63 | |
64 void SharedDeviceDisplayInfo::UpdateDisplayInfo(JNIEnv*, | |
65 jobject, | |
66 jint display_height, | |
67 jint display_width, | |
68 jint bits_per_pixel, | |
69 jint bits_per_component, | |
70 jdouble dip_scale) { | |
71 display_height_ = static_cast<int>(display_height); | |
Yaron
2013/10/11 10:18:14
Add lock_->AssertAcquired();
| |
72 display_width_ = static_cast<int>(display_width); | |
73 bits_per_pixel_ = static_cast<int>(bits_per_pixel); | |
74 bits_per_component_ = static_cast<int>(bits_per_component); | |
75 dip_scale_ = static_cast<double>(dip_scale); | |
76 } | |
77 | |
78 SharedDeviceDisplayInfo* SharedDeviceDisplayInfo::Instance() { | |
79 return g_instance_.Pointer(); | |
80 } | |
81 | |
82 SharedDeviceDisplayInfo::SharedDeviceDisplayInfo() { | |
83 JNIEnv* env = AttachCurrentThread(); | |
84 j_device_info_.Reset( | |
85 Java_DeviceDisplayInfo_createWithListener(env, | |
86 base::android::GetApplicationContext())); | |
87 UpdateDisplayInfo(env, j_device_info_.obj(), | |
88 Java_DeviceDisplayInfo_getDisplayHeight(env, j_device_info_.obj()), | |
89 Java_DeviceDisplayInfo_getDisplayWidth(env, j_device_info_.obj()), | |
90 Java_DeviceDisplayInfo_getBitsPerPixel(env, j_device_info_.obj()), | |
91 Java_DeviceDisplayInfo_getBitsPerComponent(env, j_device_info_.obj()), | |
92 Java_DeviceDisplayInfo_getDIPScale(env, j_device_info_.obj())); | |
93 } | |
94 | |
95 bool SharedDeviceDisplayInfo::RegisterSharedDeviceDisplayInfo(JNIEnv* env) { | |
96 return RegisterNativesImpl(env); | |
97 } | |
98 | |
99 } // namespace gfx | |
OLD | NEW |