Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(172)

Side by Side Diff: ui/gfx/android/shared_device_display_info.cc

Issue 93933016: Android: Add support for returning real screen resolution. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Return supported boolean. Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/gfx/android/shared_device_display_info.h" 5 #include "ui/gfx/android/shared_device_display_info.h"
6 6
7 #include "base/android/jni_android.h" 7 #include "base/android/jni_android.h"
8 #include "base/android/jni_string.h" 8 #include "base/android/jni_string.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "jni/DeviceDisplayInfo_jni.h" 10 #include "jni/DeviceDisplayInfo_jni.h"
11 11
12 namespace gfx { 12 namespace gfx {
13 13
14 // static JNI call 14 // static JNI call
15 static void UpdateSharedDeviceDisplayInfo(JNIEnv* env, 15 static void UpdateSharedDeviceDisplayInfo(JNIEnv* env,
16 jobject obj, 16 jobject obj,
17 jint display_height, 17 jint display_height,
18 jint display_width, 18 jint display_width,
19 jint real_display_height,
20 jint real_display_width,
19 jint bits_per_pixel, 21 jint bits_per_pixel,
20 jint bits_per_component, 22 jint bits_per_component,
21 jdouble dip_scale, 23 jdouble dip_scale,
22 jint smallest_dip_width) { 24 jint smallest_dip_width) {
23 SharedDeviceDisplayInfo::GetInstance()->InvokeUpdate(env, obj, 25 SharedDeviceDisplayInfo::GetInstance()->InvokeUpdate(env, obj,
24 display_height, display_width, bits_per_pixel, bits_per_component, 26 display_height, display_width,
27 real_display_height, real_display_width,
28 bits_per_pixel, bits_per_component,
25 dip_scale, smallest_dip_width); 29 dip_scale, smallest_dip_width);
26 } 30 }
27 31
28 // static 32 // static
29 SharedDeviceDisplayInfo* SharedDeviceDisplayInfo::GetInstance() { 33 SharedDeviceDisplayInfo* SharedDeviceDisplayInfo::GetInstance() {
30 return Singleton<SharedDeviceDisplayInfo>::get(); 34 return Singleton<SharedDeviceDisplayInfo>::get();
31 } 35 }
32 36
33 int SharedDeviceDisplayInfo::GetDisplayHeight() { 37 int SharedDeviceDisplayInfo::GetDisplayHeight() {
34 base::AutoLock autolock(lock_); 38 base::AutoLock autolock(lock_);
35 DCHECK_NE(0, display_height_); 39 DCHECK_NE(0, display_height_);
36 return display_height_; 40 return display_height_;
37 } 41 }
38 42
39 int SharedDeviceDisplayInfo::GetDisplayWidth() { 43 int SharedDeviceDisplayInfo::GetDisplayWidth() {
40 base::AutoLock autolock(lock_); 44 base::AutoLock autolock(lock_);
41 DCHECK_NE(0, display_width_); 45 DCHECK_NE(0, display_width_);
42 return display_width_; 46 return display_width_;
43 } 47 }
44 48
49 int SharedDeviceDisplayInfo::GetRealDisplayHeight() {
50 base::AutoLock autolock(lock_);
51 DCHECK_NE(0, real_display_height_);
no sievers 2013/12/20 19:32:45 I think if you throw an exception in Java instead,
epennerAtGoogle 2013/12/20 19:42:55 Are you thinking we should just never call the fun
no sievers 2013/12/20 19:51:19 I think you can actually do the same/similar check
52 return real_display_height_;
53 }
54
55 int SharedDeviceDisplayInfo::GetRealDisplayWidth() {
56 base::AutoLock autolock(lock_);
57 DCHECK_NE(0, real_display_width_);
58 return real_display_width_;
59 }
60
45 int SharedDeviceDisplayInfo::GetBitsPerPixel() { 61 int SharedDeviceDisplayInfo::GetBitsPerPixel() {
46 base::AutoLock autolock(lock_); 62 base::AutoLock autolock(lock_);
47 DCHECK_NE(0, bits_per_pixel_); 63 DCHECK_NE(0, bits_per_pixel_);
48 return bits_per_pixel_; 64 return bits_per_pixel_;
49 } 65 }
50 66
51 int SharedDeviceDisplayInfo::GetBitsPerComponent() { 67 int SharedDeviceDisplayInfo::GetBitsPerComponent() {
52 base::AutoLock autolock(lock_); 68 base::AutoLock autolock(lock_);
53 DCHECK_NE(0, bits_per_component_); 69 DCHECK_NE(0, bits_per_component_);
54 return bits_per_component_; 70 return bits_per_component_;
(...skipping 13 matching lines...) Expand all
68 84
69 // static 85 // static
70 bool SharedDeviceDisplayInfo::RegisterSharedDeviceDisplayInfo(JNIEnv* env) { 86 bool SharedDeviceDisplayInfo::RegisterSharedDeviceDisplayInfo(JNIEnv* env) {
71 return RegisterNativesImpl(env); 87 return RegisterNativesImpl(env);
72 } 88 }
73 89
74 void SharedDeviceDisplayInfo::InvokeUpdate(JNIEnv* env, 90 void SharedDeviceDisplayInfo::InvokeUpdate(JNIEnv* env,
75 jobject obj, 91 jobject obj,
76 jint display_height, 92 jint display_height,
77 jint display_width, 93 jint display_width,
94 jint real_display_height,
95 jint real_display_width,
78 jint bits_per_pixel, 96 jint bits_per_pixel,
79 jint bits_per_component, 97 jint bits_per_component,
80 jdouble dip_scale, 98 jdouble dip_scale,
81 jint smallest_dip_width) { 99 jint smallest_dip_width) {
82 base::AutoLock autolock(lock_); 100 base::AutoLock autolock(lock_);
83 101
84 UpdateDisplayInfo(env, obj, display_height, 102 UpdateDisplayInfo(env, obj,
85 display_width, bits_per_pixel, bits_per_component, dip_scale, 103 display_height, display_width,
104 real_display_height, real_display_width,
105 bits_per_pixel, bits_per_component, dip_scale,
86 smallest_dip_width); 106 smallest_dip_width);
87 } 107 }
88 108
89 SharedDeviceDisplayInfo::SharedDeviceDisplayInfo() 109 SharedDeviceDisplayInfo::SharedDeviceDisplayInfo()
90 : display_height_(0), 110 : display_height_(0),
91 display_width_(0), 111 display_width_(0),
92 bits_per_pixel_(0), 112 bits_per_pixel_(0),
93 bits_per_component_(0), 113 bits_per_component_(0),
94 dip_scale_(0), 114 dip_scale_(0),
95 smallest_dip_width_(0) { 115 smallest_dip_width_(0) {
96 JNIEnv* env = base::android::AttachCurrentThread(); 116 JNIEnv* env = base::android::AttachCurrentThread();
97 j_device_info_.Reset( 117 j_device_info_.Reset(
98 Java_DeviceDisplayInfo_createWithListener(env, 118 Java_DeviceDisplayInfo_createWithListener(env,
99 base::android::GetApplicationContext())); 119 base::android::GetApplicationContext()));
100 UpdateDisplayInfo(env, j_device_info_.obj(), 120 UpdateDisplayInfo(env, j_device_info_.obj(),
101 Java_DeviceDisplayInfo_getDisplayHeight(env, j_device_info_.obj()), 121 Java_DeviceDisplayInfo_getDisplayHeight(env, j_device_info_.obj()),
102 Java_DeviceDisplayInfo_getDisplayWidth(env, j_device_info_.obj()), 122 Java_DeviceDisplayInfo_getDisplayWidth(env, j_device_info_.obj()),
123 Java_DeviceDisplayInfo_getRealDisplayHeight(env, j_device_info_.obj()),
124 Java_DeviceDisplayInfo_getRealDisplayWidth(env, j_device_info_.obj()),
103 Java_DeviceDisplayInfo_getBitsPerPixel(env, j_device_info_.obj()), 125 Java_DeviceDisplayInfo_getBitsPerPixel(env, j_device_info_.obj()),
104 Java_DeviceDisplayInfo_getBitsPerComponent(env, j_device_info_.obj()), 126 Java_DeviceDisplayInfo_getBitsPerComponent(env, j_device_info_.obj()),
105 Java_DeviceDisplayInfo_getDIPScale(env, j_device_info_.obj()), 127 Java_DeviceDisplayInfo_getDIPScale(env, j_device_info_.obj()),
106 Java_DeviceDisplayInfo_getSmallestDIPWidth(env, j_device_info_.obj())); 128 Java_DeviceDisplayInfo_getSmallestDIPWidth(env, j_device_info_.obj()));
107 } 129 }
108 130
109 SharedDeviceDisplayInfo::~SharedDeviceDisplayInfo() { 131 SharedDeviceDisplayInfo::~SharedDeviceDisplayInfo() {
110 } 132 }
111 133
112 void SharedDeviceDisplayInfo::UpdateDisplayInfo(JNIEnv* env, 134 void SharedDeviceDisplayInfo::UpdateDisplayInfo(JNIEnv* env,
113 jobject jobj, 135 jobject jobj,
114 jint display_height, 136 jint display_height,
115 jint display_width, 137 jint display_width,
138 jint real_display_height,
139 jint real_display_width,
116 jint bits_per_pixel, 140 jint bits_per_pixel,
117 jint bits_per_component, 141 jint bits_per_component,
118 jdouble dip_scale, 142 jdouble dip_scale,
119 jint smallest_dip_width) { 143 jint smallest_dip_width) {
120 display_height_ = static_cast<int>(display_height); 144 display_height_ = static_cast<int>(display_height);
121 display_width_ = static_cast<int>(display_width); 145 display_width_ = static_cast<int>(display_width);
146 real_display_height_ = static_cast<int>(real_display_height);
147 real_display_width_ = static_cast<int>(real_display_width);
122 bits_per_pixel_ = static_cast<int>(bits_per_pixel); 148 bits_per_pixel_ = static_cast<int>(bits_per_pixel);
123 bits_per_component_ = static_cast<int>(bits_per_component); 149 bits_per_component_ = static_cast<int>(bits_per_component);
124 dip_scale_ = static_cast<double>(dip_scale); 150 dip_scale_ = static_cast<double>(dip_scale);
125 smallest_dip_width_ = static_cast<int>(smallest_dip_width); 151 smallest_dip_width_ = static_cast<int>(smallest_dip_width);
126 } 152 }
127 153
128 } // namespace gfx 154 } // namespace gfx
OLDNEW
« ui/gfx/android/shared_device_display_info.h ('K') | « ui/gfx/android/shared_device_display_info.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698