Title: [272175] trunk/Source/WebKit
- Revision
- 272175
- Author
- [email protected]
- Date
- 2021-02-01 13:42:27 -0800 (Mon, 01 Feb 2021)
Log Message
Add a cross-platform helper method to generate shareable bitmaps from rendered images
https://bugs.webkit.org/show_bug.cgi?id=221217
Reviewed by Tim Horton.
Pull what is currently iOS-specific logic in `imagePositionInformation` out into a private, cross-platform
helper method on `WebPage`. No change in behavior.
* WebProcess/WebPage/WebPage.cpp:
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::imagePositionInformation):
Modified Paths
Diff
Modified: trunk/Source/WebKit/ChangeLog (272174 => 272175)
--- trunk/Source/WebKit/ChangeLog 2021-02-01 21:40:55 UTC (rev 272174)
+++ trunk/Source/WebKit/ChangeLog 2021-02-01 21:42:27 UTC (rev 272175)
@@ -1,3 +1,18 @@
+2021-02-01 Wenson Hsieh <[email protected]>
+
+ Add a cross-platform helper method to generate shareable bitmaps from rendered images
+ https://bugs.webkit.org/show_bug.cgi?id=221217
+
+ Reviewed by Tim Horton.
+
+ Pull what is currently iOS-specific logic in `imagePositionInformation` out into a private, cross-platform
+ helper method on `WebPage`. No change in behavior.
+
+ * WebProcess/WebPage/WebPage.cpp:
+ * WebProcess/WebPage/WebPage.h:
+ * WebProcess/WebPage/ios/WebPageIOS.mm:
+ (WebKit::imagePositionInformation):
+
2021-02-01 Stephan Szabo <[email protected]>
[PlayStation] Build fix after r272058
Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp (272174 => 272175)
--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp 2021-02-01 21:40:55 UTC (rev 272174)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp 2021-02-01 21:42:27 UTC (rev 272175)
@@ -178,6 +178,7 @@
#include <WebCore/FrameLoaderTypes.h>
#include <WebCore/FrameView.h>
#include <WebCore/FullscreenManager.h>
+#include <WebCore/GeometryUtilities.h>
#include <WebCore/HTMLAttachmentElement.h>
#include <WebCore/HTMLFormElement.h>
#include <WebCore/HTMLImageElement.h>
@@ -216,6 +217,7 @@
#include <WebCore/RegistrableDomain.h>
#include <WebCore/RemoteDOMWindow.h>
#include <WebCore/RemoteFrame.h>
+#include <WebCore/RenderImage.h>
#include <WebCore/RenderLayer.h>
#include <WebCore/RenderTheme.h>
#include <WebCore/RenderTreeAsText.h>
@@ -7203,6 +7205,40 @@
}
#endif
+RefPtr<ShareableBitmap> WebPage::shareableBitmap(RenderImage& renderImage, Optional<FloatSize> screenSizeInPixels) const
+{
+ auto* cachedImage = renderImage.cachedImage();
+ if (!cachedImage || cachedImage->errorOccurred())
+ return nullptr;
+
+ auto* image = cachedImage->imageForRenderer(&renderImage);
+ if (!image || image->width() <= 1 || image->height() <= 1)
+ return nullptr;
+
+ auto bitmapSize = cachedImage->imageSizeForRenderer(&renderImage);
+ if (screenSizeInPixels) {
+ auto scaledSize = largestRectWithAspectRatioInsideRect(bitmapSize.width() / bitmapSize.height(), { FloatPoint(), *screenSizeInPixels }).size();
+ bitmapSize = scaledSize.width() < bitmapSize.width() ? scaledSize : bitmapSize;
+ }
+
+ // FIXME: Only select ExtendedColor on images known to need wide gamut.
+ ShareableBitmap::Configuration bitmapConfiguration;
+#if USE(CG)
+ bitmapConfiguration.colorSpace.cgColorSpace = screenColorSpace(corePage()->mainFrame().view());
+#endif
+
+ auto sharedBitmap = ShareableBitmap::createShareable(IntSize(bitmapSize), bitmapConfiguration);
+ if (!sharedBitmap)
+ return nullptr;
+
+ auto graphicsContext = sharedBitmap->createGraphicsContext();
+ if (!graphicsContext)
+ return nullptr;
+
+ graphicsContext->drawImage(*image, FloatRect(0, 0, bitmapSize.width(), bitmapSize.height()), { renderImage.imageOrientation() });
+ return sharedBitmap;
+}
+
} // namespace WebKit
#undef RELEASE_LOG_IF_ALLOWED
Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.h (272174 => 272175)
--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.h 2021-02-01 21:40:55 UTC (rev 272174)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.h 2021-02-01 21:42:27 UTC (rev 272175)
@@ -192,6 +192,7 @@
class Page;
class PrintContext;
class Range;
+class RenderImage;
class ResourceRequest;
class ResourceResponse;
class SelectionData;
@@ -1389,6 +1390,8 @@
bool shouldUsePDFPlugin(const String& contentType, StringView path) const;
#endif
+ RefPtr<ShareableBitmap> shareableBitmap(WebCore::RenderImage&, Optional<WebCore::FloatSize> screenSizeInPixels = WTF::nullopt) const;
+
private:
WebPage(WebCore::PageIdentifier, WebPageCreationParameters&&);
Modified: trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm (272174 => 272175)
--- trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm 2021-02-01 21:40:55 UTC (rev 272174)
+++ trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm 2021-02-01 21:42:27 UTC (rev 272175)
@@ -2680,30 +2680,8 @@
info.imageURL = element.document().completeURL(renderImage.cachedImage()->url().string());
info.isAnimatedImage = image->isAnimated();
- if (!request.includeSnapshot && !request.includeImageData)
- return;
-
- FloatSize screenSizeInPixels = screenSize();
- FloatSize imageSize = renderImage.cachedImage()->imageSizeForRenderer(&renderImage);
-
- screenSizeInPixels.scale(page.corePage()->deviceScaleFactor());
- FloatSize scaledSize = largestRectWithAspectRatioInsideRect(imageSize.width() / imageSize.height(), FloatRect(0, 0, screenSizeInPixels.width(), screenSizeInPixels.height())).size();
- FloatSize bitmapSize = scaledSize.width() < imageSize.width() ? scaledSize : imageSize;
-
- // FIXME: Only select ExtendedColor on images known to need wide gamut
- ShareableBitmap::Configuration bitmapConfiguration;
- bitmapConfiguration.colorSpace.cgColorSpace = screenColorSpace(page.corePage()->mainFrame().view());
-
- auto sharedBitmap = ShareableBitmap::createShareable(IntSize(bitmapSize), bitmapConfiguration);
- if (!sharedBitmap)
- return;
-
- auto graphicsContext = sharedBitmap->createGraphicsContext();
- if (!graphicsContext)
- return;
-
- graphicsContext->drawImage(*image, FloatRect(0, 0, bitmapSize.width(), bitmapSize.height()), { renderImage.imageOrientation() });
- info.image = sharedBitmap;
+ if (request.includeSnapshot || request.includeImageData)
+ info.image = page.shareableBitmap(renderImage, screenSize() * page.corePage()->deviceScaleFactor());
}
static void boundsPositionInformation(RenderObject& renderer, InteractionInformationAtPosition& info)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes