Skip to content

Commit f2be77e

Browse files
committed
[macOS Safari] Local and outgoing shared screen is not adjusted to the full screen when User resizes the shared window
rdar://161736839 https://bugs.webkit.org/show_bug.cgi?id=299955 Reviewed by Eric Carlson. The offsets need to be computed based on the input buffer to get proper cropping. We update ImageTransferSessionVT::setCroppingRectangle to take the intrinsic size as input to compute the proper offsets. We update ScreenCaptureKitCaptureSource call site. Manually tested. * Source/WebCore/platform/graphics/cv/ImageTransferSessionVT.h: (WebCore::ImageTransferSessionVT::setCroppingRectangle): * Source/WebCore/platform/graphics/cv/ImageTransferSessionVT.mm: (WebCore::ImageTransferSessionVT::setCroppingRectangle): * Source/WebCore/platform/mediastream/mac/ScreenCaptureKitCaptureSource.mm: (WebCore::ScreenCaptureKitCaptureSource::streamDidOutputVideoSampleBuffer): Canonical link: https://commits.webkit.org/301477@main
1 parent 38bdd51 commit f2be77e

File tree

3 files changed

+23
-12
lines changed

3 files changed

+23
-12
lines changed

Source/WebCore/platform/graphics/cv/ImageTransferSessionVT.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class ImageTransferSessionVT {
7070
void setMaximumBufferPoolSize(size_t maxBufferPoolSize) { m_maxBufferPoolSize = maxBufferPoolSize; }
7171

7272
RetainPtr<CMSampleBufferRef> convertCMSampleBuffer(CMSampleBufferRef, const IntSize&, const WTF::MediaTime* = nullptr);
73-
void setCroppingRectangle(std::optional<FloatRect>);
73+
void setCroppingRectangle(std::optional<FloatRect>, FloatSize = { });
7474

7575
private:
7676
WEBCORE_EXPORT ImageTransferSessionVT(uint32_t pixelFormat, bool shouldUseIOSurface);

Source/WebCore/platform/graphics/cv/ImageTransferSessionVT.mm

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,23 +75,34 @@
7575
m_pixelFormat = pixelFormat;
7676
}
7777

78-
void ImageTransferSessionVT::setCroppingRectangle(std::optional<FloatRect> rectangle)
78+
void ImageTransferSessionVT::setCroppingRectangle(std::optional<FloatRect> rectangle, FloatSize size)
7979
{
80-
if (m_croppingRectangle == rectangle)
80+
if (!rectangle) {
81+
m_sourceCroppingDictionary = { };
8182
return;
83+
}
8284

83-
m_croppingRectangle = rectangle;
85+
auto width = rectangle->width();
86+
auto height = rectangle->height();
87+
// Offsets are relative from center of image buffer
88+
auto horizontalOffset = rectangle->x() - size.width() / 2 + width / 2;
89+
auto verticalOffset = rectangle->y() - size.height() / 2 + height / 2;
8490

85-
if (!m_croppingRectangle) {
86-
m_sourceCroppingDictionary = { };
91+
FloatRect apertureRectangle {
92+
FloatPoint { horizontalOffset, verticalOffset },
93+
FloatSize { width, height }
94+
};
95+
96+
if (m_croppingRectangle == apertureRectangle)
8797
return;
88-
}
98+
99+
m_croppingRectangle = apertureRectangle;
89100

90101
m_sourceCroppingDictionary = @{
91-
(__bridge NSString *)kCVImageBufferCleanApertureWidthKey: @(rectangle->width()),
92-
(__bridge NSString *)kCVImageBufferCleanApertureHeightKey: @(rectangle->height()),
93-
(__bridge NSString *)kCVImageBufferCleanApertureVerticalOffsetKey: @(rectangle->x()),
94-
(__bridge NSString *)kCVImageBufferCleanApertureHorizontalOffsetKey: @(rectangle->y()),
102+
(__bridge NSString *)kCVImageBufferCleanApertureWidthKey: @(apertureRectangle.width()),
103+
(__bridge NSString *)kCVImageBufferCleanApertureHeightKey: @(apertureRectangle.height()),
104+
(__bridge NSString *)kCVImageBufferCleanApertureVerticalOffsetKey: @(apertureRectangle.y()),
105+
(__bridge NSString *)kCVImageBufferCleanApertureHorizontalOffsetKey: @(apertureRectangle.x()),
95106
};
96107
}
97108

Source/WebCore/platform/mediastream/mac/ScreenCaptureKitCaptureSource.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ - (void)outputVideoEffectDidStopForStream:(SCStream *)stream
624624
if (!m_transferSession)
625625
m_transferSession = ImageTransferSessionVT::create(preferedPixelBufferFormat());
626626

627-
m_transferSession->setCroppingRectangle(contentRect);
627+
m_transferSession->setCroppingRectangle(contentRect, intrinsicSize);
628628
if (auto newFrame = m_transferSession->convertCMSampleBuffer(m_currentFrame.get(), IntSize { contentRect.size() })) {
629629
m_currentFrame = WTFMove(newFrame);
630630
intrinsicSize = FloatSize(PAL::CMVideoFormatDescriptionGetPresentationDimensions(PAL::CMSampleBufferGetFormatDescription(m_currentFrame.get()), true, true));

0 commit comments

Comments
 (0)