display_size.cc 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Copyright 2019 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. #include "remoting/protocol/display_size.h"
  5. #include "build/build_config.h"
  6. #include "remoting/base/constants.h"
  7. namespace remoting {
  8. bool DisplaySize::operator==(const DisplaySize& other) {
  9. return other.width_dips_ == width_dips_ &&
  10. other.height_dips_ == height_dips_ && other.dpi_ == dpi_;
  11. }
  12. bool DisplaySize::operator!=(const DisplaySize& other) {
  13. return !(*this == other);
  14. }
  15. bool DisplaySize::IsEmpty() const {
  16. return width_dips_ == 0 || height_dips_ == 0;
  17. }
  18. int32_t DisplaySize::WidthAsPixels() const {
  19. return width_dips_ * GetScalingFactor();
  20. }
  21. int32_t DisplaySize::WidthAsDips() const {
  22. return width_dips_;
  23. }
  24. int32_t DisplaySize::HeightAsPixels() const {
  25. return height_dips_ * GetScalingFactor();
  26. }
  27. int32_t DisplaySize::HeightAsDips() const {
  28. return height_dips_;
  29. }
  30. uint32_t DisplaySize::GetDpi() const {
  31. return dpi_;
  32. }
  33. float DisplaySize::GetScalingFactor() const {
  34. return (float)dpi_ / (float)kDefaultDpi;
  35. }
  36. std::ostream& operator<<(std::ostream& out, const DisplaySize& size) {
  37. out << size.WidthAsDips() << "x" << size.HeightAsDips() << " @"
  38. << size.GetDpi();
  39. return out;
  40. }
  41. } // namespace remoting