Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "jni/DeviceDisplayInfo_jni.h" | |
| 5 #include "ui/gfx/android/device_display_info.h" | 6 #include "ui/gfx/android/device_display_info.h" |
| 6 | 7 |
| 7 #include "base/logging.h" | |
| 8 #include "ui/gfx/android/shared_device_display_info.h" | |
| 9 | |
| 10 namespace gfx { | 8 namespace gfx { |
| 11 | 9 |
| 10 DeviceDisplayInfo::DeviceDisplayInfo( | |
| 11 base::android::ScopedJavaLocalRef<jobject> context) { | |
| 12 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 13 j_device_info_.Reset(Java_DeviceDisplayInfo_create(env, context.obj())); | |
| 14 FetchDisplayInfoFromJava(env); | |
| 15 } | |
| 16 | |
| 12 DeviceDisplayInfo::DeviceDisplayInfo() { | 17 DeviceDisplayInfo::DeviceDisplayInfo() { |
| 18 JNIEnv* env = base::android::AttachCurrentThread(); | |
|
boliu
2015/07/15 06:38:47
can use c++11 delegated constructor here I think?
jdduke (slow)
2015/07/15 16:03:07
Hmm, it might be nice to have a TODO to get rid of
gsennton
2015/07/15 19:26:21
As in changing to use the WindowAndroid context or
gsennton
2015/07/15 19:26:21
Done.
boliu
2015/07/16 14:36:56
Yeah, call other constructor directly
| |
| 19 j_device_info_.Reset(Java_DeviceDisplayInfo_create( | |
| 20 env, base::android::GetApplicationContext())); | |
| 21 FetchDisplayInfoFromJava(env); | |
| 13 } | 22 } |
| 14 | 23 |
| 15 DeviceDisplayInfo::~DeviceDisplayInfo() { | 24 DeviceDisplayInfo::~DeviceDisplayInfo() { |
| 16 } | 25 } |
| 17 | 26 |
| 18 int DeviceDisplayInfo::GetDisplayHeight() { | 27 void DeviceDisplayInfo::FetchDisplayInfoFromJava(JNIEnv* env) { |
| 19 return SharedDeviceDisplayInfo::GetInstance()->GetDisplayHeight(); | 28 UpdateDisplayInfo( |
|
jdduke (slow)
2015/07/15 16:03:07
Silly question. Do we really need to hold a refere
jdduke (slow)
2015/07/15 16:13:41
Not only will that cut out most of the JNI calls,
gsennton
2015/07/15 19:26:21
I am not sure what you mean by using a static temp
boliu
2015/07/16 14:36:56
In the code snippet above, instead of "new DeviceD
jdduke (slow)
2015/07/16 15:09:03
Right, something like "private static DeviceDispla
boliu
2015/07/16 16:27:03
Actually thinking more about this, having a static
gsennton
2015/10/20 13:27:12
We do have a DeviceDisplayInfo stored in WindowAnd
| |
| 29 Java_DeviceDisplayInfo_getDisplayHeight(env, j_device_info_.obj()), | |
| 30 Java_DeviceDisplayInfo_getDisplayWidth(env, j_device_info_.obj()), | |
| 31 Java_DeviceDisplayInfo_getPhysicalDisplayHeight(env, | |
| 32 j_device_info_.obj()), | |
| 33 Java_DeviceDisplayInfo_getPhysicalDisplayWidth(env, j_device_info_.obj()), | |
| 34 Java_DeviceDisplayInfo_getBitsPerPixel(env, j_device_info_.obj()), | |
| 35 Java_DeviceDisplayInfo_getBitsPerComponent(env, j_device_info_.obj()), | |
| 36 Java_DeviceDisplayInfo_getDIPScale(env, j_device_info_.obj()), | |
| 37 Java_DeviceDisplayInfo_getSmallestDIPWidth(env, j_device_info_.obj()), | |
| 38 Java_DeviceDisplayInfo_getRotationDegrees(env, j_device_info_.obj())); | |
| 20 } | 39 } |
| 21 | 40 |
| 22 int DeviceDisplayInfo::GetDisplayWidth() { | 41 void DeviceDisplayInfo::UpdateDisplayInfo(jint display_height, |
| 23 return SharedDeviceDisplayInfo::GetInstance()->GetDisplayWidth(); | 42 jint display_width, |
| 43 jint physical_display_height, | |
| 44 jint physical_display_width, | |
| 45 jint bits_per_pixel, | |
| 46 jint bits_per_component, | |
| 47 jdouble dip_scale, | |
| 48 jint smallest_dip_width, | |
| 49 jint rotation_degrees) { | |
| 50 display_height_ = static_cast<int>(display_height); | |
| 51 display_width_ = static_cast<int>(display_width); | |
| 52 physical_display_height_ = static_cast<int>(physical_display_height); | |
| 53 physical_display_width_ = static_cast<int>(physical_display_width); | |
| 54 bits_per_pixel_ = static_cast<int>(bits_per_pixel); | |
| 55 bits_per_component_ = static_cast<int>(bits_per_component); | |
| 56 dip_scale_ = static_cast<double>(dip_scale); | |
| 57 smallest_dip_width_ = static_cast<int>(smallest_dip_width); | |
| 58 rotation_degrees_ = static_cast<int>(rotation_degrees); | |
| 24 } | 59 } |
| 25 | 60 |
| 26 int DeviceDisplayInfo::GetPhysicalDisplayHeight() { | 61 int DeviceDisplayInfo::GetDisplayHeight() const { |
| 27 return SharedDeviceDisplayInfo::GetInstance()->GetPhysicalDisplayHeight(); | 62 return display_height_; |
| 28 } | 63 } |
| 29 | 64 |
| 30 int DeviceDisplayInfo::GetPhysicalDisplayWidth() { | 65 int DeviceDisplayInfo::GetDisplayWidth() const { |
| 31 return SharedDeviceDisplayInfo::GetInstance()->GetPhysicalDisplayWidth(); | 66 return display_width_; |
| 32 } | 67 } |
| 33 | 68 |
| 34 int DeviceDisplayInfo::GetBitsPerPixel() { | 69 int DeviceDisplayInfo::GetPhysicalDisplayHeight() const { |
| 35 return SharedDeviceDisplayInfo::GetInstance()->GetBitsPerPixel(); | 70 return physical_display_height_; |
| 36 } | 71 } |
| 37 | 72 |
| 38 int DeviceDisplayInfo::GetBitsPerComponent() { | 73 int DeviceDisplayInfo::GetPhysicalDisplayWidth() const { |
| 39 return SharedDeviceDisplayInfo::GetInstance()->GetBitsPerComponent(); | 74 return physical_display_width_; |
| 40 } | 75 } |
| 41 | 76 |
| 42 double DeviceDisplayInfo::GetDIPScale() { | 77 int DeviceDisplayInfo::GetBitsPerPixel() const { |
| 43 return SharedDeviceDisplayInfo::GetInstance()->GetDIPScale(); | 78 return bits_per_pixel_; |
| 44 } | 79 } |
| 45 | 80 |
| 46 int DeviceDisplayInfo::GetSmallestDIPWidth() { | 81 int DeviceDisplayInfo::GetBitsPerComponent() const { |
| 47 return SharedDeviceDisplayInfo::GetInstance()->GetSmallestDIPWidth(); | 82 return bits_per_component_; |
| 48 } | 83 } |
| 49 | 84 |
| 50 int DeviceDisplayInfo::GetRotationDegrees() { | 85 double DeviceDisplayInfo::GetDIPScale() const { |
| 51 return SharedDeviceDisplayInfo::GetInstance()->GetRotationDegrees(); | 86 return dip_scale_; |
| 87 } | |
| 88 | |
| 89 int DeviceDisplayInfo::GetSmallestDIPWidth() const { | |
| 90 return smallest_dip_width_; | |
| 91 } | |
| 92 | |
| 93 int DeviceDisplayInfo::GetRotationDegrees() const { | |
| 94 return rotation_degrees_; | |
| 95 } | |
| 96 | |
| 97 // static | |
| 98 bool DeviceDisplayInfo::RegisterDeviceDisplayInfo(JNIEnv* env) { | |
| 99 return RegisterNativesImpl(env); | |
| 52 } | 100 } |
| 53 | 101 |
| 54 } // namespace gfx | 102 } // namespace gfx |
| OLD | NEW |