Jon Ashburn | 21001f6 | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 1 | /* |
| 2 | * XGL |
| 3 | * |
| 4 | * Copyright (C) 2014 LunarG, Inc. |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | * copy of this software and associated documentation files (the "Software"), |
| 8 | * to deal in the Software without restriction, including without limitation |
| 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 10 | * and/or sell copies of the Software, and to permit persons to whom the |
| 11 | * Software is furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included |
| 14 | * in all copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 22 | * DEALINGS IN THE SOFTWARE. |
| 23 | */ |
| 24 | #include <stdio.h> |
| 25 | |
| 26 | static XGL_LAYER_DBG_FUNCTION_NODE *g_pDbgFunctionHead = NULL; |
| 27 | static XGL_LAYER_DBG_REPORT_LEVEL g_reportingLevel = XGL_DBG_LAYER_LEVEL_INFO; |
| 28 | static XGL_LAYER_DBG_ACTION g_debugAction = XGL_DBG_LAYER_ACTION_LOG_MSG; |
| 29 | static FILE *g_logFile = NULL; |
| 30 | |
| 31 | // Utility function to handle reporting |
| 32 | // If callbacks are enabled, use them, otherwise use printf |
| 33 | static void layerCbMsg(XGL_DBG_MSG_TYPE msgType, |
| 34 | XGL_VALIDATION_LEVEL validationLevel, |
| 35 | XGL_BASE_OBJECT srcObject, |
| 36 | size_t location, |
| 37 | int32_t msgCode, |
| 38 | const char* pLayerPrefix, |
| 39 | const char* pMsg) |
| 40 | { |
| 41 | if (g_debugAction & (XGL_DBG_LAYER_ACTION_LOG_MSG | XGL_DBG_LAYER_ACTION_CALLBACK)) { |
| 42 | XGL_LAYER_DBG_FUNCTION_NODE *pTrav = g_pDbgFunctionHead; |
| 43 | switch (msgType) { |
| 44 | case XGL_DBG_MSG_ERROR: |
| 45 | if (g_reportingLevel <= XGL_DBG_LAYER_LEVEL_ERROR) { |
| 46 | if (g_debugAction & XGL_DBG_LAYER_ACTION_LOG_MSG) |
| 47 | fprintf(g_logFile, "{%s}ERROR : %s\n", pLayerPrefix, pMsg); |
| 48 | if (g_debugAction & XGL_DBG_LAYER_ACTION_CALLBACK) |
| 49 | while (pTrav) { |
| 50 | pTrav->pfnMsgCallback(msgType, validationLevel, srcObject, location, msgCode, pMsg, pTrav->pUserData); |
| 51 | pTrav = pTrav->pNext; |
| 52 | } |
| 53 | } |
| 54 | break; |
| 55 | case XGL_DBG_MSG_WARNING: |
| 56 | if (g_reportingLevel <= XGL_DBG_LAYER_LEVEL_WARN) { |
| 57 | if (g_debugAction & XGL_DBG_LAYER_ACTION_LOG_MSG) |
| 58 | fprintf(g_logFile, "{%s}WARN : %s\n", pLayerPrefix, pMsg); |
| 59 | if (g_debugAction & XGL_DBG_LAYER_ACTION_CALLBACK) |
| 60 | while (pTrav) { |
| 61 | pTrav->pfnMsgCallback(msgType, validationLevel, srcObject, location, msgCode, pMsg, pTrav->pUserData); |
| 62 | pTrav = pTrav->pNext; |
| 63 | } |
| 64 | } |
| 65 | break; |
| 66 | case XGL_DBG_MSG_PERF_WARNING: |
| 67 | if (g_reportingLevel <= XGL_DBG_LAYER_LEVEL_PERF_WARN) { |
| 68 | if (g_debugAction & XGL_DBG_LAYER_ACTION_LOG_MSG) |
| 69 | fprintf(g_logFile, "{%s}PERF_WARN : %s\n", pLayerPrefix, pMsg); |
| 70 | if (g_debugAction & XGL_DBG_LAYER_ACTION_CALLBACK) |
| 71 | while (pTrav) { |
| 72 | pTrav->pfnMsgCallback(msgType, validationLevel, srcObject, location, msgCode, pMsg, pTrav->pUserData); |
| 73 | pTrav = pTrav->pNext; |
| 74 | } |
| 75 | } |
| 76 | break; |
| 77 | default: |
| 78 | if (g_reportingLevel <= XGL_DBG_LAYER_LEVEL_INFO) { |
| 79 | if (g_debugAction & XGL_DBG_LAYER_ACTION_LOG_MSG) |
| 80 | fprintf(g_logFile, "{%s}INFO : %s\n", pLayerPrefix, pMsg); |
| 81 | if (g_debugAction & XGL_DBG_LAYER_ACTION_CALLBACK) |
| 82 | while (pTrav) { |
| 83 | pTrav->pfnMsgCallback(msgType, validationLevel, srcObject, location, msgCode, pMsg, pTrav->pUserData); |
| 84 | pTrav = pTrav->pNext; |
| 85 | } |
| 86 | } |
| 87 | break; |
| 88 | } |
| 89 | } |
| 90 | } |