API restricted on WinRT partially removed from core.

Additional CMAKE flag WITH_WINRT added.
This commit is contained in:
Alexander Smorkalov
2013-07-19 02:43:05 -07:00
parent 4c35449b7d
commit 6257df1c4b
8 changed files with 163 additions and 5 deletions

View File

@@ -47,6 +47,9 @@
#define _WIN32_WINNT 0x0400 // http://msdn.microsoft.com/en-us/library/ms686857(VS.85).aspx
#endif
#include <windows.h>
#if (_WIN32_WINNT >= 0x0602)
#include <synchapi.h>
#endif
#undef small
#undef min
#undef max
@@ -75,6 +78,32 @@
}
#endif
#endif
#ifdef HAVE_WINRT
#pragma comment(lib, "MinCore_Downlevel")
#include <wrl/client.h>
std::wstring GetTempPathWinRT()
{
return std::wstring(Windows::Storage::ApplicationData::Current->TemporaryFolder->Path->Data());
}
std::wstring GetTempFileNameWinRT(std::wstring prefix)
{
wchar_t guidStr[120];
GUID* g = 0x00;
g = new GUID;
CoCreateGuid(g);
wchar_t* mask = L"%08x_%04x_%04x_%02x%02x_%02x%02x%02x%02x%02x%02x";
swprintf(&guidStr[0],mask, 120, g->Data1,g->Data2,g->Data3,UINT(g->Data4[0]),
UINT(g->Data4[1]),UINT(g->Data4[2]),UINT(g->Data4[3]),UINT(g->Data4[4]),
UINT(g->Data4[5]),UINT(g->Data4[6]),UINT(g->Data4[7]));
delete g;
return prefix + std::wstring(guidStr);
}
#endif
#else
#include <pthread.h>
#include <sys/time.h>
@@ -359,10 +388,39 @@ string format( const char* fmt, ... )
string tempfile( const char* suffix )
{
#ifdef HAVE_WINRT
std::wstring temp_dir = L"";
wchar_t* opencv_temp_dir = _wgetenv(L"OPENCV_TEMP_PATH");
if (opencv_temp_dir)
temp_dir = std::wstring(opencv_temp_dir);
#else
const char *temp_dir = getenv("OPENCV_TEMP_PATH");
#endif
string fname;
#if defined WIN32 || defined _WIN32
#ifdef HAVE_WINRT
RoInitialize(RO_INIT_MULTITHREADED);
std::wstring temp_dir2;
if (temp_dir.empty())
temp_dir = GetTempPathWinRT();
std::wstring temp_file;
temp_file = GetTempFileNameWinRT(L"ocv");
if (temp_file.empty())
return std::string();
temp_file = temp_dir + std::wstring(L"\\") + temp_file;
DeleteFileW(temp_file.c_str());
size_t asize = wcstombs(NULL, temp_file.c_str(), 0);
char* aname = (char*)malloc((asize+1)*sizeof(char));
aname[asize] = 0;
wcstombs(aname, temp_file.c_str(), asize);
fname = std::string(aname);
free(aname);
RoUninitialize();
#else
char temp_dir2[MAX_PATH + 1] = { 0 };
char temp_file[MAX_PATH + 1] = { 0 };
@@ -377,6 +435,7 @@ string tempfile( const char* suffix )
DeleteFileA(temp_file);
fname = temp_file;
#endif
# else
# ifdef ANDROID
//char defaultTemplate[] = "/mnt/sdcard/__opencv_temp.XXXXXX";
@@ -766,7 +825,15 @@ namespace cv
struct Mutex::Impl
{
Impl() { InitializeCriticalSection(&cs); refcount = 1; }
Impl()
{
#if (_WIN32_WINNT >= 0x0600)
::InitializeCriticalSectionEx(&cs, 1000, 0);
#else
::InitializeCriticalSection(&cs);
#endif
refcount = 1;
}
~Impl() { DeleteCriticalSection(&cs); }
void lock() { EnterCriticalSection(&cs); }