OLD | NEW |
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 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 Insets insets = bounds_.InsetsFrom(work_area_); | 152 Insets insets = bounds_.InsetsFrom(work_area_); |
153 if (!HasForceDeviceScaleFactor()) { | 153 if (!HasForceDeviceScaleFactor()) { |
154 #if defined(OS_MACOSX) | 154 #if defined(OS_MACOSX) |
155 // Unless an explicit scale factor was provided for testing, ensure the | 155 // Unless an explicit scale factor was provided for testing, ensure the |
156 // scale is integral. | 156 // scale is integral. |
157 device_scale_factor = static_cast<int>(device_scale_factor); | 157 device_scale_factor = static_cast<int>(device_scale_factor); |
158 #endif | 158 #endif |
159 device_scale_factor_ = device_scale_factor; | 159 device_scale_factor_ = device_scale_factor; |
160 } | 160 } |
161 device_scale_factor_ = std::max(1.0f, device_scale_factor_); | 161 device_scale_factor_ = std::max(1.0f, device_scale_factor_); |
162 bounds_ = gfx::Rect( | 162 bounds_ = |
163 gfx::ToFlooredPoint(gfx::ScalePoint(bounds_in_pixel.origin(), | 163 gfx::Rect(gfx::ToFlooredPoint(gfx::ScalePoint( |
164 1.0f / device_scale_factor_)), | 164 bounds_in_pixel.origin(), 1.0f / device_scale_factor_)), |
165 gfx::ToFlooredSize(gfx::ScaleSize(bounds_in_pixel.size(), | 165 gfx::ScaleToFlooredSize(bounds_in_pixel.size(), |
166 1.0f / device_scale_factor_))); | 166 1.0f / device_scale_factor_)); |
167 UpdateWorkAreaFromInsets(insets); | 167 UpdateWorkAreaFromInsets(insets); |
168 } | 168 } |
169 | 169 |
170 void Display::SetSize(const gfx::Size& size_in_pixel) { | 170 void Display::SetSize(const gfx::Size& size_in_pixel) { |
171 gfx::Point origin = bounds_.origin(); | 171 gfx::Point origin = bounds_.origin(); |
172 #if defined(USE_AURA) | 172 #if defined(USE_AURA) |
173 gfx::PointF origin_f = origin; | 173 gfx::PointF origin_f = origin; |
174 origin_f.Scale(device_scale_factor_); | 174 origin_f.Scale(device_scale_factor_); |
175 origin = gfx::ToFlooredPoint(origin_f); | 175 origin = gfx::ToFlooredPoint(origin_f); |
176 #endif | 176 #endif |
177 SetScaleAndBounds(device_scale_factor_, gfx::Rect(origin, size_in_pixel)); | 177 SetScaleAndBounds(device_scale_factor_, gfx::Rect(origin, size_in_pixel)); |
178 } | 178 } |
179 | 179 |
180 void Display::UpdateWorkAreaFromInsets(const gfx::Insets& insets) { | 180 void Display::UpdateWorkAreaFromInsets(const gfx::Insets& insets) { |
181 work_area_ = bounds_; | 181 work_area_ = bounds_; |
182 work_area_.Inset(insets); | 182 work_area_.Inset(insets); |
183 } | 183 } |
184 | 184 |
185 gfx::Size Display::GetSizeInPixel() const { | 185 gfx::Size Display::GetSizeInPixel() const { |
186 return gfx::ToFlooredSize(gfx::ScaleSize(size(), device_scale_factor_)); | 186 return gfx::ScaleToFlooredSize(size(), device_scale_factor_); |
187 } | 187 } |
188 | 188 |
189 std::string Display::ToString() const { | 189 std::string Display::ToString() const { |
190 return base::StringPrintf( | 190 return base::StringPrintf( |
191 "Display[%lld] bounds=%s, workarea=%s, scale=%f, %s", | 191 "Display[%lld] bounds=%s, workarea=%s, scale=%f, %s", |
192 static_cast<long long int>(id_), | 192 static_cast<long long int>(id_), |
193 bounds_.ToString().c_str(), | 193 bounds_.ToString().c_str(), |
194 work_area_.ToString().c_str(), | 194 work_area_.ToString().c_str(), |
195 device_scale_factor_, | 195 device_scale_factor_, |
196 IsInternal() ? "internal" : "external"); | 196 IsInternal() ? "internal" : "external"); |
(...skipping 19 matching lines...) Expand all Loading... |
216 DCHECK_NE(kInvalidDisplayID, display_id); | 216 DCHECK_NE(kInvalidDisplayID, display_id); |
217 return HasInternalDisplay() && internal_display_id_ == display_id; | 217 return HasInternalDisplay() && internal_display_id_ == display_id; |
218 } | 218 } |
219 | 219 |
220 // static | 220 // static |
221 bool Display::HasInternalDisplay() { | 221 bool Display::HasInternalDisplay() { |
222 return internal_display_id_ != kInvalidDisplayID; | 222 return internal_display_id_ != kInvalidDisplayID; |
223 } | 223 } |
224 | 224 |
225 } // namespace gfx | 225 } // namespace gfx |
OLD | NEW |