EventLoop.cpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  1. /*
  2. * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2022, the SerenityOS developers.
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #include <LibCore/EventLoop.h>
  8. #include <LibJS/Runtime/VM.h>
  9. #include <LibWeb/Bindings/MainThreadVM.h>
  10. #include <LibWeb/DOM/Document.h>
  11. #include <LibWeb/HTML/BrowsingContext.h>
  12. #include <LibWeb/HTML/EventLoop/EventLoop.h>
  13. #include <LibWeb/HTML/Scripting/Environments.h>
  14. #include <LibWeb/HTML/Window.h>
  15. #include <LibWeb/HighResolutionTime/Performance.h>
  16. #include <LibWeb/HighResolutionTime/TimeOrigin.h>
  17. #include <LibWeb/Page/Page.h>
  18. #include <LibWeb/Platform/EventLoopPlugin.h>
  19. #include <LibWeb/Platform/Timer.h>
  20. namespace Web::HTML {
  21. EventLoop::EventLoop()
  22. : m_task_queue(*this)
  23. , m_microtask_queue(*this)
  24. {
  25. }
  26. EventLoop::~EventLoop() = default;
  27. void EventLoop::schedule()
  28. {
  29. if (!m_system_event_loop_timer) {
  30. m_system_event_loop_timer = Platform::Timer::create_single_shot(0, [this] {
  31. process();
  32. });
  33. }
  34. if (!m_system_event_loop_timer->is_active())
  35. m_system_event_loop_timer->restart();
  36. }
  37. void EventLoop::set_vm(JS::VM& vm)
  38. {
  39. VERIFY(!m_vm);
  40. m_vm = &vm;
  41. }
  42. EventLoop& main_thread_event_loop()
  43. {
  44. return static_cast<Bindings::WebEngineCustomData*>(Bindings::main_thread_vm().custom_data())->event_loop;
  45. }
  46. // https://html.spec.whatwg.org/multipage/webappapis.html#spin-the-event-loop
  47. void EventLoop::spin_until(JS::SafeFunction<bool()> goal_condition)
  48. {
  49. // FIXME: The spec wants us to do the rest of the enclosing algorithm (i.e. the caller)
  50. // in the context of the currently running task on entry. That's not possible with this implementation.
  51. // 1. Let task be the event loop's currently running task.
  52. // 2. Let task source be task's source.
  53. // 3. Let old stack be a copy of the JavaScript execution context stack.
  54. // 4. Empty the JavaScript execution context stack.
  55. m_vm->save_execution_context_stack();
  56. m_vm->clear_execution_context_stack();
  57. // 5. Perform a microtask checkpoint.
  58. perform_a_microtask_checkpoint();
  59. // 6. In parallel:
  60. // 1. Wait until the condition goal is met.
  61. // 2. Queue a task on task source to:
  62. // 1. Replace the JavaScript execution context stack with old stack.
  63. // 2. Perform any steps that appear after this spin the event loop instance in the original algorithm.
  64. // NOTE: This is achieved by returning from the function.
  65. Platform::EventLoopPlugin::the().spin_until([&] {
  66. if (goal_condition())
  67. return true;
  68. if (m_task_queue.has_runnable_tasks()) {
  69. schedule();
  70. // FIXME: Remove the platform event loop plugin so that this doesn't look out of place
  71. Core::EventLoop::current().wake();
  72. }
  73. return goal_condition();
  74. });
  75. m_vm->restore_execution_context_stack();
  76. // 7. Stop task, allowing whatever algorithm that invoked it to resume.
  77. // NOTE: This is achieved by returning from the function.
  78. }
  79. void EventLoop::spin_processing_tasks_with_source_until(Task::Source source, JS::SafeFunction<bool()> goal_condition)
  80. {
  81. m_vm->save_execution_context_stack();
  82. m_vm->clear_execution_context_stack();
  83. perform_a_microtask_checkpoint();
  84. // NOTE: HTML event loop processing steps could run a task with arbitrary source
  85. m_skip_event_loop_processing_steps = true;
  86. Platform::EventLoopPlugin::the().spin_until([&] {
  87. if (goal_condition())
  88. return true;
  89. if (m_task_queue.has_runnable_tasks()) {
  90. auto tasks = m_task_queue.take_tasks_matching([&](auto& task) {
  91. return task.source() == source;
  92. });
  93. for (auto& task : tasks.value()) {
  94. m_currently_running_task = task.ptr();
  95. task->execute();
  96. m_currently_running_task = nullptr;
  97. }
  98. }
  99. // FIXME: Remove the platform event loop plugin so that this doesn't look out of place
  100. Core::EventLoop::current().wake();
  101. return goal_condition();
  102. });
  103. m_skip_event_loop_processing_steps = false;
  104. schedule();
  105. m_vm->restore_execution_context_stack();
  106. }
  107. // https://html.spec.whatwg.org/multipage/webappapis.html#event-loop-processing-model
  108. void EventLoop::process()
  109. {
  110. if (m_skip_event_loop_processing_steps)
  111. return;
  112. // An event loop must continually run through the following steps for as long as it exists:
  113. // 1. Let oldestTask be null.
  114. OwnPtr<Task> oldest_task;
  115. // 2. Let taskStartTime be the current high resolution time.
  116. // FIXME: 'current high resolution time' in hr-time-3 takes a global object,
  117. // the HTML spec has not been updated to reflect this, let's use the shared timer.
  118. // - https://github.com/whatwg/html/issues/7776
  119. double task_start_time = HighResolutionTime::unsafe_shared_current_time();
  120. // 3. Let taskQueue be one of the event loop's task queues, chosen in an implementation-defined manner,
  121. // with the constraint that the chosen task queue must contain at least one runnable task.
  122. // If there is no such task queue, then jump to the microtasks step below.
  123. auto& task_queue = m_task_queue;
  124. // 4. Set oldestTask to the first runnable task in taskQueue, and remove it from taskQueue.
  125. oldest_task = task_queue.take_first_runnable();
  126. if (oldest_task) {
  127. // 5. Set the event loop's currently running task to oldestTask.
  128. m_currently_running_task = oldest_task.ptr();
  129. // 6. Perform oldestTask's steps.
  130. oldest_task->execute();
  131. // 7. Set the event loop's currently running task back to null.
  132. m_currently_running_task = nullptr;
  133. }
  134. // 8. Microtasks: Perform a microtask checkpoint.
  135. perform_a_microtask_checkpoint();
  136. // 9. Let hasARenderingOpportunity be false.
  137. [[maybe_unused]] bool has_a_rendering_opportunity = false;
  138. // FIXME: 10. Let now be the current high resolution time. [HRT]
  139. // FIXME: 11. If oldestTask is not null, then:
  140. // FIXME: 1. Let top-level browsing contexts be an empty set.
  141. // FIXME: 2. For each environment settings object settings of oldestTask's script evaluation environment settings object set, append setting's top-level browsing context to top-level browsing contexts.
  142. // FIXME: 3. Report long tasks, passing in taskStartTime, now (the end time of the task), top-level browsing contexts, and oldestTask.
  143. // FIXME: 12. Update the rendering: if this is a window event loop, then:
  144. // FIXME: 1. Let docs be all Document objects whose relevant agent's event loop is this event loop, sorted arbitrarily except that the following conditions must be met:
  145. // - Any Document B whose browsing context's container document is A must be listed after A in the list.
  146. // - If there are two documents A and B whose browsing contexts are both child browsing contexts whose container documents are another Document C, then the order of A and B in the list must match the shadow-including tree order of their respective browsing context containers in C's node tree.
  147. // FIXME: NOTE: The sort order specified above is missing here!
  148. Vector<JS::Handle<DOM::Document>> docs = documents_in_this_event_loop();
  149. auto for_each_fully_active_document_in_docs = [&](auto&& callback) {
  150. for (auto& document : docs) {
  151. if (document->is_fully_active())
  152. callback(*document);
  153. }
  154. };
  155. // AD-HOC: Since event loop processing steps do not constantly running in parallel, and
  156. // something must trigger them, we need to manually schedule a repaint for all
  157. // navigables that do not have a rendering opportunity at this event loop iteration.
  158. // Otherwise their repaint will be delayed until something else will trigger event
  159. // loop processing.
  160. for_each_fully_active_document_in_docs([&](DOM::Document& document) {
  161. auto navigable = document.navigable();
  162. if (navigable && navigable->has_a_rendering_opportunity())
  163. return;
  164. auto* browsing_context = document.browsing_context();
  165. if (!browsing_context)
  166. return;
  167. auto& page = browsing_context->page();
  168. page.client().schedule_repaint();
  169. });
  170. // 2. Rendering opportunities: Remove from docs all Document objects whose node navigables do not have a rendering opportunity.
  171. docs.remove_all_matching([&](auto& document) {
  172. auto navigable = document->navigable();
  173. return navigable && !navigable->has_a_rendering_opportunity();
  174. });
  175. // 3. If docs is not empty, then set hasARenderingOpportunity to true
  176. // and set this event loop's last render opportunity time to taskStartTime.
  177. if (!docs.is_empty()) {
  178. has_a_rendering_opportunity = true;
  179. m_last_render_opportunity_time = task_start_time;
  180. }
  181. // FIXME: 4. Unnecessary rendering: Remove from docs all Document objects which meet both of the following conditions:
  182. // - The user agent believes that updating the rendering of the Document's browsing context would have no visible effect, and
  183. // - The Document's map of animation frame callbacks is empty.
  184. // https://www.w3.org/TR/intersection-observer/#pending-initial-observation
  185. // In the HTML Event Loops Processing Model, under the "Update the rendering" step, the "Unnecessary rendering" step should be
  186. // modified to add an additional requirement for skipping the rendering update:
  187. // - The document does not have pending initial IntersectionObserver targets.
  188. // FIXME: 5. Remove from docs all Document objects for which the user agent believes that it's preferable to skip updating the rendering for other reasons.
  189. // FIXME: 6. For each fully active Document in docs, flush autofocus candidates for that Document if its browsing context is a top-level browsing context.
  190. // 7. For each fully active Document in docs, run the resize steps for that Document, passing in now as the timestamp. [CSSOMVIEW]
  191. for_each_fully_active_document_in_docs([&](DOM::Document& document) {
  192. document.run_the_resize_steps();
  193. });
  194. // 8. For each fully active Document in docs, run the scroll steps for that Document, passing in now as the timestamp. [CSSOMVIEW]
  195. for_each_fully_active_document_in_docs([&](DOM::Document& document) {
  196. document.run_the_scroll_steps();
  197. });
  198. // 9. For each fully active Document in docs, evaluate media queries and report changes for that Document, passing in now as the timestamp. [CSSOMVIEW]
  199. for_each_fully_active_document_in_docs([&](DOM::Document& document) {
  200. document.evaluate_media_queries_and_report_changes();
  201. });
  202. // 10. For each fully active Document in docs, update animations and send events for that Document, passing in now as the timestamp. [WEBANIMATIONS]
  203. // Note: This is handled by the document's animation timer
  204. // FIXME: 11. For each fully active Document in docs, run the fullscreen steps for that Document, passing in now as the timestamp. [FULLSCREEN]
  205. // FIXME: 12. For each fully active Document in docs, if the user agent detects that the backing storage associated with a CanvasRenderingContext2D or an OffscreenCanvasRenderingContext2D, context, has been lost, then it must run the context lost steps for each such context:
  206. // FIXME: 13. For each fully active Document in docs, run the animation frame callbacks for that Document, passing in now as the timestamp.
  207. auto now = HighResolutionTime::unsafe_shared_current_time();
  208. for_each_fully_active_document_in_docs([&](DOM::Document& document) {
  209. run_animation_frame_callbacks(document, now);
  210. });
  211. // FIXME: This step is implemented following the latest specification, while the rest of this method uses an outdated spec.
  212. // NOTE: Gathering and broadcasting of resize observations need to happen after evaluating media queries but before
  213. // updating intersection observations steps.
  214. for_each_fully_active_document_in_docs([&](DOM::Document& document) {
  215. // 1. Let resizeObserverDepth be 0.
  216. size_t resize_observer_depth = 0;
  217. // 2. While true:
  218. while (true) {
  219. // 1. Recalculate styles and update layout for doc.
  220. // NOTE: Recalculation of styles is handled by update_layout()
  221. document.update_layout();
  222. // FIXME: 2. Let hadInitialVisibleContentVisibilityDetermination be false.
  223. // FIXME: 3. For each element element with 'auto' used value of 'content-visibility':
  224. // FIXME: 4. If hadInitialVisibleContentVisibilityDetermination is true, then continue.
  225. // 5. Gather active resize observations at depth resizeObserverDepth for doc.
  226. document.gather_active_observations_at_depth(resize_observer_depth);
  227. // 6. If doc has active resize observations:
  228. if (document.has_active_resize_observations()) {
  229. // 1. Set resizeObserverDepth to the result of broadcasting active resize observations given doc.
  230. resize_observer_depth = document.broadcast_active_resize_observations();
  231. // 2. Continue.
  232. continue;
  233. }
  234. // 7. Otherwise, break.
  235. break;
  236. }
  237. // 3. If doc has skipped resize observations, then deliver resize loop error given doc.
  238. if (document.has_skipped_resize_observations()) {
  239. // FIXME: Deliver resize loop error.
  240. }
  241. });
  242. // 14. For each fully active Document in docs, run the update intersection observations steps for that Document, passing in now as the timestamp. [INTERSECTIONOBSERVER]
  243. for_each_fully_active_document_in_docs([&](DOM::Document& document) {
  244. document.run_the_update_intersection_observations_steps(now);
  245. });
  246. // FIXME: 15. Invoke the mark paint timing algorithm for each Document object in docs.
  247. // 16. For each fully active Document in docs, update the rendering or user interface of that Document and its browsing context to reflect the current state.
  248. for_each_fully_active_document_in_docs([&](DOM::Document& document) {
  249. auto navigable = document.navigable();
  250. if (navigable && navigable->needs_repaint()) {
  251. auto* browsing_context = document.browsing_context();
  252. auto& page = browsing_context->page();
  253. page.client().schedule_repaint();
  254. }
  255. });
  256. // 13. If all of the following are true
  257. // - this is a window event loop
  258. // - there is no task in this event loop's task queues whose document is fully active
  259. // - this event loop's microtask queue is empty
  260. // - hasARenderingOpportunity is false
  261. // FIXME: has_a_rendering_opportunity is always true
  262. if (m_type == Type::Window && !task_queue.has_runnable_tasks() && m_microtask_queue.is_empty() /*&& !has_a_rendering_opportunity*/) {
  263. // 1. Set this event loop's last idle period start time to the current high resolution time.
  264. m_last_idle_period_start_time = HighResolutionTime::unsafe_shared_current_time();
  265. // 2. Let computeDeadline be the following steps:
  266. // NOTE: instead of passing around a function we use this event loop, which has compute_deadline()
  267. // 3. For each win of the same-loop windows for this event loop,
  268. // perform the start an idle period algorithm for win with computeDeadline. [REQUESTIDLECALLBACK]
  269. for (auto& win : same_loop_windows())
  270. win->start_an_idle_period();
  271. }
  272. // FIXME: 14. If this is a worker event loop, then:
  273. // FIXME: 1. If this event loop's agent's single realm's global object is a supported DedicatedWorkerGlobalScope and the user agent believes that it would benefit from having its rendering updated at this time, then:
  274. // FIXME: 1. Let now be the current high resolution time. [HRT]
  275. // FIXME: 2. Run the animation frame callbacks for that DedicatedWorkerGlobalScope, passing in now as the timestamp.
  276. // FIXME: 3. Update the rendering of that dedicated worker to reflect the current state.
  277. // FIXME: 2. If there are no tasks in the event loop's task queues and the WorkerGlobalScope object's closing flag is true, then destroy the event loop, aborting these steps, resuming the run a worker steps described in the Web workers section below.
  278. // If there are eligible tasks in the queue, schedule a new round of processing. :^)
  279. if (m_task_queue.has_runnable_tasks() || (!m_microtask_queue.is_empty() && !m_performing_a_microtask_checkpoint))
  280. schedule();
  281. // For each doc of docs, process top layer removals given doc.
  282. for_each_fully_active_document_in_docs([&](DOM::Document& document) {
  283. document.process_top_layer_removals();
  284. });
  285. }
  286. // https://html.spec.whatwg.org/multipage/webappapis.html#queue-a-global-task
  287. int queue_global_task(HTML::Task::Source source, JS::Object& global_object, JS::SafeFunction<void()> steps)
  288. {
  289. // 1. Let event loop be global's relevant agent's event loop.
  290. auto& global_custom_data = verify_cast<Bindings::WebEngineCustomData>(*global_object.vm().custom_data());
  291. auto& event_loop = global_custom_data.event_loop;
  292. // 2. Let document be global's associated Document, if global is a Window object; otherwise null.
  293. DOM::Document* document { nullptr };
  294. if (is<HTML::Window>(global_object)) {
  295. auto& window_object = verify_cast<HTML::Window>(global_object);
  296. document = &window_object.associated_document();
  297. }
  298. // 3. Queue a task given source, event loop, document, and steps.
  299. event_loop.task_queue().add(HTML::Task::create(source, document, move(steps)));
  300. return event_loop.task_queue().last_added_task()->id();
  301. }
  302. // https://html.spec.whatwg.org/#queue-a-microtask
  303. void queue_a_microtask(DOM::Document const* document, JS::SafeFunction<void()> steps)
  304. {
  305. // 1. If event loop was not given, set event loop to the implied event loop.
  306. auto& event_loop = HTML::main_thread_event_loop();
  307. // FIXME: 2. If document was not given, set document to the implied document.
  308. // 3. Let microtask be a new task.
  309. // 4. Set microtask's steps to steps.
  310. // 5. Set microtask's source to the microtask task source.
  311. // 6. Set microtask's document to document.
  312. auto microtask = HTML::Task::create(HTML::Task::Source::Microtask, document, move(steps));
  313. // FIXME: 7. Set microtask's script evaluation environment settings object set to an empty set.
  314. // 8. Enqueue microtask on event loop's microtask queue.
  315. event_loop.microtask_queue().enqueue(move(microtask));
  316. }
  317. void perform_a_microtask_checkpoint()
  318. {
  319. main_thread_event_loop().perform_a_microtask_checkpoint();
  320. }
  321. // https://html.spec.whatwg.org/#perform-a-microtask-checkpoint
  322. void EventLoop::perform_a_microtask_checkpoint()
  323. {
  324. // 1. If the event loop's performing a microtask checkpoint is true, then return.
  325. if (m_performing_a_microtask_checkpoint)
  326. return;
  327. // 2. Set the event loop's performing a microtask checkpoint to true.
  328. m_performing_a_microtask_checkpoint = true;
  329. // 3. While the event loop's microtask queue is not empty:
  330. while (!m_microtask_queue.is_empty()) {
  331. // 1. Let oldestMicrotask be the result of dequeuing from the event loop's microtask queue.
  332. auto oldest_microtask = m_microtask_queue.dequeue();
  333. // 2. Set the event loop's currently running task to oldestMicrotask.
  334. m_currently_running_task = oldest_microtask;
  335. // 3. Run oldestMicrotask.
  336. oldest_microtask->execute();
  337. // 4. Set the event loop's currently running task back to null.
  338. m_currently_running_task = nullptr;
  339. }
  340. // 4. For each environment settings object whose responsible event loop is this event loop, notify about rejected promises on that environment settings object.
  341. for (auto& environment_settings_object : m_related_environment_settings_objects)
  342. environment_settings_object->notify_about_rejected_promises({});
  343. // FIXME: 5. Cleanup Indexed Database transactions.
  344. // 6. Perform ClearKeptObjects().
  345. vm().finish_execution_generation();
  346. // 7. Set the event loop's performing a microtask checkpoint to false.
  347. m_performing_a_microtask_checkpoint = false;
  348. }
  349. Vector<JS::Handle<DOM::Document>> EventLoop::documents_in_this_event_loop() const
  350. {
  351. Vector<JS::Handle<DOM::Document>> documents;
  352. for (auto& document : m_documents) {
  353. VERIFY(document);
  354. documents.append(JS::make_handle(*document));
  355. }
  356. return documents;
  357. }
  358. void EventLoop::register_document(Badge<DOM::Document>, DOM::Document& document)
  359. {
  360. m_documents.append(&document);
  361. }
  362. void EventLoop::unregister_document(Badge<DOM::Document>, DOM::Document& document)
  363. {
  364. bool did_remove = m_documents.remove_first_matching([&](auto& entry) { return entry.ptr() == &document; });
  365. VERIFY(did_remove);
  366. }
  367. void EventLoop::push_onto_backup_incumbent_settings_object_stack(Badge<EnvironmentSettingsObject>, EnvironmentSettingsObject& environment_settings_object)
  368. {
  369. m_backup_incumbent_settings_object_stack.append(environment_settings_object);
  370. }
  371. void EventLoop::pop_backup_incumbent_settings_object_stack(Badge<EnvironmentSettingsObject>)
  372. {
  373. m_backup_incumbent_settings_object_stack.take_last();
  374. }
  375. EnvironmentSettingsObject& EventLoop::top_of_backup_incumbent_settings_object_stack()
  376. {
  377. return m_backup_incumbent_settings_object_stack.last();
  378. }
  379. void EventLoop::register_environment_settings_object(Badge<EnvironmentSettingsObject>, EnvironmentSettingsObject& environment_settings_object)
  380. {
  381. m_related_environment_settings_objects.append(environment_settings_object);
  382. }
  383. void EventLoop::unregister_environment_settings_object(Badge<EnvironmentSettingsObject>, EnvironmentSettingsObject& environment_settings_object)
  384. {
  385. bool did_remove = m_related_environment_settings_objects.remove_first_matching([&](auto& entry) { return entry.ptr() == &environment_settings_object; });
  386. VERIFY(did_remove);
  387. }
  388. // https://html.spec.whatwg.org/multipage/webappapis.html#same-loop-windows
  389. Vector<JS::Handle<HTML::Window>> EventLoop::same_loop_windows() const
  390. {
  391. Vector<JS::Handle<HTML::Window>> windows;
  392. for (auto& document : documents_in_this_event_loop()) {
  393. if (document->is_fully_active())
  394. windows.append(JS::make_handle(document->window()));
  395. }
  396. return windows;
  397. }
  398. // https://html.spec.whatwg.org/multipage/webappapis.html#event-loop-processing-model:last-idle-period-start-time
  399. double EventLoop::compute_deadline() const
  400. {
  401. // 1. Let deadline be this event loop's last idle period start time plus 50.
  402. auto deadline = m_last_idle_period_start_time + 50;
  403. // 2. Let hasPendingRenders be false.
  404. auto has_pending_renders = false;
  405. // 3. For each windowInSameLoop of the same-loop windows for this event loop:
  406. for (auto& window : same_loop_windows()) {
  407. // 1. If windowInSameLoop's map of animation frame callbacks is not empty,
  408. // or if the user agent believes that the windowInSameLoop might have pending rendering updates,
  409. // set hasPendingRenders to true.
  410. if (window->has_animation_frame_callbacks())
  411. has_pending_renders = true;
  412. // FIXME: 2. Let timerCallbackEstimates be the result of getting the values of windowInSameLoop's map of active timers.
  413. // FIXME: 3. For each timeoutDeadline of timerCallbackEstimates, if timeoutDeadline is less than deadline, set deadline to timeoutDeadline.
  414. }
  415. // 4. If hasPendingRenders is true, then:
  416. if (has_pending_renders) {
  417. // 1. Let nextRenderDeadline be this event loop's last render opportunity time plus (1000 divided by the current refresh rate).
  418. // FIXME: Hardcoded to 60Hz
  419. auto next_render_deadline = m_last_render_opportunity_time + (1000.0 / 60.0);
  420. // 2. If nextRenderDeadline is less than deadline, then return nextRenderDeadline.
  421. if (next_render_deadline < deadline)
  422. return next_render_deadline;
  423. }
  424. // 5. Return deadline.
  425. return deadline;
  426. }
  427. }