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 |
| 12 DeviceDisplayInfo::DeviceDisplayInfo() { | 10 DeviceDisplayInfo::DeviceDisplayInfo(jobject windowAndroid) { |
| 11 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 12 j_device_info_.Reset( | |
| 13 Java_DeviceDisplayInfo_createFromWindow(env, windowAndroid)); | |
| 14 UpdateDisplayInfo( | |
| 15 Java_DeviceDisplayInfo_getDisplayHeight(env, j_device_info_.obj()), | |
| 16 Java_DeviceDisplayInfo_getDisplayWidth(env, j_device_info_.obj()), | |
| 17 Java_DeviceDisplayInfo_getPhysicalDisplayHeight(env, | |
| 18 j_device_info_.obj()), | |
| 19 Java_DeviceDisplayInfo_getPhysicalDisplayWidth(env, j_device_info_.obj()), | |
| 20 Java_DeviceDisplayInfo_getBitsPerPixel(env, j_device_info_.obj()), | |
| 21 Java_DeviceDisplayInfo_getBitsPerComponent(env, j_device_info_.obj()), | |
| 22 Java_DeviceDisplayInfo_getDIPScale(env, j_device_info_.obj()), | |
| 23 Java_DeviceDisplayInfo_getSmallestDIPWidth(env, j_device_info_.obj()), | |
| 24 Java_DeviceDisplayInfo_getRotationDegrees(env, j_device_info_.obj())); | |
| 25 } | |
| 26 | |
| 27 DeviceDisplayInfo::DeviceDisplayInfo() { // TODO ugly? | |
|
boliu
2015/06/01 15:30:18
c++11 allows just calling the other constructor no
gsennton
2015/06/04 14:10:29
I am not sure what you mean by this? The other con
boliu
2015/06/05 04:57:51
Oh good point. But you could factor out the body o
| |
| 28 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 29 j_device_info_.Reset( | |
| 30 Java_DeviceDisplayInfo_create(env, | |
| 31 base::android::GetApplicationContext())); | |
| 32 UpdateDisplayInfo( | |
| 33 Java_DeviceDisplayInfo_getDisplayHeight(env, j_device_info_.obj()), | |
| 34 Java_DeviceDisplayInfo_getDisplayWidth(env, j_device_info_.obj()), | |
| 35 Java_DeviceDisplayInfo_getPhysicalDisplayHeight(env, | |
| 36 j_device_info_.obj()), | |
| 37 Java_DeviceDisplayInfo_getPhysicalDisplayWidth(env, j_device_info_.obj()), | |
| 38 Java_DeviceDisplayInfo_getBitsPerPixel(env, j_device_info_.obj()), | |
| 39 Java_DeviceDisplayInfo_getBitsPerComponent(env, j_device_info_.obj()), | |
| 40 Java_DeviceDisplayInfo_getDIPScale(env, j_device_info_.obj()), | |
| 41 Java_DeviceDisplayInfo_getSmallestDIPWidth(env, j_device_info_.obj()), | |
| 42 Java_DeviceDisplayInfo_getRotationDegrees(env, j_device_info_.obj())); | |
| 13 } | 43 } |
| 14 | 44 |
| 15 DeviceDisplayInfo::~DeviceDisplayInfo() { | 45 DeviceDisplayInfo::~DeviceDisplayInfo() { |
| 16 } | 46 } |
| 17 | 47 |
| 48 void DeviceDisplayInfo::UpdateDisplayInfo(jint display_height, | |
| 49 jint display_width, | |
| 50 jint physical_display_height, | |
| 51 jint physical_display_width, | |
| 52 jint bits_per_pixel, | |
| 53 jint bits_per_component, | |
| 54 jdouble dip_scale, | |
| 55 jint smallest_dip_width, | |
| 56 jint rotation_degrees) { | |
| 57 display_height_ = static_cast<int>(display_height); | |
| 58 display_width_ = static_cast<int>(display_width); | |
| 59 physical_display_height_ = static_cast<int>(physical_display_height); | |
| 60 physical_display_width_ = static_cast<int>(physical_display_width); | |
| 61 bits_per_pixel_ = static_cast<int>(bits_per_pixel); | |
| 62 bits_per_component_ = static_cast<int>(bits_per_component); | |
| 63 dip_scale_ = static_cast<double>(dip_scale); | |
| 64 smallest_dip_width_ = static_cast<int>(smallest_dip_width); | |
| 65 rotation_degrees_ = static_cast<int>(rotation_degrees); | |
| 66 } | |
| 67 | |
| 18 int DeviceDisplayInfo::GetDisplayHeight() { | 68 int DeviceDisplayInfo::GetDisplayHeight() { |
| 19 return SharedDeviceDisplayInfo::GetInstance()->GetDisplayHeight(); | 69 return display_height_; |
| 20 } | 70 } |
| 21 | 71 |
| 22 int DeviceDisplayInfo::GetDisplayWidth() { | 72 int DeviceDisplayInfo::GetDisplayWidth() { |
| 23 return SharedDeviceDisplayInfo::GetInstance()->GetDisplayWidth(); | 73 return display_width_; |
| 24 } | 74 } |
| 25 | 75 |
| 26 int DeviceDisplayInfo::GetPhysicalDisplayHeight() { | 76 int DeviceDisplayInfo::GetPhysicalDisplayHeight() { |
| 27 return SharedDeviceDisplayInfo::GetInstance()->GetPhysicalDisplayHeight(); | 77 return physical_display_height_; |
| 28 } | 78 } |
| 29 | 79 |
| 30 int DeviceDisplayInfo::GetPhysicalDisplayWidth() { | 80 int DeviceDisplayInfo::GetPhysicalDisplayWidth() { |
| 31 return SharedDeviceDisplayInfo::GetInstance()->GetPhysicalDisplayWidth(); | 81 return physical_display_width_; |
| 32 } | 82 } |
| 33 | 83 |
| 34 int DeviceDisplayInfo::GetBitsPerPixel() { | 84 int DeviceDisplayInfo::GetBitsPerPixel() { |
| 35 return SharedDeviceDisplayInfo::GetInstance()->GetBitsPerPixel(); | 85 return bits_per_pixel_; |
| 36 } | 86 } |
| 37 | 87 |
| 38 int DeviceDisplayInfo::GetBitsPerComponent() { | 88 int DeviceDisplayInfo::GetBitsPerComponent() { |
| 39 return SharedDeviceDisplayInfo::GetInstance()->GetBitsPerComponent(); | 89 return bits_per_component_; |
| 40 } | 90 } |
| 41 | 91 |
| 42 double DeviceDisplayInfo::GetDIPScale() { | 92 double DeviceDisplayInfo::GetDIPScale() { |
| 43 return SharedDeviceDisplayInfo::GetInstance()->GetDIPScale(); | 93 return dip_scale_; |
| 44 } | 94 } |
| 45 | 95 |
| 46 int DeviceDisplayInfo::GetSmallestDIPWidth() { | 96 int DeviceDisplayInfo::GetSmallestDIPWidth() { |
| 47 return SharedDeviceDisplayInfo::GetInstance()->GetSmallestDIPWidth(); | 97 return smallest_dip_width_; |
| 48 } | 98 } |
| 49 | 99 |
| 50 int DeviceDisplayInfo::GetRotationDegrees() { | 100 int DeviceDisplayInfo::GetRotationDegrees() { |
| 51 return SharedDeviceDisplayInfo::GetInstance()->GetRotationDegrees(); | 101 return rotation_degrees_; |
| 102 } | |
| 103 | |
| 104 // static | |
| 105 bool DeviceDisplayInfo::RegisterDeviceDisplayInfo(JNIEnv* env) { | |
| 106 return RegisterNativesImpl(env); | |
| 52 } | 107 } |
| 53 | 108 |
| 54 } // namespace gfx | 109 } // namespace gfx |
| OLD | NEW |