From 11c1e70384acbf39a453536859af6d116f8bd5ff Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Tue, 25 Mar 2025 09:08:21 -0500 Subject: [PATCH] perf: don't wait for thumbnails if they were not requested on macOS (#46249) When using the SCK thumbnail capturer, the first refresh has the list of sources, and the second refresh has the thumbnails. If thumbnails are not needed, only wait for the first refresh. Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: John Beutner --- .../browser/api/electron_api_desktop_capturer.cc | 10 ++++++---- spec/api-desktop-capturer-spec.ts | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/shell/browser/api/electron_api_desktop_capturer.cc b/shell/browser/api/electron_api_desktop_capturer.cc index 1fcb7fbaa54c..d0b3f40b5dcc 100644 --- a/shell/browser/api/electron_api_desktop_capturer.cc +++ b/shell/browser/api/electron_api_desktop_capturer.cc @@ -328,8 +328,9 @@ void DesktopCapturer::StartHandling(bool capture_window, window_capturer_->SetThumbnailSize(thumbnail_size); #if BUILDFLAG(IS_MAC) window_capturer_->skip_next_refresh_ = - ShouldUseThumbnailCapturerMac(DesktopMediaList::Type::kWindow) ? 2 - : 0; + ShouldUseThumbnailCapturerMac(DesktopMediaList::Type::kWindow) + ? thumbnail_size.IsEmpty() ? 1 : 2 + : 0; #endif OnceCallback update_callback = base::BindOnce( @@ -358,8 +359,9 @@ void DesktopCapturer::StartHandling(bool capture_window, screen_capturer_->SetThumbnailSize(thumbnail_size); #if BUILDFLAG(IS_MAC) screen_capturer_->skip_next_refresh_ = - ShouldUseThumbnailCapturerMac(DesktopMediaList::Type::kScreen) ? 2 - : 0; + ShouldUseThumbnailCapturerMac(DesktopMediaList::Type::kScreen) + ? thumbnail_size.IsEmpty() ? 1 : 2 + : 0; #endif OnceCallback update_callback = base::BindOnce( diff --git a/spec/api-desktop-capturer-spec.ts b/spec/api-desktop-capturer-spec.ts index 5bb4943183b1..a3ff4df4a388 100644 --- a/spec/api-desktop-capturer-spec.ts +++ b/spec/api-desktop-capturer-spec.ts @@ -67,6 +67,22 @@ ifdescribe(!process.arch.includes('arm') && process.platform !== 'win32')('deskt } }); + it('enabling thumbnail should return non-empty images', async () => { + const w2 = new BrowserWindow({ show: false, width: 200, height: 200, webPreferences: { contextIsolation: false } }); + const wShown = once(w2, 'show'); + w2.show(); + await wShown; + + const isNonEmpties: boolean[] = (await desktopCapturer.getSources({ + types: ['window', 'screen'], + thumbnailSize: { width: 100, height: 100 } + })).map(s => s.thumbnail.constructor.name === 'NativeImage' && !s.thumbnail.isEmpty()); + + w2.destroy(); + expect(isNonEmpties).to.be.an('array').that.is.not.empty(); + expect(isNonEmpties.every(e => e === true)).to.be.true(); + }); + it('disabling thumbnail should return empty images', async () => { const w2 = new BrowserWindow({ show: false, width: 200, height: 200, webPreferences: { contextIsolation: false } }); const wShown = once(w2, 'show');