From 40b1a146262a912267fd5da398159f7ad5dff4a0 Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Mon, 22 Jun 2020 14:40:46 -0700 Subject: [PATCH] browser(webkit): support screencast scale on Mac (#2655) --- browser_patches/webkit/BUILD_NUMBER | 2 +- browser_patches/webkit/patches/bootstrap.diff | 28 +++++++++++-------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/browser_patches/webkit/BUILD_NUMBER b/browser_patches/webkit/BUILD_NUMBER index 250be2e8d3..7a3abe9b72 100644 --- a/browser_patches/webkit/BUILD_NUMBER +++ b/browser_patches/webkit/BUILD_NUMBER @@ -1 +1 @@ -1293 +1294 diff --git a/browser_patches/webkit/patches/bootstrap.diff b/browser_patches/webkit/patches/bootstrap.diff index c59fa70115..210268ceac 100644 --- a/browser_patches/webkit/patches/bootstrap.diff +++ b/browser_patches/webkit/patches/bootstrap.diff @@ -8553,10 +8553,10 @@ index 0000000000000000000000000000000000000000..003ad364d76071ce30d11cce7d1b61a6 +} // namespace WebKit diff --git a/Source/WebKit/UIProcess/Inspector/Agents/ScreencastEncoder.cpp b/Source/WebKit/UIProcess/Inspector/Agents/ScreencastEncoder.cpp new file mode 100644 -index 0000000000000000000000000000000000000000..f95ca1a9a9faecdc83de8289d0d5be46c135d907 +index 0000000000000000000000000000000000000000..5b28d1ba9fe79d35af2e15f97aeb8df31a898a11 --- /dev/null +++ b/Source/WebKit/UIProcess/Inspector/Agents/ScreencastEncoder.cpp -@@ -0,0 +1,440 @@ +@@ -0,0 +1,442 @@ +/* + * Copyright (c) 2010, The WebM Project authors. All rights reserved. + * Copyright (c) 2013 The Chromium Authors. All rights reserved. @@ -8727,8 +8727,9 @@ index 0000000000000000000000000000000000000000..f95ca1a9a9faecdc83de8289d0d5be46 + : m_surface(WTFMove(surface)) + { } +#elif PLATFORM(MAC) -+ explicit VPXFrame(RetainPtr windowImage) ++ VPXFrame(RetainPtr windowImage, Optional scale) + : m_windowImage(WTFMove(windowImage)) ++ , m_scale(scale) + { } +#endif + @@ -8745,7 +8746,7 @@ index 0000000000000000000000000000000000000000..f95ca1a9a9faecdc83de8289d0d5be46 + int argb_stride = image->w * 4; + UniqueArray buffer = makeUniqueArray(argb_stride * image->h); + uint8_t* argb_data = buffer.get(); -+ ScreencastEncoder::imageToARGB(m_windowImage.get(), argb_data, image->w, image->h); ++ ScreencastEncoder::imageToARGB(m_windowImage.get(), argb_data, image->w, image->h, m_scale); +#endif + const int y_stride = image->stride[0]; + ASSERT(image->stride[1] == image->stride[2]); @@ -8767,6 +8768,7 @@ index 0000000000000000000000000000000000000000..f95ca1a9a9faecdc83de8289d0d5be46 + RefPtr m_surface; +#elif PLATFORM(MAC) + RetainPtr m_windowImage; ++ Optional m_scale; +#endif + int m_duration = 0; +}; @@ -8976,7 +8978,7 @@ index 0000000000000000000000000000000000000000..f95ca1a9a9faecdc83de8289d0d5be46 + fprintf(stderr, "ScreencastEncoder::encodeFrame\n"); + flushLastFrame(); + -+ m_lastFrame = makeUnique(WTFMove(windowImage)); ++ m_lastFrame = makeUnique(WTFMove(windowImage), m_scale); +} +#endif + @@ -8999,7 +9001,7 @@ index 0000000000000000000000000000000000000000..f95ca1a9a9faecdc83de8289d0d5be46 +} // namespace WebKit diff --git a/Source/WebKit/UIProcess/Inspector/Agents/ScreencastEncoder.h b/Source/WebKit/UIProcess/Inspector/Agents/ScreencastEncoder.h new file mode 100644 -index 0000000000000000000000000000000000000000..09dca3bb8d9e50810f54298b1cf643c1fa3c5965 +index 0000000000000000000000000000000000000000..df283ee565b1691c49e68b79f40a72aefca77bf6 --- /dev/null +++ b/Source/WebKit/UIProcess/Inspector/Agents/ScreencastEncoder.h @@ -0,0 +1,75 @@ @@ -9066,7 +9068,7 @@ index 0000000000000000000000000000000000000000..09dca3bb8d9e50810f54298b1cf643c1 +private: + void flushLastFrame(); +#if PLATFORM(MAC) -+ static void imageToARGB(CGImageRef, uint8_t* rgba_data, int width, int height); ++ static void imageToARGB(CGImageRef, uint8_t* rgba_data, int width, int height, Optional scale); +#endif + + std::unique_ptr m_vpxCodec; @@ -9639,10 +9641,10 @@ index c2df3ceb4b69f32060dcbd90d04dc6cb5900de0d..af9c472a1b9137424081b3f1f9fd9448 } // namespace WebKit diff --git a/Source/WebKit/UIProcess/Inspector/mac/ScreencastEncoderMac.mm b/Source/WebKit/UIProcess/Inspector/mac/ScreencastEncoderMac.mm new file mode 100644 -index 0000000000000000000000000000000000000000..678757082a087f039e21da1456c3a28f553c1a13 +index 0000000000000000000000000000000000000000..aa06bdfb5170428ace1143ae52b413ac6b987040 --- /dev/null +++ b/Source/WebKit/UIProcess/Inspector/mac/ScreencastEncoderMac.mm -@@ -0,0 +1,47 @@ +@@ -0,0 +1,51 @@ +/* + * Copyright (C) 2020 Microsoft Corporation. + * @@ -9676,14 +9678,18 @@ index 0000000000000000000000000000000000000000..678757082a087f039e21da1456c3a28f + +namespace WebKit { + -+void ScreencastEncoder::imageToARGB(CGImageRef image, uint8_t* argb_data, int width, int height) ++void ScreencastEncoder::imageToARGB(CGImageRef image, uint8_t* argb_data, int width, int height, Optional scale) +{ + size_t bitsPerComponent = 8; + size_t bytesPerPixel = 4; + size_t bytesPerRow = bytesPerPixel * width; + RetainPtr colorSpace = adoptCF(CGColorSpaceCreateDeviceRGB()); + RetainPtr context = adoptCF(CGBitmapContextCreate(argb_data, width, height, bitsPerComponent, bytesPerRow, colorSpace.get(), kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Little)); -+ ++ if (scale) { ++ CGContextScaleCTM(context.get(), *scale, *scale); ++ // Ensure that top-left cornder stays in place. ++ CGContextTranslateCTM(context.get(), 0, ((1 - *scale) / *scale) * height); ++ } + size_t imageWidth = CGImageGetWidth(image); + size_t imageHeight = CGImageGetHeight(image); + CGContextDrawImage(context.get(), CGRectMake(0, 0, imageWidth, imageHeight), image);