diff options
Diffstat (limited to 'Source/ThirdParty/ANGLE/src/common/debug.cpp')
-rw-r--r-- | Source/ThirdParty/ANGLE/src/common/debug.cpp | 147 |
1 files changed, 103 insertions, 44 deletions
diff --git a/Source/ThirdParty/ANGLE/src/common/debug.cpp b/Source/ThirdParty/ANGLE/src/common/debug.cpp index 3de5d4e..845d258 100644 --- a/Source/ThirdParty/ANGLE/src/common/debug.cpp +++ b/Source/ThirdParty/ANGLE/src/common/debug.cpp @@ -1,44 +1,103 @@ -// -// Copyright (c) 2002-2010 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. -// - -// debug.cpp: Debugging utilities. - -#include "common/debug.h" - -#include <stdio.h> -#include <stdarg.h> - -#ifndef TRACE_OUTPUT_FILE -#define TRACE_OUTPUT_FILE "debug.txt" -#endif - -static bool trace_on = true; - -namespace gl -{ -void trace(const char *format, ...) -{ -#if !defined(ANGLE_DISABLE_TRACE) - if (trace_on) - { - if (format) - { - FILE *file = fopen(TRACE_OUTPUT_FILE, "a"); - - if (file) - { - va_list vararg; - va_start(vararg, format); - vfprintf(file, format, vararg); - va_end(vararg); - - fclose(file); - } - } - } -#endif // !defined(ANGLE_DISABLE_TRACE) -} -} +//
+// Copyright (c) 2002-2010 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.
+//
+
+// debug.cpp: Debugging utilities.
+
+#include "common/debug.h"
+
+#include <stdio.h>
+#include <stdarg.h>
+#include <d3d9.h>
+#include <windows.h>
+
+namespace gl
+{
+
+typedef void (WINAPI *PerfOutputFunction)(D3DCOLOR, LPCWSTR);
+
+static void output(bool traceFileDebugOnly, PerfOutputFunction perfFunc, const char *format, va_list vararg)
+{
+#if !defined(ANGLE_DISABLE_PERF)
+ if (perfActive())
+ {
+ char message[32768];
+ int len = vsprintf_s(message, format, vararg);
+ if (len < 0)
+ {
+ return;
+ }
+
+ // There are no ASCII variants of these D3DPERF functions.
+ wchar_t wideMessage[32768];
+ for (int i = 0; i < len; ++i)
+ {
+ wideMessage[i] = message[i];
+ }
+ wideMessage[len] = 0;
+
+ perfFunc(0, wideMessage);
+ }
+#endif
+
+#if !defined(ANGLE_DISABLE_TRACE)
+#if defined(NDEBUG)
+ if (traceFileDebugOnly)
+ {
+ return;
+ }
+#endif
+
+ FILE* file = fopen(TRACE_OUTPUT_FILE, "a");
+ if (file)
+ {
+ vfprintf(file, format, vararg);
+ fclose(file);
+ }
+#endif
+}
+
+void trace(bool traceFileDebugOnly, const char *format, ...)
+{
+ va_list vararg;
+ va_start(vararg, format);
+#if defined(ANGLE_DISABLE_PERF)
+ output(traceFileDebugOnly, NULL, format, vararg);
+#else
+ output(traceFileDebugOnly, D3DPERF_SetMarker, format, vararg);
+#endif
+ va_end(vararg);
+}
+
+bool perfActive()
+{
+#if defined(ANGLE_DISABLE_PERF)
+ return false;
+#else
+ static bool active = D3DPERF_GetStatus() != 0;
+ return active;
+#endif
+}
+
+ScopedPerfEventHelper::ScopedPerfEventHelper(const char* format, ...)
+{
+#if !defined(ANGLE_DISABLE_PERF)
+ va_list vararg;
+ va_start(vararg, format);
+ output(true, reinterpret_cast<PerfOutputFunction>(D3DPERF_BeginEvent), format, vararg);
+ va_end(vararg);
+#endif
+}
+
+ScopedPerfEventHelper::~ScopedPerfEventHelper()
+{
+#if !defined(ANGLE_DISABLE_PERF)
+ if (perfActive())
+ {
+ D3DPERF_EndEvent();
+ }
+#endif
+}
+}
|