Edit

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

Branch :

  • Show log

    Commit

  • Author : Geoff Lang
    Date : 2014-01-16 09:52:38
    Hash : 83217796
    Message : Remove system.h. The gyp files already define NOMINMAX and WIN32_LEAN_AND_MEAN. windows.h is also included via the D3D includes. This ends up speeding up the build process significantly by not having windows.h included in nearly every file. Also fixes issues on non-windows systems by not having stdarg.h included in debug.cpp. Change-Id: Id32d9aac37a5a29df832a062dd8024302a798a1c Reviewed-on: https://chromium-review.googlesource.com/183251 Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Shannon Woods <shannonwoods@chromium.org> Tested-by: Geoff Lang <geofflang@chromium.org>

  • src/common/debug.cpp
  • //
    // 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 <stdarg.h>
    
    #if defined(ANGLE_ENABLE_PERF)
    #include <d3d9.h>
    #endif
    
    namespace gl
    {
    #if defined(ANGLE_ENABLE_PERF)
    typedef void (WINAPI *PerfOutputFunction)(D3DCOLOR, LPCWSTR);
    #else
    typedef void (*PerfOutputFunction)(unsigned int, const wchar_t*);
    #endif
    
    static void output(bool traceFileDebugOnly, PerfOutputFunction perfFunc, const char *format, va_list vararg)
    {
    #if defined(ANGLE_ENABLE_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 // ANGLE_ENABLE_PERF
    
    #if defined(ANGLE_ENABLE_TRACE)
    #if defined(NDEBUG)
        if (traceFileDebugOnly)
        {
            return;
        }
    #endif // NDEBUG
    
        FILE* file = fopen(TRACE_OUTPUT_FILE, "a");
        if (file)
        {
            vfprintf(file, format, vararg);
            fclose(file);
        }
    #endif // ANGLE_ENABLE_TRACE
    }
    
    void trace(bool traceFileDebugOnly, const char *format, ...)
    {
        va_list vararg;
        va_start(vararg, format);
    #if defined(ANGLE_ENABLE_PERF)
        output(traceFileDebugOnly, D3DPERF_SetMarker, format, vararg);
    #else
        output(traceFileDebugOnly, NULL, format, vararg);
    #endif
        va_end(vararg);
    }
    
    bool perfActive()
    {
    #if defined(ANGLE_ENABLE_PERF)
        static bool active = D3DPERF_GetStatus() != 0;
        return active;
    #else
        return false;
    #endif
    }
    
    ScopedPerfEventHelper::ScopedPerfEventHelper(const char* format, ...)
    {
    #if defined(ANGLE_ENABLE_PERF)
    #if !defined(ANGLE_ENABLE_TRACE)
        if (!perfActive())
        {
            return;
        }
    #endif // !ANGLE_ENABLE_TRACE
        va_list vararg;
        va_start(vararg, format);
        output(true, reinterpret_cast<PerfOutputFunction>(D3DPERF_BeginEvent), format, vararg);
        va_end(vararg);
    #endif // ANGLE_ENABLE_PERF
    }
    
    ScopedPerfEventHelper::~ScopedPerfEventHelper()
    {
    #if defined(ANGLE_ENABLE_PERF)
        if (perfActive())
        {
            D3DPERF_EndEvent();
        }
    #endif
    }
    }