| Index: ash/display/display_info.cc
|
| diff --git a/ash/display/display_info.cc b/ash/display/display_info.cc
|
| index 5349c788eac34336a5cfb40e3dae5e27b59a40a3..21c45cdb87340e15405f153cf3139b388c5815c8 100644
|
| --- a/ash/display/display_info.cc
|
| +++ b/ash/display/display_info.cc
|
| @@ -3,9 +3,12 @@
|
| // found in the LICENSE file.
|
|
|
| #include <stdio.h>
|
| +#include <string>
|
| +#include <vector>
|
|
|
| #include "ash/display/display_info.h"
|
| #include "base/logging.h"
|
| +#include "base/string_util.h"
|
| #include "base/stringprintf.h"
|
| #include "ui/gfx/display.h"
|
|
|
| @@ -41,16 +44,46 @@ DisplayInfo DisplayInfo::CreateFromSpecWithID(const std::string& spec,
|
|
|
| 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,
|
| + std::vector<std::string> parts;
|
| + size_t count = Tokenize(spec, "/", &parts);
|
| + Rotation rotation(Rotate0);
|
| + bool has_overscan = false;
|
| + std::string main_spec = spec;
|
| + if (count) {
|
| + main_spec = parts[0];
|
| + if (count == 2) {
|
| + std::string options = parts[1];
|
| + for (size_t i = 0; i < options.size(); ++i) {
|
| + char c = options[i];
|
| + switch (c) {
|
| + case 'o':
|
| + has_overscan = true;
|
| + break;
|
| + case 'r': // rotate 90 degrees to 'right'.
|
| + rotation = Rotate90;
|
| + break;
|
| + case 'u': // 180 degrees, 'u'pside-down.
|
| + rotation = Rotate180;
|
| + break;
|
| + case 'l': // rotate 90 degrees to 'left'.
|
| + rotation = Rotate270;
|
| + break;
|
| + }
|
| + }
|
| + }
|
| + }
|
| +
|
| + if (sscanf(main_spec.c_str(), "%dx%d*%f", &width, &height, &scale) >= 2 ||
|
| + sscanf(main_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);
|
| + id, base::StringPrintf("Display-%d", static_cast<int>(id)), has_overscan);
|
| display_info.set_device_scale_factor(scale);
|
| + display_info.set_rotation(rotation);
|
| display_info.SetBounds(bounds);
|
| DVLOG(1) << "DisplayInfoFromSpec info=" << display_info.ToString()
|
| << ", spec=" << spec;
|
| @@ -60,8 +93,9 @@ DisplayInfo DisplayInfo::CreateFromSpecWithID(const std::string& spec,
|
| DisplayInfo::DisplayInfo()
|
| : id_(gfx::Display::kInvalidDisplayID),
|
| has_overscan_(false),
|
| + rotation_(Rotate0),
|
| device_scale_factor_(1.0f),
|
| - overscan_insets_in_dip_(-1, -1, -1, -1),
|
| + overscan_insets_in_dip_(0, 0, 0, 0),
|
| has_custom_overscan_insets_(false) {
|
| }
|
|
|
| @@ -71,8 +105,9 @@ DisplayInfo::DisplayInfo(int64 id,
|
| : id_(id),
|
| name_(name),
|
| has_overscan_(has_overscan),
|
| + rotation_(Rotate0),
|
| device_scale_factor_(1.0f),
|
| - overscan_insets_in_dip_(-1, -1, -1, -1),
|
| + overscan_insets_in_dip_(0, 0, 0, 0),
|
| has_custom_overscan_insets_(false) {
|
| }
|
|
|
| @@ -84,43 +119,45 @@ void DisplayInfo::CopyFromNative(const DisplayInfo& native_info) {
|
| 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_;
|
| + DCHECK(!native_info.bounds_in_pixel_.IsEmpty());
|
| bounds_in_pixel_ = native_info.bounds_in_pixel_;
|
| + size_in_pixel_ = native_info.size_in_pixel_;
|
| device_scale_factor_ = native_info.device_scale_factor_;
|
| + rotation_ = native_info.rotation_;
|
| + // Don't copy insets as it may be given by preference. |rotation_|
|
| + // is treated as a native so that it can be specified in
|
| + // |CreateFromSpec|.
|
| }
|
|
|
| -void DisplayInfo::SetBounds(const gfx::Rect& new_original_bounds) {
|
| - original_bounds_in_pixel_ = bounds_in_pixel_ = new_original_bounds;
|
| +void DisplayInfo::SetBounds(const gfx::Rect& new_bounds_in_pixel) {
|
| + bounds_in_pixel_ = new_bounds_in_pixel;
|
| + size_in_pixel_ = new_bounds_in_pixel.size();
|
| + UpdateDisplaySize();
|
| }
|
|
|
| -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::UpdateDisplaySize() {
|
| + size_in_pixel_ = bounds_in_pixel_.size();
|
| + if (has_custom_overscan_insets_) {
|
| + gfx::Insets insets_in_pixel =
|
| + overscan_insets_in_dip_.Scale(device_scale_factor_);
|
| + size_in_pixel_.Enlarge(-insets_in_pixel.width(), -insets_in_pixel.height());
|
| + } 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.
|
| + // TODO(oshima): The insets has to be applied after rotation.
|
| + // Fix this.
|
| + 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_);
|
| + size_in_pixel_.Enlarge(-insets_in_pixel.width(), -insets_in_pixel.height());
|
| + } else {
|
| + overscan_insets_in_dip_.Set(0, 0, 0, 0);
|
| }
|
| -}
|
|
|
| -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_));
|
| - }
|
| - }
|
| + if (rotation_ == Rotate90 || rotation_ == Rotate270)
|
| + size_in_pixel_.SetSize(size_in_pixel_.height(), size_in_pixel_.width());
|
| }
|
|
|
| void DisplayInfo::SetOverscanInsets(bool custom,
|
| @@ -129,14 +166,21 @@ void DisplayInfo::SetOverscanInsets(bool custom,
|
| overscan_insets_in_dip_ = insets_in_dip;
|
| }
|
|
|
| +gfx::Insets DisplayInfo::GetOverscanInsetsInPixel() const {
|
| + return overscan_insets_in_dip_.Scale(device_scale_factor_);
|
| +}
|
| +
|
| std::string DisplayInfo::ToString() const {
|
| + int rotation_degree = static_cast<int>(rotation_) * 90;
|
| return base::StringPrintf(
|
| - "DisplayInfo[%lld] bounds=%s, original=%s, scale=%f, overscan=%s",
|
| + "DisplayInfo[%lld] bounds=%s, size=%s, scale=%f, "
|
| + "overscan=%s, rotation=%d",
|
| static_cast<long long int>(id_),
|
| bounds_in_pixel_.ToString().c_str(),
|
| - original_bounds_in_pixel_.ToString().c_str(),
|
| + size_in_pixel_.ToString().c_str(),
|
| device_scale_factor_,
|
| - overscan_insets_in_dip_.ToString().c_str());
|
| + overscan_insets_in_dip_.ToString().c_str(),
|
| + rotation_degree);
|
| }
|
|
|
| } // namespace internal
|
|
|