Commit dcab56a1 by Jamie Madill Committed by Commit Bot

Move some file utils to common.

Since common is shared through all ANGLE code (libANGLE/tests/samples) this is the most general place for these utils, and will give libANGLE access to them. We'll need them to get the current executable dir for loading the Vulkan layers. This also means we'll need to fix the global static variable use when we have the ability. BUG=angleproject:1319 BUG=chromium:677841 Change-Id: I7af61920635135b28a2f02f4a8d019ee88c9dd28 Reviewed-on: https://chromium-review.googlesource.com/425440 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent de5f98cd
...@@ -131,6 +131,18 @@ config("angle_common_config") { ...@@ -131,6 +131,18 @@ config("angle_common_config") {
static_library("angle_common") { static_library("angle_common") {
sources = rebase_path(gles_gypi.libangle_common_sources, ".", "src") sources = rebase_path(gles_gypi.libangle_common_sources, ".", "src")
if (is_linux || is_android) {
sources += rebase_path(gles_gypi.libangle_common_linux_sources, ".", "src")
}
if (is_mac) {
sources += rebase_path(gles_gypi.libangle_common_mac_sources, ".", "src")
}
if (is_win) {
sources += rebase_path(gles_gypi.libangle_common_win_sources, ".", "src")
}
configs -= angle_undefine_configs configs -= angle_undefine_configs
configs += [ configs += [
":angle_common_config", ":angle_common_config",
......
...@@ -19,12 +19,14 @@ ...@@ -19,12 +19,14 @@
'includes': [ '../gyp/common_defines.gypi', ], 'includes': [ '../gyp/common_defines.gypi', ],
'dependencies': 'dependencies':
[ [
'<(angle_path)/src/angle.gyp:angle_common',
'<(angle_path)/src/angle.gyp:libEGL', '<(angle_path)/src/angle.gyp:libEGL',
'<(angle_path)/src/angle.gyp:libGLESv2', '<(angle_path)/src/angle.gyp:libGLESv2',
'<(angle_path)/util/util.gyp:angle_util', '<(angle_path)/util/util.gyp:angle_util',
], ],
'export_dependent_settings': 'export_dependent_settings':
[ [
'<(angle_path)/src/angle.gyp:angle_common',
'<(angle_path)/util/util.gyp:angle_util', '<(angle_path)/util/util.gyp:angle_util',
], ],
'include_dirs': 'include_dirs':
......
...@@ -140,7 +140,25 @@ ...@@ -140,7 +140,25 @@
], ],
}, },
}, },
'sources':
[
'<@(libangle_common_win_sources)',
],
}], }],
['OS=="mac"',
{
'sources':
[
'<@(libangle_common_mac_sources)',
],
}],
['OS=="linux"',
{
'sources':
[
'<@(libangle_common_linux_sources)',
],
}]
], ],
}, },
......
//
// Copyright (c) 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.h: declaration of OS-specific utility functions
#ifndef COMMON_SYSTEM_UTILS_H_
#define COMMON_SYSTEM_UTILS_H_
#include "common/angleutils.h"
namespace angle
{
const char *GetExecutablePath();
const char *GetExecutableDirectory();
const char *GetSharedLibraryExtension();
} // namespace angle
#endif // COMMON_SYSTEM_UTILS_H_
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
// found in the LICENSE file. // found in the LICENSE file.
// //
// Linux_system_utils.cpp: Implementation of OS-specific functions for Linux // system_utils_linux.cpp: Implementation of OS-specific functions for Linux
#include "system_utils.h" #include "system_utils.h"
...@@ -46,12 +46,14 @@ std::string GetExecutableDirectoryImpl() ...@@ -46,12 +46,14 @@ std::string GetExecutableDirectoryImpl()
const char *GetExecutablePath() const char *GetExecutablePath()
{ {
// TODO(jmadill): Make global static string thread-safe.
const static std::string &exePath = GetExecutablePathImpl(); const static std::string &exePath = GetExecutablePathImpl();
return exePath.c_str(); return exePath.c_str();
} }
const char *GetExecutableDirectory() const char *GetExecutableDirectory()
{ {
// TODO(jmadill): Make global static string thread-safe.
const static std::string &exeDir = GetExecutableDirectoryImpl(); const static std::string &exeDir = GetExecutableDirectoryImpl();
return exeDir.c_str(); return exeDir.c_str();
} }
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
// found in the LICENSE file. // found in the LICENSE file.
// //
// OSX_system_utils.cpp: Implementation of OS-specific functions for OSX // system_utils_osx.cpp: Implementation of OS-specific functions for OSX
#include "system_utils.h" #include "system_utils.h"
...@@ -49,12 +49,14 @@ std::string GetExecutableDirectoryImpl() ...@@ -49,12 +49,14 @@ std::string GetExecutableDirectoryImpl()
const char *GetExecutablePath() const char *GetExecutablePath()
{ {
// TODO(jmadill): Make global static string thread-safe.
const static std::string &exePath = GetExecutablePathImpl(); const static std::string &exePath = GetExecutablePathImpl();
return exePath.c_str(); return exePath.c_str();
} }
const char *GetExecutableDirectory() const char *GetExecutableDirectory()
{ {
// TODO(jmadill): Make global static string thread-safe.
const static std::string &exeDir = GetExecutableDirectoryImpl(); const static std::string &exeDir = GetExecutableDirectoryImpl();
return exeDir.c_str(); return exeDir.c_str();
} }
......
//
// Copyright (c) 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
{
namespace
{
std::string GetExecutablePathImpl()
{
std::array<char, MAX_PATH> executableFileBuf;
DWORD executablePathLen = GetModuleFileNameA(NULL, executableFileBuf.data(),
static_cast<DWORD>(executableFileBuf.size()));
return (executablePathLen > 0 ? std::string(executableFileBuf.data()) : "");
}
std::string GetExecutableDirectoryImpl()
{
std::string executablePath = GetExecutablePath();
size_t lastPathSepLoc = executablePath.find_last_of("\\/");
return (lastPathSepLoc != std::string::npos) ? executablePath.substr(0, lastPathSepLoc) : "";
}
} // anonymous namespace
const char *GetExecutablePath()
{
// TODO(jmadill): Make global static string thread-safe.
const static std::string &exePath = GetExecutablePathImpl();
return exePath.c_str();
}
const char *GetExecutableDirectory()
{
// TODO(jmadill): Make global static string thread-safe.
const static std::string &exeDir = GetExecutableDirectoryImpl();
return exeDir.c_str();
}
const char *GetSharedLibraryExtension()
{
return "dll";
}
} // namespace angle
...@@ -37,6 +37,18 @@ ...@@ -37,6 +37,18 @@
'common/vector_utils.h', 'common/vector_utils.h',
'common/version.h', 'common/version.h',
], ],
'libangle_common_linux_sources':
[
'common/system_utils_linux.cpp',
],
'libangle_common_mac_sources':
[
'common/system_utils_mac.cpp',
],
'libangle_common_win_sources':
[
'common/system_utils_win.cpp',
],
'libangle_image_util_sources': 'libangle_image_util_sources':
[ [
'image_util/copyimage.cpp', 'image_util/copyimage.cpp',
......
...@@ -280,6 +280,7 @@ if (build_angle_deqp_tests) { ...@@ -280,6 +280,7 @@ if (build_angle_deqp_tests) {
static_library("angle_deqp_libtester") { static_library("angle_deqp_libtester") {
public_deps = [ public_deps = [
":angle_deqp_decpp", ":angle_deqp_decpp",
"//third_party/angle:angle_common",
"//third_party/angle:angle_util", "//third_party/angle:angle_util",
"//third_party/angle:libEGL", "//third_party/angle:libEGL",
"//third_party/libpng:libpng", "//third_party/libpng:libpng",
......
...@@ -1528,6 +1528,7 @@ ...@@ -1528,6 +1528,7 @@
'type': 'static_library', 'type': 'static_library',
'dependencies': 'dependencies':
[ [
'<(angle_path)/src/angle.gyp:angle_common',
'angle_deqp_decpp', 'angle_deqp_decpp',
'angle_deqp_support', 'angle_deqp_support',
'angle_libpng', 'angle_libpng',
......
...@@ -14,14 +14,11 @@ ...@@ -14,14 +14,11 @@
#include <export.h> #include <export.h>
#include "common/angleutils.h" #include "common/angleutils.h"
#include "common/system_utils.h"
namespace angle namespace angle
{ {
ANGLE_EXPORT const char *GetExecutablePath();
ANGLE_EXPORT const char *GetExecutableDirectory();
ANGLE_EXPORT const char *GetSharedLibraryExtension();
// Cross platform equivalent of the Windows Sleep function // Cross platform equivalent of the Windows Sleep function
ANGLE_EXPORT void Sleep(unsigned int milliseconds); ANGLE_EXPORT void Sleep(unsigned int milliseconds);
......
...@@ -52,7 +52,6 @@ ...@@ -52,7 +52,6 @@
], ],
'util_linux_sources': 'util_linux_sources':
[ [
'linux/Linux_system_utils.cpp',
'linux/LinuxTimer.cpp', 'linux/LinuxTimer.cpp',
'linux/LinuxTimer.h', 'linux/LinuxTimer.h',
'posix/Posix_system_utils.cpp', 'posix/Posix_system_utils.cpp',
...@@ -72,7 +71,6 @@ ...@@ -72,7 +71,6 @@
], ],
'util_osx_sources': 'util_osx_sources':
[ [
'osx/OSX_system_utils.cpp',
'osx/OSXTimer.cpp', 'osx/OSXTimer.cpp',
'osx/OSXTimer.h', 'osx/OSXTimer.h',
'osx/OSXPixmap.mm', 'osx/OSXPixmap.mm',
......
...@@ -16,43 +16,6 @@ ...@@ -16,43 +16,6 @@
namespace angle namespace angle
{ {
namespace
{
std::string GetExecutablePathImpl()
{
std::array<char, MAX_PATH> executableFileBuf;
DWORD executablePathLen = GetModuleFileNameA(NULL, executableFileBuf.data(),
static_cast<DWORD>(executableFileBuf.size()));
return (executablePathLen > 0 ? std::string(executableFileBuf.data()) : "");
}
std::string GetExecutableDirectoryImpl()
{
std::string executablePath = GetExecutablePath();
size_t lastPathSepLoc = executablePath.find_last_of("\\/");
return (lastPathSepLoc != std::string::npos) ? executablePath.substr(0, lastPathSepLoc) : "";
}
} // anonymous namespace
const char *GetExecutablePath()
{
const static std::string &exePath = GetExecutablePathImpl();
return exePath.c_str();
}
const char *GetExecutableDirectory()
{
const static std::string &exeDir = GetExecutableDirectoryImpl();
return exeDir.c_str();
}
const char *GetSharedLibraryExtension()
{
return "dll";
}
void Sleep(unsigned int milliseconds) void Sleep(unsigned int milliseconds)
{ {
::Sleep(static_cast<DWORD>(milliseconds)); ::Sleep(static_cast<DWORD>(milliseconds));
......
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