| OLD | NEW |
| 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 "remoting/host/screen_resolution.h" | 5 #include "remoting/host/screen_resolution.h" |
| 6 | 6 |
| 7 #include <stdint.h> |
| 8 |
| 7 #include <algorithm> | 9 #include <algorithm> |
| 8 #include <limits> | 10 #include <limits> |
| 9 | 11 |
| 10 #include "base/logging.h" | 12 #include "base/logging.h" |
| 11 | 13 |
| 12 namespace remoting { | 14 namespace remoting { |
| 13 | 15 |
| 14 ScreenResolution::ScreenResolution() | 16 ScreenResolution::ScreenResolution() |
| 15 : dimensions_(webrtc::DesktopSize(0, 0)), | 17 : dimensions_(webrtc::DesktopSize(0, 0)), |
| 16 dpi_(webrtc::DesktopVector(0, 0)) { | 18 dpi_(webrtc::DesktopVector(0, 0)) { |
| 17 } | 19 } |
| 18 | 20 |
| 19 ScreenResolution::ScreenResolution(const webrtc::DesktopSize& dimensions, | 21 ScreenResolution::ScreenResolution(const webrtc::DesktopSize& dimensions, |
| 20 const webrtc::DesktopVector& dpi) | 22 const webrtc::DesktopVector& dpi) |
| 21 : dimensions_(dimensions), | 23 : dimensions_(dimensions), |
| 22 dpi_(dpi) { | 24 dpi_(dpi) { |
| 23 // Check that dimensions are not negative. | 25 // Check that dimensions are not negative. |
| 24 DCHECK(!dimensions.is_empty() || dimensions.equals(webrtc::DesktopSize())); | 26 DCHECK(!dimensions.is_empty() || dimensions.equals(webrtc::DesktopSize())); |
| 25 DCHECK_GE(dpi.x(), 0); | 27 DCHECK_GE(dpi.x(), 0); |
| 26 DCHECK_GE(dpi.y(), 0); | 28 DCHECK_GE(dpi.y(), 0); |
| 27 } | 29 } |
| 28 | 30 |
| 29 webrtc::DesktopSize ScreenResolution::ScaleDimensionsToDpi( | 31 webrtc::DesktopSize ScreenResolution::ScaleDimensionsToDpi( |
| 30 const webrtc::DesktopVector& new_dpi) const { | 32 const webrtc::DesktopVector& new_dpi) const { |
| 31 int64 width = dimensions_.width(); | 33 int64_t width = dimensions_.width(); |
| 32 int64 height = dimensions_.height(); | 34 int64_t height = dimensions_.height(); |
| 33 | 35 |
| 34 // Scale the screen dimensions to new DPI. | 36 // Scale the screen dimensions to new DPI. |
| 35 width = std::min(width * new_dpi.x() / dpi_.x(), | 37 width = std::min(width * new_dpi.x() / dpi_.x(), |
| 36 static_cast<int64>(std::numeric_limits<int32>::max())); | 38 static_cast<int64_t>(std::numeric_limits<int32_t>::max())); |
| 37 height = std::min(height * new_dpi.y() / dpi_.y(), | 39 height = std::min(height * new_dpi.y() / dpi_.y(), |
| 38 static_cast<int64>(std::numeric_limits<int32>::max())); | 40 static_cast<int64_t>(std::numeric_limits<int32_t>::max())); |
| 39 return webrtc::DesktopSize(width, height); | 41 return webrtc::DesktopSize(width, height); |
| 40 } | 42 } |
| 41 | 43 |
| 42 bool ScreenResolution::IsEmpty() const { | 44 bool ScreenResolution::IsEmpty() const { |
| 43 return dimensions_.is_empty() || dpi_.is_zero(); | 45 return dimensions_.is_empty() || dpi_.is_zero(); |
| 44 } | 46 } |
| 45 | 47 |
| 46 bool ScreenResolution::Equals(const ScreenResolution& other) const { | 48 bool ScreenResolution::Equals(const ScreenResolution& other) const { |
| 47 return dimensions_.equals(other.dimensions()) && dpi_.equals(other.dpi()); | 49 return dimensions_.equals(other.dimensions()) && dpi_.equals(other.dpi()); |
| 48 } | 50 } |
| 49 | 51 |
| 50 } // namespace remoting | 52 } // namespace remoting |
| OLD | NEW |