• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2019 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 
7 // system_utils_winuwp.cpp: Implementation of OS-specific functions for Windows UWP
8 
9 #include "system_utils.h"
10 
11 #include <stdarg.h>
12 #include <windows.h>
13 #include <array>
14 #include <codecvt>
15 #include <locale>
16 #include <string>
17 
18 namespace angle
19 {
20 
SetEnvironmentVar(const char * variableName,const char * value)21 bool SetEnvironmentVar(const char *variableName, const char *value)
22 {
23     // Not supported for UWP
24     return false;
25 }
26 
GetEnvironmentVar(const char * variableName)27 std::string GetEnvironmentVar(const char *variableName)
28 {
29     // Not supported for UWP
30     return "";
31 }
32 
33 class UwpLibrary : public Library
34 {
35   public:
UwpLibrary(const char * libraryName,SearchType searchType)36     UwpLibrary(const char *libraryName, SearchType searchType)
37     {
38         std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
39         std::wstring wideBuffer = converter.from_bytes(libraryName);
40 
41         switch (searchType)
42         {
43             case SearchType::ApplicationDir:
44                 mModule = LoadPackagedLibrary(wideBuffer.c_str(), 0);
45                 break;
46             case SearchType::SystemDir:
47                 // Not supported in UWP
48                 break;
49         }
50     }
51 
~UwpLibrary()52     ~UwpLibrary() override
53     {
54         if (mModule)
55         {
56             FreeLibrary(mModule);
57         }
58     }
59 
getSymbol(const char * symbolName)60     void *getSymbol(const char *symbolName) override
61     {
62         if (!mModule)
63         {
64             return nullptr;
65         }
66 
67         return reinterpret_cast<void *>(GetProcAddress(mModule, symbolName));
68     }
69 
getNative() const70     void *getNative() const override { return reinterpret_cast<void *>(mModule); }
71 
72   private:
73     HMODULE mModule = nullptr;
74 };
75 
OpenSharedLibrary(const char * libraryName,SearchType searchType)76 Library *OpenSharedLibrary(const char *libraryName, SearchType searchType)
77 {
78     char buffer[MAX_PATH];
79     int ret = snprintf(buffer, MAX_PATH, "%s.%s", libraryName, GetSharedLibraryExtension());
80 
81     if (ret > 0 && ret < MAX_PATH)
82     {
83         return new UwpLibrary(buffer, searchType);
84     }
85     else
86     {
87         fprintf(stderr, "Error loading shared library: 0x%x", ret);
88         return nullptr;
89     }
90 }
91 
OpenSharedLibraryWithExtension(const char * libraryName)92 Library *OpenSharedLibraryWithExtension(const char *libraryName)
93 {
94     // SystemDir is not implemented in UWP.
95     fprintf(stderr, "Error loading shared library with extension.\n");
96     return nullptr;
97 }
98 }  // namespace angle
99