- Revision
- 253495
- Author
- [email protected]
- Date
- 2019-12-13 13:22:23 -0800 (Fri, 13 Dec 2019)
Log Message
Implement encoding/decoding for DisplayList::DrawNativeImage
https://bugs.webkit.org/show_bug.cgi?id=205200
Reviewed by Simon Fraser.
Source/WebCore:
Implements basic encoding and decoding for the DrawNativeImage drawing item, such that it can be sent and
replayed in the GPU process. See WebKit ChangeLogs for more details. Eventually, we should avoid calling into
drawNativeImage in the web process altogether, but for now, both DrawNativeImage and DrawImage drawing items
rely on drawing native images into ImageBuffers. See: <https://webkit.org/b/205213>.
* platform/graphics/NativeImage.h:
Add a NativeImageHandle wrapper around a NativeImagePtr to make it simpler to decode and encode NativeImagePtrs
using << and >> operators.
* platform/graphics/displaylists/DisplayListItems.cpp:
* platform/graphics/displaylists/DisplayListItems.h:
(WebCore::DisplayList::DrawNativeImage::encode const):
(WebCore::DisplayList::DrawNativeImage::decode):
(WebCore::DisplayList::Item::encode const):
(WebCore::DisplayList::Item::decode):
Source/WebKit:
Add helper functions to encode and decode NativeImagePtr (RetainPtr<CGImageRef> on Cocoa platforms). This
mirrors the implementation of encoding and decoding for WebCore::Image, which create and draws into
ShareableBitmap, and send a handle to the data over IPC.
* Shared/WebCoreArgumentCoders.cpp:
(IPC::encodeImage):
(IPC::decodeImage):
(IPC::encodeNativeImage):
(IPC::decodeNativeImage):
Additionally make Image and NativeImagePtr encoding and decoding helpers fail quickly in the case where the
ShareableBitmap failed to create a graphics context by having the encoder indicate whether a graphics context
was created, and having the decoder fail if the graphics context could not be created.
(IPC::encodeOptionalNativeImage):
(IPC::decodeOptionalNativeImage):
(IPC::ArgumentCoder<NativeImageHandle>::encode):
(IPC::ArgumentCoder<NativeImageHandle>::decode):
* Shared/WebCoreArgumentCoders.h:
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (253494 => 253495)
--- trunk/Source/WebCore/ChangeLog 2019-12-13 20:49:10 UTC (rev 253494)
+++ trunk/Source/WebCore/ChangeLog 2019-12-13 21:22:23 UTC (rev 253495)
@@ -1,3 +1,27 @@
+2019-12-13 Wenson Hsieh <[email protected]>
+
+ Implement encoding/decoding for DisplayList::DrawNativeImage
+ https://bugs.webkit.org/show_bug.cgi?id=205200
+
+ Reviewed by Simon Fraser.
+
+ Implements basic encoding and decoding for the DrawNativeImage drawing item, such that it can be sent and
+ replayed in the GPU process. See WebKit ChangeLogs for more details. Eventually, we should avoid calling into
+ drawNativeImage in the web process altogether, but for now, both DrawNativeImage and DrawImage drawing items
+ rely on drawing native images into ImageBuffers. See: <https://webkit.org/b/205213>.
+
+ * platform/graphics/NativeImage.h:
+
+ Add a NativeImageHandle wrapper around a NativeImagePtr to make it simpler to decode and encode NativeImagePtrs
+ using << and >> operators.
+
+ * platform/graphics/displaylists/DisplayListItems.cpp:
+ * platform/graphics/displaylists/DisplayListItems.h:
+ (WebCore::DisplayList::DrawNativeImage::encode const):
+ (WebCore::DisplayList::DrawNativeImage::decode):
+ (WebCore::DisplayList::Item::encode const):
+ (WebCore::DisplayList::Item::decode):
+
2019-12-13 youenn fablet <[email protected]>
Add support for WebIDL set-like forEach
Modified: trunk/Source/WebCore/platform/graphics/NativeImage.h (253494 => 253495)
--- trunk/Source/WebCore/platform/graphics/NativeImage.h 2019-12-13 20:49:10 UTC (rev 253494)
+++ trunk/Source/WebCore/platform/graphics/NativeImage.h 2019-12-13 21:22:23 UTC (rev 253495)
@@ -61,11 +61,16 @@
typedef RefPtr<SharedBitmap> NativeImagePtr;
#endif
-IntSize nativeImageSize(const NativeImagePtr&);
+WEBCORE_EXPORT IntSize nativeImageSize(const NativeImagePtr&);
bool nativeImageHasAlpha(const NativeImagePtr&);
Color nativeImageSinglePixelSolidColor(const NativeImagePtr&);
void drawNativeImage(const NativeImagePtr&, GraphicsContext&, const FloatRect&, const FloatRect&, const IntSize&, const ImagePaintingOptions&);
void clearNativeImageSubimages(const NativeImagePtr&);
+
+class NativeImageHandle {
+public:
+ NativeImagePtr image;
+};
}
Modified: trunk/Source/WebCore/platform/graphics/displaylists/DisplayListItems.cpp (253494 => 253495)
--- trunk/Source/WebCore/platform/graphics/displaylists/DisplayListItems.cpp 2019-12-13 20:49:10 UTC (rev 253494)
+++ trunk/Source/WebCore/platform/graphics/displaylists/DisplayListItems.cpp 2019-12-13 21:22:23 UTC (rev 253495)
@@ -668,7 +668,7 @@
, m_image(image)
#endif
, m_imageSize(imageSize)
- , m_destination(destRect)
+ , m_destinationRect(destRect)
, m_srcRect(srcRect)
, m_options(options)
{
@@ -677,10 +677,12 @@
#endif
}
+DrawNativeImage::~DrawNativeImage() = default;
+
void DrawNativeImage::apply(GraphicsContext& context) const
{
#if USE(CG)
- context.drawNativeImage(m_image, m_imageSize, m_destination, m_srcRect, m_options);
+ context.drawNativeImage(m_image, m_imageSize, m_destinationRect, m_srcRect, m_options);
#else
UNUSED_PARAM(context);
#endif
@@ -691,7 +693,7 @@
ts << static_cast<const DrawingItem&>(item);
// FIXME: dump more stuff.
ts.dumpProperty("source-rect", item.source());
- ts.dumpProperty("dest-rect", item.destination());
+ ts.dumpProperty("dest-rect", item.destinationRect());
return ts;
}
#endif
Modified: trunk/Source/WebCore/platform/graphics/displaylists/DisplayListItems.h (253494 => 253495)
--- trunk/Source/WebCore/platform/graphics/displaylists/DisplayListItems.h 2019-12-13 20:49:10 UTC (rev 253494)
+++ trunk/Source/WebCore/platform/graphics/displaylists/DisplayListItems.h 2019-12-13 21:22:23 UTC (rev 253495)
@@ -1329,26 +1329,82 @@
return adoptRef(*new DrawNativeImage(image, imageSize, destRect, srcRect, options));
}
+ WEBCORE_EXPORT virtual ~DrawNativeImage();
+
FloatRect source() const { return m_srcRect; }
- FloatRect destination() const { return m_destination; }
+ FloatRect destinationRect() const { return m_destinationRect; }
+ template<class Encoder> void encode(Encoder&) const;
+ template<class Decoder> static Optional<Ref<DrawNativeImage>> decode(Decoder&);
+
private:
- DrawNativeImage(const NativeImagePtr&, const FloatSize& selfSize, const FloatRect& destRect, const FloatRect& srcRect, const ImagePaintingOptions&);
+ WEBCORE_EXPORT DrawNativeImage(const NativeImagePtr&, const FloatSize& selfSize, const FloatRect& destRect, const FloatRect& srcRect, const ImagePaintingOptions&);
void apply(GraphicsContext&) const override;
- Optional<FloatRect> localBounds(const GraphicsContext&) const override { return m_destination; }
+ Optional<FloatRect> localBounds(const GraphicsContext&) const override { return m_destinationRect; }
#if USE(CG)
- RetainPtr<CGImageRef> m_image;
+ NativeImagePtr m_image;
#endif
FloatSize m_imageSize;
- FloatRect m_destination;
+ FloatRect m_destinationRect;
FloatRect m_srcRect;
ImagePaintingOptions m_options;
};
+
+template<class Encoder>
+void DrawNativeImage::encode(Encoder& encoder) const
+{
+#if USE(CG)
+ NativeImageHandle handle { m_image };
+ encoder << handle;
#endif
+ encoder << m_imageSize;
+ encoder << m_destinationRect;
+ encoder << m_srcRect;
+ encoder << m_options;
+}
+template<class Decoder>
+Optional<Ref<DrawNativeImage>> DrawNativeImage::decode(Decoder& decoder)
+{
+#if USE(CG)
+ Optional<NativeImageHandle> handle;
+ decoder >> handle;
+ if (!handle)
+ return WTF::nullopt;
+#endif
+
+ Optional<FloatSize> imageSize;
+ decoder >> imageSize;
+ if (!imageSize)
+ return WTF::nullopt;
+
+ Optional<FloatRect> destinationRect;
+ decoder >> destinationRect;
+ if (!destinationRect)
+ return WTF::nullopt;
+
+ Optional<FloatRect> srcRect;
+ decoder >> srcRect;
+ if (!srcRect)
+ return WTF::nullopt;
+
+ Optional<ImagePaintingOptions> options;
+ decoder >> options;
+ if (!options)
+ return WTF::nullopt;
+
+#if USE(CG)
+ NativeImagePtr image = handle->image;
+#else
+ NativeImagePtr image = nullptr;
+#endif
+ return DrawNativeImage::create(image, *imageSize, *destinationRect, *srcRect, *options);
+}
+#endif
+
class DrawPattern : public DrawingItem {
public:
static Ref<DrawPattern> create(Image& image, const FloatRect& destRect, const FloatRect& tileRect, const AffineTransform& patternTransform, const FloatPoint& phase, const FloatSize& spacing, const ImagePaintingOptions& options)
@@ -2679,7 +2735,7 @@
break;
#if USE(CG) || USE(CAIRO) || USE(DIRECT2D)
case ItemType::DrawNativeImage:
- WTFLogAlways("DisplayList::Item::encode cannot yet encode DrawNativeImage");
+ encoder << downcast<DrawNativeImage>(*this);
break;
#endif
case ItemType::DrawPattern:
@@ -2859,7 +2915,8 @@
break;
#if USE(CG) || USE(CAIRO) || USE(DIRECT2D)
case ItemType::DrawNativeImage:
- WTFLogAlways("DisplayList::Item::decode cannot yet decode DrawNativeImage");
+ if (auto item = DrawNativeImage::decode(decoder))
+ return static_reference_cast<Item>(WTFMove(*item));
break;
#endif
case ItemType::DrawPattern:
Modified: trunk/Source/WebKit/ChangeLog (253494 => 253495)
--- trunk/Source/WebKit/ChangeLog 2019-12-13 20:49:10 UTC (rev 253494)
+++ trunk/Source/WebKit/ChangeLog 2019-12-13 21:22:23 UTC (rev 253495)
@@ -1,3 +1,30 @@
+2019-12-13 Wenson Hsieh <[email protected]>
+
+ Implement encoding/decoding for DisplayList::DrawNativeImage
+ https://bugs.webkit.org/show_bug.cgi?id=205200
+
+ Reviewed by Simon Fraser.
+
+ Add helper functions to encode and decode NativeImagePtr (RetainPtr<CGImageRef> on Cocoa platforms). This
+ mirrors the implementation of encoding and decoding for WebCore::Image, which create and draws into
+ ShareableBitmap, and send a handle to the data over IPC.
+
+ * Shared/WebCoreArgumentCoders.cpp:
+ (IPC::encodeImage):
+ (IPC::decodeImage):
+ (IPC::encodeNativeImage):
+ (IPC::decodeNativeImage):
+
+ Additionally make Image and NativeImagePtr encoding and decoding helpers fail quickly in the case where the
+ ShareableBitmap failed to create a graphics context by having the encoder indicate whether a graphics context
+ was created, and having the decoder fail if the graphics context could not be created.
+
+ (IPC::encodeOptionalNativeImage):
+ (IPC::decodeOptionalNativeImage):
+ (IPC::ArgumentCoder<NativeImageHandle>::encode):
+ (IPC::ArgumentCoder<NativeImageHandle>::decode):
+ * Shared/WebCoreArgumentCoders.h:
+
2019-12-13 Per Arne Vollan <[email protected]>
[iOS] Deny mach lookup access to "*.apple-extension-service" in the WebContent process
Modified: trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp (253494 => 253495)
--- trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp 2019-12-13 20:49:10 UTC (rev 253494)
+++ trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp 2019-12-13 21:22:23 UTC (rev 253495)
@@ -57,6 +57,7 @@
#include <WebCore/Length.h>
#include <WebCore/LengthBox.h>
#include <WebCore/MediaSelectionOption.h>
+#include <WebCore/NativeImage.h>
#include <WebCore/Pasteboard.h>
#include <WebCore/PluginData.h>
#include <WebCore/PromisedAttachmentInfo.h>
@@ -981,9 +982,12 @@
{
RefPtr<ShareableBitmap> bitmap = ShareableBitmap::createShareable(IntSize(image.size()), { });
auto graphicsContext = bitmap->createGraphicsContext();
- if (graphicsContext)
- graphicsContext->drawImage(image, IntPoint());
+ encoder << !!graphicsContext;
+ if (!graphicsContext)
+ return;
+ graphicsContext->drawImage(image, IntPoint());
+
ShareableBitmap::Handle handle;
bitmap->createHandle(handle);
@@ -992,6 +996,11 @@
static bool decodeImage(Decoder& decoder, RefPtr<Image>& image)
{
+ Optional<bool> didCreateGraphicsContext;
+ decoder >> didCreateGraphicsContext;
+ if (!didCreateGraphicsContext.hasValue() || !didCreateGraphicsContext.value())
+ return false;
+
ShareableBitmap::Handle handle;
if (!decoder.decode(handle))
return false;
@@ -1040,6 +1049,82 @@
return true;
}
+static void encodeNativeImage(Encoder& encoder, NativeImagePtr image)
+{
+ auto imageSize = nativeImageSize(image);
+ auto bitmap = ShareableBitmap::createShareable(imageSize, { });
+ auto graphicsContext = bitmap->createGraphicsContext();
+ encoder << !!graphicsContext;
+ if (!graphicsContext)
+ return;
+
+ graphicsContext->drawNativeImage(image, { }, FloatRect({ }, imageSize), FloatRect({ }, imageSize));
+
+ ShareableBitmap::Handle handle;
+ bitmap->createHandle(handle);
+
+ encoder << handle;
+}
+
+static bool decodeNativeImage(Decoder& decoder, NativeImagePtr& nativeImage)
+{
+ Optional<bool> didCreateGraphicsContext;
+ decoder >> didCreateGraphicsContext;
+ if (!didCreateGraphicsContext.hasValue() || !didCreateGraphicsContext.value())
+ return false;
+
+ ShareableBitmap::Handle handle;
+ if (!decoder.decode(handle))
+ return false;
+
+ auto bitmap = ShareableBitmap::create(handle);
+ if (!bitmap)
+ return false;
+
+ auto image = bitmap->createImage();
+ if (!image)
+ return false;
+
+ nativeImage = image->nativeImage();
+ if (!nativeImage)
+ return false;
+
+ return true;
+}
+
+static void encodeOptionalNativeImage(Encoder& encoder, NativeImagePtr image)
+{
+ bool hasImage = !!image;
+ encoder << hasImage;
+
+ if (hasImage)
+ encodeNativeImage(encoder, image);
+}
+
+static bool decodeOptionalNativeImage(Decoder& decoder, NativeImagePtr& image)
+{
+ image = nullptr;
+
+ bool hasImage;
+ if (!decoder.decode(hasImage))
+ return false;
+
+ if (!hasImage)
+ return true;
+
+ return decodeNativeImage(decoder, image);
+}
+
+void ArgumentCoder<NativeImageHandle>::encode(Encoder& encoder, const NativeImageHandle& imageHandle)
+{
+ encodeOptionalNativeImage(encoder, imageHandle.image.get());
+}
+
+bool ArgumentCoder<NativeImageHandle>::decode(Decoder& decoder, NativeImageHandle& imageHandle)
+{
+ return decodeOptionalNativeImage(decoder, imageHandle.image);
+}
+
#if !PLATFORM(IOS_FAMILY)
void ArgumentCoder<Cursor>::encode(Encoder& encoder, const Cursor& cursor)
{
Modified: trunk/Source/WebKit/Shared/WebCoreArgumentCoders.h (253494 => 253495)
--- trunk/Source/WebKit/Shared/WebCoreArgumentCoders.h 2019-12-13 20:49:10 UTC (rev 253494)
+++ trunk/Source/WebKit/Shared/WebCoreArgumentCoders.h 2019-12-13 21:22:23 UTC (rev 253495)
@@ -89,6 +89,7 @@
class LayoutSize;
class LayoutPoint;
class LinearTimingFunction;
+class NativeImageHandle;
class Notification;
class PasteboardCustomData;
class ProtectionSpace;
@@ -383,6 +384,11 @@
static bool decode(Decoder&, WebCore::ImageHandle&);
};
+template<> struct ArgumentCoder<WebCore::NativeImageHandle> {
+ static void encode(Encoder&, const WebCore::NativeImageHandle&);
+ static bool decode(Decoder&, WebCore::NativeImageHandle&);
+};
+
template<> struct ArgumentCoder<WebCore::ResourceRequest> {
static void encode(Encoder&, const WebCore::ResourceRequest&);
static bool decode(Decoder&, WebCore::ResourceRequest&);