Commit bf5b35f1 authored by Zebediah Figura's avatar Zebediah Figura Committed by Alexandre Julliard

quartz: Use the performance counter for the system clock.

Native probably uses timeGetTime() as a source. That doesn't actually match the performance counter on Windows, but it does on Wine, and accessing the counter directly is slightly more efficient anyway. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=51684Signed-off-by: 's avatarZebediah Figura <zfigura@codeweavers.com> Signed-off-by: 's avatarAlexandre Julliard <julliard@winehq.org>
parent 7c67ebfd
...@@ -44,6 +44,7 @@ struct system_clock ...@@ -44,6 +44,7 @@ struct system_clock
BOOL thread_created, thread_stopped; BOOL thread_created, thread_stopped;
HANDLE thread; HANDLE thread;
LARGE_INTEGER frequency;
REFERENCE_TIME last_time; REFERENCE_TIME last_time;
CRITICAL_SECTION cs; CRITICAL_SECTION cs;
CONDITION_VARIABLE cv; CONDITION_VARIABLE cv;
...@@ -51,6 +52,14 @@ struct system_clock ...@@ -51,6 +52,14 @@ struct system_clock
struct list sinks; struct list sinks;
}; };
static REFERENCE_TIME get_current_time(const struct system_clock *clock)
{
LARGE_INTEGER time;
QueryPerformanceCounter(&time);
return (time.QuadPart * 1000) / clock->frequency.QuadPart * 10000;
}
static inline struct system_clock *impl_from_IUnknown(IUnknown *iface) static inline struct system_clock *impl_from_IUnknown(IUnknown *iface)
{ {
return CONTAINING_RECORD(iface, struct system_clock, IUnknown_inner); return CONTAINING_RECORD(iface, struct system_clock, IUnknown_inner);
...@@ -145,7 +154,7 @@ static DWORD WINAPI SystemClockAdviseThread(void *param) ...@@ -145,7 +154,7 @@ static DWORD WINAPI SystemClockAdviseThread(void *param)
EnterCriticalSection(&clock->cs); EnterCriticalSection(&clock->cs);
current_time = GetTickCount64() * 10000; current_time = get_current_time(clock);
LIST_FOR_EACH_ENTRY_SAFE(sink, cursor, &clock->sinks, struct advise_sink, entry) LIST_FOR_EACH_ENTRY_SAFE(sink, cursor, &clock->sinks, struct advise_sink, entry)
{ {
...@@ -240,7 +249,7 @@ static HRESULT WINAPI SystemClockImpl_GetTime(IReferenceClock *iface, REFERENCE_ ...@@ -240,7 +249,7 @@ static HRESULT WINAPI SystemClockImpl_GetTime(IReferenceClock *iface, REFERENCE_
return E_POINTER; return E_POINTER;
} }
ret = GetTickCount64() * 10000; ret = get_current_time(clock);
EnterCriticalSection(&clock->cs); EnterCriticalSection(&clock->cs);
...@@ -336,6 +345,7 @@ HRESULT system_clock_create(IUnknown *outer, IUnknown **out) ...@@ -336,6 +345,7 @@ HRESULT system_clock_create(IUnknown *outer, IUnknown **out)
list_init(&object->sinks); list_init(&object->sinks);
InitializeCriticalSection(&object->cs); InitializeCriticalSection(&object->cs);
object->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": SystemClockImpl.cs"); object->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": SystemClockImpl.cs");
QueryPerformanceFrequency(&object->frequency);
TRACE("Created system clock %p.\n", object); TRACE("Created system clock %p.\n", object);
*out = &object->IUnknown_inner; *out = &object->IUnknown_inner;
......
TESTDLL = quartz.dll TESTDLL = quartz.dll
IMPORTS = strmbase advapi32 d3d9 dsound msdmo msvfw32 ole32 oleaut32 user32 uuid IMPORTS = strmbase advapi32 d3d9 dsound msdmo msvfw32 ole32 oleaut32 user32 uuid winmm
C_SRCS = \ C_SRCS = \
acmwrapper.c \ acmwrapper.c \
......
...@@ -22,8 +22,6 @@ ...@@ -22,8 +22,6 @@
#include "dshow.h" #include "dshow.h"
#include "wine/test.h" #include "wine/test.h"
static ULONGLONG (WINAPI *pGetTickCount64)(void);
static IReferenceClock *create_system_clock(void) static IReferenceClock *create_system_clock(void)
{ {
IReferenceClock *clock = NULL; IReferenceClock *clock = NULL;
...@@ -178,10 +176,7 @@ static void test_get_time(void) ...@@ -178,10 +176,7 @@ static void test_get_time(void)
ok(time1 % 10000 == 0, "Expected no less than 1ms coarseness, but got time %s.\n", ok(time1 % 10000 == 0, "Expected no less than 1ms coarseness, but got time %s.\n",
wine_dbgstr_longlong(time1)); wine_dbgstr_longlong(time1));
if (pGetTickCount64) ticks = (REFERENCE_TIME)timeGetTime() * 10000;
ticks = pGetTickCount64() * 10000;
else
ticks = (REFERENCE_TIME)GetTickCount() * 10000;
hr = IReferenceClock_GetTime(clock, &time2); hr = IReferenceClock_GetTime(clock, &time2);
ok(hr == (time2 == time1 ? S_FALSE : S_OK), "Got hr %#x.\n", hr); ok(hr == (time2 == time1 ? S_FALSE : S_OK), "Got hr %#x.\n", hr);
...@@ -291,8 +286,6 @@ START_TEST(systemclock) ...@@ -291,8 +286,6 @@ START_TEST(systemclock)
{ {
CoInitialize(NULL); CoInitialize(NULL);
pGetTickCount64 = (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"), "GetTickCount64");
test_interfaces(); test_interfaces();
test_aggregation(); test_aggregation();
test_get_time(); test_get_time();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment