Skip to content

Commit

Permalink
Even more dynamicDowncast<> conversion in platform code
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=270071

Reviewed by Chris Dumez.

For security & performance. Final part of auditing all downcast calls
in platform code.

* Source/WebCore/platform/graphics/filters/FilterEffect.h:
(WebCore::FilterEffect::areEqual):
* Source/WebCore/platform/graphics/filters/LightSource.h:
(WebCore::LightSource::areEqual):
* Source/WebCore/platform/mediastream/AudioTrackPrivateMediaStream.cpp:
(WebCore::audioModuleFromSource):
* Source/WebCore/platform/mediastream/mac/RealtimeOutgoingVideoSourceCocoa.cpp:
(WebCore::RealtimeOutgoingVideoSourceCocoa::videoFrameAvailable):

Canonical link: https://commits.webkit.org/275324@main
  • Loading branch information
annevk committed Feb 26, 2024
1 parent b59882b commit 3edd02f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 11 deletions.
5 changes: 2 additions & 3 deletions Source/WebCore/platform/graphics/filters/FilterEffect.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,8 @@ class FilterEffect : public FilterFunction {
template<typename FilterEffectType>
static bool areEqual(const FilterEffectType& a, const FilterEffect& b)
{
if (!is<FilterEffectType>(b))
return false;
return a.operator==(downcast<FilterEffectType>(b));
auto* bType = dynamicDowncast<FilterEffectType>(b);
return bType && a.operator==(*bType);
}

virtual unsigned numberOfEffectInputs() const { return 1; }
Expand Down
5 changes: 2 additions & 3 deletions Source/WebCore/platform/graphics/filters/LightSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,8 @@ class LightSource : public RefCounted<LightSource> {
template<typename LightSourceType>
static bool areEqual(const LightSourceType& a, const LightSource& b)
{
if (!is<LightSourceType>(b))
return false;
return a.operator==(downcast<LightSourceType>(b));
auto* bType = dynamicDowncast<LightSourceType>(b);
return bType && a.operator==(*bType);
}

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,8 @@ AudioTrackPrivateMediaStream::~AudioTrackPrivateMediaStream()
#if USE(LIBWEBRTC)
static RefPtr<LibWebRTCAudioModule> audioModuleFromSource(RealtimeMediaSource& source)
{
if (!is<RealtimeIncomingAudioSource>(source))
return nullptr;
return downcast<RealtimeIncomingAudioSource>(source).audioModule();
auto* audioSource = dynamicDowncast<RealtimeIncomingAudioSource>(source);
return audioSource ? audioSource->audioModule() : nullptr;
}
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ void RealtimeOutgoingVideoSourceCocoa::videoFrameAvailable(VideoFrame& videoFram
static_cast<int>(size.width() * videoFrameScaling), static_cast<int>(size.height() * videoFrameScaling)));
return;
}
if (videoFrame.isLibWebRTC()) {
auto webrtcBuffer = downcast<VideoFrameLibWebRTC>(videoFrame).buffer();
if (auto* webrtcVideoFrame = dynamicDowncast<VideoFrameLibWebRTC>(videoFrame)) {
auto webrtcBuffer = webrtcVideoFrame->buffer();
if (videoFrameScaling != 1)
webrtcBuffer = webrtcBuffer->Scale(webrtcBuffer->width() * videoFrameScaling, webrtcBuffer->height() * videoFrameScaling);
sendFrame(WTFMove(webrtcBuffer));
Expand Down

0 comments on commit 3edd02f

Please sign in to comment.