diff options
author | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-28 11:52:10 +0000 |
---|---|---|
committer | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-28 11:52:10 +0000 |
commit | 47ebe0c6296197904f7faf4be3f4f8670d147c12 (patch) | |
tree | be97294c4f938c1e5aad79e68a89debd8e2f4f0d /ash/display/display_info.cc | |
parent | 15a8139dec983576d677bc6b6abded5c2b451c09 (diff) | |
download | chromium_src-47ebe0c6296197904f7faf4be3f4f8670d147c12.zip chromium_src-47ebe0c6296197904f7faf4be3f4f8670d147c12.tar.gz chromium_src-47ebe0c6296197904f7faf4be3f4f8670d147c12.tar.bz2 |
Refactor DisplayInfo/Display - 2nd try
This is a first step to fix overscan issue and implement
screen rotation.
* remove bounds_in_pixel from gfx::Display
* promote DisplayInfo to separate class/file
* All display information is now generated in display_change_observer_x11.cc.
almost no X11 depenency in display_manager.cc
(I'll move FindInternalDisplayID out from display_manager.cc once https://codereview.chromium.org/12217120/ is landed)
This makes testing more consistent with real environment.
* Add DisplayManager::ClearCustomOverscanInsets so that
you can reset the insets to default value.
* Removed obsolete AshTestBase::ChangeDisplayConfig
BUG=174721,119268
TEST=covered by test
Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=185178
Review URL: https://chromiumcodereview.appspot.com/12218045
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@185230 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash/display/display_info.cc')
-rw-r--r-- | ash/display/display_info.cc | 143 |
1 files changed, 143 insertions, 0 deletions
diff --git a/ash/display/display_info.cc b/ash/display/display_info.cc new file mode 100644 index 0000000..e94ea9e --- /dev/null +++ b/ash/display/display_info.cc @@ -0,0 +1,143 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include <stdio.h> + +#include "ash/display/display_info.h" +#include "base/logging.h" +#include "base/stringprintf.h" +#include "ui/gfx/display.h" + +#if defined(OS_WIN) +#include "ui/aura/root_window_host.h" +#endif + +namespace ash { +namespace internal { + +// satic +DisplayInfo DisplayInfo::CreateFromSpec(const std::string& spec) { + return CreateFromSpecWithID(spec, gfx::Display::kInvalidDisplayID); +} + +// static +DisplayInfo DisplayInfo::CreateFromSpecWithID(const std::string& spec, + int64 id) { + // Default bounds for a display. + const int kDefaultHostWindowX = 200; + const int kDefaultHostWindowY = 200; + const int kDefaultHostWindowWidth = 1280; + const int kDefaultHostWindowHeight = 1024; + + static int64 synthesized_display_id = 1000; + +#if defined(OS_WIN) + gfx::Rect bounds(aura::RootWindowHost::GetNativeScreenSize()); +#else + gfx::Rect bounds(kDefaultHostWindowX, kDefaultHostWindowY, + kDefaultHostWindowWidth, kDefaultHostWindowHeight); +#endif + + int x = 0, y = 0, width, height; + float scale = 1.0f; + if (sscanf(spec.c_str(), "%dx%d*%f", &width, &height, &scale) >= 2 || + sscanf(spec.c_str(), "%d+%d-%dx%d*%f", &x, &y, &width, &height, + &scale) >= 4) { + bounds.SetRect(x, y, width, height); + } + if (id == gfx::Display::kInvalidDisplayID) + id = synthesized_display_id++; + DisplayInfo display_info( + id, base::StringPrintf("Display-%d", static_cast<int>(id)), false); + display_info.set_device_scale_factor(scale); + display_info.SetBounds(bounds); + DVLOG(1) << "DisplayInfoFromSpec info=" << display_info.ToString() + << ", spec=" << spec; + return display_info; +} + +DisplayInfo::DisplayInfo() + : id_(gfx::Display::kInvalidDisplayID), + has_overscan_(false), + device_scale_factor_(1.0f), + overscan_insets_in_dip_(-1, -1, -1, -1), + has_custom_overscan_insets_(false) { +} + +DisplayInfo::DisplayInfo(int64 id, + const std::string& name, + bool has_overscan) + : id_(id), + name_(name), + has_overscan_(has_overscan), + device_scale_factor_(1.0f), + overscan_insets_in_dip_(-1, -1, -1, -1), + has_custom_overscan_insets_(false) { +} + +DisplayInfo::~DisplayInfo() { +} + +void DisplayInfo::CopyFromNative(const DisplayInfo& native_info) { + DCHECK(id_ == native_info.id_); + name_ = native_info.name_; + has_overscan_ = native_info.has_overscan_; + + DCHECK(!native_info.original_bounds_in_pixel_.IsEmpty()); + original_bounds_in_pixel_ = native_info.original_bounds_in_pixel_; + bounds_in_pixel_ = native_info.bounds_in_pixel_; + device_scale_factor_ = native_info.device_scale_factor_; +} + +void DisplayInfo::SetBounds(const gfx::Rect& new_original_bounds) { + original_bounds_in_pixel_ = bounds_in_pixel_ = new_original_bounds; +} + +void DisplayInfo::UpdateBounds(const gfx::Rect& new_original_bounds) { + bool overscan = original_bounds_in_pixel_ != bounds_in_pixel_; + original_bounds_in_pixel_ = bounds_in_pixel_ = new_original_bounds; + if (overscan) { + original_bounds_in_pixel_.Inset( + overscan_insets_in_dip_.Scale(-device_scale_factor_)); + } +} + +void DisplayInfo::UpdateOverscanInfo(bool can_overscan) { + bounds_in_pixel_ = original_bounds_in_pixel_; + if (can_overscan) { + if (has_custom_overscan_insets_) { + bounds_in_pixel_.Inset( + overscan_insets_in_dip_.Scale(device_scale_factor_)); + } else if (has_overscan_) { + // Currently we assume 5% overscan and hope for the best if TV claims it + // overscan, but doesn't expose how much. + int width = bounds_in_pixel_.width() / 40; + int height = bounds_in_pixel_.height() / 40; + gfx::Insets insets_in_pixel(height, width, height, width); + overscan_insets_in_dip_ = + insets_in_pixel.Scale(1.0 / device_scale_factor_); + bounds_in_pixel_.Inset( + overscan_insets_in_dip_.Scale(device_scale_factor_)); + } + } +} + +void DisplayInfo::SetOverscanInsets(bool custom, + const gfx::Insets& insets_in_dip) { + has_custom_overscan_insets_ = custom; + overscan_insets_in_dip_ = insets_in_dip; +} + +std::string DisplayInfo::ToString() const { + return base::StringPrintf( + "DisplayInfo[%lld] bounds=%s, original=%s, scale=%f, overscan=%s", + static_cast<long long int>(id_), + bounds_in_pixel_.ToString().c_str(), + original_bounds_in_pixel_.ToString().c_str(), + device_scale_factor_, + overscan_insets_in_dip_.ToString().c_str()); +} + +} // namespace internal +} // namespace ash |