1 // Copyright 2023 The Android Open Source Project 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #pragma once 16 17 #include <cstdint> 18 #include <cstdio> 19 20 typedef void (*gfxstream_logger_t)(char severity, const char* file, unsigned int line, 21 int64_t timestamp_us, const char* message); 22 23 gfxstream_logger_t get_gfx_stream_logger(); 24 void set_gfxstream_logger(gfxstream_logger_t f); 25 void set_gfxstream_enable_verbose_logs(); 26 void set_gfxstream_enable_log_colors(); 27 28 // Outputs a log line using Google's standard prefix. (http://go/logging#prefix) 29 // 30 // Do not use this function directly. Instead, use one of the logging macros below. 31 // Note that: Logging with the 'D' (Debug) level is the least severe. 32 // 33 // stream: file handle to output to. 34 // severity: single character to indicate severity: 'D', 'V', 'I', 'W', 'E', or 'F'. 35 // file: name of the file where the message comes from (typically __FILE__) 36 // line: line number where the message comes from (typically __LINE__) 37 // timestamp_us: for testing only - timestamp of the log in microseconds since the Unix epoch. 38 // Pass 0 to use the current time. 39 // format: printf-style format specifier 40 void OutputLog(FILE* stream, char severity, const char* file, unsigned int line, 41 int64_t timestamp_us, const char* format, ...); 42 43 #define GFXSTREAM_LOG(file, severity, fmt, ...) \ 44 OutputLog(file, severity, __FILE__, __LINE__, 0, fmt, ##__VA_ARGS__) 45 46 //#define ENABLE_GL_LOG 1 47 #if defined(ENABLE_GL_LOG) 48 #define GL_LOG(fmt, ...) GFXSTREAM_LOG(stderr, 'I', fmt, ##__VA_ARGS__) 49 #else 50 #define GL_LOG(...) ((void)0) 51 #endif 52 53 //#define ENABLE_DECODER_LOG 1 54 #if defined(ENABLE_DECODER_LOG) 55 #define DECODER_DEBUG_LOG(fmt, ...) GFXSTREAM_LOG(stderr, 'I', fmt, ##__VA_ARGS__) 56 #else 57 #define DECODER_DEBUG_LOG(...) ((void)0) 58 #endif 59 60 //#define ENABLE_DISPATCH_LOG 1 61 #if defined(ENABLE_DISPATCH_LOG) 62 #define DISPATCH_DEBUG_LOG(fmt, ...) GFXSTREAM_LOG(stderr, 'I', fmt, ##__VA_ARGS__) 63 #else 64 #define DISPATCH_DEBUG_LOG(...) ((void)0) 65 #endif 66 67 #define ERR(fmt, ...) \ 68 do { \ 69 GFXSTREAM_LOG(stderr, 'E', fmt, ##__VA_ARGS__); \ 70 } while (0) 71 72 #define WARN(fmt, ...) \ 73 do { \ 74 GFXSTREAM_LOG(stderr, 'W', fmt, ##__VA_ARGS__); \ 75 } while (0) 76 77 #define INFO(fmt, ...) \ 78 do { \ 79 GFXSTREAM_LOG(stderr, 'I', fmt, ##__VA_ARGS__); \ 80 } while (0) 81 82 #define VERBOSE(fmt, ...) \ 83 do { \ 84 GFXSTREAM_LOG(stderr, 'V', fmt, ##__VA_ARGS__); \ 85 } while (0) 86 87 // Note: FATAL is defined in host-common/include/host-common/GfxstreamFatalError.h 88