display_size.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. #ifndef REMOTING_PROTOCOL_DISPLAY_SIZE_H_
  5. #define REMOTING_PROTOCOL_DISPLAY_SIZE_H_
  6. #include <stddef.h>
  7. #include <ostream>
  8. #include "remoting/base/constants.h"
  9. namespace remoting {
  10. class DisplaySize {
  11. public:
  12. constexpr DisplaySize() : width_dips_(0), height_dips_(0), dpi_(0) {}
  13. constexpr DisplaySize(int32_t width_dips, int32_t height_dips, uint32_t dpi)
  14. : width_dips_(width_dips), height_dips_(height_dips), dpi_(dpi) {}
  15. ~DisplaySize() = default;
  16. // Static method to build a DisplaySize from pixels rather than DIPs.
  17. static constexpr DisplaySize FromPixels(int32_t width_px,
  18. int32_t height_px,
  19. uint32_t dpi) {
  20. const int32_t width_dips = width_px * ((float)kDefaultDpi / dpi);
  21. const int32_t height_dips = height_px * ((float)kDefaultDpi / dpi);
  22. return DisplaySize(width_dips, height_dips, dpi);
  23. }
  24. bool operator==(const DisplaySize& other);
  25. bool operator!=(const DisplaySize& other);
  26. bool IsEmpty() const;
  27. int32_t WidthAsDips() const;
  28. int32_t HeightAsDips() const;
  29. int32_t WidthAsPixels() const;
  30. int32_t HeightAsPixels() const;
  31. uint32_t GetDpi() const;
  32. float GetScalingFactor() const;
  33. private:
  34. int32_t width_dips_, height_dips_;
  35. uint32_t dpi_;
  36. };
  37. std::ostream& operator<<(std::ostream& out, const DisplaySize& size);
  38. } // namespace remoting
  39. #endif // REMOTING_PROTOCOL_DISPLAY_SIZE_H_