Chromium Code Reviews| Index: remoting/host/screen_resolution.cc |
| diff --git a/remoting/host/screen_resolution.cc b/remoting/host/screen_resolution.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..33d14caeea50f8f0f343172705f2ebb9f33cb00c |
| --- /dev/null |
| +++ b/remoting/host/screen_resolution.cc |
| @@ -0,0 +1,41 @@ |
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "remoting/host/screen_resolution.h" |
| + |
| +#include <algorithm> |
| +#include <limits> |
| + |
| +namespace remoting { |
| + |
| +ScreenResolution::ScreenResolution() |
| + : dimensions_(SkISize::Make(0, 0)), |
| + dpi_(SkIPoint::Make(0, 0)) { |
| +} |
| + |
| +ScreenResolution::ScreenResolution(const SkISize& dimensions, |
| + const SkIPoint& dpi) |
| + : dimensions_(dimensions), |
| + dpi_(dpi) { |
| +} |
| + |
| +SkISize ScreenResolution::ScaleDimensionsToDpi(const SkIPoint& new_dpi) const { |
| + // Scale the screen dimensions to new DPI. |
|
Jamie
2013/03/15 22:06:27
DCHECK dpi_ to make sure you're not going to divid
alexeypa (please no reviews)
2013/03/15 22:32:12
It will crash nicely even without a DCHECK(). Why
|
| + int64 width = std::min(dimensions_.width() * new_dpi.x() / dpi_.x(), |
| + std::numeric_limits<int32>::max()); |
| + int64 height = std::min(dimensions_.height() * new_dpi.y() / dpi_.y(), |
| + std::numeric_limits<int32>::max()); |
| + |
| + return SkISize::Make(static_cast<int32>(width), static_cast<int32>(height)); |
| +} |
| + |
| +bool ScreenResolution::IsNull() const { |
| + return dimensions_.isEmpty() || dpi_.x() <= 0 || dpi_.y() <= 0; |
| +} |
| + |
| +bool ScreenResolution::IsValid() const { |
| + return !IsNull() || dimensions_.isZero(); |
| +} |
| + |
| +} // namespace remoting |