Adding WinUWP compilation support to WebRTC.

Windows UWP allows an application to be built that targets
across all Windows 10 based systems and the Windows store.

Change-Id: I69694bb7e83fb01ad6db2438b065b55738cf01fd
Bug: webrtc:10046
Reviewed-on: https://webrtc-review.googlesource.com/c/110570
Commit-Queue: Patrik Höglund <phoglund@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Patrik Höglund <phoglund@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#25814}
This commit is contained in:
Robin Raymond
2018-11-22 20:10:11 -05:00
committed by Commit Bot
parent 3bc24bcd3e
commit ce1b140b8d
15 changed files with 270 additions and 44 deletions

View File

@ -14,23 +14,19 @@
namespace webrtc {
static bool native_rw_locks_supported = false;
static bool module_load_attempted = false;
static HMODULE library = NULL;
typedef void(WINAPI* PInitializeSRWLock)(PSRWLOCK);
typedef void(WINAPI* InitializeSRWLock)(PSRWLOCK);
typedef void(WINAPI* PAcquireSRWLockExclusive)(PSRWLOCK);
typedef void(WINAPI* PReleaseSRWLockExclusive)(PSRWLOCK);
typedef void(WINAPI* AcquireSRWLockExclusive)(PSRWLOCK);
typedef void(WINAPI* ReleaseSRWLockExclusive)(PSRWLOCK);
typedef void(WINAPI* PAcquireSRWLockShared)(PSRWLOCK);
typedef void(WINAPI* PReleaseSRWLockShared)(PSRWLOCK);
typedef void(WINAPI* AcquireSRWLockShared)(PSRWLOCK);
typedef void(WINAPI* ReleaseSRWLockShared)(PSRWLOCK);
InitializeSRWLock initialize_srw_lock;
AcquireSRWLockExclusive acquire_srw_lock_exclusive;
AcquireSRWLockShared acquire_srw_lock_shared;
ReleaseSRWLockShared release_srw_lock_shared;
ReleaseSRWLockExclusive release_srw_lock_exclusive;
PInitializeSRWLock initialize_srw_lock;
PAcquireSRWLockExclusive acquire_srw_lock_exclusive;
PAcquireSRWLockShared acquire_srw_lock_shared;
PReleaseSRWLockShared release_srw_lock_shared;
PReleaseSRWLockExclusive release_srw_lock_exclusive;
RWLockWin::RWLockWin() {
initialize_srw_lock(&lock_);
@ -60,28 +56,31 @@ void RWLockWin::ReleaseLockShared() {
}
bool RWLockWin::LoadModule() {
static bool module_load_attempted = false;
static bool native_rw_locks_supported = false;
if (module_load_attempted) {
return native_rw_locks_supported;
}
module_load_attempted = true;
#if !defined(WINUWP)
// Use native implementation if supported (i.e Vista+)
library = LoadLibrary(TEXT("Kernel32.dll"));
static HMODULE library = LoadLibrary(TEXT("Kernel32.dll"));
if (!library) {
return false;
}
RTC_LOG(LS_VERBOSE) << "Loaded Kernel.dll";
initialize_srw_lock =
(InitializeSRWLock)GetProcAddress(library, "InitializeSRWLock");
(PInitializeSRWLock)GetProcAddress(library, "InitializeSRWLock");
acquire_srw_lock_exclusive = (AcquireSRWLockExclusive)GetProcAddress(
acquire_srw_lock_exclusive = (PAcquireSRWLockExclusive)GetProcAddress(
library, "AcquireSRWLockExclusive");
release_srw_lock_exclusive = (ReleaseSRWLockExclusive)GetProcAddress(
release_srw_lock_exclusive = (PReleaseSRWLockExclusive)GetProcAddress(
library, "ReleaseSRWLockExclusive");
acquire_srw_lock_shared =
(AcquireSRWLockShared)GetProcAddress(library, "AcquireSRWLockShared");
(PAcquireSRWLockShared)GetProcAddress(library, "AcquireSRWLockShared");
release_srw_lock_shared =
(ReleaseSRWLockShared)GetProcAddress(library, "ReleaseSRWLockShared");
(PReleaseSRWLockShared)GetProcAddress(library, "ReleaseSRWLockShared");
if (initialize_srw_lock && acquire_srw_lock_exclusive &&
release_srw_lock_exclusive && acquire_srw_lock_shared &&
@ -89,6 +88,18 @@ bool RWLockWin::LoadModule() {
RTC_LOG(LS_VERBOSE) << "Loaded Native RW Lock";
native_rw_locks_supported = true;
}
#else
// On WinUWP the symbols loaded from this library are directly present
// in the headers and thus loading the library is not required (and
// manually loading libraries is restricted due to WinUWP sandboxing).
initialize_srw_lock = InitializeSRWLock;
acquire_srw_lock_exclusive = AcquireSRWLockExclusive;
release_srw_lock_exclusive = ReleaseSRWLockExclusive;
acquire_srw_lock_shared = AcquireSRWLockShared;
release_srw_lock_shared = ReleaseSRWLockShared;
native_rw_locks_supported = true;
#endif // !defined(WINUWP)
return native_rw_locks_supported;
}