Skip to content

Commit

Permalink
Generate serialization of WCBackingStore
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=268502

Reviewed by Alex Christensen.

Modify `WCBackingStore` so its serialization can be generated. Pass an
`ImageBufferBackendHandle` through IPC. Add a constructor to create from
a handle, and a method to retrieve a handle from an instance. Adding
these allows the serialization framework to work on the class.

* Source/WebKit/PlatformWin.cmake:
* Source/WebKit/WebProcess/WebPage/wc/WCBackingStore.cpp: Copied from Source/WebKit/WebProcess/WebPage/wc/WCBackingStore.h.
(WebKit::WCBackingStore::WCBackingStore):
(WebKit::WCBackingStore::handle const):
* Source/WebKit/WebProcess/WebPage/wc/WCBackingStore.h:
(WebKit::WCBackingStore::encode const): Deleted.
(WebKit::WCBackingStore::decode): Deleted.
* Source/WebKit/WebProcess/WebPage/wc/WCBackingStore.serialization.in: Added.

Canonical link: https://commits.webkit.org/273938@main
  • Loading branch information
donny-dont committed Feb 1, 2024
1 parent 49b7512 commit e45afd8
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 25 deletions.
2 changes: 2 additions & 0 deletions Source/WebKit/PlatformWin.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ list(APPEND WebKit_SOURCES

WebProcess/WebPage/wc/DrawingAreaWC.cpp
WebProcess/WebPage/wc/GraphicsLayerWC.cpp
WebProcess/WebPage/wc/WCBackingStore.cpp
WebProcess/WebPage/wc/WCLayerFactory.cpp
WebProcess/WebPage/wc/WCTileGrid.cpp

Expand Down Expand Up @@ -172,6 +173,7 @@ list(APPEND WebKit_MESSAGES_IN_FILES
)

list(APPEND WebKit_SERIALIZATION_IN_FILES
WebProcess/WebPage/wc/WCBackingStore.serialization.in
WebProcess/WebPage/wc/WCUpdateInfo.serialization.in
)

Expand Down
55 changes: 55 additions & 0 deletions Source/WebKit/WebProcess/WebPage/wc/WCBackingStore.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright (C) 2024 Sony Interactive Entertainment Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "config.h"
#include "WCBackingStore.h"

#if USE(GRAPHICS_LAYER_WC)

#include "ImageBufferBackendHandleSharing.h"

namespace WebKit {

WCBackingStore::WCBackingStore(std::optional<ImageBufferBackendHandle>&& handle)
{
if (auto* imageHandle = handle ? std::get_if<ShareableBitmap::Handle>(&*handle) : nullptr)
m_bitmap = ShareableBitmap::create(WTFMove(*imageHandle));
}

std::optional<ImageBufferBackendHandle> WCBackingStore::handle() const
{
if (!m_imageBuffer)
return std::nullopt;

auto* sharing = m_imageBuffer->toBackendSharing();
if (!is<ImageBufferBackendHandleSharing>(sharing))
return std::nullopt;

return dynamicDowncast<ImageBufferBackendHandleSharing>(*sharing)->createBackendHandle();
}

} // namespace WebKit

#endif // USE(GRAPHICS_LAYER_WC)
29 changes: 4 additions & 25 deletions Source/WebKit/WebProcess/WebPage/wc/WCBackingStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#if USE(GRAPHICS_LAYER_WC)

#include "ImageBufferBackendHandle.h"
#include "ImageBufferBackendHandleSharing.h"
#include <WebCore/ImageBuffer.h>

namespace WebKit {
Expand All @@ -41,32 +40,12 @@ class WCBackingStore {
void setImageBuffer(RefPtr<WebCore::ImageBuffer>&& image) { m_imageBuffer = WTFMove(image); }
ShareableBitmap* bitmap() const { return m_bitmap.get(); }

template<class Encoder>
void encode(Encoder& encoder) const
{
std::optional<ImageBufferBackendHandle> handle;
if (m_imageBuffer) {
auto* sharing = m_imageBuffer->toBackendSharing();
if (is<ImageBufferBackendHandleSharing>(sharing))
handle = downcast<ImageBufferBackendHandleSharing>(*sharing).createBackendHandle();
}
encoder << WTFMove(handle);
}

template <class Decoder>
static WARN_UNUSED_RETURN bool decode(Decoder& decoder, WCBackingStore& result)
{
auto handle = decoder.template decode<std::optional<ImageBufferBackendHandle>>();
if (UNLIKELY(!decoder.isValid()))
return false;

if (*handle)
result.m_bitmap = ShareableBitmap::create(WTFMove(std::get<ShareableBitmap::Handle>(**handle)));
private:
friend struct IPC::ArgumentCoder<WCBackingStore, void>;

return true;
}
WCBackingStore(std::optional<ImageBufferBackendHandle>&&);
std::optional<ImageBufferBackendHandle> handle() const;

private:
RefPtr<WebCore::ImageBuffer> m_imageBuffer;
RefPtr<ShareableBitmap> m_bitmap;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright (C) 2024 Sony Interactive Entertainment Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#if USE(GRAPHICS_LAYER_WC)

class WebKit::WCBackingStore {
std::optional<WebKit::ImageBufferBackendHandle> handle();
}

#endif

0 comments on commit e45afd8

Please sign in to comment.