Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 28fa568972a4d34d867948618adb4f4cc5532061
      
https://github.com/WebKit/WebKit/commit/28fa568972a4d34d867948618adb4f4cc5532061
  Author: Nikolas Zimmermann <[email protected]>
  Date:   2025-11-01 (Sat, 01 Nov 2025)

  Changed paths:
    M Source/WTF/wtf/RunLoop.h
    M Source/WTF/wtf/glib/ActivityObserver.h
    M Source/WTF/wtf/glib/RunLoopGLib.cpp
    M Source/WebCore/platform/RunLoopObserver.h
    M Source/WebCore/platform/glib/RunLoopObserverGLib.cpp
    M 
Source/WebKit/WebProcess/WebPage/CoordinatedGraphics/ThreadedCompositor.cpp
    M Source/WebKit/WebProcess/WebPage/CoordinatedGraphics/ThreadedCompositor.h
    M Tools/TestWebKitAPI/Tests/WTF/glib/ActivityObserver.cpp
    M Tools/TestWebKitAPI/Tests/WebCore/glib/RunLoopObserver.cpp

  Log Message:
  -----------
  [GTK][WPE] ThreadedCompositor: Switch didRenderFrameTimer to use a 
RunLoopObserver
https://bugs.webkit.org/show_bug.cgi?id=301451

Reviewed by Carlos Garcia Campos.

Enhance GLib specific RunLoopObserver infrastructure to support cross-thread
scheduling, enabling ThreadedCompositor to replace its timer-based composition
notification with a deterministic RunLoopObserver approach.

- ActivityObserver is now ThreadSafeRefCounted for cross-thread safety
- ActivityObserver holds a ThreadSafeWeakPtr to the RunLoop it got attached to
- RunLoopObserver supports scheduling on a specific RunLoop (not just current)
- RunLoopObserver handles locking of the ActivityObserver to support
  cross-thread usage scenarios (schedule()/invalidate() on different threads)
- Rename ActivityObserver::ContinueObservation::Yes|No -> 
NotifyResult::Continue|Stop
  and handle an additional case: 'Destroyed', when the AcvitiyObserver is no 
longer
  scheduled, then we shouldn't fire a notification, nor try to invalidate.
- ActivityObserver::stops() now reset the callback to nullptr. If we get
  another notify()-request and detect that the AO was already stop()'ed
  then return 'Destroyed' and ignore the request.
- Add threading related API tests for RunLoopObserver.

Tests: Tools/TestWebKitAPI/Tests/WTF/glib/ActivityObserver.cpp (adapted)
       Tools/TestWebKitAPI/Tests/WebCore/glib/RunLoopObserver.cpp (8 new tests)

* Source/WTF/wtf/RunLoop.h:
* Source/WTF/wtf/glib/ActivityObserver.h:
(WTF::ActivityObserver::create):
(WTF::ActivityObserver::~ActivityObserver):
(WTF::ActivityObserver::start):
(WTF::ActivityObserver::stop):
(WTF::ActivityObserver::notify const):
(WTF::ActivityObserver::ActivityObserver):
* Source/WTF/wtf/glib/RunLoopGLib.cpp:
(WTF::RunLoop::notifyActivity):
* Source/WebCore/platform/RunLoopObserver.h:
* Source/WebCore/platform/glib/RunLoopObserverGLib.cpp:
(WebCore::RunLoopObserver::schedule):
(WebCore::RunLoopObserver::invalidate):
(WebCore::RunLoopObserver::isScheduled const):
* Source/WebKit/WebProcess/WebPage/CoordinatedGraphics/ThreadedCompositor.cpp:
(WebKit::m_compositingRunLoop):
(WebKit::ThreadedCompositor::invalidate):
(WebKit::ThreadedCompositor::renderLayerTree):
(WebKit::ThreadedCompositor::didCompositeRunLoopObserverFired):
(WebKit::m_didRenderFrameTimer): Deleted.
(WebKit::ThreadedCompositor::didRenderFrameTimerFired): Deleted.
* Source/WebKit/WebProcess/WebPage/CoordinatedGraphics/ThreadedCompositor.h:
* Tools/TestWebKitAPI/Tests/WTF/glib/ActivityObserver.cpp:
(TestWebKitAPI::TEST(WTF_ActivityObserver, Create)):
(TestWebKitAPI::TEST(WTF_ActivityObserver, MatchingActivity)):
(TestWebKitAPI::TEST(WTF_ActivityObserver, NonMatchingActivity)):
(TestWebKitAPI::TEST(WTF_ActivityObserver, MultipleActivities)):
(TestWebKitAPI::TEST(WTF_ActivityObserver, Ordering)):
(TestWebKitAPI::TEST(WTF_ActivityObserver, SameOrder)):
* Tools/TestWebKitAPI/Tests/WebCore/glib/RunLoopObserver.cpp:
(TestWebKitAPI::SecondaryRunLoopThread::SecondaryRunLoopThread):
(TestWebKitAPI::SecondaryRunLoopThread::~SecondaryRunLoopThread):
(TestWebKitAPI::SecondaryRunLoopThread::runLoop const):
(TestWebKitAPI::SecondaryRunLoopThread::threadId const):
(TestWebKitAPI::SecondaryRunLoopThread::dispatch):
(TestWebKitAPI::TEST(RunLoopObserver, 
CrossThread_ScheduleOnMainLoopFromSecondaryThread)):
 -> Schedule observer from secondary thread to main loop, verify it fires on 
main thread.

(TestWebKitAPI::TEST(RunLoopObserver, 
CrossThread_ScheduleOnSecondaryLoopFromSecondaryThread)):
 -> Schedule observer from secondary thread to its own loop, verify execution 
on correct thread.

(TestWebKitAPI::TEST(RunLoopObserver, 
CrossThread_ScheduleOnSecondaryLoopFromMainThread)):
 -> Schedule observer from main thread to secondary loop.

(TestWebKitAPI::TEST(RunLoopObserver, CrossThread_TwoObserversBothOnMainLoop)):
 -> Two observers scheduled from different threads to main loop, verify both 
fire on main thread.

(TestWebKitAPI::TEST(RunLoopObserver, 
CrossThread_TwoObserversOnDifferentLoops)):
 -> Two observers on separate loops (main + secondary), verify concurrent 
execution on respective threads.

(TestWebKitAPI::TEST(RunLoopObserver, 
CrossThread_InvalidateFromDifferentThread)):
 -> Invalidate observer from different thread, verify thread-safe invalidation 
stops observer.

(TestWebKitAPI::TEST(RunLoopObserver, 
CrossThread_OneShotObserverOnSecondaryLoop)):
 -> One-shot observer on secondary loop fires exactly once across multiple 
iterations.

(TestWebKitAPI::TEST(RunLoopObserver, CrossThread_MultipleScheduleAttempts)):
 -> Attempt to reschedule already-scheduled observer from different thread, 
verify first schedule wins.

Canonical link: https://commits.webkit.org/302433@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to