Title: [292864] trunk/Source/WebCore
- Revision
- 292864
- Author
- [email protected]
- Date
- 2022-04-14 07:13:38 -0700 (Thu, 14 Apr 2022)
Log Message
[GTK][WPE] Provide WK2 IPC encoding, decoding methods for the DMABufObject type
https://bugs.webkit.org/show_bug.cgi?id=239038
Reviewed by Adrian Perez de Castro.
Provide encoding and decoding methods on the DMABufObject class,
enabling transport over IPC channels.
There are two separate ref-qualified encoding methods. When encoding
an object that's managed through an lvalue reference, we duplicate the
file descriptor objects since the DMABufObject will live on. When
managed through an rvalue object, we know the object's lifetime is
intended to be limited to this encoding process, so we can avoid the
file descriptor duplication and move the fd values into the encoder.
* platform/graphics/gbm/DMABufObject.h:
(WebCore::DMABufObject::encode const):
(WebCore::DMABufObject::encode):
(WebCore::DMABufObject::decode):
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (292863 => 292864)
--- trunk/Source/WebCore/ChangeLog 2022-04-14 14:12:02 UTC (rev 292863)
+++ trunk/Source/WebCore/ChangeLog 2022-04-14 14:13:38 UTC (rev 292864)
@@ -1,3 +1,25 @@
+2022-04-14 Zan Dobersek <[email protected]>
+
+ [GTK][WPE] Provide WK2 IPC encoding, decoding methods for the DMABufObject type
+ https://bugs.webkit.org/show_bug.cgi?id=239038
+
+ Reviewed by Adrian Perez de Castro.
+
+ Provide encoding and decoding methods on the DMABufObject class,
+ enabling transport over IPC channels.
+
+ There are two separate ref-qualified encoding methods. When encoding
+ an object that's managed through an lvalue reference, we duplicate the
+ file descriptor objects since the DMABufObject will live on. When
+ managed through an rvalue object, we know the object's lifetime is
+ intended to be limited to this encoding process, so we can avoid the
+ file descriptor duplication and move the fd values into the encoder.
+
+ * platform/graphics/gbm/DMABufObject.h:
+ (WebCore::DMABufObject::encode const):
+ (WebCore::DMABufObject::encode):
+ (WebCore::DMABufObject::decode):
+
2022-04-14 Youenn Fablet <[email protected]>
Expose workers as service worker clients and implement registration matching for dedicated workers
Modified: trunk/Source/WebCore/platform/graphics/gbm/DMABufObject.h (292863 => 292864)
--- trunk/Source/WebCore/platform/graphics/gbm/DMABufObject.h 2022-04-14 14:12:02 UTC (rev 292863)
+++ trunk/Source/WebCore/platform/graphics/gbm/DMABufObject.h 2022-04-14 14:13:38 UTC (rev 292864)
@@ -31,6 +31,7 @@
#include <array>
#include <cstddef>
#include <cstdint>
+#include <optional>
#include <unistd.h>
#include <wtf/Noncopyable.h>
#include <wtf/unix/UnixFileDescriptor.h>
@@ -49,6 +50,10 @@
DMABufObject(DMABufObject&&) = default;
DMABufObject& operator=(DMABufObject&&) = default;
+ template<class Encoder> void encode(Encoder&) const &;
+ template<class Encoder> void encode(Encoder&) &&;
+ template<class Decoder> static std::optional<DMABufObject> decode(Decoder&);
+
uintptr_t handle { 0 };
DMABufFormat format { };
uint32_t width { 0 };
@@ -60,4 +65,88 @@
std::array<uint64_t, DMABufFormat::c_maxPlanes> modifier { 0, 0, 0, 0 };
};
+template<class Encoder>
+void DMABufObject::encode(Encoder& encoder) const &
+{
+ encoder << handle << uint32_t(format.fourcc) << width << height;
+ encoder << releaseFlag.fd.duplicate();
+
+ for (unsigned i = 0; i < DMABufFormat::c_maxPlanes; ++i) {
+ encoder << fd[i].duplicate();
+ encoder << offset[i] << stride[i] << modifier[i];
+ }
+}
+
+template<class Encoder>
+void DMABufObject::encode(Encoder& encoder) &&
+{
+ encoder << handle << uint32_t(format.fourcc) << width << height;
+ encoder << WTFMove(releaseFlag.fd);
+
+ for (unsigned i = 0; i < DMABufFormat::c_maxPlanes; ++i) {
+ encoder << WTFMove(fd[i]);
+ encoder << offset[i] << stride[i] << modifier[i];
+ }
+}
+
+template<class Decoder>
+std::optional<DMABufObject> DMABufObject::decode(Decoder& decoder)
+{
+ std::optional<uintptr_t> handle;
+ decoder >> handle;
+ if (!handle)
+ return std::nullopt;
+ std::optional<uint32_t> fourcc;
+ decoder >> fourcc;
+ if (!fourcc)
+ return std::nullopt;
+ std::optional<uint32_t> width;
+ decoder >> width;
+ if (!width)
+ return std::nullopt;
+ std::optional<uint32_t> height;
+ decoder >> height;
+ if (!height)
+ return std::nullopt;
+
+ DMABufObject dmabufObject(*handle);
+ dmabufObject.format = DMABufFormat::create(*fourcc);
+ dmabufObject.width = *width;
+ dmabufObject.height = *height;
+
+ std::optional<WTF::UnixFileDescriptor> releaseFlag;
+ decoder >> releaseFlag;
+ if (!releaseFlag)
+ return std::nullopt;
+ dmabufObject.releaseFlag.fd = WTFMove(*releaseFlag);
+
+ for (unsigned i = 0; i < DMABufFormat::c_maxPlanes; ++i) {
+ std::optional<WTF::UnixFileDescriptor> fd;
+ decoder >> fd;
+ if (!fd)
+ return std::nullopt;
+ dmabufObject.fd[i] = WTFMove(*fd);
+
+ std::optional<size_t> offset;
+ decoder >> offset;
+ if (!offset)
+ return std::nullopt;
+ dmabufObject.offset[i] = *offset;
+
+ std::optional<uint32_t> stride;
+ decoder >> stride;
+ if (!stride)
+ return std::nullopt;
+ dmabufObject.stride[i] = *stride;
+
+ std::optional<uint64_t> modifier;
+ decoder >> modifier;
+ if (!modifier)
+ return std::nullopt;
+ dmabufObject.modifier[i] = *modifier;
+ }
+
+ return dmabufObject;
+}
+
} // namespace WebCore
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes