| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 <stdio.h> | 5 #include <stdio.h> |
| 6 #include <string> | 6 #include <string> |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "ash/display/display_info.h" | 9 #include "ash/display/display_info.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 } | 149 } |
| 150 } | 150 } |
| 151 display_modes[native_mode].native = true; | 151 display_modes[native_mode].native = true; |
| 152 } | 152 } |
| 153 | 153 |
| 154 if (id == gfx::Display::kInvalidDisplayID) | 154 if (id == gfx::Display::kInvalidDisplayID) |
| 155 id = synthesized_display_id++; | 155 id = synthesized_display_id++; |
| 156 DisplayInfo display_info( | 156 DisplayInfo display_info( |
| 157 id, base::StringPrintf("Display-%d", static_cast<int>(id)), has_overscan); | 157 id, base::StringPrintf("Display-%d", static_cast<int>(id)), has_overscan); |
| 158 display_info.set_device_scale_factor(device_scale_factor); | 158 display_info.set_device_scale_factor(device_scale_factor); |
| 159 display_info.set_rotation(rotation); | 159 display_info.SetRotation(rotation, ui::USER); |
| 160 display_info.set_configured_ui_scale(ui_scale); | 160 display_info.set_configured_ui_scale(ui_scale); |
| 161 display_info.SetBounds(bounds_in_native); | 161 display_info.SetBounds(bounds_in_native); |
| 162 display_info.set_display_modes(display_modes); | 162 display_info.set_display_modes(display_modes); |
| 163 | 163 |
| 164 // To test the overscan, it creates the default 5% overscan. | 164 // To test the overscan, it creates the default 5% overscan. |
| 165 if (has_overscan) { | 165 if (has_overscan) { |
| 166 int width = bounds_in_native.width() / device_scale_factor / 40; | 166 int width = bounds_in_native.width() / device_scale_factor / 40; |
| 167 int height = bounds_in_native.height() / device_scale_factor / 40; | 167 int height = bounds_in_native.height() / device_scale_factor / 40; |
| 168 display_info.SetOverscanInsets(gfx::Insets(height, width, height, width)); | 168 display_info.SetOverscanInsets(gfx::Insets(height, width, height, width)); |
| 169 display_info.UpdateDisplaySize(); | 169 display_info.UpdateDisplaySize(); |
| 170 } | 170 } |
| 171 | 171 |
| 172 DVLOG(1) << "DisplayInfoFromSpec info=" << display_info.ToString() | 172 DVLOG(1) << "DisplayInfoFromSpec info=" << display_info.ToString() |
| 173 << ", spec=" << spec; | 173 << ", spec=" << spec; |
| 174 return display_info; | 174 return display_info; |
| 175 } | 175 } |
| 176 | 176 |
| 177 DisplayInfo::DisplayInfo() | 177 DisplayInfo::DisplayInfo() |
| 178 : id_(gfx::Display::kInvalidDisplayID), | 178 : id_(gfx::Display::kInvalidDisplayID), |
| 179 has_overscan_(false), | 179 has_overscan_(false), |
| 180 rotation_(gfx::Display::ROTATE_0), | 180 current_rotation_(gfx::Display::ROTATE_0), |
| 181 touch_support_(gfx::Display::TOUCH_SUPPORT_UNKNOWN), | 181 touch_support_(gfx::Display::TOUCH_SUPPORT_UNKNOWN), |
| 182 touch_device_id_(0), | 182 touch_device_id_(0), |
| 183 device_scale_factor_(1.0f), | 183 device_scale_factor_(1.0f), |
| 184 overscan_insets_in_dip_(0, 0, 0, 0), | 184 overscan_insets_in_dip_(0, 0, 0, 0), |
| 185 configured_ui_scale_(1.0f), | 185 configured_ui_scale_(1.0f), |
| 186 native_(false), | 186 native_(false), |
| 187 color_profile_(ui::COLOR_PROFILE_STANDARD) { | 187 color_profile_(ui::COLOR_PROFILE_STANDARD) { |
| 188 } | 188 } |
| 189 | 189 |
| 190 DisplayInfo::DisplayInfo(int64 id, | 190 DisplayInfo::DisplayInfo(int64 id, |
| 191 const std::string& name, | 191 const std::string& name, |
| 192 bool has_overscan) | 192 bool has_overscan) |
| 193 : id_(id), | 193 : id_(id), |
| 194 name_(name), | 194 name_(name), |
| 195 has_overscan_(has_overscan), | 195 has_overscan_(has_overscan), |
| 196 rotation_(gfx::Display::ROTATE_0), | 196 current_rotation_(gfx::Display::ROTATE_0), |
| 197 touch_support_(gfx::Display::TOUCH_SUPPORT_UNKNOWN), | 197 touch_support_(gfx::Display::TOUCH_SUPPORT_UNKNOWN), |
| 198 touch_device_id_(0), | 198 touch_device_id_(0), |
| 199 device_scale_factor_(1.0f), | 199 device_scale_factor_(1.0f), |
| 200 overscan_insets_in_dip_(0, 0, 0, 0), | 200 overscan_insets_in_dip_(0, 0, 0, 0), |
| 201 configured_ui_scale_(1.0f), | 201 configured_ui_scale_(1.0f), |
| 202 native_(false), | 202 native_(false), |
| 203 color_profile_(ui::COLOR_PROFILE_STANDARD) { | 203 color_profile_(ui::COLOR_PROFILE_STANDARD) { |
| 204 } | 204 } |
| 205 | 205 |
| 206 DisplayInfo::~DisplayInfo() { | 206 DisplayInfo::~DisplayInfo() { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 223 // cases which use "/o" annotation which sets the overscan inset | 223 // cases which use "/o" annotation which sets the overscan inset |
| 224 // to native, and that overscan has to be propagated. This does not | 224 // to native, and that overscan has to be propagated. This does not |
| 225 // happen on the real environment. | 225 // happen on the real environment. |
| 226 if (!native_info.overscan_insets_in_dip_.empty()) | 226 if (!native_info.overscan_insets_in_dip_.empty()) |
| 227 overscan_insets_in_dip_ = native_info.overscan_insets_in_dip_; | 227 overscan_insets_in_dip_ = native_info.overscan_insets_in_dip_; |
| 228 | 228 |
| 229 // Rotation_ and ui_scale_ color_profile_ are given by preference, | 229 // Rotation_ and ui_scale_ color_profile_ are given by preference, |
| 230 // or unit tests. Don't copy if this native_info came from | 230 // or unit tests. Don't copy if this native_info came from |
| 231 // DisplayChangeObserver. | 231 // DisplayChangeObserver. |
| 232 if (!native_info.native()) { | 232 if (!native_info.native()) { |
| 233 rotation_ = native_info.rotation_; | 233 current_rotation_ = native_info.current_rotation_; |
| 234 rotations_ = native_info.rotations_; |
| 234 configured_ui_scale_ = native_info.configured_ui_scale_; | 235 configured_ui_scale_ = native_info.configured_ui_scale_; |
| 235 color_profile_ = native_info.color_profile(); | 236 color_profile_ = native_info.color_profile(); |
| 236 } | 237 } |
| 237 | 238 |
| 238 available_color_profiles_ = native_info.available_color_profiles(); | 239 available_color_profiles_ = native_info.available_color_profiles(); |
| 239 | 240 |
| 240 // Don't copy insets as it may be given by preference. |rotation_| | 241 // Don't copy insets as it may be given by preference. |rotation_| |
| 241 // is treated as a native so that it can be specified in | 242 // is treated as a native so that it can be specified in |
| 242 // |CreateFromSpec|. | 243 // |CreateFromSpec|. |
| 243 } | 244 } |
| 244 | 245 |
| 245 void DisplayInfo::SetBounds(const gfx::Rect& new_bounds_in_native) { | 246 void DisplayInfo::SetBounds(const gfx::Rect& new_bounds_in_native) { |
| 246 bounds_in_native_ = new_bounds_in_native; | 247 bounds_in_native_ = new_bounds_in_native; |
| 247 size_in_pixel_ = new_bounds_in_native.size(); | 248 size_in_pixel_ = new_bounds_in_native.size(); |
| 248 UpdateDisplaySize(); | 249 UpdateDisplaySize(); |
| 249 } | 250 } |
| 250 | 251 |
| 252 gfx::Display::Rotation DisplayInfo::GetRotation(ui::RotationSource source) { |
| 253 return rotations_[source]; |
| 254 } |
| 255 |
| 256 void DisplayInfo::SetRotation(gfx::Display::Rotation rotation, |
| 257 ui::RotationSource source) { |
| 258 rotations_[source] = rotation; |
| 259 current_rotation_ = rotation; |
| 260 } |
| 261 |
| 262 |
| 251 float DisplayInfo::GetEffectiveDeviceScaleFactor() const { | 263 float DisplayInfo::GetEffectiveDeviceScaleFactor() const { |
| 252 if (allow_upgrade_to_high_dpi && configured_ui_scale_ < 1.0f && | 264 if (allow_upgrade_to_high_dpi && configured_ui_scale_ < 1.0f && |
| 253 device_scale_factor_ == 1.0f) { | 265 device_scale_factor_ == 1.0f) { |
| 254 return 2.0f; | 266 return 2.0f; |
| 255 } else if (device_scale_factor_ == 2.0f && configured_ui_scale_ == 2.0f) { | 267 } else if (device_scale_factor_ == 2.0f && configured_ui_scale_ == 2.0f) { |
| 256 return 1.0f; | 268 return 1.0f; |
| 257 } | 269 } |
| 258 return device_scale_factor_; | 270 return device_scale_factor_; |
| 259 } | 271 } |
| 260 | 272 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 271 void DisplayInfo::UpdateDisplaySize() { | 283 void DisplayInfo::UpdateDisplaySize() { |
| 272 size_in_pixel_ = bounds_in_native_.size(); | 284 size_in_pixel_ = bounds_in_native_.size(); |
| 273 if (!overscan_insets_in_dip_.empty()) { | 285 if (!overscan_insets_in_dip_.empty()) { |
| 274 gfx::Insets insets_in_pixel = | 286 gfx::Insets insets_in_pixel = |
| 275 overscan_insets_in_dip_.Scale(device_scale_factor_); | 287 overscan_insets_in_dip_.Scale(device_scale_factor_); |
| 276 size_in_pixel_.Enlarge(-insets_in_pixel.width(), -insets_in_pixel.height()); | 288 size_in_pixel_.Enlarge(-insets_in_pixel.width(), -insets_in_pixel.height()); |
| 277 } else { | 289 } else { |
| 278 overscan_insets_in_dip_.Set(0, 0, 0, 0); | 290 overscan_insets_in_dip_.Set(0, 0, 0, 0); |
| 279 } | 291 } |
| 280 | 292 |
| 281 if (rotation_ == gfx::Display::ROTATE_90 || | 293 if (current_rotation_ == gfx::Display::ROTATE_90 || |
| 282 rotation_ == gfx::Display::ROTATE_270) | 294 current_rotation_ == gfx::Display::ROTATE_270) |
| 283 size_in_pixel_.SetSize(size_in_pixel_.height(), size_in_pixel_.width()); | 295 size_in_pixel_.SetSize(size_in_pixel_.height(), size_in_pixel_.width()); |
| 284 gfx::SizeF size_f(size_in_pixel_); | 296 gfx::SizeF size_f(size_in_pixel_); |
| 285 size_f.Scale(GetEffectiveUIScale()); | 297 size_f.Scale(GetEffectiveUIScale()); |
| 286 size_in_pixel_ = gfx::ToFlooredSize(size_f); | 298 size_in_pixel_ = gfx::ToFlooredSize(size_f); |
| 287 } | 299 } |
| 288 | 300 |
| 289 void DisplayInfo::SetOverscanInsets(const gfx::Insets& insets_in_dip) { | 301 void DisplayInfo::SetOverscanInsets(const gfx::Insets& insets_in_dip) { |
| 290 overscan_insets_in_dip_ = insets_in_dip; | 302 overscan_insets_in_dip_ = insets_in_dip; |
| 291 } | 303 } |
| 292 | 304 |
| 293 gfx::Insets DisplayInfo::GetOverscanInsetsInPixel() const { | 305 gfx::Insets DisplayInfo::GetOverscanInsetsInPixel() const { |
| 294 return overscan_insets_in_dip_.Scale(device_scale_factor_); | 306 return overscan_insets_in_dip_.Scale(device_scale_factor_); |
| 295 } | 307 } |
| 296 | 308 |
| 297 std::string DisplayInfo::ToString() const { | 309 std::string DisplayInfo::ToString() const { |
| 298 int rotation_degree = static_cast<int>(rotation_) * 90; | 310 int rotation_degree = static_cast<int>(current_rotation_) * 90; |
| 299 return base::StringPrintf( | 311 return base::StringPrintf( |
| 300 "DisplayInfo[%lld] native bounds=%s, size=%s, scale=%f, " | 312 "DisplayInfo[%lld] native bounds=%s, size=%s, scale=%f, " |
| 301 "overscan=%s, rotation=%d, ui-scale=%f, touchscreen=%s, " | 313 "overscan=%s, rotation=%d, ui-scale=%f, touchscreen=%s, " |
| 302 "touch-device-id=%d", | 314 "touch-device-id=%d", |
| 303 static_cast<long long int>(id_), | 315 static_cast<long long int>(id_), |
| 304 bounds_in_native_.ToString().c_str(), | 316 bounds_in_native_.ToString().c_str(), |
| 305 size_in_pixel_.ToString().c_str(), | 317 size_in_pixel_.ToString().c_str(), |
| 306 device_scale_factor_, | 318 device_scale_factor_, |
| 307 overscan_insets_in_dip_.ToString().c_str(), | 319 overscan_insets_in_dip_.ToString().c_str(), |
| 308 rotation_degree, | 320 rotation_degree, |
| (...skipping 29 matching lines...) Expand all Loading... |
| 338 } | 350 } |
| 339 | 351 |
| 340 bool DisplayInfo::IsColorProfileAvailable( | 352 bool DisplayInfo::IsColorProfileAvailable( |
| 341 ui::ColorCalibrationProfile profile) const { | 353 ui::ColorCalibrationProfile profile) const { |
| 342 return std::find(available_color_profiles_.begin(), | 354 return std::find(available_color_profiles_.begin(), |
| 343 available_color_profiles_.end(), | 355 available_color_profiles_.end(), |
| 344 profile) != available_color_profiles_.end(); | 356 profile) != available_color_profiles_.end(); |
| 345 } | 357 } |
| 346 | 358 |
| 347 } // namespace ash | 359 } // namespace ash |
| OLD | NEW |