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

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

Issue 12746002: Re-implement overscan & Implement Display Rotation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « ash/display/display_info.h ('k') | ash/display/display_info_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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>
7 #include <vector>
6 8
7 #include "ash/display/display_info.h" 9 #include "ash/display/display_info.h"
8 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/string_util.h"
9 #include "base/stringprintf.h" 12 #include "base/stringprintf.h"
10 #include "ui/gfx/display.h" 13 #include "ui/gfx/display.h"
11 14
12 #if defined(OS_WIN) 15 #if defined(OS_WIN)
13 #include "ui/aura/root_window_host.h" 16 #include "ui/aura/root_window_host.h"
14 #endif 17 #endif
15 18
16 namespace ash { 19 namespace ash {
17 namespace internal { 20 namespace internal {
18 21
(...skipping 15 matching lines...) Expand all
34 37
35 #if defined(OS_WIN) 38 #if defined(OS_WIN)
36 gfx::Rect bounds(aura::RootWindowHost::GetNativeScreenSize()); 39 gfx::Rect bounds(aura::RootWindowHost::GetNativeScreenSize());
37 #else 40 #else
38 gfx::Rect bounds(kDefaultHostWindowX, kDefaultHostWindowY, 41 gfx::Rect bounds(kDefaultHostWindowX, kDefaultHostWindowY,
39 kDefaultHostWindowWidth, kDefaultHostWindowHeight); 42 kDefaultHostWindowWidth, kDefaultHostWindowHeight);
40 #endif 43 #endif
41 44
42 int x = 0, y = 0, width, height; 45 int x = 0, y = 0, width, height;
43 float scale = 1.0f; 46 float scale = 1.0f;
44 if (sscanf(spec.c_str(), "%dx%d*%f", &width, &height, &scale) >= 2 || 47 std::vector<std::string> parts;
45 sscanf(spec.c_str(), "%d+%d-%dx%d*%f", &x, &y, &width, &height, 48 size_t count = Tokenize(spec, "/", &parts);
49 Rotation rotation(ROTATE_0);
50 bool has_overscan = false;
51 std::string main_spec = spec;
52 if (count) {
53 main_spec = parts[0];
54 if (count == 2) {
55 std::string options = parts[1];
56 for (size_t i = 0; i < options.size(); ++i) {
57 char c = options[i];
58 switch (c) {
59 case 'o':
60 has_overscan = true;
61 break;
62 case 'r': // rotate 90 degrees to 'right'.
63 rotation = ROTATE_90;
64 break;
65 case 'u': // 180 degrees, 'u'pside-down.
66 rotation = ROTATE_180;
67 break;
68 case 'l': // rotate 90 degrees to 'left'.
69 rotation = ROTATE_270;
70 break;
71 }
72 }
73 }
74 }
75
76 if (sscanf(main_spec.c_str(), "%dx%d*%f", &width, &height, &scale) >= 2 ||
77 sscanf(main_spec.c_str(), "%d+%d-%dx%d*%f", &x, &y, &width, &height,
46 &scale) >= 4) { 78 &scale) >= 4) {
47 bounds.SetRect(x, y, width, height); 79 bounds.SetRect(x, y, width, height);
48 } 80 }
49 if (id == gfx::Display::kInvalidDisplayID) 81 if (id == gfx::Display::kInvalidDisplayID)
50 id = synthesized_display_id++; 82 id = synthesized_display_id++;
51 DisplayInfo display_info( 83 DisplayInfo display_info(
52 id, base::StringPrintf("Display-%d", static_cast<int>(id)), false); 84 id, base::StringPrintf("Display-%d", static_cast<int>(id)), has_overscan);
53 display_info.set_device_scale_factor(scale); 85 display_info.set_device_scale_factor(scale);
86 display_info.set_rotation(rotation);
54 display_info.SetBounds(bounds); 87 display_info.SetBounds(bounds);
55 DVLOG(1) << "DisplayInfoFromSpec info=" << display_info.ToString() 88 DVLOG(1) << "DisplayInfoFromSpec info=" << display_info.ToString()
56 << ", spec=" << spec; 89 << ", spec=" << spec;
57 return display_info; 90 return display_info;
58 } 91 }
59 92
60 DisplayInfo::DisplayInfo() 93 DisplayInfo::DisplayInfo()
61 : id_(gfx::Display::kInvalidDisplayID), 94 : id_(gfx::Display::kInvalidDisplayID),
62 has_overscan_(false), 95 has_overscan_(false),
96 rotation_(ROTATE_0),
63 device_scale_factor_(1.0f), 97 device_scale_factor_(1.0f),
64 overscan_insets_in_dip_(-1, -1, -1, -1), 98 overscan_insets_in_dip_(0, 0, 0, 0),
65 has_custom_overscan_insets_(false) { 99 has_custom_overscan_insets_(false) {
66 } 100 }
67 101
68 DisplayInfo::DisplayInfo(int64 id, 102 DisplayInfo::DisplayInfo(int64 id,
69 const std::string& name, 103 const std::string& name,
70 bool has_overscan) 104 bool has_overscan)
71 : id_(id), 105 : id_(id),
72 name_(name), 106 name_(name),
73 has_overscan_(has_overscan), 107 has_overscan_(has_overscan),
108 rotation_(ROTATE_0),
74 device_scale_factor_(1.0f), 109 device_scale_factor_(1.0f),
75 overscan_insets_in_dip_(-1, -1, -1, -1), 110 overscan_insets_in_dip_(0, 0, 0, 0),
76 has_custom_overscan_insets_(false) { 111 has_custom_overscan_insets_(false) {
77 } 112 }
78 113
79 DisplayInfo::~DisplayInfo() { 114 DisplayInfo::~DisplayInfo() {
80 } 115 }
81 116
82 void DisplayInfo::CopyFromNative(const DisplayInfo& native_info) { 117 void DisplayInfo::CopyFromNative(const DisplayInfo& native_info) {
83 DCHECK(id_ == native_info.id_); 118 DCHECK(id_ == native_info.id_);
84 name_ = native_info.name_; 119 name_ = native_info.name_;
85 has_overscan_ = native_info.has_overscan_; 120 has_overscan_ = native_info.has_overscan_;
86 121
87 DCHECK(!native_info.original_bounds_in_pixel_.IsEmpty()); 122 DCHECK(!native_info.bounds_in_pixel_.IsEmpty());
88 original_bounds_in_pixel_ = native_info.original_bounds_in_pixel_;
89 bounds_in_pixel_ = native_info.bounds_in_pixel_; 123 bounds_in_pixel_ = native_info.bounds_in_pixel_;
124 size_in_pixel_ = native_info.size_in_pixel_;
90 device_scale_factor_ = native_info.device_scale_factor_; 125 device_scale_factor_ = native_info.device_scale_factor_;
126 rotation_ = native_info.rotation_;
127 // Don't copy insets as it may be given by preference. |rotation_|
128 // is treated as a native so that it can be specified in
129 // |CreateFromSpec|.
91 } 130 }
92 131
93 void DisplayInfo::SetBounds(const gfx::Rect& new_original_bounds) { 132 void DisplayInfo::SetBounds(const gfx::Rect& new_bounds_in_pixel) {
94 original_bounds_in_pixel_ = bounds_in_pixel_ = new_original_bounds; 133 bounds_in_pixel_ = new_bounds_in_pixel;
134 size_in_pixel_ = new_bounds_in_pixel.size();
135 UpdateDisplaySize();
95 } 136 }
96 137
97 void DisplayInfo::UpdateBounds(const gfx::Rect& new_original_bounds) { 138 void DisplayInfo::UpdateDisplaySize() {
98 bool overscan = original_bounds_in_pixel_ != bounds_in_pixel_; 139 size_in_pixel_ = bounds_in_pixel_.size();
99 original_bounds_in_pixel_ = bounds_in_pixel_ = new_original_bounds; 140 if (has_custom_overscan_insets_) {
100 if (overscan) { 141 gfx::Insets insets_in_pixel =
101 original_bounds_in_pixel_.Inset( 142 overscan_insets_in_dip_.Scale(device_scale_factor_);
102 overscan_insets_in_dip_.Scale(-device_scale_factor_)); 143 size_in_pixel_.Enlarge(-insets_in_pixel.width(), -insets_in_pixel.height());
144 } else if (has_overscan_) {
145 // Currently we assume 5% overscan and hope for the best if TV claims it
146 // overscan, but doesn't expose how much.
147 // TODO(oshima): The insets has to be applied after rotation.
148 // Fix this.
149 int width = bounds_in_pixel_.width() / 40;
150 int height = bounds_in_pixel_.height() / 40;
151 gfx::Insets insets_in_pixel(height, width, height, width);
152 overscan_insets_in_dip_ =
153 insets_in_pixel.Scale(1.0 / device_scale_factor_);
154 size_in_pixel_.Enlarge(-insets_in_pixel.width(), -insets_in_pixel.height());
155 } else {
156 overscan_insets_in_dip_.Set(0, 0, 0, 0);
103 } 157 }
104 }
105 158
106 void DisplayInfo::UpdateOverscanInfo(bool can_overscan) { 159 if (rotation_ == ROTATE_90 || rotation_ == ROTATE_270)
107 bounds_in_pixel_ = original_bounds_in_pixel_; 160 size_in_pixel_.SetSize(size_in_pixel_.height(), size_in_pixel_.width());
108 if (can_overscan) {
109 if (has_custom_overscan_insets_) {
110 bounds_in_pixel_.Inset(
111 overscan_insets_in_dip_.Scale(device_scale_factor_));
112 } else if (has_overscan_) {
113 // Currently we assume 5% overscan and hope for the best if TV claims it
114 // overscan, but doesn't expose how much.
115 int width = bounds_in_pixel_.width() / 40;
116 int height = bounds_in_pixel_.height() / 40;
117 gfx::Insets insets_in_pixel(height, width, height, width);
118 overscan_insets_in_dip_ =
119 insets_in_pixel.Scale(1.0 / device_scale_factor_);
120 bounds_in_pixel_.Inset(
121 overscan_insets_in_dip_.Scale(device_scale_factor_));
122 }
123 }
124 } 161 }
125 162
126 void DisplayInfo::SetOverscanInsets(bool custom, 163 void DisplayInfo::SetOverscanInsets(bool custom,
127 const gfx::Insets& insets_in_dip) { 164 const gfx::Insets& insets_in_dip) {
128 has_custom_overscan_insets_ = custom; 165 has_custom_overscan_insets_ = custom;
129 overscan_insets_in_dip_ = insets_in_dip; 166 overscan_insets_in_dip_ = insets_in_dip;
130 } 167 }
131 168
169 gfx::Insets DisplayInfo::GetOverscanInsetsInPixel() const {
170 return overscan_insets_in_dip_.Scale(device_scale_factor_);
171 }
172
132 std::string DisplayInfo::ToString() const { 173 std::string DisplayInfo::ToString() const {
174 int rotation_degree = static_cast<int>(rotation_) * 90;
133 return base::StringPrintf( 175 return base::StringPrintf(
134 "DisplayInfo[%lld] bounds=%s, original=%s, scale=%f, overscan=%s", 176 "DisplayInfo[%lld] bounds=%s, size=%s, scale=%f, "
177 "overscan=%s, rotation=%d",
135 static_cast<long long int>(id_), 178 static_cast<long long int>(id_),
136 bounds_in_pixel_.ToString().c_str(), 179 bounds_in_pixel_.ToString().c_str(),
137 original_bounds_in_pixel_.ToString().c_str(), 180 size_in_pixel_.ToString().c_str(),
138 device_scale_factor_, 181 device_scale_factor_,
139 overscan_insets_in_dip_.ToString().c_str()); 182 overscan_insets_in_dip_.ToString().c_str(),
183 rotation_degree);
140 } 184 }
141 185
142 } // namespace internal 186 } // namespace internal
143 } // namespace ash 187 } // namespace ash
OLDNEW
« no previous file with comments | « ash/display/display_info.h ('k') | ash/display/display_info_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698