From 4105c1de7b67f290dd81382c835065013a82a64f Mon Sep 17 00:00:00 2001 From: Andrey Belonogov Date: Fri, 24 Apr 2026 16:41:35 -0700 Subject: [PATCH] use only one flush and and only in case of existing masks --- .../ScreenCapture/ImageCaptureService.swift | 7 +++++-- TestApp/Sources/MainMenuView.swift | 4 +++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Sources/LaunchDarklySessionReplay/ScreenCapture/ImageCaptureService.swift b/Sources/LaunchDarklySessionReplay/ScreenCapture/ImageCaptureService.swift index f0befa3..8a38cee 100644 --- a/Sources/LaunchDarklySessionReplay/ScreenCapture/ImageCaptureService.swift +++ b/Sources/LaunchDarklySessionReplay/ScreenCapture/ImageCaptureService.swift @@ -53,7 +53,6 @@ public final class ImageCaptureService { let enclosingBounds = windowCaptureManager.minimalBoundsEnclosingWindows(windows) let renderer = windowCaptureManager.makeRenderer(size: enclosingBounds.size, scale: scale) - CATransaction.flush() let maskOperationsBefore = windows.map { maskCollector.collectViewMasks(in: $0, window: $0, scale: scale) } let image = renderer.image { ctx in windowCaptureManager.drawWindows(windows, into: ctx.cgContext, bounds: enclosingBounds, afterScreenUpdates: false) @@ -63,8 +62,12 @@ public final class ImageCaptureService { DispatchQueue.main.async { [weak self, weak maskCollector] in // Move collecting masks after to the next tick guard let self, let maskCollector, shouldCapture else { return } + + let hasMasks = maskOperationsBefore.contains(where: { !$0.maskOperations.isEmpty }) + if (hasMasks) { + CATransaction.flush() + } - CATransaction.flush() let maskOperationsAfter = windows.map { maskCollector.collectViewMasks(in: $0, window: $0, scale: self.scale) } Task { diff --git a/TestApp/Sources/MainMenuView.swift b/TestApp/Sources/MainMenuView.swift index 0d5b0f0..db21d8f 100644 --- a/TestApp/Sources/MainMenuView.swift +++ b/TestApp/Sources/MainMenuView.swift @@ -107,7 +107,8 @@ struct MainMenuView: View { Section { MaskingGridRow(title: "One TextField", uikitAction: { isMaskingUIKitOneFieldEnabled = true - }, swiftUIAction: nil) + }, swiftUIAction: nil).ldMask() + #if os(iOS) MaskingGridRow(title: "Credit Card", uikitAction: { isMaskingUIKitCreditCardEnabled = true @@ -133,6 +134,7 @@ struct MainMenuView: View { isNotebookEnabled = true } .buttonStyle(.borderedProminent) + Button("Storyboard") { isStoryboardEnabled = true }