1 #ifndef GLES_MACROS_H 2 #define GLES_MACROS_H 3 4 #if defined(__linux__) || defined(__APPLE__) 5 6 #include <mutex> 7 #include "aemu/base/files/PathUtils.h" 8 #include "aemu/base/memory/MemoryTracker.h" 9 10 #if 0 11 12 #define MEM_TRACE_IF(condition, group) \ 13 if ((condition)) { \ 14 static std::once_flag once_flag; \ 15 const std::string func(__FUNCTION__); \ 16 std::call_once(once_flag, [&func]() { \ 17 if (android::base::MemoryTracker::get()) { \ 18 std::string baseName; \ 19 android::base::PathUtils::split(std::string(__FILE__), NULL, &baseName); \ 20 android::base::MemoryTracker::get()->addToGroup( \ 21 group, baseName.r() + ":" + func); \ 22 } \ 23 }); \ 24 } 25 #else 26 27 #define MEM_TRACE_IF(condition, group) 28 29 #endif 30 31 #else 32 // windows 33 #define MEM_TRACE_IF(condition, group) 34 #endif 35 36 #define MEM_TRACE(group) MEM_TRACE_IF(true, group) 37 38 #define FAIL_IF(condition, description) if((condition)) { \ 39 fprintf(stderr, "%s:%s:%d error %s\n", __FILE__, __FUNCTION__, __LINE__, description); \ 40 return; \ 41 } 42 43 #define RET_AND_FAIL_IF(condition, description, ret) if((condition)) { \ 44 fprintf(stderr, "%s:%s:%d error %s\n", __FILE__, __FUNCTION__, __LINE__, description); \ 45 return ret; \ 46 } 47 48 #define GET_CTX() \ 49 MEM_TRACE_IF(strncmp(__FUNCTION__, "gl", 2) == 0, "EMUGL") \ 50 FAIL_IF(!s_eglIface, "null s_eglIface") \ 51 GLEScontext* ctx = s_eglIface->getGLESContext(); \ 52 FAIL_IF(!ctx, "null ctx") 53 54 #define GET_CTX_CM() \ 55 MEM_TRACE_IF(strncmp(__FUNCTION__, "gl", 2) == 0, "EMUGL") \ 56 FAIL_IF(!s_eglIface, "null s_eglIface") \ 57 GLEScmContext* ctx = \ 58 static_cast<GLEScmContext*>(s_eglIface->getGLESContext()); \ 59 FAIL_IF(!ctx, "null ctx") 60 61 #define GET_CTX_V2() \ 62 MEM_TRACE_IF(strncmp(__FUNCTION__, "gl", 2) == 0, "EMUGL") \ 63 FAIL_IF(!s_eglIface, "null s_eglIface") \ 64 GLESv2Context* ctx = \ 65 static_cast<GLESv2Context*>(s_eglIface->getGLESContext()); \ 66 FAIL_IF(!ctx, "null ctx") 67 68 #define GET_CTX_RET(failure_ret) \ 69 MEM_TRACE_IF(strncmp(__FUNCTION__, "gl", 2) == 0, "EMUGL") \ 70 RET_AND_FAIL_IF(!s_eglIface, "null s_eglIface", failure_ret) \ 71 GLEScontext* ctx = s_eglIface->getGLESContext(); \ 72 RET_AND_FAIL_IF(!ctx, "null ctx", failure_ret) 73 74 #define GET_CTX_CM_RET(failure_ret) \ 75 MEM_TRACE_IF(strncmp(__FUNCTION__, "gl", 2) == 0, "EMUGL") \ 76 RET_AND_FAIL_IF(!s_eglIface, "null s_eglIface", failure_ret) \ 77 GLEScmContext* ctx = \ 78 static_cast<GLEScmContext*>(s_eglIface->getGLESContext()); \ 79 RET_AND_FAIL_IF(!ctx, "null ctx", failure_ret) 80 81 #define GET_CTX_V2_RET(failure_ret) \ 82 MEM_TRACE_IF(strncmp(__FUNCTION__, "gl", 2) == 0, "EMUGL") \ 83 RET_AND_FAIL_IF(!s_eglIface, "null s_eglIface", failure_ret) \ 84 GLESv2Context* ctx = \ 85 static_cast<GLESv2Context*>(s_eglIface->getGLESContext()); \ 86 RET_AND_FAIL_IF(!ctx, "null ctx", failure_ret) 87 88 #define SET_ERROR_IF(condition,err) if((condition)) { \ 89 fprintf(stderr, "%s:%s:%d error 0x%x\n", __FILE__, __FUNCTION__, __LINE__, err); \ 90 ctx->setGLerror(err); \ 91 return; \ 92 } 93 94 95 #define RET_AND_SET_ERROR_IF(condition,err,ret) if((condition)) { \ 96 fprintf(stderr, "%s:%s:%d error 0x%x\n", __FILE__, __FUNCTION__, __LINE__, err); \ 97 ctx->setGLerror(err); \ 98 return ret; \ 99 } 100 101 #define SET_ERROR_IF_DISPATCHER_NOT_SUPPORT(func) \ 102 SET_ERROR_IF(!ctx->dispatcher().func, GL_INVALID_OPERATION) 103 104 #define RET_AND_SET_ERROR_IF_DISPATCHER_NOT_SUPPORT(func, ret) \ 105 RET_AND_SET_ERROR_IF(!ctx->dispatcher().func, GL_INVALID_OPERATION, ret) 106 107 // Define the following flag to work around cocos2d rendering bug 108 // BUG: 119568237 109 #define TOLERATE_PROGRAM_LINK_ERROR 1 110 111 #endif 112