From 185ec1cabd0a0323b1c41efc5d7893f841ac2a6c Mon Sep 17 00:00:00 2001 From: Garo Bournoutian Date: Tue, 28 Nov 2023 01:57:04 -0800 Subject: [PATCH] Deprecate SbTime APIs (partial) - Add emulation of POSIX APIs for Windows platforms - Provide common helper functions to simplify getting usec timestamps - Replace usages of SbTimeGetNow and SbTimeGetMonotonicNow in `cobalt` b/302733082 Test-On-Device: true --- base/files/file_enumerator_starboard.cc | 3 +- base/files/file_starboard.cc | 9 +- base/files/file_util_starboard.cc | 9 +- base/logging.cc | 4 +- .../message_loop/message_pump_io_starboard.cc | 2 +- .../message_loop/message_pump_ui_starboard.cc | 2 +- .../condition_variable_starboard.cc | 2 +- base/threading/platform_thread_starboard.cc | 2 +- base/time/time.h | 9 -- base/time/time_now_starboard.cc | 7 +- base/time/time_starboard.cc | 22 ++--- cobalt/base/statistics.h | 2 +- cobalt/base/wrap_main.h | 5 +- .../bindings/testing/bindings_sandbox_main.cc | 3 +- cobalt/bindings/testing/date_bindings_test.cc | 19 ++-- cobalt/browser/application.cc | 12 +-- cobalt/browser/application.h | 15 ++- cobalt/browser/browser_module.cc | 37 +++---- cobalt/browser/browser_module.h | 23 +++-- cobalt/browser/debug_console.h | 12 +-- cobalt/browser/lifecycle_observer.h | 12 +-- cobalt/browser/main.cc | 6 +- cobalt/browser/splash_screen.h | 12 +-- cobalt/browser/web_module.cc | 57 ++++++----- cobalt/browser/web_module.h | 16 +-- cobalt/demos/simple_sandbox/simple_sandbox.cc | 4 +- cobalt/dom/document.cc | 6 +- cobalt/dom/document.h | 10 +- cobalt/dom/html_element.cc | 25 ++--- cobalt/dom/html_element.h | 7 +- cobalt/dom/html_link_element.cc | 5 +- cobalt/dom/html_media_element.cc | 2 +- cobalt/dom/html_style_element.cc | 5 +- cobalt/dom/performance.cc | 8 +- cobalt/dom/performance.h | 7 +- cobalt/dom/performance_lifecycle_timing.cc | 25 +++-- cobalt/dom/performance_lifecycle_timing.h | 28 +++--- cobalt/dom/serialized_algorithm_runner.h | 23 +++-- cobalt/dom/source_buffer_metrics.cc | 16 +-- cobalt/dom/source_buffer_metrics.h | 10 +- cobalt/dom/window.cc | 2 +- cobalt/dom/window.h | 3 +- cobalt/input/input_device_manager_desktop.cc | 2 +- cobalt/media/base/cval_stats.cc | 18 ++-- cobalt/media/base/cval_stats.h | 20 ++-- cobalt/media/base/cval_stats_test.cc | 2 +- .../base/format_support_query_metrics.cc | 13 +-- .../media/base/format_support_query_metrics.h | 9 +- cobalt/media/base/sbplayer_bridge.cc | 47 +++++---- cobalt/media/base/sbplayer_bridge.h | 16 +-- cobalt/media/base/sbplayer_interface.cc | 2 +- cobalt/media/base/sbplayer_interface.h | 4 +- cobalt/media/base/sbplayer_pipeline.cc | 49 +++++----- cobalt/media/base/sbplayer_pipeline.h | 31 +++--- cobalt/media/decoder_buffer_allocator.cc | 2 +- cobalt/media/decoder_buffer_allocator.h | 2 +- cobalt/media/media_module.h | 4 +- cobalt/media/player/web_media_player_impl.cc | 5 +- cobalt/media/player/web_media_player_impl.h | 4 +- .../progressive/demuxer_extension_wrapper.cc | 2 +- .../demuxer_extension_wrapper_test.cc | 12 +-- .../media/progressive/progressive_demuxer.cc | 3 +- .../media/sandbox/web_media_player_sandbox.cc | 17 ++-- cobalt/media_session/BUILD.gn | 1 + cobalt/media_session/media_session.h | 8 +- cobalt/media_session/media_session_client.cc | 12 +-- cobalt/media_session/media_session_client.h | 1 - cobalt/media_session/media_session_state.cc | 35 +++---- cobalt/media_session/media_session_state.h | 24 ++--- cobalt/media_session/media_session_test.cc | 68 +++++++------ cobalt/network/network_module.cc | 2 +- cobalt/network/network_module.h | 8 +- .../renderer/backend/graphics_system_test.cc | 52 ++++++---- .../skia/skia/src/ports/SkTime_cobalt.cc | 5 +- .../renderer/sandbox/renderer_sandbox_main.cc | 3 +- cobalt/script/v8c/v8c.cc | 3 +- .../codelabs/starboard_extensions/codelab.md | 6 +- cobalt/speech/microphone_fake.cc | 1 - cobalt/speech/sandbox/speech_sandbox_main.cc | 3 +- cobalt/system_window/BUILD.gn | 1 + cobalt/system_window/input_event.h | 7 +- cobalt/system_window/system_window.cc | 6 +- .../scroll_engine/scroll_engine.cc | 5 +- .../scroll_engine/scroll_engine.h | 12 +-- cobalt/updater/BUILD.gn | 6 +- cobalt/updater/noop_sandbox.cc | 4 +- cobalt/updater/one_app_only_sandbox.cc | 4 +- cobalt/updater/unzipper.cc | 21 ++-- cobalt/watchdog/watchdog.cc | 41 ++++---- cobalt/watchdog/watchdog.h | 15 ++- cobalt/web/BUILD.gn | 1 + cobalt/web/event.cc | 25 +++-- cobalt/web/event.h | 2 +- cobalt/xhr/xml_http_request.cc | 18 ++-- cobalt/xhr/xml_http_request.h | 2 +- glimp/egl/display.cc | 2 +- net/socket/tcp_socket_starboard.cc | 5 +- net/url_request/url_fetcher_core.cc | 13 +-- starboard/common/BUILD.gn | 2 + starboard/common/time.cc | 59 +++++++++++ starboard/common/time.h | 37 +++++++ starboard/elf_loader/exported_symbols.cc | 4 + .../pthread/condition_variable_wait_timed.cc | 10 +- .../shared/widevine/drm_system_widevine.cc | 3 +- .../shared/win32/posix_emu/include/sys/time.h | 39 ++++++++ .../shared/win32/posix_emu/include/time.h | 41 ++++++++ starboard/shared/win32/posix_emu/time.cc | 98 +++++++++++++++++++ .../api_leak_detector/api_leak_detector.py | 3 + .../stub/debug/docker_debian10_manifest | 1 - .../debug/gn_built_docker_debian10_manifest | 1 - .../api_leak_detector/stub/debug/manifest | 1 - .../stub/devel/docker_debian10_manifest | 1 - .../devel/gn_built_docker_debian10_manifest | 1 - .../api_leak_detector/stub/devel/manifest | 1 - .../stub/gold/docker_debian10_manifest | 1 - .../gold/gn_built_docker_debian10_manifest | 1 - .../api_leak_detector/stub/gold/manifest | 1 - .../stub/qa/docker_debian10_manifest | 1 - .../stub/qa/gn_built_docker_debian10_manifest | 1 - .../tools/api_leak_detector/stub/qa/manifest | 1 - starboard/win/shared/BUILD.gn | 1 + .../shared/platform_configuration/BUILD.gn | 4 +- .../media/filters/source_buffer_stream.cc | 6 +- third_party/musl/BUILD.gn | 1 + third_party/musl/include/sys/time.h | 2 + third_party/musl/include/time.h | 2 + .../src/starboard/sys/time/gettimeofday.c | 22 +++++ .../musl/src/starboard/time/clock_gettime.c | 5 + third_party/musl/src/starboard/time/time.c | 5 + third_party/v8/src/base/platform/time.cc | 13 +-- 130 files changed, 953 insertions(+), 590 deletions(-) create mode 100644 starboard/common/time.cc create mode 100644 starboard/common/time.h create mode 100644 starboard/shared/win32/posix_emu/include/sys/time.h create mode 100644 starboard/shared/win32/posix_emu/include/time.h create mode 100644 starboard/shared/win32/posix_emu/time.cc create mode 100644 third_party/musl/src/starboard/sys/time/gettimeofday.c diff --git a/base/files/file_enumerator_starboard.cc b/base/files/file_enumerator_starboard.cc index 978e9405b6d8..ed6fe9d338a7 100644 --- a/base/files/file_enumerator_starboard.cc +++ b/base/files/file_enumerator_starboard.cc @@ -43,7 +43,8 @@ int64_t FileEnumerator::FileInfo::GetSize() const { } base::Time FileEnumerator::FileInfo::GetLastModifiedTime() const { - return base::Time::FromSbTime(sb_info_.last_modified); + return base::Time::FromDeltaSinceWindowsEpoch( + base::TimeDelta::FromMicroseconds(sb_info_.last_modified)); } // FileEnumerator -------------------------------------------------------------- diff --git a/base/files/file_starboard.cc b/base/files/file_starboard.cc index 40e63d2fc0ac..b3f7362fc745 100644 --- a/base/files/file_starboard.cc +++ b/base/files/file_starboard.cc @@ -256,9 +256,12 @@ bool File::GetInfo(Info* info) { info->is_directory = file_info.is_directory; info->is_symbolic_link = file_info.is_symbolic_link; info->size = file_info.size; - info->last_modified = base::Time::FromSbTime(file_info.last_modified); - info->last_accessed = base::Time::FromSbTime(file_info.last_accessed); - info->creation_time = base::Time::FromSbTime(file_info.creation_time); + info->last_modified = base::Time::FromDeltaSinceWindowsEpoch( + base::TimeDelta::FromMicroseconds(file_info.last_modified)); + info->last_accessed = base::Time::FromDeltaSinceWindowsEpoch( + base::TimeDelta::FromMicroseconds(file_info.last_accessed)); + info->creation_time = base::Time::FromDeltaSinceWindowsEpoch( + base::TimeDelta::FromMicroseconds(file_info.creation_time)); return true; } diff --git a/base/files/file_util_starboard.cc b/base/files/file_util_starboard.cc index be80ab1605e8..83194f42dbbe 100644 --- a/base/files/file_util_starboard.cc +++ b/base/files/file_util_starboard.cc @@ -374,9 +374,12 @@ bool GetFileInfo(const FilePath &file_path, File::Info *results) { results->is_directory = info.is_directory; results->size = info.size; - results->last_modified = base::Time::FromSbTime(info.last_modified); - results->last_accessed = base::Time::FromSbTime(info.last_accessed); - results->creation_time = base::Time::FromSbTime(info.creation_time); + results->last_modified = base::Time::FromDeltaSinceWindowsEpoch( + base::TimeDelta::FromMicroseconds(info.last_modified)); + results->last_accessed = base::Time::FromDeltaSinceWindowsEpoch( + base::TimeDelta::FromMicroseconds(info.last_accessed)); + results->creation_time = base::Time::FromDeltaSinceWindowsEpoch( + base::TimeDelta::FromMicroseconds(info.creation_time)); return true; } diff --git a/base/logging.cc b/base/logging.cc index 5a159ff4f3a0..df473b4b4a46 100644 --- a/base/logging.cc +++ b/base/logging.cc @@ -15,11 +15,11 @@ #include "starboard/client_porting/eztime/eztime.h" #include "starboard/common/log.h" #include "starboard/common/mutex.h" +#include "starboard/common/time.h" #include "starboard/configuration.h" #include "starboard/configuration_constants.h" #include "starboard/file.h" #include "starboard/system.h" -#include "starboard/time.h" typedef SbFile FileHandle; typedef SbMutex MutexHandle; #else @@ -210,7 +210,7 @@ int32_t CurrentProcessId() { uint64_t TickCount() { #if defined(STARBOARD) - return static_cast(SbTimeGetMonotonicNow()); + return starboard::CurrentMonotonicTime(); #else #if defined(OS_WIN) return GetTickCount(); diff --git a/base/message_loop/message_pump_io_starboard.cc b/base/message_loop/message_pump_io_starboard.cc index 0194e5442a8f..5072fc188b37 100644 --- a/base/message_loop/message_pump_io_starboard.cc +++ b/base/message_loop/message_pump_io_starboard.cc @@ -215,7 +215,7 @@ void MessagePumpIOStarboard::Run(Delegate* delegate) { } else { TimeDelta delay = delayed_work_time_ - TimeTicks::Now(); if (delay > TimeDelta()) { - SbSocketWaiterWaitTimed(waiter_, delay.ToSbTime()); + SbSocketWaiterWaitTimed(waiter_, delay.InMicroseconds()); } else { // It looks like delayed_work_time_ indicates a time in the past, so we // need to call DoDelayedWork now. diff --git a/base/message_loop/message_pump_ui_starboard.cc b/base/message_loop/message_pump_ui_starboard.cc index ca6ce46ae41b..32b9e09b9a48 100644 --- a/base/message_loop/message_pump_ui_starboard.cc +++ b/base/message_loop/message_pump_ui_starboard.cc @@ -120,7 +120,7 @@ void MessagePumpUIStarboard::ScheduleDelayedWork( CancelDelayedLocked(); outstanding_delayed_events_.insert( - SbEventSchedule(&CallMessagePumpDelayed, this, delay.ToSbTime())); + SbEventSchedule(&CallMessagePumpDelayed, this, delay.InMicroseconds())); } } diff --git a/base/synchronization/condition_variable_starboard.cc b/base/synchronization/condition_variable_starboard.cc index 67747f0c90e3..b5a782d3dfcd 100644 --- a/base/synchronization/condition_variable_starboard.cc +++ b/base/synchronization/condition_variable_starboard.cc @@ -56,7 +56,7 @@ void ConditionVariable::Wait() { void ConditionVariable::TimedWait(const TimeDelta& max_time) { internal::ScopedBlockingCallWithBaseSyncPrimitives scoped_blocking_call( BlockingType::MAY_BLOCK); - SbTime duration = max_time.ToSbTime(); + int64_t duration = max_time.InMicroseconds(); #if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON) user_lock_->CheckHeldAndUnmark(); diff --git a/base/threading/platform_thread_starboard.cc b/base/threading/platform_thread_starboard.cc index 0139ec28b381..4f26edef57e7 100644 --- a/base/threading/platform_thread_starboard.cc +++ b/base/threading/platform_thread_starboard.cc @@ -101,7 +101,7 @@ void PlatformThread::YieldCurrentThread() { // static void PlatformThread::Sleep(TimeDelta duration) { - SbThreadSleep(duration.ToSbTime()); + SbThreadSleep(duration.InMicroseconds()); } // static diff --git a/base/time/time.h b/base/time/time.h index 58305d86afc3..1d6e281a9278 100644 --- a/base/time/time.h +++ b/base/time/time.h @@ -182,10 +182,6 @@ class BASE_EXPORT TimeDelta { return delta_ == std::numeric_limits::min(); } -#if defined(STARBOARD) - SbTime ToSbTime() const; -#endif - #if defined(OS_POSIX) || defined(OS_FUCHSIA) struct timespec ToTimeSpec() const; #endif @@ -578,11 +574,6 @@ class BASE_EXPORT Time : public time_internal::TimeBase