chromium/third_party/angle/src/common/debug.h

//
// Copyright 2002 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.h: Debugging utilities. A lot of the logging code is adapted from Chromium's
// base/logging.h.

#ifndef COMMON_DEBUG_H_
#define COMMON_DEBUG_H_

#include <assert.h>
#include <stdio.h>

#include <iomanip>
#include <ios>
#include <mutex>
#include <sstream>
#include <string>

#include "common/SimpleMutex.h"
#include "common/angleutils.h"
#include "common/entry_points_enum_autogen.h"
#include "common/log_utils.h"
#include "common/platform.h"

#if defined(ANGLE_PLATFORM_WINDOWS)
#    include <sal.h>
typedef unsigned long DWORD;
typedef _Return_type_success_(return >= 0) long HRESULT;
#endif

#if !defined(TRACE_OUTPUT_FILE)
#define TRACE_OUTPUT_FILE
#endif

namespace gl
{
class Context;

// Pairs a begin event with an end event.
class [[nodiscard]] ScopedPerfEventHelper : angle::NonCopyable
{};

// Wraps the API/Platform-specific debug annotation functions.
// Also handles redirecting logging destination.
class DebugAnnotator : angle::NonCopyable
{};

void InitializeDebugAnnotations(DebugAnnotator *debugAnnotator);
void UninitializeDebugAnnotations();
bool DebugAnnotationsActive(const gl::Context *context);
bool DebugAnnotationsInitialized();

void InitializeDebugMutexIfNeeded();

angle::SimpleMutex &GetDebugMutex();
}  // namespace gl

// The state tracked by ANGLE will be validated with the driver state before each call
#if defined(ANGLE_ENABLE_DEBUG_TRACE)
#define ANGLE_STATE_VALIDATION_ENABLED
#endif

#if defined(__GNUC__)
#define ANGLE_CRASH()
#else
#define ANGLE_CRASH
#endif

#define ANGLE_UNUSED_VARIABLE(variable)

// Defining ANGLE_ENABLE_STRUCT_PADDING_WARNINGS will enable warnings when members are added to
// structs to enforce packing. This is helpful for diagnosing unexpected struct sizes when making
// fast cache variables.
#if defined(__clang__)
#define ANGLE_ENABLE_STRUCT_PADDING_WARNINGS
#define ANGLE_DISABLE_STRUCT_PADDING_WARNINGS
#elif defined(__GNUC__)
#define ANGLE_ENABLE_STRUCT_PADDING_WARNINGS
#define ANGLE_DISABLE_STRUCT_PADDING_WARNINGS
#elif defined(_MSC_VER)
#define ANGLE_ENABLE_STRUCT_PADDING_WARNINGS
#define ANGLE_DISABLE_STRUCT_PADDING_WARNINGS
#else
#define ANGLE_ENABLE_STRUCT_PADDING_WARNINGS
#define ANGLE_DISABLE_STRUCT_PADDING_WARNINGS
#endif

#if defined(__clang__)
#define ANGLE_DISABLE_SUGGEST_OVERRIDE_WARNINGS
#define ANGLE_REENABLE_SUGGEST_OVERRIDE_WARNINGS
#else
#define ANGLE_DISABLE_SUGGEST_OVERRIDE_WARNINGS
#define ANGLE_REENABLE_SUGGEST_OVERRIDE_WARNINGS
#endif

#if defined(__clang__)
#define ANGLE_DISABLE_EXTRA_SEMI_WARNING
#define ANGLE_REENABLE_EXTRA_SEMI_WARNING
#else
#define ANGLE_DISABLE_EXTRA_SEMI_WARNING
#define ANGLE_REENABLE_EXTRA_SEMI_WARNING
#endif

#if defined(__clang__)
#define ANGLE_DISABLE_EXTRA_SEMI_STMT_WARNING
#define ANGLE_REENABLE_EXTRA_SEMI_STMT_WARNING
#else
#define ANGLE_DISABLE_EXTRA_SEMI_STMT_WARNING
#define ANGLE_REENABLE_EXTRA_SEMI_STMT_WARNING
#endif

#if defined(__clang__)
#define ANGLE_DISABLE_SHADOWING_WARNING
#define ANGLE_REENABLE_SHADOWING_WARNING
#else
#define ANGLE_DISABLE_SHADOWING_WARNING
#define ANGLE_REENABLE_SHADOWING_WARNING
#endif

#if defined(__clang__)
#define ANGLE_DISABLE_DESTRUCTOR_OVERRIDE_WARNING
#define ANGLE_REENABLE_DESTRUCTOR_OVERRIDE_WARNING
#else
#define ANGLE_DISABLE_DESTRUCTOR_OVERRIDE_WARNING
#define ANGLE_REENABLE_DESTRUCTOR_OVERRIDE_WARNING
#endif

#if defined(__clang__)
#define ANGLE_DISABLE_UNUSED_FUNCTION_WARNING
#define ANGLE_REENABLE_UNUSED_FUNCTION_WARNING
#else
#define ANGLE_DISABLE_UNUSED_FUNCTION_WARNING
#define ANGLE_REENABLE_UNUSED_FUNCTION_WARNING
#endif

#endif  // COMMON_DEBUG_H_