@@ -1272,10 +1272,10 @@ index 0000000000000000000000000000000000000000..ce69bc6a10b49460c73110e54b2936af
1272
1272
+}
1273
1273
diff --git a/Source/JavaScriptCore/inspector/protocol/Screencast.json b/Source/JavaScriptCore/inspector/protocol/Screencast.json
1274
1274
new file mode 100644
1275
- index 0000000000000000000000000000000000000000..b8bf514e01071898216b2c8b00210f5b6bbde440
1275
+ index 0000000000000000000000000000000000000000..f6c541d63c0b8251874eaf8818aabe0e0449401d
1276
1276
--- /dev/null
1277
1277
+++ b/Source/JavaScriptCore/inspector/protocol/Screencast.json
1278
- @@ -0,0 +1,63 @@
1278
+ @@ -0,0 +1,65 @@
1279
1279
+{
1280
1280
+ "domain": "Screencast",
1281
1281
+ "availability": ["web"],
@@ -1294,6 +1294,7 @@ index 0000000000000000000000000000000000000000..b8bf514e01071898216b2c8b00210f5b
1294
1294
+ { "name": "file", "type": "string", "description": "Output file location." },
1295
1295
+ { "name": "width", "type": "integer" },
1296
1296
+ { "name": "height", "type": "integer" },
1297
+ + { "name": "toolbarHeight", "type": "integer" },
1297
1298
+ { "name": "scale", "type": "number", "optional": true }
1298
1299
+ ],
1299
1300
+ "returns": [
@@ -1311,6 +1312,7 @@ index 0000000000000000000000000000000000000000..b8bf514e01071898216b2c8b00210f5b
1311
1312
+ "parameters": [
1312
1313
+ { "name": "width", "type": "integer" },
1313
1314
+ { "name": "height", "type": "integer" },
1315
+ + { "name": "toolbarHeight", "type": "integer" },
1314
1316
+ { "name": "quality", "type": "integer" }
1315
1317
+ ],
1316
1318
+ "returns": [
@@ -11801,10 +11803,10 @@ index 0000000000000000000000000000000000000000..4ec8b96bbbddf8a7b042f53a8068754a
11801
11803
+cairo_status_t cairo_image_surface_write_to_jpeg_mem(cairo_surface_t *sfc, unsigned char **data, size_t *len, int quality);
11802
11804
diff --git a/Source/WebKit/UIProcess/Inspector/Agents/InspectorScreencastAgent.cpp b/Source/WebKit/UIProcess/Inspector/Agents/InspectorScreencastAgent.cpp
11803
11805
new file mode 100644
11804
- index 0000000000000000000000000000000000000000..5cacf99f0c809497b06a54f02767663b85a94e24
11806
+ index 0000000000000000000000000000000000000000..46ab327b4e8d87ba9872a9bb5bb1d09e68e19d6b
11805
11807
--- /dev/null
11806
11808
+++ b/Source/WebKit/UIProcess/Inspector/Agents/InspectorScreencastAgent.cpp
11807
- @@ -0,0 +1,253 @@
11809
+ @@ -0,0 +1,272 @@
11808
11810
+/*
11809
11811
+ * Copyright (C) 2020 Microsoft Corporation.
11810
11812
+ *
@@ -11900,28 +11902,32 @@ index 0000000000000000000000000000000000000000..5cacf99f0c809497b06a54f02767663b
11900
11902
+ if (m_screencastFramesInFlight > kMaxFramesInFlight)
11901
11903
+ return;
11902
11904
+ // 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
+ + }
11914
11920
+ unsigned char *data = nullptr;
11915
11921
+ 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);
11917
11923
+ String result = base64Encode(data, len);
11918
11924
+ ++m_screencastFramesInFlight;
11919
- + m_frontendDispatcher->screencastFrame(result, size .width(), size .height());
11925
+ + m_frontendDispatcher->screencastFrame(result, displaySize .width(), displaySize .height());
11920
11926
+ }
11921
11927
+}
11922
11928
+#endif
11923
11929
+
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)
11925
11931
+{
11926
11932
+ if (m_encoder)
11927
11933
+ return makeUnexpected("Already recording"_s);
@@ -11940,7 +11946,7 @@ index 0000000000000000000000000000000000000000..5cacf99f0c809497b06a54f02767663b
11940
11946
+ m_currentScreencastID = createCanonicalUUIDString();
11941
11947
+
11942
11948
+#if PLATFORM(MAC)
11943
- + m_encoder->setOffsetTop(m_page.pageClient().browserToolbarHeight() );
11949
+ + m_encoder->setOffsetTop(toolbarHeight );
11944
11950
+#endif
11945
11951
+
11946
11952
+ kickFramesStarted();
@@ -11965,14 +11971,15 @@ index 0000000000000000000000000000000000000000..5cacf99f0c809497b06a54f02767663b
11965
11971
+ m_framesAreGoing = false;
11966
11972
+}
11967
11973
+
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)
11969
11975
+{
11970
11976
+ if (m_screencast)
11971
11977
+ return makeUnexpected("Already screencasting"_s);
11972
11978
+ m_screencast = true;
11973
11979
+ m_screencastWidth = width;
11974
11980
+ m_screencastHeight = height;
11975
11981
+ m_screencastQuality = quality;
11982
+ + m_screencastToolbarHeight = toolbarHeight;
11976
11983
+ m_screencastFramesInFlight = 0;
11977
11984
+ ++m_screencastGeneration;
11978
11985
+ kickFramesStarted();
@@ -12031,15 +12038,29 @@ index 0000000000000000000000000000000000000000..5cacf99f0c809497b06a54f02767663b
12031
12038
+ return;
12032
12039
+ RetainPtr<CGImageRef> imageRef = m_page.pageClient().takeSnapshotForAutomation();
12033
12040
+ 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
+ + }
12034
12058
+ 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());
12036
12060
+ Vector<char> base64Data;
12037
12061
+ base64Encode(CFDataGetBytePtr(cfData.get()), CFDataGetLength(cfData.get()), base64Data);
12038
12062
+ ++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());
12043
12064
+ }
12044
12065
+ if (m_encoder)
12045
12066
+ m_encoder->encodeFrame(WTFMove(imageRef));
@@ -12060,10 +12081,10 @@ index 0000000000000000000000000000000000000000..5cacf99f0c809497b06a54f02767663b
12060
12081
+} // namespace WebKit
12061
12082
diff --git a/Source/WebKit/UIProcess/Inspector/Agents/InspectorScreencastAgent.h b/Source/WebKit/UIProcess/Inspector/Agents/InspectorScreencastAgent.h
12062
12083
new file mode 100644
12063
- index 0000000000000000000000000000000000000000..759ea406372f734dec37955becb5ec7499645198
12084
+ index 0000000000000000000000000000000000000000..85084cced95b8b3c58e08f01f286c42e986b7c1a
12064
12085
--- /dev/null
12065
12086
+++ b/Source/WebKit/UIProcess/Inspector/Agents/InspectorScreencastAgent.h
12066
- @@ -0,0 +1,95 @@
12087
+ @@ -0,0 +1,96 @@
12067
12088
+/*
12068
12089
+ * Copyright (C) 2020 Microsoft Corporation.
12069
12090
+ *
@@ -12129,10 +12150,10 @@ index 0000000000000000000000000000000000000000..759ea406372f734dec37955becb5ec74
12129
12150
+ void didPaint(cairo_surface_t*);
12130
12151
+#endif
12131
12152
+
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;
12133
12154
+ void stopVideo(Ref<StopVideoCallback>&&) override;
12134
12155
+
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;
12136
12157
+ Inspector::Protocol::ErrorStringOr<void> screencastFrameAck(int generation) override;
12137
12158
+ Inspector::Protocol::ErrorStringOr<void> stopScreencast() override;
12138
12159
+
@@ -12153,6 +12174,7 @@ index 0000000000000000000000000000000000000000..759ea406372f734dec37955becb5ec74
12153
12174
+ double m_screencastWidth = 0;
12154
12175
+ double m_screencastHeight = 0;
12155
12176
+ int m_screencastQuality = 0;
12177
+ + int m_screencastToolbarHeight = 0;
12156
12178
+ int m_screencastGeneration = 0;
12157
12179
+ int m_screencastFramesInFlight = 0;
12158
12180
+ String m_currentScreencastID;
@@ -14683,7 +14705,7 @@ index 7a14cfba15c103a2d4fe263fa49d25af3c396ec2..3ee0e154349661632799057c71f1d1f1
14683
14705
BOOL result = ::CreateProcess(0, commandLine.data(), 0, 0, true, 0, 0, 0, &startupInfo, &processInformation);
14684
14706
14685
14707
diff --git a/Source/WebKit/UIProcess/PageClient.h b/Source/WebKit/UIProcess/PageClient.h
14686
- index 70c6bb6d64b25fce9f231fbce708c0515fb73789..f60b57b1e844716cc748b290f9ff73457b020a4f 100644
14708
+ index 70c6bb6d64b25fce9f231fbce708c0515fb73789..6b970003b28722d9eee029c070b36f31d5377b9f 100644
14687
14709
--- a/Source/WebKit/UIProcess/PageClient.h
14688
14710
+++ b/Source/WebKit/UIProcess/PageClient.h
14689
14711
@@ -312,6 +312,11 @@ public:
@@ -14698,14 +14720,6 @@ index 70c6bb6d64b25fce9f231fbce708c0515fb73789..f60b57b1e844716cc748b290f9ff7345
14698
14720
#if PLATFORM(COCOA) || PLATFORM(GTK)
14699
14721
virtual RefPtr<ViewSnapshot> takeViewSnapshot(Optional<WebCore::IntRect>&&) = 0;
14700
14722
#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;
14709
14723
diff --git a/Source/WebKit/UIProcess/ProvisionalPageProxy.cpp b/Source/WebKit/UIProcess/ProvisionalPageProxy.cpp
14710
14724
index 226d2933405ea5b6f0bc369e51fd07862e37af76..7796abccb6b80baccf826a24fe4f45a4a56bb9d6 100644
14711
14725
--- a/Source/WebKit/UIProcess/ProvisionalPageProxy.cpp
@@ -17319,7 +17333,7 @@ index 0000000000000000000000000000000000000000..721826c8c98fc85b68a4f45deaee69c1
17319
17333
+
17320
17334
+#endif
17321
17335
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
17323
17337
--- a/Source/WebKit/UIProcess/mac/PageClientImplMac.h
17324
17338
+++ b/Source/WebKit/UIProcess/mac/PageClientImplMac.h
17325
17339
@@ -53,6 +53,8 @@ class PageClientImpl final : public PageClientImplCocoa
@@ -17331,15 +17345,7 @@ index c58ad478af24f439872c514b17b370601e4e1c93..95dd9423528177d12f16d9975947061d
17331
17345
PageClientImpl(NSView *, WKWebView *);
17332
17346
virtual ~PageClientImpl();
17333
17347
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:
17343
17349
void updateAcceleratedCompositingMode(const LayerTreeContext&) override;
17344
17350
void didFirstLayerFlush(const LayerTreeContext&) override;
17345
17351
@@ -17349,7 +17355,7 @@ index c58ad478af24f439872c514b17b370601e4e1c93..95dd9423528177d12f16d9975947061d
17349
17355
RefPtr<ViewSnapshot> takeViewSnapshot(Optional<WebCore::IntRect>&&) override;
17350
17356
void wheelEventWasNotHandledByWebCore(const NativeWebWheelEvent&) override;
17351
17357
#if ENABLE(MAC_GESTURE_EVENTS)
17352
- @@ -219,6 +225 ,10 @@ private:
17358
+ @@ -219,6 +224 ,10 @@ private:
17353
17359
void beganExitFullScreen(const WebCore::IntRect& initialFrame, const WebCore::IntRect& finalFrame) override;
17354
17360
#endif
17355
17361
@@ -17361,7 +17367,7 @@ index c58ad478af24f439872c514b17b370601e4e1c93..95dd9423528177d12f16d9975947061d
17361
17367
void navigationGestureWillEnd(bool willNavigate, WebBackForwardListItem&) override;
17362
17368
void navigationGestureDidEnd(bool willNavigate, WebBackForwardListItem&) override;
17363
17369
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
17365
17371
--- a/Source/WebKit/UIProcess/mac/PageClientImplMac.mm
17366
17372
+++ b/Source/WebKit/UIProcess/mac/PageClientImplMac.mm
17367
17373
@@ -81,6 +81,7 @@
@@ -17426,23 +17432,7 @@ index 67dfe20726b9d6b7e0173801da7b8bae3a87ee28..cfd251d192c0ba17d99fabb533d4b5ab
17426
17432
}
17427
17433
17428
17434
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)
17446
17436
17447
17437
void PageClientImpl::doneWithKeyEvent(const NativeWebKeyboardEvent& event, bool eventWasHandled)
17448
17438
{
@@ -17451,7 +17441,7 @@ index 67dfe20726b9d6b7e0173801da7b8bae3a87ee28..cfd251d192c0ba17d99fabb533d4b5ab
17451
17441
m_impl->doneWithKeyEvent(event.nativeEvent(), eventWasHandled);
17452
17442
}
17453
17443
17454
- @@ -497,6 +526 ,8 @@ void PageClientImpl::computeCanRevealImage(const URL& imageURL, ShareableBitmap&
17444
+ @@ -497,6 +517 ,8 @@ void PageClientImpl::computeCanRevealImage(const URL& imageURL, ShareableBitmap&
17455
17445
17456
17446
RefPtr<WebPopupMenuProxy> PageClientImpl::createPopupMenuProxy(WebPageProxy& page)
17457
17447
{
@@ -17460,7 +17450,7 @@ index 67dfe20726b9d6b7e0173801da7b8bae3a87ee28..cfd251d192c0ba17d99fabb533d4b5ab
17460
17450
return WebPopupMenuProxyMac::create(m_view, page);
17461
17451
}
17462
17452
17463
- @@ -628,6 +659 ,12 @@ CALayer *PageClientImpl::acceleratedCompositingRootLayer() const
17453
+ @@ -628,6 +650 ,12 @@ CALayer *PageClientImpl::acceleratedCompositingRootLayer() const
17464
17454
return m_impl->acceleratedCompositingRootLayer();
17465
17455
}
17466
17456
@@ -17473,7 +17463,7 @@ index 67dfe20726b9d6b7e0173801da7b8bae3a87ee28..cfd251d192c0ba17d99fabb533d4b5ab
17473
17463
RefPtr<ViewSnapshot> PageClientImpl::takeViewSnapshot(Optional<WebCore::IntRect>&&)
17474
17464
{
17475
17465
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
17477
17467
17478
17468
#endif // ENABLE(FULLSCREEN_API)
17479
17469
@@ -17487,7 +17477,7 @@ index 67dfe20726b9d6b7e0173801da7b8bae3a87ee28..cfd251d192c0ba17d99fabb533d4b5ab
17487
17477
void PageClientImpl::navigationGestureDidBegin()
17488
17478
{
17489
17479
m_impl->dismissContentRelativeChildWindowsWithAnimation(true);
17490
- @@ -972,6 +1016 ,9 @@ void PageClientImpl::didRestoreScrollPosition()
17480
+ @@ -972,6 +1007 ,9 @@ void PageClientImpl::didRestoreScrollPosition()
17491
17481
17492
17482
bool PageClientImpl::windowIsFrontWindowUnderMouse(const NativeWebMouseEvent& event)
17493
17483
{
0 commit comments