Browse Source

* Add performance.now API to timer APIs

Michael Van Canneyt 3 months ago
parent
commit
dd4b9fbbd0

+ 15 - 0
packages/wasm-utils/src/wasm.pas2js.timer.pas

@@ -26,6 +26,7 @@ Type
   private
   private
     function AllocateTimer(ainterval: longint; userdata: TWasmPointer): TWasmTimerID;
     function AllocateTimer(ainterval: longint; userdata: TWasmPointer): TWasmTimerID;
     procedure DeallocateTimer(timerid: TWasmTimerID);
     procedure DeallocateTimer(timerid: TWasmTimerID);
+    function PerformanceNow(aNow : TWasmPointer) : Longint;
     function GetLogApiCalls: Boolean;
     function GetLogApiCalls: Boolean;
     procedure SetLogApiCalls(AValue: Boolean);
     procedure SetLogApiCalls(AValue: Boolean);
   Protected
   Protected
@@ -68,6 +69,7 @@ procedure TWasmTimerAPI.FillImportObject(aObject: TJSObject);
 begin
 begin
   aObject[TimerFN_Allocate]:=@AllocateTimer;
   aObject[TimerFN_Allocate]:=@AllocateTimer;
   aObject[TimerFN_DeAllocate]:=@DeAllocateTimer;
   aObject[TimerFN_DeAllocate]:=@DeAllocateTimer;
+  aObject[TimerFN_Performance_Now]:=@PerformanceNow;
 end;
 end;
 
 
 
 
@@ -134,6 +136,19 @@ begin
   {$endif}
   {$endif}
 end;
 end;
 
 
+function TWasmTimerAPI.PerformanceNow(aNow: TWasmPointer): Longint;
+
+begin
+  if assigned(self_.Performance) then
+    begin
+    env.SetMemInfoFloat64(aNow,self_.Performance.Now);
+    Result:=ETIMER_SUCCESS;
+    end
+  else
+    Result:=ETIMER_NOPERFORMANCE;
+
+end;
+
 function TWasmTimerAPI.GetLogApiCalls: Boolean;
 function TWasmTimerAPI.GetLogApiCalls: Boolean;
 begin
 begin
   Result:=LogAPI;
   Result:=LogAPI;

+ 6 - 1
packages/wasm-utils/src/wasm.timer.shared.pas

@@ -7,11 +7,16 @@ interface
 Type
 Type
   TWasmTimerID = Longint;
   TWasmTimerID = Longint;
 
 
-const
+Const
+  ETIMER_SUCCESS       = 0;
+  ETIMER_NOPERFORMANCE = -1;
+
   TimerExportName  = 'timer';
   TimerExportName  = 'timer';
   TimerFN_Allocate = 'allocate_timer';
   TimerFN_Allocate = 'allocate_timer';
   TimerFN_DeAllocate = 'deallocate_timer';
   TimerFN_DeAllocate = 'deallocate_timer';
 
 
+  TimerFN_Performance_Now = 'timer_performance_now';
+
 
 
 implementation
 implementation