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)(const char* fmt, ...); 21 22 void set_gfxstream_logger(gfxstream_logger_t f); 23 void set_gfxstream_fine_logger(gfxstream_logger_t f); 24 25 // Outputs a log line using Google's standard prefix. (http://go/logging#prefix) 26 // 27 // Do not use this function directly. Instead, use one of the logging macros below. 28 // 29 // stream: file handle to output to. 30 // severity: single character to indicate severity: 'V', 'D', 'I', 'W', 'E', or 'F'. 31 // file: name of the file where the message comes from (typically __FILE__) 32 // line: line number where the message comes from (typically __LINE__) 33 // timestamp_us: for testing only - timestamp of the log in microseconds since the Unix epoch. 34 // Pass 0 to use the current time. 35 // format: printf-style format specifier 36 void OutputLog(FILE* stream, char severity, const char* file, unsigned int line, 37 int64_t timestamp_us, const char* format, ...); 38 39 #define GFXSTREAM_LOG(file, severity, fmt, ...) \ 40 OutputLog(file, severity, __FILE__, __LINE__, 0, fmt, ##__VA_ARGS__) 41 42 //#define ENABLE_GL_LOG 1 43 #if defined(ENABLE_GL_LOG) 44 #define GL_LOG(fmt, ...) GFXSTREAM_LOG(stderr, 'I', fmt, ##__VA_ARGS__) 45 #else 46 #define GL_LOG(...) ((void)0) 47 #endif 48 49 //#define ENABLE_DECODER_LOG 1 50 #if defined(ENABLE_DECODER_LOG) 51 #define DECODER_DEBUG_LOG(fmt, ...) GFXSTREAM_LOG(stderr, 'I', fmt, ##__VA_ARGS__) 52 #else 53 #define DECODER_DEBUG_LOG(...) ((void)0) 54 #endif 55 56 //#define ENABLE_DISPATCH_LOG 1 57 #if defined(ENABLE_DISPATCH_LOG) 58 #define DISPATCH_DEBUG_LOG(fmt, ...) GFXSTREAM_LOG(stderr, 'I', fmt, ##__VA_ARGS__) 59 #else 60 #define DISPATCH_DEBUG_LOG(...) ((void)0) 61 #endif 62 63 #define ERR(fmt, ...) \ 64 do { \ 65 GFXSTREAM_LOG(stderr, 'E', fmt, ##__VA_ARGS__); \ 66 } while (0) 67 68 #define WARN(fmt, ...) \ 69 do { \ 70 GFXSTREAM_LOG(stderr, 'W', fmt, ##__VA_ARGS__); \ 71 } while (0) 72 73 #define INFO(fmt, ...) \ 74 do { \ 75 GFXSTREAM_LOG(stderr, 'I', fmt, ##__VA_ARGS__); \ 76 } while (0) 77 78 // Note: FATAL is defined in host-common/include/host-common/GfxstreamFatalError.h 79