diff options
author | jamiewalch@chromium.org <jamiewalch@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-01 17:21:18 +0000 |
---|---|---|
committer | jamiewalch@chromium.org <jamiewalch@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-01 17:21:18 +0000 |
commit | fcce48d9b942dba39471b78fdf2332adcb653c27 (patch) | |
tree | 3e043c5abf97d4e3c1ebc23152ec76c3e99d04f9 /remoting | |
parent | e7e3802f6dc5ac415ef926ee022d1e26f10a50b9 (diff) | |
download | chromium_src-fcce48d9b942dba39471b78fdf2332adcb653c27.zip chromium_src-fcce48d9b942dba39471b78fdf2332adcb653c27.tar.gz chromium_src-fcce48d9b942dba39471b78fdf2332adcb653c27.tar.bz2 |
Make DesktopResizer use ScreenResolution to facilitate DPI-awareness.
This CL just gets the DPI information into the DesktopResizer back-ends. They
don't do anything with it yet, and there should be no functional changes.
BUG=172405
Review URL: https://codereview.chromium.org/54273006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@232422 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting')
-rw-r--r-- | remoting/host/desktop_resizer.h | 40 | ||||
-rw-r--r-- | remoting/host/desktop_resizer_linux.cc | 108 | ||||
-rw-r--r-- | remoting/host/desktop_resizer_mac.cc | 77 | ||||
-rw-r--r-- | remoting/host/desktop_resizer_win.cc | 93 | ||||
-rw-r--r-- | remoting/host/resizing_host_observer.cc | 97 | ||||
-rw-r--r-- | remoting/host/resizing_host_observer.h | 3 | ||||
-rw-r--r-- | remoting/host/resizing_host_observer_unittest.cc | 164 | ||||
-rw-r--r-- | remoting/host/screen_resolution.cc | 4 | ||||
-rw-r--r-- | remoting/host/screen_resolution.h | 3 |
9 files changed, 339 insertions, 250 deletions
diff --git a/remoting/host/desktop_resizer.h b/remoting/host/desktop_resizer.h index 2243917..945605a 100644 --- a/remoting/host/desktop_resizer.h +++ b/remoting/host/desktop_resizer.h @@ -8,6 +8,7 @@ #include <list> #include "base/memory/scoped_ptr.h" +#include "remoting/host/screen_resolution.h" #include "third_party/skia/include/core/SkRect.h" namespace remoting { @@ -19,30 +20,31 @@ class DesktopResizer { // Create a platform-specific DesktopResizer instance. static scoped_ptr<DesktopResizer> Create(); - // Return the current size of the desktop. - virtual SkISize GetCurrentSize() = 0; + // Return the current resolution of the desktop. + virtual ScreenResolution GetCurrentResolution() = 0; - // Get the list of supported sizes, which should ideally include |preferred|. - // Implementations will generally do one of the following: - // 1. Return the list of sizes supported by the underlying video driver, - // regardless of |preferred|. + // Get the list of supported resolutions, which should ideally include + // |preferred|. Implementations will generally do one of the following: + // 1. Return the list of resolutions supported by the underlying video + // driver, regardless of |preferred|. // 2. Return a list containing just |preferred|, perhaps after imposing // some minimum size constraint. This will typically be the case if // there are no constraints imposed by the underlying video driver. // 3. Return an empty list if resize is not supported. - virtual std::list<SkISize> GetSupportedSizes(const SkISize& preferred) = 0; - - // Set the size of the desktop. |size| must be one of the sizes previously - // returned by |GetSupportedSizes|. Note that implementations should fail - // gracefully if the specified size is no longer supported, since monitor - // configurations may change on the fly. - virtual void SetSize(const SkISize& size) = 0; - - // Restore the original desktop size. The caller must provide the original - // size of the desktop, as returned by |GetCurrentSize|, as a hint. However, - // implementaions are free to ignore this. For example, virtual hosts will - // typically ignore it to avoid unnecessary resize operations. - virtual void RestoreSize(const SkISize& original) = 0; + virtual std::list<ScreenResolution> GetSupportedResolutions( + const ScreenResolution& preferred) = 0; + + // Set the resolution of the desktop. |resolution| must be one of the + // resolutions previously returned by |GetSupportedResolutions|. Note that + // implementations should fail gracefully if the specified resolution is no + // longer supported, since monitor configurations may change on the fly. + virtual void SetResolution(const ScreenResolution& resolution) = 0; + + // Restore the original desktop resolution. The caller must provide the + // original resolution of the desktop, as returned by |GetCurrentResolution|, + // as a hint. However, implementaions are free to ignore this. For example, + // virtual hosts will typically ignore it to avoid unnecessary resizes. + virtual void RestoreResolution(const ScreenResolution& original) = 0; }; } // namespace remoting diff --git a/remoting/host/desktop_resizer_linux.cc b/remoting/host/desktop_resizer_linux.cc index 3c7d326..1ecca28 100644 --- a/remoting/host/desktop_resizer_linux.cc +++ b/remoting/host/desktop_resizer_linux.cc @@ -12,35 +12,36 @@ #include "base/command_line.h" #include "base/logging.h" -// On Linux, we use the xrandr extension to change the desktop size. For now, -// we only support resize-to-client for Xvfb-based servers that can match the -// client size exactly. To support best-size matching, it would be necessary -// to implement |GetSupportedSizes|, but it's not considered a priority now. +// On Linux, we use the xrandr extension to change the desktop resolution. For +// now, we only support resize-to-client for Xvfb-based servers that can match +// the client resolution exactly. To support best-resolution matching, it would +// be necessary to implement |GetSupportedResolutions|, but it's not considered +// a priority now. // // Xrandr has a number of restrictions that make this code more complex: // -// 1. It's not possible to change the size of an existing mode. Instead, the -// mode must be deleted and recreated. +// 1. It's not possible to change the resolution of an existing mode. Instead, +// the mode must be deleted and recreated. // 2. It's not possible to delete a mode that's in use. // 3. Errors are communicated via Xlib's spectacularly unhelpful mechanism // of terminating the process unless you install an error handler. // // The basic approach is as follows: // -// 1. Create a new mode with the correct size; +// 1. Create a new mode with the correct resolution; // 2. Switch to the new mode; // 3. Delete the old mode. // // Since the new mode must have a different name, and we want the current mode // name to be consistent, we then additionally: // -// 4. Recreate the old mode at the new size; +// 4. Recreate the old mode at the new resolution; // 5. Switch to the old mode; // 6. Delete the temporary mode. // // Name consistency will allow a future CL to disable resize-to-client if the // user has changed the mode to something other than "Chrome Remote Desktop -// client size". It doesn't make the code significantly more complex. +// client resolution". It doesn't make the code significantly more complex. namespace { @@ -55,6 +56,9 @@ int PixelsToMillimeters(int pixels, int dpi) { return static_cast<int>(kMillimetersPerInch * pixels / dpi); } +// TODO(jamiewalch): Use the correct DPI for the mode: http://crbug.com/172405. +const int kDefaultDPI = 96; + } // namespace namespace remoting { @@ -123,11 +127,11 @@ class DesktopResizerLinux : public DesktopResizer { virtual ~DesktopResizerLinux(); // 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: // Create a mode, and attach it to the primary output. If the mode already @@ -140,7 +144,7 @@ class DesktopResizerLinux : public DesktopResizer { // Switch the primary output to the specified mode. If name is NULL, the // primary output is disabled instead, which is required before changing - // its size. + // its resolution. void SwitchToMode(const char* name); Display* display_; @@ -165,11 +169,11 @@ DesktopResizerLinux::~DesktopResizerLinux() { XCloseDisplay(display_); } -SkISize DesktopResizerLinux::GetCurrentSize() { +ScreenResolution DesktopResizerLinux::GetCurrentResolution() { if (!exact_resize_) { // TODO(jamiewalch): Remove this early return if we decide to support // non-Xvfb servers. - return SkISize::Make(0, 0); + return ScreenResolution(); } // TODO(lambroslambrou): Xrandr requires that we process RRScreenChangeNotify @@ -187,35 +191,41 @@ SkISize DesktopResizerLinux::GetCurrentSize() { XRRUpdateConfiguration(&event); } - SkISize result = SkISize::Make( - DisplayWidth (display_, DefaultScreen(display_)), - DisplayHeight(display_, DefaultScreen(display_))); + ScreenResolution result( + webrtc::DesktopSize( + DisplayWidth(display_, DefaultScreen(display_)), + DisplayHeight(display_, DefaultScreen(display_))), + webrtc::DesktopVector(kDefaultDPI, kDefaultDPI)); return result; } -std::list<SkISize> DesktopResizerLinux::GetSupportedSizes( - const SkISize& preferred) { - std::list<SkISize> result; +std::list<ScreenResolution> DesktopResizerLinux::GetSupportedResolutions( + const ScreenResolution& preferred) { + std::list<ScreenResolution> result; if (exact_resize_) { // Clamp the specified size to something valid for the X server. int min_width = 0, min_height = 0, max_width = 0, max_height = 0; XRRGetScreenSizeRange(display_, root_, &min_width, &min_height, &max_width, &max_height); - int width = std::min(std::max(preferred.width(), min_width), max_width); - int height = std::min(std::max(preferred.height(), min_height), max_height); + int width = std::min(std::max(preferred.dimensions().width(), min_width), + max_width); + int height = std::min(std::max(preferred.dimensions().height(), min_height), + max_height); // Additionally impose a minimum size of 640x480, since anything smaller // doesn't seem very useful. - SkISize actual = SkISize::Make(std::max(640, width), std::max(480, height)); + ScreenResolution actual( + webrtc::DesktopSize(std::max(640, width), std::max(480, height)), + webrtc::DesktopVector(kDefaultDPI, kDefaultDPI)); result.push_back(actual); } else { - // TODO(jamiewalch): Return the list of supported sizes if we can't support - // exact-size matching. + // TODO(jamiewalch): Return the list of supported resolutions if we can't + // support exact-size matching. } return result; } -void DesktopResizerLinux::SetSize(const SkISize& size) { +void DesktopResizerLinux::SetResolution(const ScreenResolution& resolution) { if (!exact_resize_) { // TODO(jamiewalch): Remove this early return if we decide to support // non-Xvfb servers. @@ -224,47 +234,51 @@ void DesktopResizerLinux::SetSize(const SkISize& size) { // Ignore X errors encountered while resizing the display. We might hit an // error, for example if xrandr has been used to add a mode with the same - // name as our temporary mode, or to remove the "client size" mode. We don't - // want to terminate the process if this happens. + // name as our temporary mode, or to remove the "client resolution" mode. We + // don't want to terminate the process if this happens. ScopedXErrorHandler handler(ScopedXErrorHandler::Ignore()); - // Grab the X server while we're changing the display size. This ensures + // Grab the X server while we're changing the display resolution. This ensures // that the display configuration doesn't change under our feet. ScopedXGrabServer grabber(display_); - // The name of the mode representing the current client view size and the - // temporary mode used for the reasons described at the top of this file. + // The name of the mode representing the current client view resolution and + // the temporary mode used for the reasons described at the top of this file. // The former should be localized if it's user-visible; the latter only // exists briefly and does not need to localized. - const char* kModeName = "Chrome Remote Desktop client size"; + const char* kModeName = "Chrome Remote Desktop client resolution"; const char* kTempModeName = "Chrome Remote Desktop temporary mode"; // Actually do the resize operation, preserving the current mode name. Note // that we have to detach the output from any mode in order to resize it // (strictly speaking, this is only required when reducing the size, but it // seems safe to do it regardless). - LOG(INFO) << "Changing desktop size to " << size.width() - << "x" << size.height(); + LOG(INFO) << "Changing desktop size to " << resolution.dimensions().width() + << "x" << resolution.dimensions().height(); // TODO(lambroslambrou): Use the DPI from client size information. - const int kDPI = 96; - int width_mm = PixelsToMillimeters(size.width(), kDPI); - int height_mm = PixelsToMillimeters(size.height(), kDPI); - CreateMode(kTempModeName, size.width(), size.height()); + int width_mm = PixelsToMillimeters(resolution.dimensions().width(), + kDefaultDPI); + int height_mm = PixelsToMillimeters(resolution.dimensions().height(), + kDefaultDPI); + CreateMode(kTempModeName, resolution.dimensions().width(), + resolution.dimensions().height()); SwitchToMode(NULL); - XRRSetScreenSize(display_, root_, size.width(), size.height(), width_mm, - height_mm); + XRRSetScreenSize(display_, root_, resolution.dimensions().width(), + resolution.dimensions().height(), width_mm, height_mm); SwitchToMode(kTempModeName); DeleteMode(kModeName); - CreateMode(kModeName, size.width(), size.height()); + CreateMode(kModeName, resolution.dimensions().width(), + resolution.dimensions().height()); SwitchToMode(kModeName); DeleteMode(kTempModeName); } -void DesktopResizerLinux::RestoreSize(const SkISize& original) { +void DesktopResizerLinux::RestoreResolution(const ScreenResolution& original) { // Since the desktop is only visible via a remote connection, the original - // size of the desktop will never been seen and there's no point restoring - // it; if we did, we'd just risk messing up the user's window layout. + // resolution of the desktop will never been seen and there's no point + // restoring it; if we did, we'd just risk messing up the user's window + // layout. } void DesktopResizerLinux::CreateMode(const char* name, int width, int height) { diff --git a/remoting/host/desktop_resizer_mac.cc b/remoting/host/desktop_resizer_mac.cc index 57f01ee..0cec2a9 100644 --- a/remoting/host/desktop_resizer_mac.cc +++ b/remoting/host/desktop_resizer_mac.cc @@ -12,6 +12,11 @@ #include "base/mac/mac_util.h" #include "base/mac/scoped_cftyperef.h" +namespace { +// TODO(jamiewalch): Use the correct DPI for the mode: http://crbug.com/172405. +const int kDefaultDPI = 96; +} // namespace + namespace remoting { class DesktopResizerMac : public DesktopResizer { @@ -19,59 +24,61 @@ class DesktopResizerMac : public DesktopResizer { DesktopResizerMac(); // 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: // If there is a single display, get its id and return true, otherwise return // false. We don't currently support resize-to-client on multi-monitor Macs. bool GetSoleDisplayId(CGDirectDisplayID* display); - void GetSupportedModesAndSizes( + void GetSupportedModesAndResolutions( base::ScopedCFTypeRef<CFMutableArrayRef>* modes, - std::list<SkISize>* sizes); + std::list<ScreenResolution>* resolutions); DISALLOW_COPY_AND_ASSIGN(DesktopResizerMac); }; DesktopResizerMac::DesktopResizerMac() {} -SkISize DesktopResizerMac::GetCurrentSize() { +ScreenResolution DesktopResizerMac::GetCurrentResolution() { CGDirectDisplayID display; if (!base::mac::IsOSSnowLeopard() && GetSoleDisplayId(&display)) { CGRect rect = CGDisplayBounds(display); - return SkISize::Make(rect.size.width, rect.size.height); + return ScreenResolution( + webrtc::DesktopSize(rect.size.width, rect.size.height), + webrtc::DesktopVector(kDefaultDPI, kDefaultDPI)); } - return SkISize::Make(0, 0); + return ScreenResolution(); } -std::list<SkISize> DesktopResizerMac::GetSupportedSizes( - const SkISize& preferred) { +std::list<ScreenResolution> DesktopResizerMac::GetSupportedResolutions( + const ScreenResolution& preferred) { base::ScopedCFTypeRef<CFMutableArrayRef> modes; - std::list<SkISize> sizes; - GetSupportedModesAndSizes(&modes, &sizes); - return sizes; + std::list<ScreenResolution> resolutions; + GetSupportedModesAndResolutions(&modes, &resolutions); + return resolutions; } -void DesktopResizerMac::SetSize(const SkISize& size) { +void DesktopResizerMac::SetResolution(const ScreenResolution& resolution) { CGDirectDisplayID display; if (base::mac::IsOSSnowLeopard() || !GetSoleDisplayId(&display)) { return; } base::ScopedCFTypeRef<CFMutableArrayRef> modes; - std::list<SkISize> sizes; - GetSupportedModesAndSizes(&modes, &sizes); - // There may be many modes with the requested size. Pick the one with the - // highest color depth. + std::list<ScreenResolution> resolutions; + GetSupportedModesAndResolutions(&modes, &resolutions); + // There may be many modes with the requested resolution. Pick the one with + // the highest color depth. int index = 0, best_depth = 0; CGDisplayModeRef best_mode = NULL; - for (std::list<SkISize>::const_iterator i = sizes.begin(); i != sizes.end(); - ++i, ++index) { - if (*i == size) { + for (std::list<ScreenResolution>::const_iterator i = resolutions.begin(); + i != resolutions.end(); ++i, ++index) { + if (!i->Equals(resolution)) { CGDisplayModeRef mode = const_cast<CGDisplayModeRef>( static_cast<const CGDisplayMode*>( CFArrayGetValueAtIndex(modes, index))); @@ -97,19 +104,22 @@ void DesktopResizerMac::SetSize(const SkISize& size) { } } if (best_mode) { - LOG(INFO) << "Changing mode to " << best_mode << " (" << size.width() - << "x" << size.height() << "x" << best_depth << ")"; + LOG(INFO) << "Changing mode to " << best_mode << " (" + << resolution.dimensions().width() << "x" + << "x" << resolution.dimensions().height() << "x" + << best_depth << " @ " + << resolution.dpi().x() << "x" << resolution.dpi().y() << " dpi)"; CGDisplaySetDisplayMode(display, best_mode, NULL); } } -void DesktopResizerMac::RestoreSize(const SkISize& original) { - SetSize(original); +void DesktopResizerMac::RestoreResolution(const ScreenResolution& original) { + SetResolution(original); } -void DesktopResizerMac::GetSupportedModesAndSizes( +void DesktopResizerMac::GetSupportedModesAndResolutions( base::ScopedCFTypeRef<CFMutableArrayRef>* modes, - std::list<SkISize>* sizes) { + std::list<ScreenResolution>* resolutions) { CGDirectDisplayID display; if (!GetSoleDisplayId(&display)) { return; @@ -128,9 +138,12 @@ void DesktopResizerMac::GetSupportedModesAndSizes( static_cast<const CGDisplayMode*>( CFArrayGetValueAtIndex(*modes, i))); if (CGDisplayModeIsUsableForDesktopGUI(mode)) { - SkISize size = SkISize::Make(CGDisplayModeGetWidth(mode), - CGDisplayModeGetHeight(mode)); - sizes->push_back(size); + // TODO(jamiewalch): Get the correct DPI: http://crbug.com/172405. + ScreenResolution resolution( + webrtc::DesktopSize(CGDisplayModeGetWidth(mode), + CGDisplayModeGetHeight(mode)), + webrtc::DesktopVector(kDefaultDPI, kDefaultDPI)); + resolutions->push_back(resolution); } else { CFArrayRemoveValueAtIndex(*modes, i); --count; diff --git a/remoting/host/desktop_resizer_win.cc b/remoting/host/desktop_resizer_win.cc index 813a487..9f2de40 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 kDefaultDPI = 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.dimensions().width() != b.dimensions().width()) + return a.dimensions().width() < b.dimensions().width(); + if (a.dimensions().height() != b.dimensions().height()) + return a.dimensions().height() < b.dimensions().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, ¤t_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, ¤t_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( + webrtc::DesktopSize(mode.dmPelsWidth, mode.dmPelsHeight), + webrtc::DesktopVector(kDefaultDPI, kDefaultDPI)); } scoped_ptr<DesktopResizer> DesktopResizer::Create() { diff --git a/remoting/host/resizing_host_observer.cc b/remoting/host/resizing_host_observer.cc index 8ef1306..5b69e85 100644 --- a/remoting/host/resizing_host_observer.cc +++ b/remoting/host/resizing_host_observer.cc @@ -12,6 +12,7 @@ #include "remoting/host/desktop_resizer.h" #include "remoting/host/screen_resolution.h" +namespace remoting { namespace { // Minimum amount of time to wait between desktop resizes. Note that this @@ -19,22 +20,25 @@ namespace { // unit-test and must be kept in sync. const int kMinimumResizeIntervalMs = 1000; -class CandidateSize { +class CandidateResolution { public: - CandidateSize(const SkISize& candidate, const SkISize& preferred) - : size_(candidate) { + CandidateResolution(const ScreenResolution& candidate, + const ScreenResolution& preferred) + : resolution_(candidate) { // Protect against division by zero. - CHECK(!candidate.isEmpty()); - DCHECK(!preferred.isEmpty()); + CHECK(!candidate.IsEmpty()); + DCHECK(!preferred.IsEmpty()); // The client scale factor is the smaller of the candidate:preferred ratios // for width and height. - if ((candidate.width() > preferred.width()) || - (candidate.height() > preferred.height())) { + if ((candidate.dimensions().width() > preferred.dimensions().width()) || + (candidate.dimensions().height() > preferred.dimensions().height())) { const float width_ratio = - static_cast<float>(preferred.width()) / candidate.width(); + static_cast<float>(preferred.dimensions().width()) / + candidate.dimensions().width(); const float height_ratio = - static_cast<float>(preferred.height()) / candidate.height(); + static_cast<float>(preferred.dimensions().height()) / + candidate.dimensions().height(); client_scale_factor_ = std::min(width_ratio, height_ratio); } else { // Since clients do not scale up, 1.0 is the maximum. @@ -48,9 +52,11 @@ class CandidateSize { // By keeping the values < 1.0, it allows ratios that differ in opposite // directions to be compared numerically. float candidate_aspect_ratio = - static_cast<float>(candidate.width()) / candidate.height(); + static_cast<float>(candidate.dimensions().width()) / + candidate.dimensions().height(); float preferred_aspect_ratio = - static_cast<float>(preferred.width()) / preferred.height(); + static_cast<float>(preferred.dimensions().width()) / + preferred.dimensions().height(); if (candidate_aspect_ratio > preferred_aspect_ratio) { aspect_ratio_goodness_ = preferred_aspect_ratio / candidate_aspect_ratio; } else { @@ -58,64 +64,67 @@ class CandidateSize { } } - const SkISize& size() const { return size_; } + const ScreenResolution& resolution() const { return resolution_; } float client_scale_factor() const { return client_scale_factor_; } float aspect_ratio_goodness() const { return aspect_ratio_goodness_; } int64 area() const { - return static_cast<int64>(size_.width()) * size_.height(); + return static_cast<int64>(resolution_.dimensions().width()) * + resolution_.dimensions().height(); } - bool IsBetterThan(const CandidateSize& other) const { - // If either size would require down-scaling, prefer the one that down- - // scales the least (since the client scale factor is at most 1.0, this - // does not differentiate between sizes that don't require down-scaling). + // TODO(jamiewalch): Also compare the DPI: http://crbug.com/172405 + bool IsBetterThan(const CandidateResolution& other) const { + // If either resolution would require down-scaling, prefer the one that + // down-scales the least (since the client scale factor is at most 1.0, + // this does not differentiate between resolutions that don't require + // down-scaling). if (client_scale_factor() < other.client_scale_factor()) { return false; } else if (client_scale_factor() > other.client_scale_factor()) { return true; } - // If the scale factors are the same, pick the size with the largest area. + // If the scale factors are the same, pick the resolution with the largest + // area. if (area() < other.area()) { return false; } else if (area() > other.area()) { return true; } - // If the areas are equal, pick the size with the "best" aspect ratio. + // If the areas are equal, pick the resolution with the "best" aspect ratio. if (aspect_ratio_goodness() < other.aspect_ratio_goodness()) { return false; } else if (aspect_ratio_goodness() > other.aspect_ratio_goodness()) { return true; } - // If the aspect ratios are equally good (for example, comparing 640x480 - // to 480x640 w.r.t. 640x640), just pick the widest, since desktop UIs - // are typically designed for landscape aspect ratios. - return size().width() > other.size().width(); + // All else being equal (for example, comparing 640x480 to 480x640 w.r.t. + // 640x640), just pick the widest, since desktop UIs are typically designed + // for landscape aspect ratios. + return resolution().dimensions().width() > + other.resolution().dimensions().width(); } private: float client_scale_factor_; float aspect_ratio_goodness_; - SkISize size_; + ScreenResolution resolution_; }; } // namespace -namespace remoting { - ResizingHostObserver::ResizingHostObserver( scoped_ptr<DesktopResizer> desktop_resizer) : desktop_resizer_(desktop_resizer.Pass()), - original_size_(desktop_resizer_->GetCurrentSize()), + original_resolution_(desktop_resizer_->GetCurrentResolution()), now_function_(base::Bind(base::Time::Now)), weak_factory_(this) { } ResizingHostObserver::~ResizingHostObserver() { - if (!original_size_.isZero()) - desktop_resizer_->RestoreSize(original_size_); + if (!original_resolution_.IsEmpty()) + desktop_resizer_->RestoreResolution(original_resolution_); } void ResizingHostObserver::SetScreenResolution( @@ -143,24 +152,24 @@ void ResizingHostObserver::SetScreenResolution( return; } - // If the implementation returns any sizes, pick the best one according to - // the algorithm described in CandidateSize::IsBetterThen. - SkISize dimensions = SkISize::Make( - resolution.dimensions().width(), resolution.dimensions().height()); - std::list<SkISize> sizes = desktop_resizer_->GetSupportedSizes(dimensions); - if (sizes.empty()) + // If the implementation returns any resolutions, pick the best one according + // to the algorithm described in CandidateResolution::IsBetterThen. + std::list<ScreenResolution> resolutions = + desktop_resizer_->GetSupportedResolutions(resolution); + if (resolutions.empty()) return; - CandidateSize best_size(sizes.front(), dimensions); - for (std::list<SkISize>::const_iterator i = ++sizes.begin(); - i != sizes.end(); ++i) { - CandidateSize candidate_size(*i, dimensions); - if (candidate_size.IsBetterThan(best_size)) { - best_size = candidate_size; + CandidateResolution best_candidate(resolutions.front(), resolution); + for (std::list<ScreenResolution>::const_iterator i = ++resolutions.begin(); + i != resolutions.end(); ++i) { + CandidateResolution candidate(*i, resolution); + if (candidate.IsBetterThan(best_candidate)) { + best_candidate = candidate; } } - SkISize current_size = desktop_resizer_->GetCurrentSize(); - if (best_size.size() != current_size) - desktop_resizer_->SetSize(best_size.size()); + ScreenResolution current_resolution = + desktop_resizer_->GetCurrentResolution(); + if (!best_candidate.resolution().Equals(current_resolution)) + desktop_resizer_->SetResolution(best_candidate.resolution()); // Update the time of last resize to allow it to be rate-limited. previous_resize_time_ = now; diff --git a/remoting/host/resizing_host_observer.h b/remoting/host/resizing_host_observer.h index 1eda70d..c6ad714 100644 --- a/remoting/host/resizing_host_observer.h +++ b/remoting/host/resizing_host_observer.h @@ -14,7 +14,6 @@ #include "base/timer/timer.h" #include "remoting/host/screen_controls.h" #include "remoting/host/screen_resolution.h" -#include "third_party/skia/include/core/SkSize.h" namespace remoting { @@ -42,7 +41,7 @@ class ResizingHostObserver : public ScreenControls { private: scoped_ptr<DesktopResizer> desktop_resizer_; - SkISize original_size_; + ScreenResolution original_resolution_; // State to manage rate-limiting of desktop resizes. base::OneShotTimer<ResizingHostObserver> deferred_resize_timer_; diff --git a/remoting/host/resizing_host_observer_unittest.cc b/remoting/host/resizing_host_observer_unittest.cc index 4eb7fc6..a8a0eef 100644 --- a/remoting/host/resizing_host_observer_unittest.cc +++ b/remoting/host/resizing_host_observer_unittest.cc @@ -13,63 +13,75 @@ #include "remoting/host/resizing_host_observer.h" #include "remoting/host/screen_resolution.h" #include "testing/gtest/include/gtest/gtest.h" -#include "third_party/skia/include/core/SkSize.h" #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" -std::ostream& operator<<(std::ostream& os, const SkISize& size) { - return os << size.width() << "x" << size.height(); +namespace remoting { + +std::ostream& operator<<(std::ostream& os, const ScreenResolution& resolution) { + return os << resolution.dimensions().width() << "x" + << resolution.dimensions().height() << " @ " + << resolution.dpi().x() << "x" << resolution.dpi().y(); +} + +bool operator==(const ScreenResolution& a, const ScreenResolution& b) { + return a.Equals(b); } const int kDefaultDPI = 96; -namespace remoting { +ScreenResolution MakeResolution(int width, int height) { + return ScreenResolution(webrtc::DesktopSize(width, height), + webrtc::DesktopVector(kDefaultDPI, kDefaultDPI)); +} class FakeDesktopResizer : public DesktopResizer { public: - FakeDesktopResizer(const SkISize& initial_size, bool exact_size_supported, - const SkISize* supported_sizes, int num_supported_sizes) - : initial_size_(initial_size), - current_size_(initial_size), + FakeDesktopResizer(const ScreenResolution& initial_resolution, + bool exact_size_supported, + const ScreenResolution* supported_resolutions, + int num_supported_resolutions) + : initial_resolution_(initial_resolution), + current_resolution_(initial_resolution), exact_size_supported_(exact_size_supported), - set_size_call_count_(0) { - for (int i = 0; i < num_supported_sizes; ++i) { - supported_sizes_.push_back(supported_sizes[i]); + set_resolution_call_count_(0) { + for (int i = 0; i < num_supported_resolutions; ++i) { + supported_resolutions_.push_back(supported_resolutions[i]); } } virtual ~FakeDesktopResizer() { - EXPECT_EQ(initial_size_, GetCurrentSize()); + EXPECT_EQ(initial_resolution_, GetCurrentResolution()); } - int set_size_call_count() { return set_size_call_count_; } + int set_resolution_call_count() { return set_resolution_call_count_; } // remoting::DesktopResizer interface - virtual SkISize GetCurrentSize() OVERRIDE { - return current_size_; + virtual ScreenResolution GetCurrentResolution() OVERRIDE { + return current_resolution_; } - virtual std::list<SkISize> GetSupportedSizes( - const SkISize& preferred) OVERRIDE { - std::list<SkISize> result = supported_sizes_; + virtual std::list<ScreenResolution> GetSupportedResolutions( + const ScreenResolution& preferred) OVERRIDE { + std::list<ScreenResolution> result = supported_resolutions_; if (exact_size_supported_) { result.push_back(preferred); } return result; } - virtual void SetSize(const SkISize& size) OVERRIDE { - current_size_ = size; - ++set_size_call_count_; + virtual void SetResolution(const ScreenResolution& resolution) OVERRIDE { + current_resolution_ = resolution; + ++set_resolution_call_count_; } - virtual void RestoreSize(const SkISize& size) OVERRIDE { - current_size_ = size; + virtual void RestoreResolution(const ScreenResolution& resolution) OVERRIDE { + current_resolution_ = resolution; } private: - SkISize initial_size_; - SkISize current_size_; + ScreenResolution initial_resolution_; + ScreenResolution current_resolution_; bool exact_size_supported_; - std::list<SkISize> supported_sizes_; + std::list<ScreenResolution> supported_resolutions_; - int set_size_call_count_; + int set_resolution_call_count_; }; class ResizingHostObserverTest : public testing::Test { @@ -97,19 +109,18 @@ class ResizingHostObserverTest : public testing::Test { base::Unretained(this))); } - SkISize GetBestSize(const SkISize& client_size) { - resizing_host_observer_->SetScreenResolution(ScreenResolution( - webrtc::DesktopSize(client_size.width(), client_size.height()), - webrtc::DesktopVector(kDefaultDPI, kDefaultDPI))); - return desktop_resizer_->GetCurrentSize(); + ScreenResolution GetBestResolution(const ScreenResolution& client_size) { + resizing_host_observer_->SetScreenResolution(client_size); + return desktop_resizer_->GetCurrentResolution(); } - void VerifySizes(const SkISize* client_sizes, const SkISize* expected_sizes, + void VerifySizes(const ScreenResolution* client_sizes, + const ScreenResolution* expected_sizes, int number_of_sizes) { for (int i = 0; i < number_of_sizes; ++i) { - SkISize best_size = GetBestSize(client_sizes[i]); + ScreenResolution best_size = GetBestResolution(client_sizes[i]); EXPECT_EQ(expected_sizes[i], best_size) - << "Input size = " << client_sizes[i]; + << "Input resolution = " << client_sizes[i]; } } @@ -127,40 +138,46 @@ class ResizingHostObserverTest : public testing::Test { // Check that the host is not resized if GetSupportedSizes returns an empty // list (even if GetCurrentSize is supported). TEST_F(ResizingHostObserverTest, EmptyGetSupportedSizes) { - SkISize initial = { 640, 480 }; + ScreenResolution initial = MakeResolution(640, 480); scoped_ptr<FakeDesktopResizer> desktop_resizer( new FakeDesktopResizer(initial, false, NULL, 0)); SetDesktopResizer(desktop_resizer.Pass()); - SkISize client_sizes[] = { { 200, 100 }, { 100, 200 } }; - SkISize expected_sizes[] = { initial, initial }; + ScreenResolution client_sizes[] = { MakeResolution(200, 100), + MakeResolution(100, 200) }; + ScreenResolution expected_sizes[] = { initial, initial }; VerifySizes(client_sizes, expected_sizes, arraysize(client_sizes)); } // Check that if the implementation supports exact size matching, it is used. TEST_F(ResizingHostObserverTest, SelectExactSize) { scoped_ptr<FakeDesktopResizer> desktop_resizer( - new FakeDesktopResizer(SkISize::Make(640, 480), true, NULL, 0)); + new FakeDesktopResizer(MakeResolution(640, 480), true, NULL, 0)); SetDesktopResizer(desktop_resizer.Pass()); - SkISize client_sizes[] = { { 200, 100 }, { 100, 200 } , { 640, 480 }, - { 480, 640 }, { 1280, 1024 } }; + ScreenResolution client_sizes[] = { MakeResolution(200, 100), + MakeResolution(100, 200), + MakeResolution(640, 480), + MakeResolution(480, 640), + MakeResolution(1280, 1024) }; VerifySizes(client_sizes, client_sizes, arraysize(client_sizes)); } // Check that if the implementation supports a size that is no larger than // the requested size, then the largest such size is used. TEST_F(ResizingHostObserverTest, SelectBestSmallerSize) { - SkISize supported_sizes[] = { - SkISize::Make(639, 479), SkISize::Make(640, 480) }; + ScreenResolution supported_sizes[] = { MakeResolution(639, 479), + MakeResolution(640, 480) }; scoped_ptr<FakeDesktopResizer> desktop_resizer( - new FakeDesktopResizer(SkISize::Make(640, 480), false, + new FakeDesktopResizer(MakeResolution(640, 480), false, supported_sizes, arraysize(supported_sizes))); SetDesktopResizer(desktop_resizer.Pass()); - SkISize client_sizes[] = { { 639, 479 }, { 640, 480 }, { 641, 481 }, - { 999, 999 } }; - SkISize expected_sizes[] = { supported_sizes[0], supported_sizes[1], + ScreenResolution client_sizes[] = { MakeResolution(639, 479), + MakeResolution(640, 480), + MakeResolution(641, 481), + MakeResolution(999, 999) }; + ScreenResolution expected_sizes[] = { supported_sizes[0], supported_sizes[1], supported_sizes[1], supported_sizes[1] }; VerifySizes(client_sizes, expected_sizes, arraysize(client_sizes)); } @@ -168,14 +185,17 @@ TEST_F(ResizingHostObserverTest, SelectBestSmallerSize) { // Check that if the implementation supports only sizes that are larger than // the requested size, then the one that requires the least down-scaling. TEST_F(ResizingHostObserverTest, SelectBestScaleFactor) { - SkISize supported_sizes[] = { { 100, 100 }, { 200, 100 } }; + ScreenResolution supported_sizes[] = { MakeResolution(100, 100), + MakeResolution(200, 100) }; scoped_ptr<FakeDesktopResizer> desktop_resizer( - new FakeDesktopResizer(SkISize::Make(200, 100), false, + new FakeDesktopResizer(MakeResolution(200, 100), false, supported_sizes, arraysize(supported_sizes))); SetDesktopResizer(desktop_resizer.Pass()); - SkISize client_sizes[] = { { 1, 1 }, { 99, 99 }, { 199, 99 } }; - SkISize expected_sizes[] = { supported_sizes[0], supported_sizes[0], + ScreenResolution client_sizes[] = { MakeResolution(1, 1), + MakeResolution(99, 99), + MakeResolution(199, 99) }; + ScreenResolution expected_sizes[] = { supported_sizes[0], supported_sizes[0], supported_sizes[1] }; VerifySizes(client_sizes, expected_sizes, arraysize(client_sizes)); } @@ -183,15 +203,19 @@ TEST_F(ResizingHostObserverTest, SelectBestScaleFactor) { // Check that if the implementation supports two sizes that have the same // resultant scale factor, then the widest one is selected. TEST_F(ResizingHostObserverTest, SelectWidest) { - SkISize supported_sizes[] = { { 640, 480 }, { 480, 640 } }; + ScreenResolution supported_sizes[] = { MakeResolution(640, 480), + MakeResolution(480, 640) }; scoped_ptr<FakeDesktopResizer> desktop_resizer( - new FakeDesktopResizer(SkISize::Make(480, 640), false, + new FakeDesktopResizer(MakeResolution(480, 640), false, supported_sizes, arraysize(supported_sizes))); SetDesktopResizer(desktop_resizer.Pass()); - SkISize client_sizes[] = { { 100, 100 }, { 480, 480 }, { 500, 500 }, - { 640, 640 }, { 1000, 1000 } }; - SkISize expected_sizes[] = { supported_sizes[0], supported_sizes[0], + ScreenResolution client_sizes[] = { MakeResolution(100, 100), + MakeResolution(480, 480), + MakeResolution(500, 500), + MakeResolution(640, 640), + MakeResolution(1000, 1000) }; + ScreenResolution expected_sizes[] = { supported_sizes[0], supported_sizes[0], supported_sizes[0], supported_sizes[0], supported_sizes[0] }; VerifySizes(client_sizes, expected_sizes, arraysize(client_sizes)); @@ -200,23 +224,28 @@ TEST_F(ResizingHostObserverTest, SelectWidest) { // Check that if the best match for the client size doesn't change, then we // don't call SetSize. TEST_F(ResizingHostObserverTest, NoSetSizeForSameSize) { - SkISize supported_sizes[] = { { 640, 480 }, { 480, 640 } }; + ScreenResolution supported_sizes[] = { MakeResolution(640, 480), + MakeResolution(480, 640) }; FakeDesktopResizer* desktop_resizer = - new FakeDesktopResizer(SkISize::Make(640, 480), false, + new FakeDesktopResizer(MakeResolution(640, 480), false, supported_sizes, arraysize(supported_sizes)); SetDesktopResizer(scoped_ptr<FakeDesktopResizer>(desktop_resizer)); - SkISize client_sizes[] = { { 640, 640 }, { 1024, 768 }, { 640, 480 } }; - SkISize expected_sizes[] = { { 640, 480 }, { 640, 480 }, { 640, 480 } }; + ScreenResolution client_sizes[] = { MakeResolution(640, 640), + MakeResolution(1024, 768), + MakeResolution(640, 480) }; + ScreenResolution expected_sizes[] = { MakeResolution(640, 480), + MakeResolution(640, 480), + MakeResolution(640, 480) }; VerifySizes(client_sizes, expected_sizes, arraysize(client_sizes)); - EXPECT_EQ(desktop_resizer->set_size_call_count(), 0); + EXPECT_EQ(desktop_resizer->set_resolution_call_count(), 0); } // Check that desktop resizes are rate-limited, and that if multiple resize // requests are received in the time-out period, the most recent is respected. TEST_F(ResizingHostObserverTest, RateLimited) { FakeDesktopResizer* desktop_resizer = - new FakeDesktopResizer(SkISize::Make(640, 480), true, NULL, 0); + new FakeDesktopResizer(MakeResolution(640, 480), true, NULL, 0); SetDesktopResizer(scoped_ptr<FakeDesktopResizer>(desktop_resizer)); resizing_host_observer_->SetNowFunctionForTesting( base::Bind(&ResizingHostObserverTest::GetTime, base::Unretained(this))); @@ -224,11 +253,14 @@ TEST_F(ResizingHostObserverTest, RateLimited) { base::MessageLoop message_loop; base::RunLoop run_loop; - EXPECT_EQ(GetBestSize(SkISize::Make(100, 100)), SkISize::Make(100, 100)); + EXPECT_EQ(GetBestResolution(MakeResolution(100, 100)), + MakeResolution(100, 100)); now_ += base::TimeDelta::FromMilliseconds(900); - EXPECT_EQ(GetBestSize(SkISize::Make(200, 200)), SkISize::Make(100, 100)); + EXPECT_EQ(GetBestResolution(MakeResolution(200, 200)), + MakeResolution(100, 100)); now_ += base::TimeDelta::FromMilliseconds(99); - EXPECT_EQ(GetBestSize(SkISize::Make(300, 300)), SkISize::Make(100, 100)); + EXPECT_EQ(GetBestResolution(MakeResolution(300, 300)), + MakeResolution(100, 100)); now_ += base::TimeDelta::FromMilliseconds(1); // Due to the kMinimumResizeIntervalMs constant in resizing_host_observer.cc, @@ -243,7 +275,7 @@ TEST_F(ResizingHostObserverTest, RateLimited) { run_loop.Run(); // If the QuitClosure fired before the final resize, it's a test failure. - EXPECT_EQ(desktop_resizer_->GetCurrentSize(), SkISize::Make(300, 300)); + EXPECT_EQ(desktop_resizer_->GetCurrentResolution(), MakeResolution(300, 300)); } } // namespace remoting diff --git a/remoting/host/screen_resolution.cc b/remoting/host/screen_resolution.cc index b792cef..ff3c477 100644 --- a/remoting/host/screen_resolution.cc +++ b/remoting/host/screen_resolution.cc @@ -43,4 +43,8 @@ bool ScreenResolution::IsEmpty() const { return dimensions_.is_empty() || dpi_.is_zero(); } +bool ScreenResolution::Equals(const ScreenResolution& other) const { + return dimensions_.equals(other.dimensions()) && dpi_.equals(other.dpi()); +} + } // namespace remoting diff --git a/remoting/host/screen_resolution.h b/remoting/host/screen_resolution.h index 81690db..8adc25e 100644 --- a/remoting/host/screen_resolution.h +++ b/remoting/host/screen_resolution.h @@ -32,6 +32,9 @@ class ScreenResolution { // IsValid() returns false. bool IsEmpty() const; + // Returns true if the dimensions and DPI of the two resolutions match. + bool Equals(const ScreenResolution& other) const; + private: webrtc::DesktopSize dimensions_; webrtc::DesktopVector dpi_; |