[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 <jamiewalch@chromium.org>
Commit-Queue: Brave Yao <braveyao@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23048}
This commit is contained in:
braveyao 2018-04-26 14:39:36 -07:00 committed by Commit Bot
parent 65e9439f38
commit ad7f6e5ccf
2 changed files with 17 additions and 4 deletions

View file

@ -40,6 +40,9 @@ struct MacDisplayConfiguration {
// Scale factor from DIPs to physical pixels. // Scale factor from DIPs to physical pixels.
float dip_to_pixel_scale = 1.0f; float dip_to_pixel_scale = 1.0f;
// Display type, built-in or external.
bool is_builtin;
}; };
typedef std::vector<MacDisplayConfiguration> MacDisplayConfigurations; typedef std::vector<MacDisplayConfiguration> MacDisplayConfigurations;
@ -67,7 +70,9 @@ struct MacDesktopConfiguration {
// Returns true if the given desktop configuration equals this one. // Returns true if the given desktop configuration equals this one.
bool Equals(const MacDesktopConfiguration& other); 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( const MacDisplayConfiguration* FindDisplayConfigurationById(
CGDirectDisplayID id); CGDirectDisplayID id);

View file

@ -69,6 +69,9 @@ MacDisplayConfiguration GetConfigurationForScreen(NSScreen* screen) {
display_config.pixel_bounds = display_config.bounds; 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; return display_config;
} }
@ -164,14 +167,19 @@ bool MacDesktopConfiguration::Equals(const MacDesktopConfiguration& other) {
displays == other.displays; displays == other.displays;
} }
// Finds the display configuration with the specified id.
const MacDisplayConfiguration* const MacDisplayConfiguration*
MacDesktopConfiguration::FindDisplayConfigurationById( MacDesktopConfiguration::FindDisplayConfigurationById(
CGDirectDisplayID id) { CGDirectDisplayID id) {
bool is_builtin = CGDisplayIsBuiltin(id);
for (MacDisplayConfigurations::const_iterator it = displays.begin(); for (MacDisplayConfigurations::const_iterator it = displays.begin();
it != displays.end(); ++it) { it != displays.end(); ++it) {
if (it->id == id) // The MBP having both discrete and integrated graphic cards will do
return &(*it); // 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; return NULL;
} }