From 67d3e5e5289c11f1f5f319458b3d4a7528bad39c Mon Sep 17 00:00:00 2001 From: salvadordf Date: Tue, 14 Jun 2022 11:27:45 +0200 Subject: [PATCH] Added more time handling functions --- source/uCEFApplicationCore.pas | 20 +++++++- source/uCEFLibFunctions.pas | 8 +++ source/uCEFMiscFunctions.pas | 90 ++++++++++++++++++++++++++++++++++ update_CEF4Delphi.json | 2 +- 4 files changed, 118 insertions(+), 2 deletions(-) diff --git a/source/uCEFApplicationCore.pas b/source/uCEFApplicationCore.pas index c42bb36d..f6f70021 100644 --- a/source/uCEFApplicationCore.pas +++ b/source/uCEFApplicationCore.pas @@ -345,6 +345,7 @@ type function Load_cef_textfield_capi_h : boolean; function Load_cef_window_capi_h : boolean; function Load_cef_types_linux_h : boolean; + function Load_cef_time_h : boolean; procedure ShutDown; procedure FreeLibcefLibrary; @@ -2549,7 +2550,8 @@ begin Load_cef_scroll_view_capi_h and Load_cef_textfield_capi_h and Load_cef_window_capi_h and - Load_cef_types_linux_h then + Load_cef_types_linux_h and + Load_cef_time_h then begin FStatus := asLoaded; FLibLoaded := True; @@ -3185,6 +3187,22 @@ begin {$ENDIF} end; +function TCefApplicationCore.Load_cef_time_h : boolean; +begin + {$IFDEF FPC}Pointer({$ENDIF}cef_time_to_timet{$IFDEF FPC}){$ENDIF} := GetProcAddress(FLibHandle, 'cef_time_to_timet'); + {$IFDEF FPC}Pointer({$ENDIF}cef_time_from_timet{$IFDEF FPC}){$ENDIF} := GetProcAddress(FLibHandle, 'cef_time_from_timet'); + {$IFDEF FPC}Pointer({$ENDIF}cef_time_to_doublet{$IFDEF FPC}){$ENDIF} := GetProcAddress(FLibHandle, 'cef_time_to_doublet'); + {$IFDEF FPC}Pointer({$ENDIF}cef_time_from_doublet{$IFDEF FPC}){$ENDIF} := GetProcAddress(FLibHandle, 'cef_time_from_doublet'); + {$IFDEF FPC}Pointer({$ENDIF}cef_time_now{$IFDEF FPC}){$ENDIF} := GetProcAddress(FLibHandle, 'cef_time_now'); + {$IFDEF FPC}Pointer({$ENDIF}cef_time_delta{$IFDEF FPC}){$ENDIF} := GetProcAddress(FLibHandle, 'cef_time_delta'); + + Result := assigned(cef_time_to_timet) and + assigned(cef_time_from_timet) and + assigned(cef_time_to_doublet) and + assigned(cef_time_from_doublet) and + assigned(cef_time_now) and + assigned(cef_time_delta); +end; // TCEFDirectoryDeleterThread diff --git a/source/uCEFLibFunctions.pas b/source/uCEFLibFunctions.pas index 0e9a86f6..7ede398e 100644 --- a/source/uCEFLibFunctions.pas +++ b/source/uCEFLibFunctions.pas @@ -347,6 +347,14 @@ var cef_get_current_platform_thread_id : function : TCefPlatformThreadId; cdecl; cef_get_current_platform_thread_handle : function : TCefPlatformThreadHandle; cdecl; + // /include/internal/cef_time.h + cef_time_to_timet : function(const cef_time: PCefTime; out time_: Int64): integer; cdecl; + cef_time_from_timet : function(time_: int64; out cef_time: TCefTime): integer; cdecl; + cef_time_to_doublet : function(const cef_time: PCefTime; out time_: double): integer; cdecl; + cef_time_from_doublet : function(time: double; out cef_time: TCefTime): integer; cdecl; + cef_time_now : function(out cef_time: TCefTime): integer; cdecl; + cef_time_delta : function(const cef_time1, cef_time2: PCefTime; out delta: int64): integer; cdecl; + // /include/internal/cef_trace_event_internal.h cef_trace_event_instant : procedure(const category, name, arg1_name: PAnsiChar; arg1_val: uint64; const arg2_name: PAnsiChar; arg2_val: UInt64; copy: Integer); cdecl; cef_trace_event_begin : procedure(const category, name, arg1_name: PAnsiChar; arg1_val: UInt64; const arg2_name: PAnsiChar; arg2_val: UInt64; copy: Integer); cdecl; diff --git a/source/uCEFMiscFunctions.pas b/source/uCEFMiscFunctions.pas index c7c22395..3f586784 100644 --- a/source/uCEFMiscFunctions.pas +++ b/source/uCEFMiscFunctions.pas @@ -129,6 +129,15 @@ function SystemTimeToCefTime(const dt: TSystemTime): TCefTime; function FixCefTime(const dt : TCefTime): TCefTime; function CefTimeToDateTime(const dt: TCefTime): TDateTime; function DateTimeToCefTime(dt: TDateTime): TCefTime; +function CefTimeToDouble(const dt: TCefTime): double; +function DoubleToCefTime(const dt: double): TCefTime; +function CefTimeToUnixTime(const dt: TCefTime): int64; +function UnixTimeToCefTime(const dt: int64): TCefTime; +function CefTimeNow: TCefTime; +function DoubleTimeNow: double; +function CefTimeDelta(const cef_time1, cef_time2: TCefTime): int64; +function GetTimeIntervalMilliseconds(const from_: TCefTime): integer; +procedure InitializeCefTime(var aTime : TCefTime); function cef_string_wide_copy(const src: PWideChar; src_len: NativeUInt; output: PCefStringWide): Integer; function cef_string_utf8_copy(const src: PAnsiChar; src_len: NativeUInt; output: PCefStringUtf8): Integer; @@ -617,6 +626,87 @@ begin Result.millisecond := TempMSec; end; +function CefTimeToDouble(const dt: TCefTime): double; +begin + Result := 0; + if (GlobalCEFApp <> nil) and GlobalCEFApp.LibLoaded then + cef_time_to_doublet(@dt, Result); +end; + +function DoubleToCefTime(const dt: double): TCefTime; +begin + FillChar(Result, SizeOf(TCefTime), #0); + if (GlobalCEFApp <> nil) and GlobalCEFApp.LibLoaded then + cef_time_from_doublet(dt, Result); +end; + +function CefTimeToUnixTime(const dt: TCefTime): int64; +begin + Result := 0; + if (GlobalCEFApp <> nil) and GlobalCEFApp.LibLoaded then + cef_time_to_timet(@dt, Result); +end; + +function UnixTimeToCefTime(const dt: int64): TCefTime; +begin + FillChar(Result, SizeOf(TCefTime), #0); + if (GlobalCEFApp <> nil) and GlobalCEFApp.LibLoaded then + cef_time_from_timet(dt, Result); +end; + +function CefTimeNow: TCefTime; +begin + FillChar(Result, SizeOf(TCefTime), #0); + if (GlobalCEFApp <> nil) and GlobalCEFApp.LibLoaded then + cef_time_now(Result); +end; + +function DoubleTimeNow: double; +var + TempTime : TCefTime; +begin + Result := 0; + if (GlobalCEFApp <> nil) and GlobalCEFApp.LibLoaded then + begin + FillChar(TempTime, SizeOf(TCefTime), #0); + if (cef_time_now(TempTime) <> 0) then + cef_time_to_doublet(@TempTime, Result); + end; +end; + +function CefTimeDelta(const cef_time1, cef_time2: TCefTime): int64; +begin + Result := 0; + if (GlobalCEFApp <> nil) and GlobalCEFApp.LibLoaded then + cef_time_delta(@cef_time1, @cef_time2, Result); +end; + +function GetTimeIntervalMilliseconds(const from_: TCefTime): integer; +var + TempFrom : double; + TempDelay : integer; +begin + Result := -1; + TempFrom := CefTimeToDouble(from_); + + if (TempFrom = 0) then exit; + + TempDelay := ceil((TempFrom - DoubleTimeNow) * 1000); + Result := max(0, TempDelay); +end; + +procedure InitializeCefTime(var aTime : TCefTime); +begin + aTime.year := 0; + aTime.month := 0; + aTime.day_of_week := 0; + aTime.day_of_month := 0; + aTime.hour := 0; + aTime.minute := 0; + aTime.second := 0; + aTime.millisecond := 0; +end; + function cef_string_wide_copy(const src: PWideChar; src_len: NativeUInt; output: PCefStringWide): Integer; begin if (GlobalCEFApp <> nil) and GlobalCEFApp.LibLoaded then diff --git a/update_CEF4Delphi.json b/update_CEF4Delphi.json index 092c23d7..9be88468 100644 --- a/update_CEF4Delphi.json +++ b/update_CEF4Delphi.json @@ -2,7 +2,7 @@ "UpdateLazPackages" : [ { "ForceNotify" : true, - "InternalVersion" : 400, + "InternalVersion" : 401, "Name" : "cef4delphi_lazarus.lpk", "Version" : "102.0.9.0" }