1 // Copyright 2015 Samsung Electronics. 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.
5 #include "ui/display/device_display_info_efl.h"
7 #include "base/logging.h"
8 #include "tizen/system_info.h"
14 const double kBaselineDPIDensity = 160.0;
15 const int kInvalidRotationDegrees = -1;
17 int GetDensityRange(int dpi) {
18 if (IsMobileProfile() || IsWearableProfile()) {
19 // Copied from Android platform and extended to support UHD displays,
20 // (http://developer.android.com/reference/android/util/DisplayMetrics.html).
21 const int density_range[] = {
42 const int range_size = sizeof(density_range) / sizeof(*density_range);
43 int upper_bound = density_range[range_size - 1];
44 for (int i = range_size - 2; i >= 0 && dpi <= density_range[i]; --i) {
45 upper_bound = density_range[i];
50 // For platforms other than mobile, the user agents expect 1.0 as DIP scale
51 // for the contents to be delivered.
58 // DeviceDisplayInfoEflImpl
59 class DISPLAY_EXPORT DeviceDisplayInfoEflImpl {
61 static DeviceDisplayInfoEflImpl* GetInstance();
63 void Update(int display_width, int display_height, double dip_scale,
64 int rotation_degrees);
65 void SetRotationDegrees(int rotation_degrees);
66 int GetDisplayWidth() const;
67 int GetDisplayHeight() const;
68 double GetDIPScale() const;
69 int GetRotationDegrees() const;
72 DeviceDisplayInfoEflImpl();
74 friend struct base::DefaultSingletonTraits<DeviceDisplayInfoEflImpl>;
76 mutable base::Lock display_info_accessor_;
77 mutable base::Lock rotation_accessor_;
82 int rotation_degrees_;
84 DISALLOW_COPY_AND_ASSIGN(DeviceDisplayInfoEflImpl);
88 DeviceDisplayInfoEflImpl* DeviceDisplayInfoEflImpl::GetInstance() {
89 return base::Singleton<DeviceDisplayInfoEflImpl>::get();
92 void DeviceDisplayInfoEflImpl::Update(int display_width, int display_height,
93 double dip_scale, int rotation_degrees) {
95 base::AutoLock autolock(display_info_accessor_);
96 display_width_ = display_width;
97 display_height_ = display_height;
98 dip_scale_ = dip_scale;
100 DCHECK_NE(0, display_width_);
101 DCHECK_NE(0, display_height_);
102 DCHECK_NE(0, dip_scale_);
106 base::AutoLock autolock(rotation_accessor_);
107 rotation_degrees_ = rotation_degrees;
108 DCHECK_NE(kInvalidRotationDegrees, rotation_degrees_);
112 void DeviceDisplayInfoEflImpl::SetRotationDegrees(int rotation_degrees) {
113 base::AutoLock autolock(rotation_accessor_);
114 rotation_degrees_ = rotation_degrees;
117 int DeviceDisplayInfoEflImpl::GetDisplayWidth() const {
118 base::AutoLock autolock(display_info_accessor_);
119 DCHECK_NE(0, display_width_);
120 return display_width_;
123 int DeviceDisplayInfoEflImpl::GetDisplayHeight() const {
124 base::AutoLock autolock(display_info_accessor_);
125 DCHECK_NE(0, display_height_);
126 return display_height_;
129 double DeviceDisplayInfoEflImpl::GetDIPScale() const {
130 base::AutoLock autolock(display_info_accessor_);
131 DCHECK_NE(0, dip_scale_);
135 int DeviceDisplayInfoEflImpl::GetRotationDegrees() const {
136 base::AutoLock autolock(rotation_accessor_);
137 DCHECK_NE(kInvalidRotationDegrees, rotation_degrees_);
138 return rotation_degrees_;
141 DeviceDisplayInfoEflImpl::DeviceDisplayInfoEflImpl()
145 rotation_degrees_(kInvalidRotationDegrees) {
148 // DeviceDisplayInfoEfl
149 DeviceDisplayInfoEfl::DeviceDisplayInfoEfl() {
150 DCHECK(DeviceDisplayInfoEflImpl::GetInstance());
153 void DeviceDisplayInfoEfl::Update(int display_width, int display_height,
154 double dip_scale, int rotation_degrees) {
155 DeviceDisplayInfoEflImpl::GetInstance()->Update(
156 display_width, display_height, dip_scale, rotation_degrees);
159 void DeviceDisplayInfoEfl::SetRotationDegrees(int rotation_degrees) {
160 DeviceDisplayInfoEflImpl::GetInstance()->SetRotationDegrees(rotation_degrees);
163 int DeviceDisplayInfoEfl::GetDisplayWidth() const {
164 return DeviceDisplayInfoEflImpl::GetInstance()->GetDisplayWidth();
167 int DeviceDisplayInfoEfl::GetDisplayHeight() const {
168 return DeviceDisplayInfoEflImpl::GetInstance()->GetDisplayHeight();
171 double DeviceDisplayInfoEfl::ComputeDIPScale(int dpi) const {
172 if (IsMobileProfile()) {
173 double dip_scale = static_cast<double>(GetDensityRange(dpi));
175 dip_scale /= kBaselineDPIDensity;
178 // For platforms other than mobile, the user agents expect 1.0 as DIP scale
179 // for the contents to be delivered.
184 double DeviceDisplayInfoEfl::GetDIPScale() const {
185 return DeviceDisplayInfoEflImpl::GetInstance()->GetDIPScale();
188 int DeviceDisplayInfoEfl::GetRotationDegrees() const {
189 return DeviceDisplayInfoEflImpl::GetInstance()->GetRotationDegrees();
192 } // namespace display