Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(145)

Side by Side Diff: ash/display/display_info.cc

Issue 1071353003: Prevent DisplayPreferences from saving incorrect rotations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 } 200 }
201 } 201 }
202 display_modes[native_mode].native = true; 202 display_modes[native_mode].native = true;
203 } 203 }
204 204
205 if (id == gfx::Display::kInvalidDisplayID) 205 if (id == gfx::Display::kInvalidDisplayID)
206 id = synthesized_display_id++; 206 id = synthesized_display_id++;
207 DisplayInfo display_info( 207 DisplayInfo display_info(
208 id, base::StringPrintf("Display-%d", static_cast<int>(id)), has_overscan); 208 id, base::StringPrintf("Display-%d", static_cast<int>(id)), has_overscan);
209 display_info.set_device_scale_factor(device_scale_factor); 209 display_info.set_device_scale_factor(device_scale_factor);
210 display_info.set_rotation(rotation); 210 display_info.SetRotation(rotation, gfx::Display::ROTATION_SOURCE_ACTIVE);
211 display_info.set_configured_ui_scale(ui_scale); 211 display_info.set_configured_ui_scale(ui_scale);
212 display_info.SetBounds(bounds_in_native); 212 display_info.SetBounds(bounds_in_native);
213 display_info.SetDisplayModes(display_modes); 213 display_info.SetDisplayModes(display_modes);
214 214
215 // To test the overscan, it creates the default 5% overscan. 215 // To test the overscan, it creates the default 5% overscan.
216 if (has_overscan) { 216 if (has_overscan) {
217 int width = bounds_in_native.width() / device_scale_factor / 40; 217 int width = bounds_in_native.width() / device_scale_factor / 40;
218 int height = bounds_in_native.height() / device_scale_factor / 40; 218 int height = bounds_in_native.height() / device_scale_factor / 40;
219 display_info.SetOverscanInsets(gfx::Insets(height, width, height, width)); 219 display_info.SetOverscanInsets(gfx::Insets(height, width, height, width));
220 display_info.UpdateDisplaySize(); 220 display_info.UpdateDisplaySize();
221 } 221 }
222 222
223 DVLOG(1) << "DisplayInfoFromSpec info=" << display_info.ToString() 223 DVLOG(1) << "DisplayInfoFromSpec info=" << display_info.ToString()
224 << ", spec=" << spec; 224 << ", spec=" << spec;
225 return display_info; 225 return display_info;
226 } 226 }
227 227
228 DisplayInfo::DisplayInfo() 228 DisplayInfo::DisplayInfo()
229 : id_(gfx::Display::kInvalidDisplayID), 229 : id_(gfx::Display::kInvalidDisplayID),
230 has_overscan_(false), 230 has_overscan_(false),
231 rotation_(gfx::Display::ROTATE_0),
232 touch_support_(gfx::Display::TOUCH_SUPPORT_UNKNOWN), 231 touch_support_(gfx::Display::TOUCH_SUPPORT_UNKNOWN),
233 touch_device_id_(0), 232 touch_device_id_(0),
234 device_scale_factor_(1.0f), 233 device_scale_factor_(1.0f),
235 overscan_insets_in_dip_(0, 0, 0, 0), 234 overscan_insets_in_dip_(0, 0, 0, 0),
236 configured_ui_scale_(1.0f), 235 configured_ui_scale_(1.0f),
237 native_(false), 236 native_(false),
238 is_aspect_preserving_scaling_(false), 237 is_aspect_preserving_scaling_(false),
239 clear_overscan_insets_(false), 238 clear_overscan_insets_(false),
240 color_profile_(ui::COLOR_PROFILE_STANDARD) { 239 color_profile_(ui::COLOR_PROFILE_STANDARD) {
241 } 240 }
242 241
243 DisplayInfo::DisplayInfo(int64 id, 242 DisplayInfo::DisplayInfo(int64 id,
244 const std::string& name, 243 const std::string& name,
245 bool has_overscan) 244 bool has_overscan)
246 : id_(id), 245 : id_(id),
247 name_(name), 246 name_(name),
248 has_overscan_(has_overscan), 247 has_overscan_(has_overscan),
249 rotation_(gfx::Display::ROTATE_0),
250 touch_support_(gfx::Display::TOUCH_SUPPORT_UNKNOWN), 248 touch_support_(gfx::Display::TOUCH_SUPPORT_UNKNOWN),
251 touch_device_id_(0), 249 touch_device_id_(0),
252 device_scale_factor_(1.0f), 250 device_scale_factor_(1.0f),
253 overscan_insets_in_dip_(0, 0, 0, 0), 251 overscan_insets_in_dip_(0, 0, 0, 0),
254 configured_ui_scale_(1.0f), 252 configured_ui_scale_(1.0f),
255 native_(false), 253 native_(false),
256 is_aspect_preserving_scaling_(false), 254 is_aspect_preserving_scaling_(false),
257 clear_overscan_insets_(false), 255 clear_overscan_insets_(false),
258 color_profile_(ui::COLOR_PROFILE_STANDARD) { 256 color_profile_(ui::COLOR_PROFILE_STANDARD) {
259 } 257 }
260 258
261 DisplayInfo::~DisplayInfo() { 259 DisplayInfo::~DisplayInfo() {
262 } 260 }
263 261
262 void DisplayInfo::SetRotation(gfx::Display::Rotation rotation,
263 gfx::Display::RotationSource source) {
264 rotations_[source] = rotation;
265 rotations_[gfx::Display::ROTATION_SOURCE_ACTIVE] = rotation;
266 }
267
268 gfx::Display::Rotation DisplayInfo::Rotation(
tdanderson 2015/04/13 22:44:46 Maybe name this GetRotation() or GetRotationForSou
jonross 2015/04/15 17:43:12 Done.
269 gfx::Display::RotationSource source) const {
270 if (rotations_.find(source) == rotations_.end())
271 return gfx::Display::ROTATE_0;
272 return rotations_.at(source);
273 }
274
264 void DisplayInfo::Copy(const DisplayInfo& native_info) { 275 void DisplayInfo::Copy(const DisplayInfo& native_info) {
265 DCHECK(id_ == native_info.id_); 276 DCHECK(id_ == native_info.id_);
266 name_ = native_info.name_; 277 name_ = native_info.name_;
267 has_overscan_ = native_info.has_overscan_; 278 has_overscan_ = native_info.has_overscan_;
268 279
269 touch_support_ = native_info.touch_support_; 280 touch_support_ = native_info.touch_support_;
270 touch_device_id_ = native_info.touch_device_id_; 281 touch_device_id_ = native_info.touch_device_id_;
271 device_scale_factor_ = native_info.device_scale_factor_; 282 device_scale_factor_ = native_info.device_scale_factor_;
272 DCHECK(!native_info.bounds_in_native_.IsEmpty()); 283 DCHECK(!native_info.bounds_in_native_.IsEmpty());
273 bounds_in_native_ = native_info.bounds_in_native_; 284 bounds_in_native_ = native_info.bounds_in_native_;
274 size_in_pixel_ = native_info.size_in_pixel_; 285 size_in_pixel_ = native_info.size_in_pixel_;
275 is_aspect_preserving_scaling_ = native_info.is_aspect_preserving_scaling_; 286 is_aspect_preserving_scaling_ = native_info.is_aspect_preserving_scaling_;
276 display_modes_ = native_info.display_modes_; 287 display_modes_ = native_info.display_modes_;
277 available_color_profiles_ = native_info.available_color_profiles_; 288 available_color_profiles_ = native_info.available_color_profiles_;
278 289
279 // Rotation, ui_scale, color_profile and overscan are given by preference, 290 // Rotation, ui_scale, color_profile and overscan are given by preference,
280 // or unit tests. Don't copy if this native_info came from 291 // or unit tests. Don't copy if this native_info came from
281 // DisplayChangeObserver. 292 // DisplayChangeObserver.
282 if (!native_info.native()) { 293 if (!native_info.native()) {
283 // Update the overscan_insets_in_dip_ either if the inset should be 294 // Update the overscan_insets_in_dip_ either if the inset should be
284 // cleared, or has non empty insts. 295 // cleared, or has non empty insts.
285 if (native_info.clear_overscan_insets()) 296 if (native_info.clear_overscan_insets())
286 overscan_insets_in_dip_.Set(0, 0, 0, 0); 297 overscan_insets_in_dip_.Set(0, 0, 0, 0);
287 else if (!native_info.overscan_insets_in_dip_.empty()) 298 else if (!native_info.overscan_insets_in_dip_.empty())
288 overscan_insets_in_dip_ = native_info.overscan_insets_in_dip_; 299 overscan_insets_in_dip_ = native_info.overscan_insets_in_dip_;
289 300
290 rotation_ = native_info.rotation_; 301 rotations_ = native_info.rotations_;
291 configured_ui_scale_ = native_info.configured_ui_scale_; 302 configured_ui_scale_ = native_info.configured_ui_scale_;
292 color_profile_ = native_info.color_profile(); 303 color_profile_ = native_info.color_profile();
293 } 304 }
294 } 305 }
295 306
296 void DisplayInfo::SetBounds(const gfx::Rect& new_bounds_in_native) { 307 void DisplayInfo::SetBounds(const gfx::Rect& new_bounds_in_native) {
297 bounds_in_native_ = new_bounds_in_native; 308 bounds_in_native_ = new_bounds_in_native;
298 size_in_pixel_ = new_bounds_in_native.size(); 309 size_in_pixel_ = new_bounds_in_native.size();
299 UpdateDisplaySize(); 310 UpdateDisplaySize();
300 } 311 }
(...skipping 17 matching lines...) Expand all
318 void DisplayInfo::UpdateDisplaySize() { 329 void DisplayInfo::UpdateDisplaySize() {
319 size_in_pixel_ = bounds_in_native_.size(); 330 size_in_pixel_ = bounds_in_native_.size();
320 if (!overscan_insets_in_dip_.empty()) { 331 if (!overscan_insets_in_dip_.empty()) {
321 gfx::Insets insets_in_pixel = 332 gfx::Insets insets_in_pixel =
322 overscan_insets_in_dip_.Scale(device_scale_factor_); 333 overscan_insets_in_dip_.Scale(device_scale_factor_);
323 size_in_pixel_.Enlarge(-insets_in_pixel.width(), -insets_in_pixel.height()); 334 size_in_pixel_.Enlarge(-insets_in_pixel.width(), -insets_in_pixel.height());
324 } else { 335 } else {
325 overscan_insets_in_dip_.Set(0, 0, 0, 0); 336 overscan_insets_in_dip_.Set(0, 0, 0, 0);
326 } 337 }
327 338
328 if (rotation_ == gfx::Display::ROTATE_90 || 339 if (rotations_[gfx::Display::ROTATION_SOURCE_ACTIVE] ==
329 rotation_ == gfx::Display::ROTATE_270) 340 gfx::Display::ROTATE_90 ||
341 rotations_[gfx::Display::ROTATION_SOURCE_ACTIVE] ==
342 gfx::Display::ROTATE_270)
330 size_in_pixel_.SetSize(size_in_pixel_.height(), size_in_pixel_.width()); 343 size_in_pixel_.SetSize(size_in_pixel_.height(), size_in_pixel_.width());
331 gfx::SizeF size_f(size_in_pixel_); 344 gfx::SizeF size_f(size_in_pixel_);
332 size_f.Scale(GetEffectiveUIScale()); 345 size_f.Scale(GetEffectiveUIScale());
333 size_in_pixel_ = gfx::ToFlooredSize(size_f); 346 size_in_pixel_ = gfx::ToFlooredSize(size_f);
334 } 347 }
335 348
336 void DisplayInfo::SetOverscanInsets(const gfx::Insets& insets_in_dip) { 349 void DisplayInfo::SetOverscanInsets(const gfx::Insets& insets_in_dip) {
337 overscan_insets_in_dip_ = insets_in_dip; 350 overscan_insets_in_dip_ = insets_in_dip;
338 } 351 }
339 352
(...skipping 11 matching lines...) Expand all
351 gfx::Size DisplayInfo::GetNativeModeSize() const { 364 gfx::Size DisplayInfo::GetNativeModeSize() const {
352 for (size_t i = 0; i < display_modes_.size(); ++i) { 365 for (size_t i = 0; i < display_modes_.size(); ++i) {
353 if (display_modes_[i].native) 366 if (display_modes_[i].native)
354 return display_modes_[i].size; 367 return display_modes_[i].size;
355 } 368 }
356 369
357 return gfx::Size(); 370 return gfx::Size();
358 } 371 }
359 372
360 std::string DisplayInfo::ToString() const { 373 std::string DisplayInfo::ToString() const {
361 int rotation_degree = static_cast<int>(rotation_) * 90; 374 int rotation_degree =
375 static_cast<int>(Rotation(gfx::Display::ROTATION_SOURCE_ACTIVE)) * 90;
362 return base::StringPrintf( 376 return base::StringPrintf(
363 "DisplayInfo[%lld] native bounds=%s, size=%s, scale=%f, " 377 "DisplayInfo[%lld] native bounds=%s, size=%s, scale=%f, "
364 "overscan=%s, rotation=%d, ui-scale=%f, touchscreen=%s, " 378 "overscan=%s, rotation=%d, ui-scale=%f, touchscreen=%s, "
365 "touch-device-id=%d", 379 "touch-device-id=%d",
366 static_cast<long long int>(id_), 380 static_cast<long long int>(id_),
367 bounds_in_native_.ToString().c_str(), 381 bounds_in_native_.ToString().c_str(),
368 size_in_pixel_.ToString().c_str(), 382 size_in_pixel_.ToString().c_str(),
369 device_scale_factor_, 383 device_scale_factor_,
370 overscan_insets_in_dip_.ToString().c_str(), 384 overscan_insets_in_dip_.ToString().c_str(),
371 rotation_degree, 385 rotation_degree,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 return std::find(available_color_profiles_.begin(), 419 return std::find(available_color_profiles_.begin(),
406 available_color_profiles_.end(), 420 available_color_profiles_.end(),
407 profile) != available_color_profiles_.end(); 421 profile) != available_color_profiles_.end();
408 } 422 }
409 423
410 bool DisplayInfo::Use125DSFRorUIScaling() const { 424 bool DisplayInfo::Use125DSFRorUIScaling() const {
411 return use_125_dsf_for_ui_scaling && id_ == gfx::Display::InternalDisplayId(); 425 return use_125_dsf_for_ui_scaling && id_ == gfx::Display::InternalDisplayId();
412 } 426 }
413 427
414 } // namespace ash 428 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698