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..af9482064f97542a49339bf9b003ae733111686d |
| --- /dev/null |
| +++ b/remoting/host/screen_resolution.cc |
| @@ -0,0 +1,60 @@ |
| +// 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> |
| + |
| +// Default dots per inch is 96 DPI. |
|
Jamie
2013/03/15 18:33:24
I think the default DPI on Mac is 72, but we ignor
alexeypa (please no reviews)
2013/03/15 20:30:41
Talked to Wez. He said it is better to have this c
|
| +const int kDefaultDpiX = 96; |
| +const int kDefaultDpiY = 96; |
| + |
| +namespace remoting { |
| + |
| +ScreenResolution::ScreenResolution() |
| + : dimensions_(SkISize::Make(0, 0)), |
| + dpi_(SkIPoint::Make(0, 0)) { |
| +} |
| + |
| +ScreenResolution::ScreenResolution(const SkISize& dimensions) |
| + : dimensions_(dimensions), |
| + dpi_(SkIPoint::Make(0, 0)) { |
| +} |
| + |
| +SkIPoint ScreenResolution::GetEffectiveDpi() const { |
| + SkIPoint dpi = dpi_; |
| + if (!dpi.x()) |
| + dpi.setX(kDefaultDpiX); |
| + if (!dpi.y()) |
| + dpi.setY(kDefaultDpiY); |
| + return dpi; |
| +} |
| + |
| +SkISize ScreenResolution::GetLogicalDimensions() const { |
| + SkIPoint dpi = GetEffectiveDpi(); |
| + |
| + // Make sure there will be no integer overflow while scaling the screen |
| + // dimensions. |
| + SkISize dimensions = SkISize::Make( |
| + std::min(dimensions_.width(), |
| + std::numeric_limits<int32_t>::max() / kDefaultDpiX), |
| + std::min(dimensions_.height(), |
| + std::numeric_limits<int32_t>::max() / kDefaultDpiY)); |
| + |
| + // Scale the screen dimensions as if DPI was 96. |
| + return SkISize::Make(dimensions.width() * kDefaultDpiX / dpi.x(), |
| + dimensions.height() * kDefaultDpiY / dpi.y()); |
| +} |
| + |
| +bool ScreenResolution::IsNull() const { |
| + return !IsValid() || dimensions_.isZero(); |
| +} |
| + |
| +bool ScreenResolution::IsValid() const { |
| + return dimensions_.width() >= 0 && dimensions_.height() >= 0 && |
| + dpi_.x() >= 0 && dpi_.y() >= 0; |
| +} |
| + |
| +} // namespace remoting |