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; }