Skip to content

Commit a5143eb

Browse files
authored
browser(webkit): fix the screencast scale and toolbar offset on Mac (#6474)
1 parent 5c1ddc7 commit a5143eb

File tree

2 files changed

+63
-73
lines changed

2 files changed

+63
-73
lines changed

browser_patches/webkit/BUILD_NUMBER

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
1475
2-
Changed: [email protected] Thu 06 May 2021 01:05:28 PM PDT
1+
1476
2+
Changed: [email protected] Sun May 9 11:33:51 PDT 2021

browser_patches/webkit/patches/bootstrap.diff

Lines changed: 61 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,10 +1272,10 @@ index 0000000000000000000000000000000000000000..ce69bc6a10b49460c73110e54b2936af
12721272
+}
12731273
diff --git a/Source/JavaScriptCore/inspector/protocol/Screencast.json b/Source/JavaScriptCore/inspector/protocol/Screencast.json
12741274
new file mode 100644
1275-
index 0000000000000000000000000000000000000000..b8bf514e01071898216b2c8b00210f5b6bbde440
1275+
index 0000000000000000000000000000000000000000..f6c541d63c0b8251874eaf8818aabe0e0449401d
12761276
--- /dev/null
12771277
+++ b/Source/JavaScriptCore/inspector/protocol/Screencast.json
1278-
@@ -0,0 +1,63 @@
1278+
@@ -0,0 +1,65 @@
12791279
+{
12801280
+ "domain": "Screencast",
12811281
+ "availability": ["web"],
@@ -1294,6 +1294,7 @@ index 0000000000000000000000000000000000000000..b8bf514e01071898216b2c8b00210f5b
12941294
+ { "name": "file", "type": "string", "description": "Output file location." },
12951295
+ { "name": "width", "type": "integer" },
12961296
+ { "name": "height", "type": "integer" },
1297+
+ { "name": "toolbarHeight", "type": "integer" },
12971298
+ { "name": "scale", "type": "number", "optional": true }
12981299
+ ],
12991300
+ "returns": [
@@ -1311,6 +1312,7 @@ index 0000000000000000000000000000000000000000..b8bf514e01071898216b2c8b00210f5b
13111312
+ "parameters": [
13121313
+ { "name": "width", "type": "integer" },
13131314
+ { "name": "height", "type": "integer" },
1315+
+ { "name": "toolbarHeight", "type": "integer" },
13141316
+ { "name": "quality", "type": "integer" }
13151317
+ ],
13161318
+ "returns": [
@@ -11801,10 +11803,10 @@ index 0000000000000000000000000000000000000000..4ec8b96bbbddf8a7b042f53a8068754a
1180111803
+cairo_status_t cairo_image_surface_write_to_jpeg_mem(cairo_surface_t *sfc, unsigned char **data, size_t *len, int quality);
1180211804
diff --git a/Source/WebKit/UIProcess/Inspector/Agents/InspectorScreencastAgent.cpp b/Source/WebKit/UIProcess/Inspector/Agents/InspectorScreencastAgent.cpp
1180311805
new file mode 100644
11804-
index 0000000000000000000000000000000000000000..5cacf99f0c809497b06a54f02767663b85a94e24
11806+
index 0000000000000000000000000000000000000000..46ab327b4e8d87ba9872a9bb5bb1d09e68e19d6b
1180511807
--- /dev/null
1180611808
+++ b/Source/WebKit/UIProcess/Inspector/Agents/InspectorScreencastAgent.cpp
11807-
@@ -0,0 +1,253 @@
11809+
@@ -0,0 +1,272 @@
1180811810
+/*
1180911811
+ * Copyright (C) 2020 Microsoft Corporation.
1181011812
+ *
@@ -11900,28 +11902,32 @@ index 0000000000000000000000000000000000000000..5cacf99f0c809497b06a54f02767663b
1190011902
+ if (m_screencastFramesInFlight > kMaxFramesInFlight)
1190111903
+ return;
1190211904
+ // Scale image to fit width / height
11903-
+ WebCore::IntSize size = m_page.drawingArea()->size();
11904-
+ double scale = std::min(m_screencastWidth / size.width(), m_screencastHeight / size.height());
11905-
+ cairo_matrix_t transform;
11906-
+ cairo_matrix_init_scale(&transform, scale, scale);
11907-
+
11908-
+ RefPtr<cairo_surface_t> scaledSurface = adoptRef(cairo_image_surface_create(CAIRO_FORMAT_ARGB32, ceil(size.width() * scale), ceil(size.height() * scale)));
11909-
+ RefPtr<cairo_t> cr = adoptRef(cairo_create(scaledSurface.get()));
11910-
+ cairo_transform(cr.get(), &transform);
11911-
+ cairo_set_source_surface(cr.get(), surface, 0, 0);
11912-
+ cairo_paint(cr.get());
11913-
+
11905+
+ WebCore::IntSize displaySize = m_page.drawingArea()->size();
11906+
+ double scale = std::min(m_screencastWidth / displaySize.width(), m_screencastHeight / displaySize.height());
11907+
+ RefPtr<cairo_surface_t> scaledSurface;
11908+
+ if (scale < 1) {
11909+
+ WebCore::IntSize scaledSize = displaySize;
11910+
+ scaledSize.scale(scale);
11911+
+ cairo_matrix_t transform;
11912+
+ cairo_matrix_init_scale(&transform, scale, scale);
11913+
+ scaledSurface = adoptRef(cairo_image_surface_create(CAIRO_FORMAT_ARGB32, scaledSize.width(), scaledSize.height()));
11914+
+ RefPtr<cairo_t> cr = adoptRef(cairo_create(scaledSurface.get()));
11915+
+ cairo_transform(cr.get(), &transform);
11916+
+ cairo_set_source_surface(cr.get(), surface, 0, 0);
11917+
+ cairo_paint(cr.get());
11918+
+ surface = scaledSurface.get();
11919+
+ }
1191411920
+ unsigned char *data = nullptr;
1191511921
+ size_t len = 0;
11916-
+ cairo_image_surface_write_to_jpeg_mem(scaledSurface.get(), &data, &len, m_screencastQuality);
11922+
+ cairo_image_surface_write_to_jpeg_mem(surface, &data, &len, m_screencastQuality);
1191711923
+ String result = base64Encode(data, len);
1191811924
+ ++m_screencastFramesInFlight;
11919-
+ m_frontendDispatcher->screencastFrame(result, size.width(), size.height());
11925+
+ m_frontendDispatcher->screencastFrame(result, displaySize.width(), displaySize.height());
1192011926
+ }
1192111927
+}
1192211928
+#endif
1192311929
+
11924-
+Inspector::Protocol::ErrorStringOr<String /* screencastID */> InspectorScreencastAgent::startVideo(const String& file, int width, int height, Optional<double>&& scale)
11930+
+Inspector::Protocol::ErrorStringOr<String /* screencastID */> InspectorScreencastAgent::startVideo(const String& file, int width, int height, int toolbarHeight, Optional<double>&& scale)
1192511931
+{
1192611932
+ if (m_encoder)
1192711933
+ return makeUnexpected("Already recording"_s);
@@ -11940,7 +11946,7 @@ index 0000000000000000000000000000000000000000..5cacf99f0c809497b06a54f02767663b
1194011946
+ m_currentScreencastID = createCanonicalUUIDString();
1194111947
+
1194211948
+#if PLATFORM(MAC)
11943-
+ m_encoder->setOffsetTop(m_page.pageClient().browserToolbarHeight());
11949+
+ m_encoder->setOffsetTop(toolbarHeight);
1194411950
+#endif
1194511951
+
1194611952
+ kickFramesStarted();
@@ -11965,14 +11971,15 @@ index 0000000000000000000000000000000000000000..5cacf99f0c809497b06a54f02767663b
1196511971
+ m_framesAreGoing = false;
1196611972
+}
1196711973
+
11968-
+Inspector::Protocol::ErrorStringOr<int /* generation */> InspectorScreencastAgent::startScreencast(int width, int height, int quality)
11974+
+Inspector::Protocol::ErrorStringOr<int /* generation */> InspectorScreencastAgent::startScreencast(int width, int height, int toolbarHeight, int quality)
1196911975
+{
1197011976
+ if (m_screencast)
1197111977
+ return makeUnexpected("Already screencasting"_s);
1197211978
+ m_screencast = true;
1197311979
+ m_screencastWidth = width;
1197411980
+ m_screencastHeight = height;
1197511981
+ m_screencastQuality = quality;
11982+
+ m_screencastToolbarHeight = toolbarHeight;
1197611983
+ m_screencastFramesInFlight = 0;
1197711984
+ ++m_screencastGeneration;
1197811985
+ kickFramesStarted();
@@ -12031,15 +12038,29 @@ index 0000000000000000000000000000000000000000..5cacf99f0c809497b06a54f02767663b
1203112038
+ return;
1203212039
+ RetainPtr<CGImageRef> imageRef = m_page.pageClient().takeSnapshotForAutomation();
1203312040
+ if (m_screencast && m_screencastFramesInFlight <= kMaxFramesInFlight) {
12041+
+ CGImage* imagePtr = imageRef.get();
12042+
+ WebCore::IntSize imageSize(CGImageGetWidth(imagePtr), CGImageGetHeight(imagePtr));
12043+
+ WebCore::IntSize displaySize = imageSize;
12044+
+ displaySize.contract(0, m_screencastToolbarHeight);
12045+
+ double scale = std::min(m_screencastWidth / displaySize.width(), m_screencastHeight / displaySize.height());
12046+
+ RetainPtr<CGImageRef> scaledImageRef;
12047+
+ if (scale < 1 || m_screencastToolbarHeight) {
12048+
+ WebCore::IntSize screencastSize = displaySize;
12049+
+ screencastSize.scale(scale);
12050+
+ WebCore::IntSize scaledImageSize = imageSize;
12051+
+ scaledImageSize.scale(scale);
12052+
+ auto colorSpace = adoptCF(CGColorSpaceCreateDeviceRGB());
12053+
+ auto context = adoptCF(CGBitmapContextCreate(nullptr, screencastSize.width(), screencastSize.height(), 8, 4 * screencastSize.width(), colorSpace.get(), kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host));
12054+
+ CGContextDrawImage(context.get(), CGRectMake(0, 0, scaledImageSize.width(), scaledImageSize.height()), imagePtr);
12055+
+ scaledImageRef = adoptCF(CGBitmapContextCreateImage(context.get()));
12056+
+ imagePtr = scaledImageRef.get();
12057+
+ }
1203412058
+ auto cfData = adoptCF(CFDataCreateMutable(kCFAllocatorDefault, 0));
12035-
+ WebCore::encodeImage(imageRef.get(), CFSTR("public.jpeg"), m_screencastQuality * 0.1, cfData.get());
12059+
+ WebCore::encodeImage(imagePtr, CFSTR("public.jpeg"), m_screencastQuality * 0.1, cfData.get());
1203612060
+ Vector<char> base64Data;
1203712061
+ base64Encode(CFDataGetBytePtr(cfData.get()), CFDataGetLength(cfData.get()), base64Data);
1203812062
+ ++m_screencastFramesInFlight;
12039-
+ m_frontendDispatcher->screencastFrame(
12040-
+ String(base64Data.data(), base64Data.size()),
12041-
+ CGImageGetWidth(imageRef.get()),
12042-
+ CGImageGetHeight(imageRef.get()));
12063+
+ m_frontendDispatcher->screencastFrame(String(base64Data.data(), base64Data.size()), displaySize.width(), displaySize.height());
1204312064
+ }
1204412065
+ if (m_encoder)
1204512066
+ m_encoder->encodeFrame(WTFMove(imageRef));
@@ -12060,10 +12081,10 @@ index 0000000000000000000000000000000000000000..5cacf99f0c809497b06a54f02767663b
1206012081
+} // namespace WebKit
1206112082
diff --git a/Source/WebKit/UIProcess/Inspector/Agents/InspectorScreencastAgent.h b/Source/WebKit/UIProcess/Inspector/Agents/InspectorScreencastAgent.h
1206212083
new file mode 100644
12063-
index 0000000000000000000000000000000000000000..759ea406372f734dec37955becb5ec7499645198
12084+
index 0000000000000000000000000000000000000000..85084cced95b8b3c58e08f01f286c42e986b7c1a
1206412085
--- /dev/null
1206512086
+++ b/Source/WebKit/UIProcess/Inspector/Agents/InspectorScreencastAgent.h
12066-
@@ -0,0 +1,95 @@
12087+
@@ -0,0 +1,96 @@
1206712088
+/*
1206812089
+ * Copyright (C) 2020 Microsoft Corporation.
1206912090
+ *
@@ -12129,10 +12150,10 @@ index 0000000000000000000000000000000000000000..759ea406372f734dec37955becb5ec74
1212912150
+ void didPaint(cairo_surface_t*);
1213012151
+#endif
1213112152
+
12132-
+ Inspector::Protocol::ErrorStringOr<String /* screencastID */> startVideo(const String& file, int width, int height, Optional<double>&& scale) override;
12153+
+ Inspector::Protocol::ErrorStringOr<String /* screencastID */> startVideo(const String& file, int width, int height, int toolbarHeight, Optional<double>&& scale) override;
1213312154
+ void stopVideo(Ref<StopVideoCallback>&&) override;
1213412155
+
12135-
+ Inspector::Protocol::ErrorStringOr<int /* generation */> startScreencast(int width, int height, int quality) override;
12156+
+ Inspector::Protocol::ErrorStringOr<int /* generation */> startScreencast(int width, int height, int toolbarHeight, int quality) override;
1213612157
+ Inspector::Protocol::ErrorStringOr<void> screencastFrameAck(int generation) override;
1213712158
+ Inspector::Protocol::ErrorStringOr<void> stopScreencast() override;
1213812159
+
@@ -12153,6 +12174,7 @@ index 0000000000000000000000000000000000000000..759ea406372f734dec37955becb5ec74
1215312174
+ double m_screencastWidth = 0;
1215412175
+ double m_screencastHeight = 0;
1215512176
+ int m_screencastQuality = 0;
12177+
+ int m_screencastToolbarHeight = 0;
1215612178
+ int m_screencastGeneration = 0;
1215712179
+ int m_screencastFramesInFlight = 0;
1215812180
+ String m_currentScreencastID;
@@ -14683,7 +14705,7 @@ index 7a14cfba15c103a2d4fe263fa49d25af3c396ec2..3ee0e154349661632799057c71f1d1f1
1468314705
BOOL result = ::CreateProcess(0, commandLine.data(), 0, 0, true, 0, 0, 0, &startupInfo, &processInformation);
1468414706

1468514707
diff --git a/Source/WebKit/UIProcess/PageClient.h b/Source/WebKit/UIProcess/PageClient.h
14686-
index 70c6bb6d64b25fce9f231fbce708c0515fb73789..f60b57b1e844716cc748b290f9ff73457b020a4f 100644
14708+
index 70c6bb6d64b25fce9f231fbce708c0515fb73789..6b970003b28722d9eee029c070b36f31d5377b9f 100644
1468714709
--- a/Source/WebKit/UIProcess/PageClient.h
1468814710
+++ b/Source/WebKit/UIProcess/PageClient.h
1468914711
@@ -312,6 +312,11 @@ public:
@@ -14698,14 +14720,6 @@ index 70c6bb6d64b25fce9f231fbce708c0515fb73789..f60b57b1e844716cc748b290f9ff7345
1469814720
#if PLATFORM(COCOA) || PLATFORM(GTK)
1469914721
virtual RefPtr<ViewSnapshot> takeViewSnapshot(Optional<WebCore::IntRect>&&) = 0;
1470014722
#endif
14701-
@@ -328,6 +333,7 @@ public:
14702-
virtual WebCore::IntRect rootViewToAccessibilityScreen(const WebCore::IntRect&) = 0;
14703-
#if PLATFORM(MAC)
14704-
virtual WebCore::IntRect rootViewToWindow(const WebCore::IntRect&) = 0;
14705-
+ virtual int browserToolbarHeight() const { return 0; }
14706-
#endif
14707-
#if PLATFORM(IOS_FAMILY)
14708-
virtual void didNotHandleTapAsClick(const WebCore::IntPoint&) = 0;
1470914723
diff --git a/Source/WebKit/UIProcess/ProvisionalPageProxy.cpp b/Source/WebKit/UIProcess/ProvisionalPageProxy.cpp
1471014724
index 226d2933405ea5b6f0bc369e51fd07862e37af76..7796abccb6b80baccf826a24fe4f45a4a56bb9d6 100644
1471114725
--- a/Source/WebKit/UIProcess/ProvisionalPageProxy.cpp
@@ -17319,7 +17333,7 @@ index 0000000000000000000000000000000000000000..721826c8c98fc85b68a4f45deaee69c1
1731917333
+
1732017334
+#endif
1732117335
diff --git a/Source/WebKit/UIProcess/mac/PageClientImplMac.h b/Source/WebKit/UIProcess/mac/PageClientImplMac.h
17322-
index c58ad478af24f439872c514b17b370601e4e1c93..95dd9423528177d12f16d9975947061d807207b3 100644
17336+
index c58ad478af24f439872c514b17b370601e4e1c93..09f173efa30f7a3489b22a11e0292ba157f73c68 100644
1732317337
--- a/Source/WebKit/UIProcess/mac/PageClientImplMac.h
1732417338
+++ b/Source/WebKit/UIProcess/mac/PageClientImplMac.h
1732517339
@@ -53,6 +53,8 @@ class PageClientImpl final : public PageClientImplCocoa
@@ -17331,15 +17345,7 @@ index c58ad478af24f439872c514b17b370601e4e1c93..95dd9423528177d12f16d9975947061d
1733117345
PageClientImpl(NSView *, WKWebView *);
1733217346
virtual ~PageClientImpl();
1733317347

17334-
@@ -119,6 +121,7 @@ private:
17335-
WebCore::IntRect rootViewToScreen(const WebCore::IntRect&) override;
17336-
#if PLATFORM(MAC)
17337-
WebCore::IntRect rootViewToWindow(const WebCore::IntRect&) override;
17338-
+ int browserToolbarHeight() const override;
17339-
#endif
17340-
WebCore::IntPoint accessibilityScreenToRootView(const WebCore::IntPoint&) override;
17341-
WebCore::IntRect rootViewToAccessibilityScreen(const WebCore::IntRect&) override;
17342-
@@ -165,6 +168,9 @@ private:
17348+
@@ -165,6 +167,9 @@ private:
1734317349
void updateAcceleratedCompositingMode(const LayerTreeContext&) override;
1734417350
void didFirstLayerFlush(const LayerTreeContext&) override;
1734517351

@@ -17349,7 +17355,7 @@ index c58ad478af24f439872c514b17b370601e4e1c93..95dd9423528177d12f16d9975947061d
1734917355
RefPtr<ViewSnapshot> takeViewSnapshot(Optional<WebCore::IntRect>&&) override;
1735017356
void wheelEventWasNotHandledByWebCore(const NativeWebWheelEvent&) override;
1735117357
#if ENABLE(MAC_GESTURE_EVENTS)
17352-
@@ -219,6 +225,10 @@ private:
17358+
@@ -219,6 +224,10 @@ private:
1735317359
void beganExitFullScreen(const WebCore::IntRect& initialFrame, const WebCore::IntRect& finalFrame) override;
1735417360
#endif
1735517361

@@ -17361,7 +17367,7 @@ index c58ad478af24f439872c514b17b370601e4e1c93..95dd9423528177d12f16d9975947061d
1736117367
void navigationGestureWillEnd(bool willNavigate, WebBackForwardListItem&) override;
1736217368
void navigationGestureDidEnd(bool willNavigate, WebBackForwardListItem&) override;
1736317369
diff --git a/Source/WebKit/UIProcess/mac/PageClientImplMac.mm b/Source/WebKit/UIProcess/mac/PageClientImplMac.mm
17364-
index 67dfe20726b9d6b7e0173801da7b8bae3a87ee28..cfd251d192c0ba17d99fabb533d4b5abe4eb3a18 100644
17370+
index 67dfe20726b9d6b7e0173801da7b8bae3a87ee28..8a21a3b5c9834d2cc4d9726b7b862758976542a2 100644
1736517371
--- a/Source/WebKit/UIProcess/mac/PageClientImplMac.mm
1736617372
+++ b/Source/WebKit/UIProcess/mac/PageClientImplMac.mm
1736717373
@@ -81,6 +81,7 @@
@@ -17426,23 +17432,7 @@ index 67dfe20726b9d6b7e0173801da7b8bae3a87ee28..cfd251d192c0ba17d99fabb533d4b5ab
1742617432
}
1742717433

1742817434
void PageClientImpl::toolTipChanged(const String& oldToolTip, const String& newToolTip)
17429-
@@ -466,6 +484,15 @@ IntRect PageClientImpl::rootViewToWindow(const WebCore::IntRect& rect)
17430-
return enclosingIntRect(tempRect);
17431-
}
17432-
17433-
+int PageClientImpl::browserToolbarHeight() const
17434-
+{
17435-
+ // There are no controls in headless mode.
17436-
+ if (_headless)
17437-
+ return 0;
17438-
+
17439-
+ return 55;
17440-
+}
17441-
+
17442-
IntPoint PageClientImpl::accessibilityScreenToRootView(const IntPoint& point)
17443-
{
17444-
return screenToRootView(point);
17445-
@@ -478,6 +505,8 @@ IntRect PageClientImpl::rootViewToAccessibilityScreen(const IntRect& rect)
17435+
@@ -478,6 +496,8 @@ IntRect PageClientImpl::rootViewToAccessibilityScreen(const IntRect& rect)
1744617436

1744717437
void PageClientImpl::doneWithKeyEvent(const NativeWebKeyboardEvent& event, bool eventWasHandled)
1744817438
{
@@ -17451,7 +17441,7 @@ index 67dfe20726b9d6b7e0173801da7b8bae3a87ee28..cfd251d192c0ba17d99fabb533d4b5ab
1745117441
m_impl->doneWithKeyEvent(event.nativeEvent(), eventWasHandled);
1745217442
}
1745317443

17454-
@@ -497,6 +526,8 @@ void PageClientImpl::computeCanRevealImage(const URL& imageURL, ShareableBitmap&
17444+
@@ -497,6 +517,8 @@ void PageClientImpl::computeCanRevealImage(const URL& imageURL, ShareableBitmap&
1745517445

1745617446
RefPtr<WebPopupMenuProxy> PageClientImpl::createPopupMenuProxy(WebPageProxy& page)
1745717447
{
@@ -17460,7 +17450,7 @@ index 67dfe20726b9d6b7e0173801da7b8bae3a87ee28..cfd251d192c0ba17d99fabb533d4b5ab
1746017450
return WebPopupMenuProxyMac::create(m_view, page);
1746117451
}
1746217452

17463-
@@ -628,6 +659,12 @@ CALayer *PageClientImpl::acceleratedCompositingRootLayer() const
17453+
@@ -628,6 +650,12 @@ CALayer *PageClientImpl::acceleratedCompositingRootLayer() const
1746417454
return m_impl->acceleratedCompositingRootLayer();
1746517455
}
1746617456

@@ -17473,7 +17463,7 @@ index 67dfe20726b9d6b7e0173801da7b8bae3a87ee28..cfd251d192c0ba17d99fabb533d4b5ab
1747317463
RefPtr<ViewSnapshot> PageClientImpl::takeViewSnapshot(Optional<WebCore::IntRect>&&)
1747417464
{
1747517465
return m_impl->takeViewSnapshot();
17476-
@@ -806,6 +843,13 @@ void PageClientImpl::beganExitFullScreen(const IntRect& initialFrame, const IntR
17466+
@@ -806,6 +834,13 @@ void PageClientImpl::beganExitFullScreen(const IntRect& initialFrame, const IntR
1747717467

1747817468
#endif // ENABLE(FULLSCREEN_API)
1747917469

@@ -17487,7 +17477,7 @@ index 67dfe20726b9d6b7e0173801da7b8bae3a87ee28..cfd251d192c0ba17d99fabb533d4b5ab
1748717477
void PageClientImpl::navigationGestureDidBegin()
1748817478
{
1748917479
m_impl->dismissContentRelativeChildWindowsWithAnimation(true);
17490-
@@ -972,6 +1016,9 @@ void PageClientImpl::didRestoreScrollPosition()
17480+
@@ -972,6 +1007,9 @@ void PageClientImpl::didRestoreScrollPosition()
1749117481

1749217482
bool PageClientImpl::windowIsFrontWindowUnderMouse(const NativeWebMouseEvent& event)
1749317483
{

0 commit comments

Comments
 (0)