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

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

Issue 12257016: (Not ready for review!) Toolbar and views high dpi support. Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Cleaned up more useless diffs. Created 7 years, 10 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
« no previous file with comments | « ui/gfx/display.h ('k') | ui/gfx/screen_win.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) 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 "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/string_number_conversions.h" 9 #include "base/string_number_conversions.h"
10 #include "base/stringprintf.h" 10 #include "base/stringprintf.h"
(...skipping 11 matching lines...) Expand all
22 } 22 }
23 23
24 float GetForcedDeviceScaleFactorImpl() { 24 float GetForcedDeviceScaleFactorImpl() {
25 double scale_in_double = 1.0; 25 double scale_in_double = 1.0;
26 if (HasForceDeviceScaleFactorImpl()) { 26 if (HasForceDeviceScaleFactorImpl()) {
27 std::string value = CommandLine::ForCurrentProcess()-> 27 std::string value = CommandLine::ForCurrentProcess()->
28 GetSwitchValueASCII(switches::kForceDeviceScaleFactor); 28 GetSwitchValueASCII(switches::kForceDeviceScaleFactor);
29 if (!base::StringToDouble(value, &scale_in_double)) 29 if (!base::StringToDouble(value, &scale_in_double))
30 LOG(ERROR) << "Failed to parse the default device scale factor:" << value; 30 LOG(ERROR) << "Failed to parse the default device scale factor:" << value;
31 } 31 }
32 #if defined(OS_WIN)
33 else {
34 static double os_scale = ui::GetDPIScale();
35 scale_in_double = os_scale;
36 }
37 #endif
38
32 return static_cast<float>(scale_in_double); 39 return static_cast<float>(scale_in_double);
33 } 40 }
34 41
35 } // namespace 42 } // namespace
36 43
37 const int64 Display::kInvalidDisplayID = -1; 44 const int64 Display::kInvalidDisplayID = -1;
38 45
39 // static 46 // static
40 float Display::GetForcedDeviceScaleFactor() { 47 float Display::GetForcedDeviceScaleFactor() {
41 static const float kForcedDeviceScaleFactor = 48 static const float kForcedDeviceScaleFactor =
42 GetForcedDeviceScaleFactorImpl(); 49 GetForcedDeviceScaleFactorImpl();
43 return kForcedDeviceScaleFactor; 50 return kForcedDeviceScaleFactor;
44 } 51 }
45
46 //static 52 //static
47 bool Display::HasForceDeviceScaleFactor() { 53 bool Display::HasForceDeviceScaleFactor() {
48 return HasForceDeviceScaleFactorImpl(); 54 return HasForceDeviceScaleFactorImpl();
49 } 55 }
50 56
57
51 // static 58 // static
52 int64 Display::GetID(uint16 manufacturer_id, 59 int64 Display::GetID(uint16 manufacturer_id,
53 uint16 product_code, 60 uint16 product_code,
54 uint8 output_index) { 61 uint8 output_index) {
55 int64 new_id = ((static_cast<int64>(manufacturer_id) << 24) | 62 int64 new_id = ((static_cast<int64>(manufacturer_id) << 24) |
56 (static_cast<int64>(product_code) << 8) | output_index); 63 (static_cast<int64>(product_code) << 8) | output_index);
57 DCHECK_NE(kInvalidDisplayID, new_id); 64 DCHECK_NE(kInvalidDisplayID, new_id);
58 return new_id; 65 return new_id;
59 } 66 }
60 67
61 Display::Display() 68 Display::Display()
62 : id_(kInvalidDisplayID), 69 : id_(kInvalidDisplayID),
63 device_scale_factor_(GetForcedDeviceScaleFactor()) { 70 device_scale_factor_(GetForcedDeviceScaleFactor()) {
64 } 71 }
65 72
66 Display::Display(int64 id) 73 Display::Display(int64 id)
67 : id_(id), 74 : id_(id),
68 device_scale_factor_(GetForcedDeviceScaleFactor()) { 75 device_scale_factor_(GetForcedDeviceScaleFactor()) {
69 } 76 }
70 77
71 Display::Display(int64 id, const gfx::Rect& bounds) 78 Display::Display(int64 id, const gfx::Rect& bounds)
72 : id_(id), 79 : id_(id),
73 bounds_(bounds), 80 bounds_(bounds),
74 work_area_(bounds), 81 work_area_(bounds),
75 device_scale_factor_(GetForcedDeviceScaleFactor()) { 82 device_scale_factor_(GetForcedDeviceScaleFactor()) {
76 #if defined(USE_AURA) 83 #if defined(USE_AURA) // || defined(OS_WIN)
77 SetScaleAndBounds(device_scale_factor_, bounds); 84 SetScaleAndBounds(device_scale_factor_, bounds);
78 #endif 85 #endif
79 } 86 }
80 87
81 Display::~Display() { 88 Display::~Display() {
82 } 89 }
83 90
84 Insets Display::GetWorkAreaInsets() const { 91 Insets Display::GetWorkAreaInsets() const {
85 return gfx::Insets(work_area_.y() - bounds_.y(), 92 return gfx::Insets(work_area_.y() - bounds_.y(),
86 work_area_.x() - bounds_.x(), 93 work_area_.x() - bounds_.x(),
87 bounds_.bottom() - work_area_.bottom(), 94 bounds_.bottom() - work_area_.bottom(),
88 bounds_.right() - work_area_.right()); 95 bounds_.right() - work_area_.right());
89 } 96 }
90 97
91 void Display::SetScaleAndBounds( 98 void Display::SetScaleAndBounds(
92 float device_scale_factor, 99 float device_scale_factor,
93 const gfx::Rect& bounds_in_pixel) { 100 const gfx::Rect& bounds_in_pixel) {
94 Insets insets = bounds_.InsetsFrom(work_area_); 101 Insets insets = bounds_.InsetsFrom(work_area_);
95 if (!HasForceDeviceScaleFactor()) { 102 if (!HasForceDeviceScaleFactor()) {
96 #if defined(OS_MACOSX) 103 #if defined(OS_MACOSX)
97 // Unless an explicit scale factor was provided for testing, ensure the 104 // Unless an explicit scale factor was provided for testing, ensure the
98 // scale is integral. 105 // scale is integral.
99 device_scale_factor = static_cast<int>(device_scale_factor); 106 device_scale_factor = static_cast<int>(device_scale_factor);
100 #endif 107 #endif
101 device_scale_factor_ = device_scale_factor; 108 device_scale_factor_ = device_scale_factor;
102 } 109 }
103 device_scale_factor_ = std::max(1.0f, device_scale_factor_); 110 device_scale_factor_ = std::max(1.0f, device_scale_factor_);
104 #if defined(USE_AURA) 111 #if defined(USE_AURA) || defined(OS_WIN)
105 bounds_in_pixel_ = bounds_in_pixel; 112 bounds_in_pixel_ = bounds_in_pixel;
106 #endif 113 #endif
107 bounds_ = gfx::Rect(gfx::ToFlooredSize( 114 bounds_ = gfx::Rect(gfx::ToFlooredSize(
108 gfx::ScaleSize(bounds_in_pixel.size(), 1.0f / device_scale_factor_))); 115 gfx::ScaleSize(bounds_in_pixel.size(), 1.0f / device_scale_factor_)));
109 UpdateWorkAreaFromInsets(insets); 116 UpdateWorkAreaFromInsets(insets);
110 } 117 }
111 118
112 void Display::SetSize(const gfx::Size& size_in_pixel) { 119 void Display::SetSize(const gfx::Size& size_in_pixel) {
113 SetScaleAndBounds( 120 SetScaleAndBounds(
114 device_scale_factor_, 121 device_scale_factor_,
115 #if defined(USE_AURA) 122 #if defined(USE_AURA) || defined(OS_WIN)
116 gfx::Rect(bounds_in_pixel_.origin(), size_in_pixel)); 123 gfx::Rect(bounds_in_pixel_.origin(), size_in_pixel));
117 #else 124 #else
118 gfx::Rect(bounds_.origin(), size_in_pixel)); 125 gfx::Rect(bounds_.origin(), size_in_pixel));
119 #endif 126 #endif
120 } 127 }
121 128
122 void Display::UpdateWorkAreaFromInsets(const gfx::Insets& insets) { 129 void Display::UpdateWorkAreaFromInsets(const gfx::Insets& insets) {
123 work_area_ = bounds_; 130 work_area_ = bounds_;
124 work_area_.Inset(insets); 131 work_area_.Inset(insets);
125 } 132 }
126 133
127 gfx::Size Display::GetSizeInPixel() const { 134 gfx::Size Display::GetSizeInPixel() const {
128 return gfx::ToFlooredSize(gfx::ScaleSize(size(), device_scale_factor_)); 135 return gfx::ToFlooredSize(gfx::ScaleSize(size(), device_scale_factor_));
129 } 136 }
130 137
131 std::string Display::ToString() const { 138 std::string Display::ToString() const {
132 return base::StringPrintf("Display[%lld] bounds=%s, workarea=%s, scale=%f", 139 return base::StringPrintf("Display[%lld] bounds=%s, workarea=%s, scale=%f",
133 static_cast<long long int>(id_), 140 static_cast<long long int>(id_),
134 bounds_.ToString().c_str(), 141 bounds_.ToString().c_str(),
135 work_area_.ToString().c_str(), 142 work_area_.ToString().c_str(),
136 device_scale_factor_); 143 device_scale_factor_);
137 } 144 }
138 145
139 } // namespace gfx 146 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/display.h ('k') | ui/gfx/screen_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698