browser(webkit): drop scale parameter from startVideo (#10690)

This commit is contained in:
Yury Semikhatsky 2021-12-02 19:09:08 -08:00 committed by GitHub
parent 402ed16849
commit fbc7539c10
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 43 deletions

View file

@ -1,2 +1,2 @@
1582 1583
Changed: yurys@chromium.org Thu 02 Dec 2021 05:01:39 PM PST Changed: yurys@chromium.org Thu 02 Dec 2021 07:00:45 PM PST

View file

@ -1611,10 +1611,10 @@ index 274b01596d490fb81b48cf89bf668e0634e8b423..d08a9ddd745c748767ba8055907daa7b
"name": "getPreview", "name": "getPreview",
diff --git a/Source/JavaScriptCore/inspector/protocol/Screencast.json b/Source/JavaScriptCore/inspector/protocol/Screencast.json diff --git a/Source/JavaScriptCore/inspector/protocol/Screencast.json b/Source/JavaScriptCore/inspector/protocol/Screencast.json
new file mode 100644 new file mode 100644
index 0000000000000000000000000000000000000000..f6c541d63c0b8251874eaf8818aabe0e0449401d index 0000000000000000000000000000000000000000..73a4e53ced3acc41316bb8d4c787306d3f28a27e
--- /dev/null --- /dev/null
+++ b/Source/JavaScriptCore/inspector/protocol/Screencast.json +++ b/Source/JavaScriptCore/inspector/protocol/Screencast.json
@@ -0,0 +1,65 @@ @@ -0,0 +1,64 @@
+{ +{
+ "domain": "Screencast", + "domain": "Screencast",
+ "availability": ["web"], + "availability": ["web"],
@ -1633,8 +1633,7 @@ index 0000000000000000000000000000000000000000..f6c541d63c0b8251874eaf8818aabe0e
+ { "name": "file", "type": "string", "description": "Output file location." }, + { "name": "file", "type": "string", "description": "Output file location." },
+ { "name": "width", "type": "integer" }, + { "name": "width", "type": "integer" },
+ { "name": "height", "type": "integer" }, + { "name": "height", "type": "integer" },
+ { "name": "toolbarHeight", "type": "integer" }, + { "name": "toolbarHeight", "type": "integer" }
+ { "name": "scale", "type": "number", "optional": true }
+ ], + ],
+ "returns": [ + "returns": [
+ { "name": "screencastId", "$ref": "ScreencastId", "description": "Unique identifier of the screencast." } + { "name": "screencastId", "$ref": "ScreencastId", "description": "Unique identifier of the screencast." }
@ -13084,10 +13083,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); +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 diff --git a/Source/WebKit/UIProcess/Inspector/Agents/InspectorScreencastAgent.cpp b/Source/WebKit/UIProcess/Inspector/Agents/InspectorScreencastAgent.cpp
new file mode 100644 new file mode 100644
index 0000000000000000000000000000000000000000..694b5afbc78861f0262a33959b3a1644acc8fc82 index 0000000000000000000000000000000000000000..288f46125a3ed43af1ce977c658fd49ad4c97ee1
--- /dev/null --- /dev/null
+++ b/Source/WebKit/UIProcess/Inspector/Agents/InspectorScreencastAgent.cpp +++ b/Source/WebKit/UIProcess/Inspector/Agents/InspectorScreencastAgent.cpp
@@ -0,0 +1,298 @@ @@ -0,0 +1,295 @@
+/* +/*
+ * Copyright (C) 2020 Microsoft Corporation. + * Copyright (C) 2020 Microsoft Corporation.
+ * + *
@ -13228,7 +13227,7 @@ index 0000000000000000000000000000000000000000..694b5afbc78861f0262a33959b3a1644
+} +}
+#endif +#endif
+ +
+Inspector::Protocol::ErrorStringOr<String /* screencastID */> InspectorScreencastAgent::startVideo(const String& file, int width, int height, int toolbarHeight, std::optional<double>&& scale) +Inspector::Protocol::ErrorStringOr<String /* screencastID */> InspectorScreencastAgent::startVideo(const String& file, int width, int height, int toolbarHeight)
+{ +{
+ if (m_encoder) + if (m_encoder)
+ return makeUnexpected("Already recording"_s); + return makeUnexpected("Already recording"_s);
@ -13236,11 +13235,8 @@ index 0000000000000000000000000000000000000000..694b5afbc78861f0262a33959b3a1644
+ if (width < 10 || width > 10000 || height < 10 || height > 10000) + if (width < 10 || width > 10000 || height < 10 || height > 10000)
+ return makeUnexpected("Invalid size"_s); + return makeUnexpected("Invalid size"_s);
+ +
+ if (scale && (*scale <= 0 || *scale > 1))
+ return makeUnexpected("Unsupported scale"_s);
+
+ String errorString; + String errorString;
+ m_encoder = ScreencastEncoder::create(errorString, file, WebCore::IntSize(width, height), WTFMove(scale)); + m_encoder = ScreencastEncoder::create(errorString, file, WebCore::IntSize(width, height));
+ if (!m_encoder) + if (!m_encoder)
+ return makeUnexpected(errorString); + return makeUnexpected(errorString);
+ +
@ -13388,7 +13384,7 @@ index 0000000000000000000000000000000000000000..694b5afbc78861f0262a33959b3a1644
+} // namespace WebKit +} // namespace WebKit
diff --git a/Source/WebKit/UIProcess/Inspector/Agents/InspectorScreencastAgent.h b/Source/WebKit/UIProcess/Inspector/Agents/InspectorScreencastAgent.h diff --git a/Source/WebKit/UIProcess/Inspector/Agents/InspectorScreencastAgent.h b/Source/WebKit/UIProcess/Inspector/Agents/InspectorScreencastAgent.h
new file mode 100644 new file mode 100644
index 0000000000000000000000000000000000000000..a45b32a1c839cf019fcece2f950e595d89d93fa7 index 0000000000000000000000000000000000000000..d28dde452275f18739e3b1c8d709185c9bf0f40e
--- /dev/null --- /dev/null
+++ b/Source/WebKit/UIProcess/Inspector/Agents/InspectorScreencastAgent.h +++ b/Source/WebKit/UIProcess/Inspector/Agents/InspectorScreencastAgent.h
@@ -0,0 +1,97 @@ @@ -0,0 +1,97 @@
@ -13457,7 +13453,7 @@ index 0000000000000000000000000000000000000000..a45b32a1c839cf019fcece2f950e595d
+ void didPaint(cairo_surface_t*); + void didPaint(cairo_surface_t*);
+#endif +#endif
+ +
+ Inspector::Protocol::ErrorStringOr<String /* screencastID */> startVideo(const String& file, int width, int height, int toolbarHeight, std::optional<double>&& scale) override; + Inspector::Protocol::ErrorStringOr<String /* screencastID */> startVideo(const String& file, int width, int height, int toolbarHeight) override;
+ void stopVideo(Ref<StopVideoCallback>&&) override; + void stopVideo(Ref<StopVideoCallback>&&) override;
+ +
+ Inspector::Protocol::ErrorStringOr<int /* generation */> startScreencast(int width, int height, int toolbarHeight, int quality) override; + Inspector::Protocol::ErrorStringOr<int /* generation */> startScreencast(int width, int height, int toolbarHeight, int quality) override;
@ -13491,10 +13487,10 @@ index 0000000000000000000000000000000000000000..a45b32a1c839cf019fcece2f950e595d
+} // namespace WebKit +} // namespace WebKit
diff --git a/Source/WebKit/UIProcess/Inspector/Agents/ScreencastEncoder.cpp b/Source/WebKit/UIProcess/Inspector/Agents/ScreencastEncoder.cpp diff --git a/Source/WebKit/UIProcess/Inspector/Agents/ScreencastEncoder.cpp b/Source/WebKit/UIProcess/Inspector/Agents/ScreencastEncoder.cpp
new file mode 100644 new file mode 100644
index 0000000000000000000000000000000000000000..47b1594e0af11849dc975d9479c72e90481bcb54 index 0000000000000000000000000000000000000000..a3eebdc92962a46a4861e75cd9a7f931722748ff
--- /dev/null --- /dev/null
+++ b/Source/WebKit/UIProcess/Inspector/Agents/ScreencastEncoder.cpp +++ b/Source/WebKit/UIProcess/Inspector/Agents/ScreencastEncoder.cpp
@@ -0,0 +1,385 @@ @@ -0,0 +1,379 @@
+/* +/*
+ * Copyright (c) 2010, The WebM Project authors. All rights reserved. + * Copyright (c) 2010, The WebM Project authors. All rights reserved.
+ * Copyright (c) 2013 The Chromium Authors. All rights reserved. + * Copyright (c) 2013 The Chromium Authors. All rights reserved.
@ -13617,9 +13613,8 @@ index 0000000000000000000000000000000000000000..47b1594e0af11849dc975d9479c72e90
+ : m_surface(WTFMove(surface)) + : m_surface(WTFMove(surface))
+ { } + { }
+#elif PLATFORM(MAC) +#elif PLATFORM(MAC)
+ VPXFrame(RetainPtr<CGImageRef> windowImage, std::optional<double> scale, int offsetTop) + VPXFrame(RetainPtr<CGImageRef> windowImage, int offsetTop)
+ : m_windowImage(WTFMove(windowImage)) + : m_windowImage(WTFMove(windowImage))
+ , m_scale(scale)
+ , m_offsetTop(offsetTop) + , m_offsetTop(offsetTop)
+ { } + { }
+#endif +#endif
@ -13637,7 +13632,7 @@ index 0000000000000000000000000000000000000000..47b1594e0af11849dc975d9479c72e90
+ int argb_stride = image->w * 4; + int argb_stride = image->w * 4;
+ UniqueArray<uint8_t> buffer = makeUniqueArray<uint8_t>(argb_stride * image->h); + UniqueArray<uint8_t> buffer = makeUniqueArray<uint8_t>(argb_stride * image->h);
+ uint8_t* argb_data = buffer.get(); + uint8_t* argb_data = buffer.get();
+ ScreencastEncoder::imageToARGB(m_windowImage.get(), argb_data, image->w, image->h, m_scale, m_offsetTop); + ScreencastEncoder::imageToARGB(m_windowImage.get(), argb_data, image->w, image->h, m_offsetTop);
+#endif +#endif
+ const int y_stride = image->stride[0]; + const int y_stride = image->stride[0];
+ ASSERT(image->stride[1] == image->stride[2]); + ASSERT(image->stride[1] == image->stride[2]);
@ -13659,7 +13654,6 @@ index 0000000000000000000000000000000000000000..47b1594e0af11849dc975d9479c72e90
+ RefPtr<cairo_surface_t> m_surface; + RefPtr<cairo_surface_t> m_surface;
+#elif PLATFORM(MAC) +#elif PLATFORM(MAC)
+ RetainPtr<CGImageRef> m_windowImage; + RetainPtr<CGImageRef> m_windowImage;
+ std::optional<double> m_scale;
+ int m_offsetTop { 0 }; + int m_offsetTop { 0 };
+#endif +#endif
+ Seconds m_duration; + Seconds m_duration;
@ -13750,10 +13744,9 @@ index 0000000000000000000000000000000000000000..47b1594e0af11849dc975d9479c72e90
+ std::unique_ptr<vpx_image_t> m_image; + std::unique_ptr<vpx_image_t> m_image;
+}; +};
+ +
+ScreencastEncoder::ScreencastEncoder(std::unique_ptr<VPXCodec>&& vpxCodec, IntSize size, std::optional<double> scale) +ScreencastEncoder::ScreencastEncoder(std::unique_ptr<VPXCodec>&& vpxCodec, IntSize size)
+ : m_vpxCodec(WTFMove(vpxCodec)) + : m_vpxCodec(WTFMove(vpxCodec))
+ , m_size(size) + , m_size(size)
+ , m_scale(scale)
+{ +{
+ ASSERT(!size.isZero()); + ASSERT(!size.isZero());
+} +}
@ -13762,7 +13755,7 @@ index 0000000000000000000000000000000000000000..47b1594e0af11849dc975d9479c72e90
+{ +{
+} +}
+ +
+RefPtr<ScreencastEncoder> ScreencastEncoder::create(String& errorString, const String& filePath, IntSize size, std::optional<double> scale) +RefPtr<ScreencastEncoder> ScreencastEncoder::create(String& errorString, const String& filePath, IntSize size)
+{ +{
+ vpx_codec_iface_t* codec_interface = vpx_codec_vp8_cx(); + vpx_codec_iface_t* codec_interface = vpx_codec_vp8_cx();
+ if (!codec_interface) { + if (!codec_interface) {
@ -13802,7 +13795,7 @@ index 0000000000000000000000000000000000000000..47b1594e0af11849dc975d9479c72e90
+ } + }
+ +
+ std::unique_ptr<VPXCodec> vpxCodec(new VPXCodec(codec, cfg, file)); + std::unique_ptr<VPXCodec> vpxCodec(new VPXCodec(codec, cfg, file));
+ return adoptRef(new ScreencastEncoder(WTFMove(vpxCodec), size, scale)); + return adoptRef(new ScreencastEncoder(WTFMove(vpxCodec), size));
+} +}
+ +
+void ScreencastEncoder::flushLastFrame() +void ScreencastEncoder::flushLastFrame()
@ -13835,10 +13828,7 @@ index 0000000000000000000000000000000000000000..47b1594e0af11849dc975d9479c72e90
+ RefPtr<cairo_t> cr = adoptRef(cairo_create(surface.get())); + RefPtr<cairo_t> cr = adoptRef(cairo_create(surface.get()));
+ +
+ cairo_matrix_t transform; + cairo_matrix_t transform;
+ if (m_scale) { + if (size.width() > m_size.width() || size.height() > m_size.height()) {
+ cairo_matrix_init_scale(&transform, *m_scale, *m_scale);
+ cairo_transform(cr.get(), &transform);
+ } else if (size.width() > m_size.width() || size.height() > m_size.height()) {
+ // If no scale is specified shrink to fit the frame. + // If no scale is specified shrink to fit the frame.
+ double scale = std::min(static_cast<double>(m_size.width()) / size.width(), + double scale = std::min(static_cast<double>(m_size.width()) / size.width(),
+ static_cast<double>(m_size.height()) / size.height()); + static_cast<double>(m_size.height()) / size.height());
@ -13859,7 +13849,7 @@ index 0000000000000000000000000000000000000000..47b1594e0af11849dc975d9479c72e90
+{ +{
+ flushLastFrame(); + flushLastFrame();
+ +
+ m_lastFrame = makeUnique<VPXFrame>(WTFMove(windowImage), m_scale, m_offsetTop); + m_lastFrame = makeUnique<VPXFrame>(WTFMove(windowImage), m_offsetTop);
+} +}
+#endif +#endif
+ +
@ -13882,10 +13872,10 @@ index 0000000000000000000000000000000000000000..47b1594e0af11849dc975d9479c72e90
+} // namespace WebKit +} // namespace WebKit
diff --git a/Source/WebKit/UIProcess/Inspector/Agents/ScreencastEncoder.h b/Source/WebKit/UIProcess/Inspector/Agents/ScreencastEncoder.h diff --git a/Source/WebKit/UIProcess/Inspector/Agents/ScreencastEncoder.h b/Source/WebKit/UIProcess/Inspector/Agents/ScreencastEncoder.h
new file mode 100644 new file mode 100644
index 0000000000000000000000000000000000000000..1683da93db6b9088c3a472472c1b71477b47a7fd index 0000000000000000000000000000000000000000..36df6131950ca95f74dc191628376fc589dbcb33
--- /dev/null --- /dev/null
+++ b/Source/WebKit/UIProcess/Inspector/Agents/ScreencastEncoder.h +++ b/Source/WebKit/UIProcess/Inspector/Agents/ScreencastEncoder.h
@@ -0,0 +1,81 @@ @@ -0,0 +1,80 @@
+/* +/*
+ * Copyright (C) 2020 Microsoft Corporation. + * Copyright (C) 2020 Microsoft Corporation.
+ * + *
@ -13934,10 +13924,10 @@ index 0000000000000000000000000000000000000000..1683da93db6b9088c3a472472c1b7147
+public: +public:
+ static constexpr int fps = 25; + static constexpr int fps = 25;
+ +
+ static RefPtr<ScreencastEncoder> create(String& errorString, const String& filePath, WebCore::IntSize, std::optional<double> scale); + static RefPtr<ScreencastEncoder> create(String& errorString, const String& filePath, WebCore::IntSize);
+ +
+ class VPXCodec; + class VPXCodec;
+ ScreencastEncoder(std::unique_ptr<VPXCodec>&&, WebCore::IntSize, std::optional<double> scale); + ScreencastEncoder(std::unique_ptr<VPXCodec>&&, WebCore::IntSize);
+ ~ScreencastEncoder(); + ~ScreencastEncoder();
+ +
+#if USE(CAIRO) +#if USE(CAIRO)
@ -13952,12 +13942,11 @@ index 0000000000000000000000000000000000000000..1683da93db6b9088c3a472472c1b7147
+private: +private:
+ void flushLastFrame(); + void flushLastFrame();
+#if PLATFORM(MAC) +#if PLATFORM(MAC)
+ static void imageToARGB(CGImageRef, uint8_t* rgba_data, int width, int height, std::optional<double> scale, int offsetTop); + static void imageToARGB(CGImageRef, uint8_t* rgba_data, int width, int height, int offsetTop);
+#endif +#endif
+ +
+ std::unique_ptr<VPXCodec> m_vpxCodec; + std::unique_ptr<VPXCodec> m_vpxCodec;
+ const WebCore::IntSize m_size; + const WebCore::IntSize m_size;
+ std::optional<double> m_scale;
+ MonotonicTime m_lastFrameTimestamp; + MonotonicTime m_lastFrameTimestamp;
+ class VPXFrame; + class VPXFrame;
+ std::unique_ptr<VPXFrame> m_lastFrame; + std::unique_ptr<VPXFrame> m_lastFrame;
@ -14674,10 +14663,10 @@ index 8c1339345d451874502b271f6aa2eca3fa0d3faf..1f8f5e74c86b61c1c5a16ac33d48afdd
} // namespace WebKit } // namespace WebKit
diff --git a/Source/WebKit/UIProcess/Inspector/mac/ScreencastEncoderMac.mm b/Source/WebKit/UIProcess/Inspector/mac/ScreencastEncoderMac.mm diff --git a/Source/WebKit/UIProcess/Inspector/mac/ScreencastEncoderMac.mm b/Source/WebKit/UIProcess/Inspector/mac/ScreencastEncoderMac.mm
new file mode 100644 new file mode 100644
index 0000000000000000000000000000000000000000..66d1c743de1cb35e29d6fc9b69379d265a59961f index 0000000000000000000000000000000000000000..235e9a3f8455f1113109631b54c7e90cfad8a614
--- /dev/null --- /dev/null
+++ b/Source/WebKit/UIProcess/Inspector/mac/ScreencastEncoderMac.mm +++ b/Source/WebKit/UIProcess/Inspector/mac/ScreencastEncoderMac.mm
@@ -0,0 +1,58 @@ @@ -0,0 +1,55 @@
+/* +/*
+ * Copyright (C) 2020 Microsoft Corporation. + * Copyright (C) 2020 Microsoft Corporation.
+ * + *
@ -14712,7 +14701,7 @@ index 0000000000000000000000000000000000000000..66d1c743de1cb35e29d6fc9b69379d26
+ +
+namespace WebKit { +namespace WebKit {
+ +
+void ScreencastEncoder::imageToARGB(CGImageRef image, uint8_t* argb_data, int width, int height, std::optional<double> scale, int offsetTop) +void ScreencastEncoder::imageToARGB(CGImageRef image, uint8_t* argb_data, int width, int height, int offsetTop)
+{ +{
+ size_t bitsPerComponent = 8; + size_t bitsPerComponent = 8;
+ size_t bytesPerPixel = 4; + size_t bytesPerPixel = 4;
@ -14721,12 +14710,9 @@ index 0000000000000000000000000000000000000000..66d1c743de1cb35e29d6fc9b69379d26
+ RetainPtr<CGContextRef> context = adoptCF(CGBitmapContextCreate(argb_data, width, height, bitsPerComponent, bytesPerRow, colorSpace.get(), kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Little)); + RetainPtr<CGContextRef> context = adoptCF(CGBitmapContextCreate(argb_data, width, height, bitsPerComponent, bytesPerRow, colorSpace.get(), kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Little));
+ double imageWidth = CGImageGetWidth(image); + double imageWidth = CGImageGetWidth(image);
+ double imageHeight = CGImageGetHeight(image); + double imageHeight = CGImageGetHeight(image);
+ // TODO: exclude controls from original screenshot
+ double pageHeight = imageHeight - offsetTop; + double pageHeight = imageHeight - offsetTop;
+ double ratio = 1; + double ratio = 1;
+ if (scale) { + if (imageWidth > width || pageHeight > height) {
+ ratio = *scale;
+ } else if (imageWidth > width || pageHeight > height) {
+ ratio = std::min(width / imageWidth, height / pageHeight); + ratio = std::min(width / imageWidth, height / pageHeight);
+ } + }
+ imageWidth *= ratio; + imageWidth *= ratio;