1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/angle/src/common/debug.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,106 @@ 1.4 +// 1.5 +// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved. 1.6 +// Use of this source code is governed by a BSD-style license that can be 1.7 +// found in the LICENSE file. 1.8 +// 1.9 + 1.10 +// debug.cpp: Debugging utilities. 1.11 + 1.12 +#include "common/debug.h" 1.13 +#include "common/system.h" 1.14 +#include <d3d9.h> 1.15 + 1.16 +namespace gl 1.17 +{ 1.18 + 1.19 +typedef void (WINAPI *PerfOutputFunction)(D3DCOLOR, LPCWSTR); 1.20 + 1.21 +static void output(bool traceFileDebugOnly, PerfOutputFunction perfFunc, const char *format, va_list vararg) 1.22 +{ 1.23 +#if !defined(ANGLE_DISABLE_PERF) 1.24 + if (perfActive()) 1.25 + { 1.26 + char message[32768]; 1.27 + int len = vsprintf_s(message, format, vararg); 1.28 + if (len < 0) 1.29 + { 1.30 + return; 1.31 + } 1.32 + 1.33 + // There are no ASCII variants of these D3DPERF functions. 1.34 + wchar_t wideMessage[32768]; 1.35 + for (int i = 0; i < len; ++i) 1.36 + { 1.37 + wideMessage[i] = message[i]; 1.38 + } 1.39 + wideMessage[len] = 0; 1.40 + 1.41 + perfFunc(0, wideMessage); 1.42 + } 1.43 +#endif 1.44 + 1.45 +#if !defined(ANGLE_DISABLE_TRACE) 1.46 +#if defined(NDEBUG) 1.47 + if (traceFileDebugOnly) 1.48 + { 1.49 + return; 1.50 + } 1.51 +#endif 1.52 + 1.53 + FILE* file = fopen(TRACE_OUTPUT_FILE, "a"); 1.54 + if (file) 1.55 + { 1.56 + vfprintf(file, format, vararg); 1.57 + fclose(file); 1.58 + } 1.59 +#endif 1.60 +} 1.61 + 1.62 +void trace(bool traceFileDebugOnly, const char *format, ...) 1.63 +{ 1.64 + va_list vararg; 1.65 + va_start(vararg, format); 1.66 +#if defined(ANGLE_DISABLE_PERF) 1.67 + output(traceFileDebugOnly, NULL, format, vararg); 1.68 +#else 1.69 + output(traceFileDebugOnly, D3DPERF_SetMarker, format, vararg); 1.70 +#endif 1.71 + va_end(vararg); 1.72 +} 1.73 + 1.74 +bool perfActive() 1.75 +{ 1.76 +#if defined(ANGLE_DISABLE_PERF) 1.77 + return false; 1.78 +#else 1.79 + static bool active = D3DPERF_GetStatus() != 0; 1.80 + return active; 1.81 +#endif 1.82 +} 1.83 + 1.84 +ScopedPerfEventHelper::ScopedPerfEventHelper(const char* format, ...) 1.85 +{ 1.86 +#if !defined(ANGLE_DISABLE_PERF) 1.87 +#if defined(ANGLE_DISABLE_TRACE) 1.88 + if (!perfActive()) 1.89 + { 1.90 + return; 1.91 + } 1.92 +#endif 1.93 + va_list vararg; 1.94 + va_start(vararg, format); 1.95 + output(true, reinterpret_cast<PerfOutputFunction>(D3DPERF_BeginEvent), format, vararg); 1.96 + va_end(vararg); 1.97 +#endif 1.98 +} 1.99 + 1.100 +ScopedPerfEventHelper::~ScopedPerfEventHelper() 1.101 +{ 1.102 +#if !defined(ANGLE_DISABLE_PERF) 1.103 + if (perfActive()) 1.104 + { 1.105 + D3DPERF_EndEvent(); 1.106 + } 1.107 +#endif 1.108 +} 1.109 +}