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