[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}
diff --git a/modules/desktop_capture/mac/desktop_configuration.h b/modules/desktop_capture/mac/desktop_configuration.h
index 2cf2840..736d623 100644
--- a/modules/desktop_capture/mac/desktop_configuration.h
+++ b/modules/desktop_capture/mac/desktop_configuration.h
@@ -40,6 +40,9 @@
// 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<MacDisplayConfiguration> MacDisplayConfigurations;
@@ -67,7 +70,9 @@
// 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 e631663..5962fabb 100644
--- a/modules/desktop_capture/mac/desktop_configuration.mm
+++ b/modules/desktop_capture/mac/desktop_configuration.mm
@@ -69,6 +69,9 @@
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 @@
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;
}