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( | |
|
jdduke (slow)
2015/06/16 15:01:28
So, there's an assumption currently that creating
gsennton
2015/06/17 11:40:36
Potentially stupid question from my part -- why is
jdduke (slow)
2015/06/17 15:56:04
Now we have to construct a new Java object, and ca
boliu
2015/06/17 16:02:20
The bigger issue is to avoid gc pauses. Eg during
gsennton
2015/06/18 11:37:22
Oh, right, I missed this entirely -- if jni calls
gsennton
2015/06/25 13:59:58
To answer the original question here,
Chrome:
Whe
| |
| 11 base::android::ScopedJavaLocalRef<jobject> context) { | |
| 12 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 13 j_device_info_.Reset( | |
| 14 Java_DeviceDisplayInfo_create(env, context.obj())); | |
| 15 FetchDisplayInfoFromJava(env); | |
| 16 } | |
| 17 | |
| 12 DeviceDisplayInfo::DeviceDisplayInfo() { | 18 DeviceDisplayInfo::DeviceDisplayInfo() { |
| 19 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 20 j_device_info_.Reset( | |
|
jdduke (slow)
2015/06/17 15:56:04
It's a shame to have to create a Java object here
gsennton
2015/06/18 11:37:22
We could cache the primary display info in some sh
| |
| 21 Java_DeviceDisplayInfo_create(env, | |
| 22 base::android::GetApplicationContext())); | |
| 23 FetchDisplayInfoFromJava(env); | |
| 13 } | 24 } |
| 14 | 25 |
| 15 DeviceDisplayInfo::~DeviceDisplayInfo() { | 26 DeviceDisplayInfo::~DeviceDisplayInfo() { |
| 16 } | 27 } |
| 17 | 28 |
| 29 void DeviceDisplayInfo::FetchDisplayInfoFromJava(JNIEnv* env) { | |
| 30 UpdateDisplayInfo( | |
| 31 Java_DeviceDisplayInfo_getDisplayHeight(env, j_device_info_.obj()), | |
| 32 Java_DeviceDisplayInfo_getDisplayWidth(env, j_device_info_.obj()), | |
| 33 Java_DeviceDisplayInfo_getPhysicalDisplayHeight(env, | |
| 34 j_device_info_.obj()), | |
| 35 Java_DeviceDisplayInfo_getPhysicalDisplayWidth(env, j_device_info_.obj()), | |
| 36 Java_DeviceDisplayInfo_getBitsPerPixel(env, j_device_info_.obj()), | |
| 37 Java_DeviceDisplayInfo_getBitsPerComponent(env, j_device_info_.obj()), | |
| 38 Java_DeviceDisplayInfo_getDIPScale(env, j_device_info_.obj()), | |
| 39 Java_DeviceDisplayInfo_getSmallestDIPWidth(env, j_device_info_.obj()), | |
| 40 Java_DeviceDisplayInfo_getRotationDegrees(env, j_device_info_.obj())); | |
| 41 } | |
| 42 | |
| 43 void DeviceDisplayInfo::UpdateDisplayInfo(jint display_height, | |
| 44 jint display_width, | |
| 45 jint physical_display_height, | |
| 46 jint physical_display_width, | |
| 47 jint bits_per_pixel, | |
| 48 jint bits_per_component, | |
| 49 jdouble dip_scale, | |
| 50 jint smallest_dip_width, | |
| 51 jint rotation_degrees) { | |
| 52 display_height_ = static_cast<int>(display_height); | |
| 53 display_width_ = static_cast<int>(display_width); | |
| 54 physical_display_height_ = static_cast<int>(physical_display_height); | |
| 55 physical_display_width_ = static_cast<int>(physical_display_width); | |
| 56 bits_per_pixel_ = static_cast<int>(bits_per_pixel); | |
| 57 bits_per_component_ = static_cast<int>(bits_per_component); | |
| 58 dip_scale_ = static_cast<double>(dip_scale); | |
| 59 smallest_dip_width_ = static_cast<int>(smallest_dip_width); | |
| 60 rotation_degrees_ = static_cast<int>(rotation_degrees); | |
| 61 } | |
| 62 | |
| 63 // TODO all these can be const if we only return the stored values here | |
| 18 int DeviceDisplayInfo::GetDisplayHeight() { | 64 int DeviceDisplayInfo::GetDisplayHeight() { |
| 19 return SharedDeviceDisplayInfo::GetInstance()->GetDisplayHeight(); | 65 return display_height_; |
| 20 } | 66 } |
| 21 | 67 |
| 22 int DeviceDisplayInfo::GetDisplayWidth() { | 68 int DeviceDisplayInfo::GetDisplayWidth() { |
| 23 return SharedDeviceDisplayInfo::GetInstance()->GetDisplayWidth(); | 69 return display_width_; |
| 24 } | 70 } |
| 25 | 71 |
| 26 int DeviceDisplayInfo::GetPhysicalDisplayHeight() { | 72 int DeviceDisplayInfo::GetPhysicalDisplayHeight() { |
| 27 return SharedDeviceDisplayInfo::GetInstance()->GetPhysicalDisplayHeight(); | 73 return physical_display_height_; |
| 28 } | 74 } |
| 29 | 75 |
| 30 int DeviceDisplayInfo::GetPhysicalDisplayWidth() { | 76 int DeviceDisplayInfo::GetPhysicalDisplayWidth() { |
| 31 return SharedDeviceDisplayInfo::GetInstance()->GetPhysicalDisplayWidth(); | 77 return physical_display_width_; |
| 32 } | 78 } |
| 33 | 79 |
| 34 int DeviceDisplayInfo::GetBitsPerPixel() { | 80 int DeviceDisplayInfo::GetBitsPerPixel() { |
| 35 return SharedDeviceDisplayInfo::GetInstance()->GetBitsPerPixel(); | 81 return bits_per_pixel_; |
| 36 } | 82 } |
| 37 | 83 |
| 38 int DeviceDisplayInfo::GetBitsPerComponent() { | 84 int DeviceDisplayInfo::GetBitsPerComponent() { |
| 39 return SharedDeviceDisplayInfo::GetInstance()->GetBitsPerComponent(); | 85 return bits_per_component_; |
| 40 } | 86 } |
| 41 | 87 |
| 42 double DeviceDisplayInfo::GetDIPScale() { | 88 double DeviceDisplayInfo::GetDIPScale() { |
| 43 return SharedDeviceDisplayInfo::GetInstance()->GetDIPScale(); | 89 return dip_scale_; |
| 44 } | 90 } |
| 45 | 91 |
| 46 int DeviceDisplayInfo::GetSmallestDIPWidth() { | 92 int DeviceDisplayInfo::GetSmallestDIPWidth() { |
| 47 return SharedDeviceDisplayInfo::GetInstance()->GetSmallestDIPWidth(); | 93 return smallest_dip_width_; |
| 48 } | 94 } |
| 49 | 95 |
| 50 int DeviceDisplayInfo::GetRotationDegrees() { | 96 int DeviceDisplayInfo::GetRotationDegrees() { |
| 51 return SharedDeviceDisplayInfo::GetInstance()->GetRotationDegrees(); | 97 return rotation_degrees_; |
| 98 } | |
| 99 | |
| 100 // static | |
| 101 bool DeviceDisplayInfo::RegisterDeviceDisplayInfo(JNIEnv* env) { | |
| 102 return RegisterNativesImpl(env); | |
| 52 } | 103 } |
| 53 | 104 |
| 54 } // namespace gfx | 105 } // namespace gfx |
| OLD | NEW |