summaryrefslogtreecommitdiff
path: root/Source/ThirdParty/ANGLE/src/common/angleutils.h
diff options
context:
space:
mode:
Diffstat (limited to 'Source/ThirdParty/ANGLE/src/common/angleutils.h')
-rw-r--r--Source/ThirdParty/ANGLE/src/common/angleutils.h162
1 files changed, 148 insertions, 14 deletions
diff --git a/Source/ThirdParty/ANGLE/src/common/angleutils.h b/Source/ThirdParty/ANGLE/src/common/angleutils.h
index 9761567fb..eab8c793b 100644
--- a/Source/ThirdParty/ANGLE/src/common/angleutils.h
+++ b/Source/ThirdParty/ANGLE/src/common/angleutils.h
@@ -1,5 +1,5 @@
//
-// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
+// Copyright (c) 2002-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.
//
@@ -9,16 +9,35 @@
#ifndef COMMON_ANGLEUTILS_H_
#define COMMON_ANGLEUTILS_H_
-#include <stddef.h>
+#include "common/platform.h"
-// A macro to disallow the copy constructor and operator= functions
-// This must be used in the private: declarations for a class
-#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
- TypeName(const TypeName&); \
- void operator=(const TypeName&)
+#include <climits>
+#include <cstdarg>
+#include <cstddef>
+#include <string>
+#include <set>
+#include <sstream>
+#include <vector>
-template <typename T, unsigned int N>
-inline unsigned int ArraySize(T(&)[N])
+// A helper class to disallow copy and assignment operators
+namespace angle
+{
+
+class NonCopyable
+{
+ public:
+ NonCopyable() = default;
+ ~NonCopyable() = default;
+ protected:
+ NonCopyable(const NonCopyable&) = delete;
+ void operator=(const NonCopyable&) = delete;
+};
+
+extern const uintptr_t DirtyPointer;
+} // namespace angle
+
+template <typename T, size_t N>
+constexpr inline size_t ArraySize(T (&)[N])
{
return N;
}
@@ -42,15 +61,130 @@ void SafeRelease(T& resource)
}
}
-#if defined(_MSC_VER)
+template <typename T>
+void SafeDelete(T *&resource)
+{
+ delete resource;
+ resource = NULL;
+}
+
+template <typename T>
+void SafeDeleteContainer(T& resource)
+{
+ for (auto &element : resource)
+ {
+ SafeDelete(element);
+ }
+ resource.clear();
+}
+
+template <typename T>
+void SafeDeleteArray(T*& resource)
+{
+ delete[] resource;
+ resource = NULL;
+}
+
+// Provide a less-than function for comparing structs
+// Note: struct memory must be initialized to zero, because of packing gaps
+template <typename T>
+inline bool StructLessThan(const T &a, const T &b)
+{
+ return (memcmp(&a, &b, sizeof(T)) < 0);
+}
+
+// Provide a less-than function for comparing structs
+// Note: struct memory must be initialized to zero, because of packing gaps
+template <typename T>
+inline bool StructEquals(const T &a, const T &b)
+{
+ return (memcmp(&a, &b, sizeof(T)) == 0);
+}
+
+template <typename T>
+inline void StructZero(T *obj)
+{
+ memset(obj, 0, sizeof(T));
+}
+
+template <typename T>
+inline bool IsMaskFlagSet(T mask, T flag)
+{
+ // Handles multibit flags as well
+ return (mask & flag) == flag;
+}
+
+inline const char* MakeStaticString(const std::string &str)
+{
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wexit-time-destructors"
+ static std::set<std::string> strings;
+#pragma clang diagnostic pop
+ std::set<std::string>::iterator it = strings.find(str);
+ if (it != strings.end())
+ {
+ return it->c_str();
+ }
+
+ return strings.insert(str).first->c_str();
+}
+
+inline std::string ArrayString(unsigned int i)
+{
+ // We assume UINT_MAX and GL_INVALID_INDEX are equal
+ // See DynamicHLSL.cpp
+ if (i == UINT_MAX)
+ {
+ return "";
+ }
+
+ std::stringstream strstr;
+
+ strstr << "[";
+ strstr << i;
+ strstr << "]";
+
+ return strstr.str();
+}
+
+inline std::string Str(int i)
+{
+ std::stringstream strstr;
+ strstr << i;
+ return strstr.str();
+}
+
+size_t FormatStringIntoVector(const char *fmt, va_list vararg, std::vector<char>& buffer);
+
+std::string FormatString(const char *fmt, va_list vararg);
+std::string FormatString(const char *fmt, ...);
+
+template <typename T>
+std::string ToString(const T &value)
+{
+ std::ostringstream o;
+ o << value;
+ return o.str();
+}
+
+// snprintf is not defined with MSVC prior to to msvc14
+#if defined(_MSC_VER) && _MSC_VER < 1900
#define snprintf _snprintf
#endif
-#define VENDOR_ID_AMD 0x1002
-#define VENDOR_ID_INTEL 0x8086
-#define VENDOR_ID_NVIDIA 0x10DE
-
+#define GL_BGR565_ANGLEX 0x6ABB
#define GL_BGRA4_ANGLEX 0x6ABC
#define GL_BGR5_A1_ANGLEX 0x6ABD
+#define GL_INT_64_ANGLEX 0x6ABE
+#define GL_STRUCT_ANGLEX 0x6ABF
+
+// Hidden enum for the NULL D3D device type.
+#define EGL_PLATFORM_ANGLE_DEVICE_TYPE_NULL_ANGLE 0x6AC0
+
+#define ANGLE_TRY_CHECKED_MATH(result) \
+ if (!result.IsValid()) \
+ { \
+ return gl::Error(GL_INVALID_OPERATION, "Integer overflow."); \
+ }
#endif // COMMON_ANGLEUTILS_H_