Edit

kc3-lang/angle/src/common/system_utils_win.cpp

Branch :

  • Show log

    Commit

  • Author : Jonah Ryan-Davis
    Date : 2021-05-18 15:10:58
    Hash : ffb71dc2
    Message : Revert "Reland Change to module directory when loading swiftshader ICD." This reverts commit c8c414b084fa3b6550b10dff48cf429719e04579. Reason for revert: Breaking fuchsia_x64 and ANGLE autoroller Original change's description: > Reland Change to module directory when loading swiftshader ICD. > > This is a reland of commit 3b10dda6a479612a07673b5c87d3560e0941d41b. > > Extra changes: > Be explicit about calling GetModuleHandleA > Do not use the general GetModuleHandle, which may use wide strings > > GetModuleDirectory should return the full path, not relative. > ANGLE wasn't able to locate the vulkan ICD file because it was > searching down an invalid relative path. This can be fixed by > ensuring the module directory is always the full path. > on some platforms. > > Original change's description: > > When loading vulkan, we can be running from any directory. We need > > to change to the module directory to ensure the swiftshader ICD is > > loaded properly. For example, in some Chrome releases, libGLESv2.dll > > and libvk_swiftshader.dll are in a subdirectory relative to chrome.exe > > > > Bug: chromium:1198567 > > Change-Id: I9e68927e512b239728fb2903d1a04702508a4948 > > Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2873452 > > Commit-Queue: Jonah Ryan-Davis <jonahr@google.com> > > Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> > > Reviewed-by: Jamie Madill <jmadill@chromium.org> > > Bug: chromium:1198567 > Bug: angleproject:5949 > Change-Id: Ib34067002c788f00b5ae2fa11d1e465f57bd7be8 > Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2893503 > Reviewed-by: Jamie Madill <jmadill@chromium.org> > Reviewed-by: Cody Northrop <cnorthrop@google.com> > Commit-Queue: Jonah Ryan-Davis <jonahr@google.com> Bug: chromium:1198567 Bug: angleproject:5949 Change-Id: Ic0be8949cc27b231be4f982ea6e22beed590d24d Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2903786 Reviewed-by: Jamie Madill <jmadill@chromium.org>

  • src/common/system_utils_win.cpp
  • //
    // Copyright 2014 The ANGLE Project Authors. All rights reserved.
    // Use of this source code is governed by a BSD-style license that can be
    // found in the LICENSE file.
    //
    
    // system_utils_win.cpp: Implementation of OS-specific functions for Windows
    
    #include "system_utils.h"
    
    #include <stdarg.h>
    #include <windows.h>
    #include <array>
    #include <vector>
    
    namespace angle
    {
    std::string GetExecutablePath()
    {
        std::array<char, MAX_PATH> executableFileBuf;
        DWORD executablePathLen = GetModuleFileNameA(nullptr, executableFileBuf.data(),
                                                     static_cast<DWORD>(executableFileBuf.size()));
        return (executablePathLen > 0 ? std::string(executableFileBuf.data()) : "");
    }
    
    std::string GetExecutableDirectory()
    {
        std::string executablePath = GetExecutablePath();
        size_t lastPathSepLoc      = executablePath.find_last_of("\\/");
        return (lastPathSepLoc != std::string::npos) ? executablePath.substr(0, lastPathSepLoc) : "";
    }
    
    const char *GetSharedLibraryExtension()
    {
        return "dll";
    }
    
    Optional<std::string> GetCWD()
    {
        std::array<char, MAX_PATH> pathBuf;
        DWORD result = GetCurrentDirectoryA(static_cast<DWORD>(pathBuf.size()), pathBuf.data());
        if (result == 0)
        {
            return Optional<std::string>::Invalid();
        }
        return std::string(pathBuf.data());
    }
    
    bool SetCWD(const char *dirName)
    {
        return (SetCurrentDirectoryA(dirName) == TRUE);
    }
    
    const char *GetPathSeparatorForEnvironmentVar()
    {
        return ";";
    }
    
    double GetCurrentTime()
    {
        LARGE_INTEGER frequency = {};
        QueryPerformanceFrequency(&frequency);
    
        LARGE_INTEGER curTime;
        QueryPerformanceCounter(&curTime);
    
        return static_cast<double>(curTime.QuadPart) / frequency.QuadPart;
    }
    
    bool IsDirectory(const char *filename)
    {
        WIN32_FILE_ATTRIBUTE_DATA fileInformation;
    
        BOOL result = GetFileAttributesExA(filename, GetFileExInfoStandard, &fileInformation);
        if (result)
        {
            DWORD attribs = fileInformation.dwFileAttributes;
            return (attribs != INVALID_FILE_ATTRIBUTES) && ((attribs & FILE_ATTRIBUTE_DIRECTORY) > 0);
        }
    
        return false;
    }
    
    bool IsDebuggerAttached()
    {
        return !!::IsDebuggerPresent();
    }
    
    void BreakDebugger()
    {
        __debugbreak();
    }
    
    const char *GetExecutableExtension()
    {
        return ".exe";
    }
    
    char GetPathSeparator()
    {
        return '\\';
    }
    
    std::string GetHelperExecutableDir()
    {
        return "";
    }
    }  // namespace angle