Skip to content

Commit e203e1a

Browse files
shallawaSaid Abou-Hallawa
authored andcommitted
Implement the IDL changes for WebCodecsImageDecoder
https://bugs.webkit.org/show_bug.cgi?id=320947 rdar://183978625 Reviewed by Simon Fraser. This change implements the IDL additions which are required for the WebCodecs ImageDecoder[1]. The WebCore sources were changed just to allow compiling. New functionalities will be filled later. An internal feature flag for enabling WebCodecsImageDecoder is added. It is off by default for now. [1] https://w3c.github.io/webcodecs/#imagedecoder-interface * Source/WTF/Scripts/Preferences/UnifiedWebPreferences.yaml: * Source/WebCore/DerivedSources.make: * Source/WebCore/Modules/webcodecs/WebCodecsImageDecodeResult.h: Added. * Source/WebCore/Modules/webcodecs/WebCodecsImageDecodeResult.idl: Added. * Source/WebCore/Modules/webcodecs/WebCodecsImageDecoder.cpp: Added. (WebCore::WebCodecsImageDecoder::create): (WebCore::WebCodecsImageDecoder::WebCodecsImageDecoder): (WebCore::WebCodecsImageDecoder::tracks const): (WebCore::WebCodecsImageDecoder::decode): (WebCore::WebCodecsImageDecoder::reset): (WebCore::WebCodecsImageDecoder::close): (WebCore::WebCodecsImageDecoder::isTypeSupported): (WebCore::WebCodecsImageDecoder::suspend): (WebCore::WebCodecsImageDecoder::stop): * Source/WebCore/Modules/webcodecs/WebCodecsImageDecoder.h: Added. * Source/WebCore/Modules/webcodecs/WebCodecsImageDecoder.idl: Added. * Source/WebCore/Modules/webcodecs/WebCodecsImageTrack.cpp: Added. (WebCore::WebCodecsImageTrack::create): (WebCore::WebCodecsImageTrack::WebCodecsImageTrack): * Source/WebCore/Modules/webcodecs/WebCodecsImageTrack.h: Added. (WebCore::WebCodecsImageTrack::animated const): (WebCore::WebCodecsImageTrack::frameCount const): (WebCore::WebCodecsImageTrack::repetitionCount const): * Source/WebCore/Modules/webcodecs/WebCodecsImageTrack.idl: Added. * Source/WebCore/Modules/webcodecs/WebCodecsImageTrackList.cpp: Added. (WebCore::WebCodecsImageTrackList::create): (WebCore::WebCodecsImageTrackList::WebCodecsImageTrackList): (WebCore::WebCodecsImageTrackList::item): (WebCore::WebCodecsImageTrackList::selectedTrack const): (WebCore::WebCodecsImageTrackList::item const): * Source/WebCore/Modules/webcodecs/WebCodecsImageTrackList.h: Added. (WebCore::WebCodecsImageTrackList::length const): (WebCore::WebCodecsImageTrackList::isSupportedPropertyIndex const): * Source/WebCore/Modules/webcodecs/WebCodecsImageTrackList.idl: Added. * Source/WebCore/Sources.txt: * Source/WebCore/WebCore.xcodeproj/project.pbxproj: * Source/WebCore/bindings/js/JSWebCodecsImageDecoderCustom.cpp: Added. (WebCore::JSWebCodecsImageDecoder::visitAdditionalChildrenInGCThread): * Source/WebCore/bindings/js/WebCoreBuiltinNames.h: * Source/WebCore/dom/EventTargetFactory.in: * Source/WebCore/CMakeLists.txt: * Source/WebCore/Modules/websockets/WebSocketChannelInspector.h: Canonical link: https://commits.webkit.org/318598@main
1 parent 6bdb4f6 commit e203e1a

20 files changed

Lines changed: 783 additions & 1 deletion

Source/WTF/Scripts/Preferences/UnifiedWebPreferences.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10151,6 +10151,22 @@ WebCodecsHEVCEnabled:
1015110151
"PLATFORM(COCOA)": true
1015210152
default: false
1015310153

10154+
WebCodecsImageEnabled:
10155+
type: bool
10156+
status: unstable
10157+
category: media
10158+
webcoreOnChange: setNeedsRelayoutAllFrames
10159+
humanReadableName: "WebCodecs Image API"
10160+
humanReadableDescription: "Enable WebCodecs Image API"
10161+
condition: ENABLE(WEB_CODECS)
10162+
defaultValue:
10163+
WebKitLegacy:
10164+
default: false
10165+
WebKit:
10166+
default: false
10167+
WebCore:
10168+
default: false
10169+
1015410170
WebCodecsVideoEnabled:
1015510171
type: bool
1015610172
status: mature

Source/WebCore/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -883,6 +883,10 @@ set(WebCore_NON_SVG_IDL_FILES
883883
Modules/webcodecs/WebCodecsEncodedVideoChunkOutputCallback.idl
884884
Modules/webcodecs/WebCodecsEncodedVideoChunkType.idl
885885
Modules/webcodecs/WebCodecsErrorCallback.idl
886+
Modules/webcodecs/WebCodecsImageDecodeResult.idl
887+
Modules/webcodecs/WebCodecsImageDecoder.idl
888+
Modules/webcodecs/WebCodecsImageTrack.idl
889+
Modules/webcodecs/WebCodecsImageTrackList.idl
886890
Modules/webcodecs/WebCodecsSvcOutputMetadata.idl
887891
Modules/webcodecs/WebCodecsVideoDecoder.idl
888892
Modules/webcodecs/WebCodecsVideoDecoderConfig.idl

Source/WebCore/DerivedSources.make

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,10 @@ JS_BINDING_IDLS := \
818818
$(WebCore)/Modules/webcodecs/WebCodecsEncodedVideoChunkOutputCallback.idl \
819819
$(WebCore)/Modules/webcodecs/WebCodecsEncodedVideoChunkType.idl \
820820
$(WebCore)/Modules/webcodecs/WebCodecsErrorCallback.idl \
821+
$(WebCore)/Modules/webcodecs/WebCodecsImageDecodeResult.idl \
822+
$(WebCore)/Modules/webcodecs/WebCodecsImageDecoder.idl \
823+
$(WebCore)/Modules/webcodecs/WebCodecsImageTrack.idl \
824+
$(WebCore)/Modules/webcodecs/WebCodecsImageTrackList.idl \
821825
$(WebCore)/Modules/webcodecs/WebCodecsSvcOutputMetadata.idl \
822826
$(WebCore)/Modules/webcodecs/WebCodecsVideoDecoder.idl \
823827
$(WebCore)/Modules/webcodecs/WebCodecsVideoDecoderConfig.idl \
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright (C) 2026 Apple Inc. All rights reserved.
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions
6+
* are met:
7+
* 1. Redistributions of source code must retain the above copyright
8+
* notice, this list of conditions and the following disclaimer.
9+
* 2. Redistributions in binary form must reproduce the above copyright
10+
* notice, this list of conditions and the following disclaimer in the
11+
* documentation and/or other materials provided with the distribution.
12+
*
13+
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15+
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17+
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23+
* THE POSSIBILITY OF SUCH DAMAGE.
24+
*/
25+
26+
#pragma once
27+
28+
#if ENABLE(WEB_CODECS)
29+
30+
namespace WebCore {
31+
32+
class WebCodecsVideoFrame;
33+
34+
struct WebCodecsImageDecodeResult {
35+
Ref<WebCodecsVideoFrame> image;
36+
bool complete;
37+
};
38+
39+
} // namespace WebCore
40+
41+
#endif
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright (C) 2026 Apple Inc. All rights reserved.
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions
6+
* are met:
7+
* 1. Redistributions of source code must retain the above copyright
8+
* notice, this list of conditions and the following disclaimer.
9+
* 2. Redistributions in binary form must reproduce the above copyright
10+
* notice, this list of conditions and the following disclaimer in the
11+
* documentation and/or other materials provided with the distribution.
12+
*
13+
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15+
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17+
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23+
* THE POSSIBILITY OF SUCH DAMAGE.
24+
*/
25+
26+
// https://w3c.github.io/webcodecs/#dictdef-imagedecoderesult
27+
28+
[
29+
Conditional=WEB_CODECS,
30+
EnabledBySetting=WebCodecsImageEnabled,
31+
JSGenerateToJSObject
32+
] dictionary WebCodecsImageDecodeResult {
33+
required WebCodecsVideoFrame image;
34+
required boolean complete;
35+
};
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
* Copyright (C) 2026 Apple Inc. All rights reserved.
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions
6+
* are met:
7+
* 1. Redistributions of source code must retain the above copyright
8+
* notice, this list of conditions and the following disclaimer.
9+
* 2. Redistributions in binary form must reproduce the above copyright
10+
* notice, this list of conditions and the following disclaimer in the
11+
* documentation and/or other materials provided with the distribution.
12+
*
13+
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15+
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17+
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23+
* THE POSSIBILITY OF SUCH DAMAGE.
24+
*/
25+
26+
#include "config.h"
27+
#include "WebCodecsImageDecoder.h"
28+
29+
#if ENABLE(WEB_CODECS)
30+
31+
#include "JSDOMConvertDictionary.h"
32+
#include "JSDOMPromiseDeferred.h"
33+
#include "JSWebCodecsImageDecodeResult.h"
34+
#include "WebCodecsImageDecodeResult.h"
35+
#include "WebCodecsVideoFrame.h"
36+
#include <wtf/TZoneMallocInlines.h>
37+
38+
namespace WebCore {
39+
40+
WTF_MAKE_TZONE_ALLOCATED_IMPL(WebCodecsImageDecoder);
41+
42+
Ref<WebCodecsImageDecoder> WebCodecsImageDecoder::create(ScriptExecutionContext& context, Init&& init)
43+
{
44+
Ref decoder = adoptRef(*new WebCodecsImageDecoder(context, WTF::move(init)));
45+
decoder->suspendIfNeeded();
46+
return decoder;
47+
}
48+
49+
WebCodecsImageDecoder::WebCodecsImageDecoder(ScriptExecutionContext& context, Init&&)
50+
: WebCodecsBase(context)
51+
, m_completedPromise(makeUniqueRef<CompletedPromise>())
52+
{
53+
}
54+
55+
WebCodecsImageDecoder::~WebCodecsImageDecoder() = default;
56+
57+
Ref<WebCodecsImageTrackList> WebCodecsImageDecoder::tracks() const
58+
{
59+
if (!m_tracks)
60+
m_tracks = WebCodecsImageTrackList::create({ WebCodecsImageTrack::create() });
61+
62+
return *m_tracks;
63+
}
64+
65+
ExceptionOr<void> WebCodecsImageDecoder::decode(std::optional<DecodeOptions>&&, Ref<DeferredPromise>&&)
66+
{
67+
return Exception { ExceptionCode::NotSupportedError };
68+
}
69+
70+
ExceptionOr<void> WebCodecsImageDecoder::reset()
71+
{
72+
return Exception { ExceptionCode::NotSupportedError };
73+
}
74+
75+
ExceptionOr<void> WebCodecsImageDecoder::close()
76+
{
77+
return Exception { ExceptionCode::NotSupportedError };
78+
}
79+
80+
void WebCodecsImageDecoder::isTypeSupported(ScriptExecutionContext&, String&&, Ref<DeferredPromise>&&)
81+
{
82+
}
83+
84+
void WebCodecsImageDecoder::suspend(ReasonForSuspension)
85+
{
86+
}
87+
88+
void WebCodecsImageDecoder::stop()
89+
{
90+
}
91+
92+
} // namespace WebCore
93+
94+
#endif // ENABLE(WEB_CODECS)
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*
2+
* Copyright (C) 2026 Apple Inc. All rights reserved.
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions
6+
* are met:
7+
* 1. Redistributions of source code must retain the above copyright
8+
* notice, this list of conditions and the following disclaimer.
9+
* 2. Redistributions in binary form must reproduce the above copyright
10+
* notice, this list of conditions and the following disclaimer in the
11+
* documentation and/or other materials provided with the distribution.
12+
*
13+
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15+
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17+
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23+
* THE POSSIBILITY OF SUCH DAMAGE.
24+
*/
25+
26+
#pragma once
27+
28+
#if ENABLE(WEB_CODECS)
29+
30+
#include "DOMPromiseProxy.h"
31+
#include "EventTargetInterfaces.h"
32+
#include "ExceptionOr.h"
33+
#include "IDLTypes.h"
34+
#include "JSDOMPromiseDeferredForward.h"
35+
#include "WebCodecsBase.h"
36+
#include "WebCodecsImageTrackList.h"
37+
#include <JavaScriptCore/ArrayBuffer.h>
38+
#include <JavaScriptCore/ArrayBufferView.h>
39+
#include <wtf/UniqueRef.h>
40+
41+
namespace WebCore {
42+
43+
class ReadableStream;
44+
class WebCodecsVideoFrame;
45+
46+
using ImageBufferSource = Variant
47+
< Ref<JSC::ArrayBuffer>
48+
, Ref<JSC::ArrayBufferView>
49+
, Ref<ReadableStream>
50+
>;
51+
52+
class WebCodecsImageDecoder final : public WebCodecsBase {
53+
WTF_MAKE_TZONE_ALLOCATED(WebCodecsImageDecoder);
54+
public:
55+
~WebCodecsImageDecoder();
56+
57+
enum class ColorSpaceConversion : bool { None, Default };
58+
59+
struct Init {
60+
String type;
61+
ImageBufferSource data;
62+
ColorSpaceConversion colorSpaceConversion { ColorSpaceConversion::Default };
63+
std::optional<size_t> desiredWidth;
64+
std::optional<size_t> desiredHeight;
65+
std::optional<bool> preferAnimation;
66+
};
67+
68+
struct DecodeOptions {
69+
size_t frameIndex { 0 };
70+
bool completeFramesOnly { true };
71+
};
72+
73+
static Ref<WebCodecsImageDecoder> create(ScriptExecutionContext&, Init&&);
74+
75+
String type() const { return m_type; }
76+
bool complete() const { return true; }
77+
78+
using CompletedPromise = DOMPromiseProxy<IDLUndefined>;
79+
CompletedPromise& completed() { return m_completedPromise.get(); }
80+
81+
Ref<WebCodecsImageTrackList> tracks() const;
82+
83+
ExceptionOr<void> decode(std::optional<DecodeOptions>&&, Ref<DeferredPromise>&&);
84+
ExceptionOr<void> reset();
85+
ExceptionOr<void> close();
86+
87+
static void isTypeSupported(ScriptExecutionContext&, String&& type, Ref<DeferredPromise>&&);
88+
89+
private:
90+
WebCodecsImageDecoder(ScriptExecutionContext&, Init&&);
91+
92+
// ActiveDOMObject.
93+
void stop() final;
94+
void NODELETE suspend(ReasonForSuspension) final;
95+
96+
// EventTarget.
97+
enum EventTargetInterfaceType eventTargetInterface() const final { return EventTargetInterfaceType::WebCodecsImageDecoder; }
98+
99+
String m_type;
100+
UniqueRef<CompletedPromise> m_completedPromise;
101+
mutable RefPtr<WebCodecsImageTrackList> m_tracks;
102+
};
103+
104+
} // namespace WebCore
105+
106+
SPECIALIZE_TYPE_TRAITS_EVENTTARGET(WebCodecsImageDecoder)
107+
108+
#endif

0 commit comments

Comments
 (0)