Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

browser(webkit): dedupe screencast frames (#9386)

Pavel Feldman349f3444e64e
diff --git a/browser_patches/webkit/BUILD_NUMBER b/browser_patches/webkit/BUILD_NUMBER
index aea3e97eff..c27bae9c85 100644
--- a/browser_patches/webkit/BUILD_NUMBER
+++ b/browser_patches/webkit/BUILD_NUMBER
@@ -1,2 +1,2 @@
-1558
-Changed: [email protected] Tue 05 Oct 2021 03:13:20 PM PDT
+1559
+Changed: [email protected] Thu 07 Oct 2021 06:57:27 PM PDT
diff --git a/browser_patches/webkit/patches/bootstrap.diff b/browser_patches/webkit/patches/bootstrap.diff
index 0300ae071c..07c5e4c180 100644
--- a/browser_patches/webkit/patches/bootstrap.diff
+++ b/browser_patches/webkit/patches/bootstrap.diff
@@ -13438,10 +13438,10 @@ index 0000000000000000000000000000000000000000..4ec8b96bbbddf8a7b042f53a8068754a
+cairo_status_t cairo_image_surface_write_to_jpeg_mem(cairo_surface_t *sfc, unsigned char **data, size_t *len, int quality);
diff --git a/Source/WebKit/UIProcess/Inspector/Agents/InspectorScreencastAgent.cpp b/Source/WebKit/UIProcess/Inspector/Agents/InspectorScreencastAgent.cpp
new file mode 100644
-index 0000000000000000000000000000000000000000..20122bd89c3ba0ec4ff878ac895bddd497cc9789
+index 0000000000000000000000000000000000000000..9a1547d6ad27f58d8276b657c6c7190ebc6b75dc
--- /dev/null
+++ b/Source/WebKit/UIProcess/Inspector/Agents/InspectorScreencastAgent.cpp
-@@ -0,0 +1,269 @@
+@@ -0,0 +1,284 @@
+/*
+ * Copyright (C) 2020 Microsoft Corporation.
+ *
@@ -13476,6 +13476,7 @@ index 0000000000000000000000000000000000000000..20122bd89c3ba0ec4ff878ac895bddd4
+#include "WebPageInspectorController.h"
+#include "WebPageProxy.h"
+#include "WebsiteDataStore.h"
++#include <pal/crypto/CryptoDigest.h>
+#include <JavaScriptCore/InspectorFrontendRouter.h>
+#include <WebCore/NotImplemented.h>
+#include <wtf/RunLoop.h>
@@ -13534,6 +13535,20 @@ index 0000000000000000000000000000000000000000..20122bd89c3ba0ec4ff878ac895bddd4
+ if (m_encoder)
+ m_encoder->encodeFrame(surface, m_page.drawingArea()->size());
+ if (m_screencast) {
++
++ {
++ // Do not send the same frame over and over.
++ unsigned char *data = cairo_image_surface_get_data(surface);
++ int stride = cairo_image_surface_get_stride(surface);
++ int height = cairo_image_surface_get_height(surface);
++ auto cryptoDigest = PAL::CryptoDigest::create(PAL::CryptoDigest::Algorithm::SHA_1);
++ cryptoDigest->addBytes(data, stride * height);
++ auto digest = cryptoDigest->computeHash();
++ if (m_lastFrameDigest == digest)
++ return;
++ m_lastFrameDigest = digest;
++ }
++
+ if (m_screencastFramesInFlight > kMaxFramesInFlight)
+ return;
+ // Scale image to fit width / height
@@ -13713,10 +13728,10 @@ index 0000000000000000000000000000000000000000..20122bd89c3ba0ec4ff878ac895bddd4
+} // namespace WebKit
diff --git a/Source/WebKit/UIProcess/Inspector/Agents/InspectorScreencastAgent.h b/Source/WebKit/UIProcess/Inspector/Agents/InspectorScreencastAgent.h
new file mode 100644
-index 0000000000000000000000000000000000000000..8f2795dbf1323dd8d5f986f18e6fe16431dd7f70
+index 0000000000000000000000000000000000000000..a45b32a1c839cf019fcece2f950e595d89d93fa7
--- /dev/null
+++ b/Source/WebKit/UIProcess/Inspector/Agents/InspectorScreencastAgent.h
-@@ -0,0 +1,96 @@
+@@ -0,0 +1,97 @@
+/*
+ * Copyright (C) 2020 Microsoft Corporation.
+ *
@@ -13800,6 +13815,7 @@ index 0000000000000000000000000000000000000000..8f2795dbf1323dd8d5f986f18e6fe164
+ std::unique_ptr<Inspector::ScreencastFrontendDispatcher> m_frontendDispatcher;
+ Ref<Inspector::ScreencastBackendDispatcher> m_backendDispatcher;
+ WebPageProxy& m_page;
++ Vector<uint8_t> m_lastFrameDigest;
+ RefPtr<ScreencastEncoder> m_encoder;
+ bool m_screencast = false;
+ bool m_framesAreGoing = false;