From ad7f6e5ccf77d8e66da46572f89c49b513ba9774 Mon Sep 17 00:00:00 2001 From: braveyao Date: Thu, 26 Apr 2018 14:39:36 -0700 Subject: [PATCH] [desktopCapture Mac] Continue screen capture at graphic cards switching The MBP having both discrete and integrated graphic cards will do automate graphics switching by default. When it switches from discrete to integrated one, the current display ID of the built-in display will change and this will cause screen capture stops. So make screen capture of built-in display continuing even if its display ID is changed. Bug: chromium:836979 Change-Id: If4f2d04d99a2690ccd6f894d94e6f8ff58ba2ec8 Reviewed-on: https://webrtc-review.googlesource.com/72603 Reviewed-by: Jamie Walch Commit-Queue: Brave Yao Cr-Commit-Position: refs/heads/master@{#23048} --- .../desktop_capture/mac/desktop_configuration.h | 7 ++++++- .../desktop_capture/mac/desktop_configuration.mm | 14 +++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/modules/desktop_capture/mac/desktop_configuration.h b/modules/desktop_capture/mac/desktop_configuration.h index 2cf28406fa..736d623685 100644 --- a/modules/desktop_capture/mac/desktop_configuration.h +++ b/modules/desktop_capture/mac/desktop_configuration.h @@ -40,6 +40,9 @@ struct MacDisplayConfiguration { // Scale factor from DIPs to physical pixels. float dip_to_pixel_scale = 1.0f; + + // Display type, built-in or external. + bool is_builtin; }; typedef std::vector MacDisplayConfigurations; @@ -67,7 +70,9 @@ struct MacDesktopConfiguration { // Returns true if the given desktop configuration equals this one. bool Equals(const MacDesktopConfiguration& other); - // Returns the pointer to the display configuration with the specified id. + // If |id| corresponds to the built-in display, return its configuration, + // otherwise return the configuration for the display with the specified id, + // or nullptr if no such display exists. const MacDisplayConfiguration* FindDisplayConfigurationById( CGDirectDisplayID id); diff --git a/modules/desktop_capture/mac/desktop_configuration.mm b/modules/desktop_capture/mac/desktop_configuration.mm index e6316632c5..5962fabb70 100644 --- a/modules/desktop_capture/mac/desktop_configuration.mm +++ b/modules/desktop_capture/mac/desktop_configuration.mm @@ -69,6 +69,9 @@ MacDisplayConfiguration GetConfigurationForScreen(NSScreen* screen) { display_config.pixel_bounds = display_config.bounds; } + // Determine if the display is built-in or external. + display_config.is_builtin = CGDisplayIsBuiltin(display_config.id); + return display_config; } @@ -164,14 +167,19 @@ bool MacDesktopConfiguration::Equals(const MacDesktopConfiguration& other) { displays == other.displays; } -// Finds the display configuration with the specified id. const MacDisplayConfiguration* MacDesktopConfiguration::FindDisplayConfigurationById( CGDirectDisplayID id) { + bool is_builtin = CGDisplayIsBuiltin(id); for (MacDisplayConfigurations::const_iterator it = displays.begin(); it != displays.end(); ++it) { - if (it->id == id) - return &(*it); + // The MBP having both discrete and integrated graphic cards will do + // automate graphics switching by default. When it switches from discrete to + // integrated one, the current display ID of the built-in display will + // change and this will cause screen capture stops. + // So make screen capture of built-in display continuing even if its display + // ID is changed. + if ((is_builtin && it->is_builtin) || (!is_builtin && it->id == id)) return &(*it); } return NULL; }