Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(919)

Unified Diff: remoting/host/desktop_resizer_win.cc

Issue 47653003: Make DesktopResizer use ScreenResolution to facilitate DPI-awareness. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « remoting/host/desktop_resizer_mac.cc ('k') | remoting/host/resizing_host_observer.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/host/desktop_resizer_win.cc
diff --git a/remoting/host/desktop_resizer_win.cc b/remoting/host/desktop_resizer_win.cc
index 813a487e654e6d4f06bdc02144bfcda10f35ef59..f12b4729971958c473d9859cfad9089e1fd8b50a 100644
--- a/remoting/host/desktop_resizer_win.cc
+++ b/remoting/host/desktop_resizer_win.cc
@@ -8,26 +8,37 @@
#include "base/logging.h"
-// Provide comparison operation for SkISize so we can use it in std::map.
-static inline bool operator <(const SkISize& a, const SkISize& b) {
- if (a.width() != b.width())
- return a.width() < b.width();
- return a.height() < b.height();
-}
+namespace {
+// TODO(jamiewalch): Use the correct DPI for the mode: http://crbug.com/172405.
+const int kDPI = 96;
+}; // namespace
namespace remoting {
+// Provide comparison operation for ScreenResolution so we can use it in
+// std::map.
+static inline bool operator <(const ScreenResolution& a,
+ const ScreenResolution& b) {
+ if (a.resolution().width() != b.resolution().width())
+ return a.width() < b.width();
+ if (a.resolution().height() != b.resolution().height())
+ return a.height() < b.height();
+ if (a.dpi().x() != b.dpi().x())
+ return a.dpi().x() < b.dpi().x();
+ return a.dpi().y() < b.dpi().y();
+}
+
class DesktopResizerWin : public DesktopResizer {
public:
DesktopResizerWin();
virtual ~DesktopResizerWin();
// DesktopResizer interface.
- virtual SkISize GetCurrentSize() OVERRIDE;
- virtual std::list<SkISize> GetSupportedSizes(
- const SkISize& preferred) OVERRIDE;
- virtual void SetSize(const SkISize& size) OVERRIDE;
- virtual void RestoreSize(const SkISize& original) OVERRIDE;
+ virtual ScreenResolution GetCurrentResolution() OVERRIDE;
+ virtual std::list<ScreenResolution> GetSupportedResolutions(
+ const ScreenResolution& preferred) OVERRIDE;
+ virtual void SetResolution(const ScreenResolution& resolution) OVERRIDE;
+ virtual void RestoreResolution(const ScreenResolution& original) OVERRIDE;
private:
static bool IsResizeSupported();
@@ -42,9 +53,9 @@ class DesktopResizerWin : public DesktopResizer {
static bool IsModeValid(const DEVMODE& mode);
// Returns the width & height of |mode|, or 0x0 if they are missing.
- static SkISize GetModeSize(const DEVMODE& mode);
+ static ScreenResolution GetModeResolution(const DEVMODE& mode);
- std::map<SkISize, DEVMODE> best_mode_for_size_;
+ std::map<ScreenResolution, DEVMODE> best_mode_for_resolution_;
DISALLOW_COPY_AND_ASSIGN(DesktopResizerWin);
};
@@ -55,29 +66,29 @@ DesktopResizerWin::DesktopResizerWin() {
DesktopResizerWin::~DesktopResizerWin() {
}
-SkISize DesktopResizerWin::GetCurrentSize() {
+ScreenResolution DesktopResizerWin::GetCurrentResolution() {
DEVMODE current_mode;
if (GetPrimaryDisplayMode(ENUM_CURRENT_SETTINGS, 0, &current_mode) &&
IsModeValid(current_mode))
- return GetModeSize(current_mode);
- return SkISize::Make(0, 0);
+ return GetModeResolution(current_mode);
+ return ScreenResolution();
}
-std::list<SkISize> DesktopResizerWin::GetSupportedSizes(
- const SkISize& preferred) {
+std::list<ScreenResolution> DesktopResizerWin::GetSupportedResolutions(
+ const ScreenResolution& preferred) {
if (!IsResizeSupported())
- return std::list<SkISize>();
+ return std::list<ScreenResolution>();
- // Enumerate the sizes to return, and where there are multiple modes of
- // the same size, store the one most closely matching the current mode
- // in |best_mode_for_size_|.
+ // Enumerate the resolutions to return, and where there are multiple modes of
+ // the same resolution, store the one most closely matching the current mode
+ // in |best_mode_for_resolution_|.
DEVMODE current_mode;
if (!GetPrimaryDisplayMode(ENUM_CURRENT_SETTINGS, 0, &current_mode) ||
!IsModeValid(current_mode))
- return std::list<SkISize>();
+ return std::list<ScreenResolution>();
- std::list<SkISize> sizes;
- best_mode_for_size_.clear();
+ std::list<ScreenResolution> resolutions;
+ best_mode_for_resolution_.clear();
for (DWORD i = 0; ; ++i) {
DEVMODE candidate_mode;
if (!GetPrimaryDisplayMode(i, EDS_ROTATEDMODE, &candidate_mode))
@@ -95,9 +106,9 @@ std::list<SkISize> DesktopResizerWin::GetSupportedSizes(
// - Prefer the modes which match the current rotation.
// - Among those, prefer modes which match the current frequency.
// - Otherwise, prefer modes with a higher frequency.
- SkISize candidate_size = GetModeSize(candidate_mode);
- if (best_mode_for_size_.count(candidate_size) != 0) {
- DEVMODE best_mode = best_mode_for_size_[candidate_size];
+ ScreenResolution candidate_resolution = GetModeResolution(candidate_mode);
+ if (best_mode_for_resolution_.count(candidate_resolution) != 0) {
+ DEVMODE best_mode = best_mode_for_resolution_[candidate_resolution];
if ((candidate_mode.dmDisplayOrientation !=
current_mode.dmDisplayOrientation) &&
@@ -113,31 +124,31 @@ std::list<SkISize> DesktopResizerWin::GetSupportedSizes(
continue;
}
} else {
- // If we haven't seen this size before, add it to those we return.
- sizes.push_back(candidate_size);
+ // If we haven't seen this resolution before, add it to those we return.
+ resolutions.push_back(candidate_resolution);
}
- best_mode_for_size_[candidate_size] = candidate_mode;
+ best_mode_for_resolution_[candidate_resolution] = candidate_mode;
}
- return sizes;
+ return resolutions;
}
-void DesktopResizerWin::SetSize(const SkISize& size) {
- if (best_mode_for_size_.count(size) == 0)
+void DesktopResizerWin::SetResolution(const ScreenResolution& resolution) {
+ if (best_mode_for_resolution_.count(resolution) == 0)
return;
- DEVMODE new_mode = best_mode_for_size_[size];
+ DEVMODE new_mode = best_mode_for_resolution_[resolution];
DWORD result = ChangeDisplaySettings(&new_mode, CDS_FULLSCREEN);
if (result != DISP_CHANGE_SUCCESSFUL)
- LOG(ERROR) << "SetSize failed: " << result;
+ LOG(ERROR) << "SetResolution failed: " << result;
}
-void DesktopResizerWin::RestoreSize(const SkISize& original) {
+void DesktopResizerWin::RestoreResolution(const ScreenResolution& original) {
// Restore the display mode based on the registry configuration.
DWORD result = ChangeDisplaySettings(NULL, 0);
if (result != DISP_CHANGE_SUCCESSFUL)
- LOG(ERROR) << "RestoreSize failed: " << result;
+ LOG(ERROR) << "RestoreResolution failed: " << result;
}
// static
@@ -165,9 +176,11 @@ bool DesktopResizerWin::IsModeValid(const DEVMODE& mode) {
}
// static
-SkISize DesktopResizerWin::GetModeSize(const DEVMODE& mode) {
+ScreenResolution DesktopResizerWin::GetModeResolution(const DEVMODE& mode) {
DCHECK(IsModeValid(mode));
- return SkISize::Make(mode.dmPelsWidth, mode.dmPelsHeight);
+ return ScreenResolution::Make(
+ webrtc::DesktopSize(mode.dmPelsWidth, mode.dmPelsHeight),
+ webrtc::DesktopVector(kDPI, kDPI));
}
scoped_ptr<DesktopResizer> DesktopResizer::Create() {
« no previous file with comments | « remoting/host/desktop_resizer_mac.cc ('k') | remoting/host/resizing_host_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698