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

Side by Side Diff: ui/gfx/display.cc

Issue 1563183008: Added capability on Windows to get the physical dimensions of your attached monitors. Also added th… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 11 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ui/gfx/display.h" 5 #include "ui/gfx/display.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector>
8 9
9 #include "base/command_line.h" 10 #include "base/command_line.h"
10 #include "base/logging.h" 11 #include "base/logging.h"
11 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
12 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
13 #include "build/build_config.h" 14 #include "build/build_config.h"
14 #include "ui/gfx/geometry/insets.h" 15 #include "ui/gfx/geometry/insets.h"
15 #include "ui/gfx/geometry/point_conversions.h" 16 #include "ui/gfx/geometry/point_conversions.h"
16 #include "ui/gfx/geometry/point_f.h" 17 #include "ui/gfx/geometry/point_f.h"
17 #include "ui/gfx/geometry/size_conversions.h" 18 #include "ui/gfx/geometry/size_conversions.h"
18 #include "ui/gfx/switches.h" 19 #include "ui/gfx/switches.h"
19 20
21 #if defined(OS_WIN)
22 #include "ui/gfx/screen_win.h"
23 #include "ui/gfx/win/physical_size.h"
24 #endif
25
20 namespace gfx { 26 namespace gfx {
21 namespace { 27 namespace {
22 28
23 // This variable tracks whether the forced device scale factor switch needs to 29 // This variable tracks whether the forced device scale factor switch needs to
24 // be read from the command line, i.e. if it is set to -1 then the command line 30 // be read from the command line, i.e. if it is set to -1 then the command line
25 // is checked. 31 // is checked.
26 int g_has_forced_device_scale_factor = -1; 32 int g_has_forced_device_scale_factor = -1;
27 33
28 // This variable caches the forced device scale factor value which is read off 34 // This variable caches the forced device scale factor value which is read off
29 // the command line. If the cache is invalidated by setting this variable to 35 // the command line. If the cache is invalidated by setting this variable to
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 bounds_.ToString().c_str(), 194 bounds_.ToString().c_str(),
189 work_area_.ToString().c_str(), 195 work_area_.ToString().c_str(),
190 device_scale_factor_, 196 device_scale_factor_,
191 IsInternal() ? "internal" : "external"); 197 IsInternal() ? "internal" : "external");
192 } 198 }
193 199
194 bool Display::IsInternal() const { 200 bool Display::IsInternal() const {
195 return is_valid() && (id_ == internal_display_id_); 201 return is_valid() && (id_ == internal_display_id_);
196 } 202 }
197 203
204 bool Display::GetPhysicalSize(int* width_mm, int* height_mm) const {
205 #if defined(OS_WIN)
206 std::vector<gfx::PhysicalDisplaySize> display_sizes;
207 gfx::GetPhysicalSizeForDisplays(&display_sizes);
208 for (const auto& display_size : display_sizes) {
209 int64_t interface_id =
210 ScreenWin::GenerateDisplayId(display_size.display_name);
211 if (interface_id == id_) {
212 *width_mm = display_size.width_mm;
213 *height_mm = display_size.height_mm;
214 return true;
215 }
216 }
217 return false;
218 #else
219 NOTREACHED();
220 #endif
221 }
222
198 // static 223 // static
199 int64_t Display::InternalDisplayId() { 224 int64_t Display::InternalDisplayId() {
200 DCHECK_NE(kInvalidDisplayID, internal_display_id_); 225 DCHECK_NE(kInvalidDisplayID, internal_display_id_);
201 return internal_display_id_; 226 return internal_display_id_;
202 } 227 }
203 228
204 // static 229 // static
205 void Display::SetInternalDisplayId(int64_t internal_display_id) { 230 void Display::SetInternalDisplayId(int64_t internal_display_id) {
206 internal_display_id_ = internal_display_id; 231 internal_display_id_ = internal_display_id;
207 } 232 }
208 233
209 // static 234 // static
210 bool Display::IsInternalDisplayId(int64_t display_id) { 235 bool Display::IsInternalDisplayId(int64_t display_id) {
211 DCHECK_NE(kInvalidDisplayID, display_id); 236 DCHECK_NE(kInvalidDisplayID, display_id);
212 return HasInternalDisplay() && internal_display_id_ == display_id; 237 return HasInternalDisplay() && internal_display_id_ == display_id;
213 } 238 }
214 239
215 // static 240 // static
216 bool Display::HasInternalDisplay() { 241 bool Display::HasInternalDisplay() {
217 return internal_display_id_ != kInvalidDisplayID; 242 return internal_display_id_ != kInvalidDisplayID;
218 } 243 }
219 244
220 } // namespace gfx 245 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698