diff options
author | Michael Meeks <michael.meeks@collabora.com> | 2015-08-28 11:28:13 +0100 |
---|---|---|
committer | Michael Meeks <michael.meeks@collabora.com> | 2015-08-28 11:31:38 +0100 |
commit | b051c3716a8275e8ce7cbc4ba233ad5a075d386f (patch) | |
tree | 086f307898164b1ac151a3d359125300f69f1f2b | |
parent | fd3468024e1ac199f4a2f4108321ef8100d58414 (diff) |
tdf#93529 - add glDebugMessageInsert wrappers to help with API tracing.
Change-Id: Icf75e0e477be1b2bbbe5095aee33e681d212be0b
-rw-r--r-- | include/vcl/opengl/OpenGLHelper.hxx | 23 | ||||
-rw-r--r-- | vcl/source/opengl/OpenGLContext.cxx | 2 | ||||
-rw-r--r-- | vcl/source/opengl/OpenGLHelper.cxx | 38 |
3 files changed, 62 insertions, 1 deletions
diff --git a/include/vcl/opengl/OpenGLHelper.hxx b/include/vcl/opengl/OpenGLHelper.hxx index 95c23c8deeaa..f2fb2141af37 100644 --- a/include/vcl/opengl/OpenGLHelper.hxx +++ b/include/vcl/opengl/OpenGLHelper.hxx @@ -11,6 +11,7 @@ #define INCLUDED_VCL_OPENGL_OPENGLHELPER_HXX #include <GL/glew.h> +#include <sal/log.hxx> #include <vcl/dllapi.h> #include <vcl/bitmapex.hxx> @@ -22,6 +23,18 @@ # include <postx.h> #endif +/// Helper to do a SAL_INFO as well as a GL log. +#if OSL_DEBUG_LEVEL > 0 +# define VCL_GL_INFO(area,stream) \ + do { \ + ::std::ostringstream detail_stream; \ + detail_stream << stream; \ + OpenGLHelper::debugMsgStream((area),detail_stream); \ + } while (0) +#else +# define VCL_GL_INFO(area,stream) +#endif + class VCL_DLLPUBLIC OpenGLHelper { public: @@ -48,15 +61,23 @@ public: static void createFramebuffer(long nWidth, long nHeight, GLuint& nFramebufferId, GLuint& nRenderbufferDepthId, GLuint& nRenderbufferColorId, bool bRenderbuffer = true); - // Get OpenGL version (needs a context) + /// Get OpenGL version (needs a context) static float getGLVersion(); static void checkGLError(const char* aFile, size_t nLine); /** + * Insert a glDebugMessage into the queue - helpful for debugging + * with apitrace to annotate the output and correlate it with code. + */ + static void debugMsgPrint(const char *pArea, const char *pFormat, ...); + static void debugMsgStream(const char *pArea, std::ostringstream const &pStream); + + /** * checks if the device/driver pair is on our OpenGL blacklist */ static bool isDeviceBlacklisted(); + /** * checks if the system supports all features that are necessary for the OpenGL VCL support */ diff --git a/vcl/source/opengl/OpenGLContext.cxx b/vcl/source/opengl/OpenGLContext.cxx index ff152d99f75c..74b6f418372c 100644 --- a/vcl/source/opengl/OpenGLContext.cxx +++ b/vcl/source/opengl/OpenGLContext.cxx @@ -1008,6 +1008,8 @@ void OpenGLContext::InitGLEWDebugging() } } + // Test hooks for inserting tracing messages into the stream + VCL_GL_INFO("vcl.opengl", "LibreOffice GLContext initialized: " << this); #endif } diff --git a/vcl/source/opengl/OpenGLHelper.cxx b/vcl/source/opengl/OpenGLHelper.cxx index 2e0dcfd4e0ef..87fec55fb3e9 100644 --- a/vcl/source/opengl/OpenGLHelper.cxx +++ b/vcl/source/opengl/OpenGLHelper.cxx @@ -23,6 +23,7 @@ #include <com/sun/star/util/XFlushable.hpp> #include <com/sun/star/configuration/theDefaultProvider.hpp> +#include <stdarg.h> #include <vector> #include "opengl/zone.hxx" @@ -622,6 +623,43 @@ bool OpenGLHelper::isVCLOpenGLEnabled() return bRet; } +void OpenGLHelper::debugMsgStream(const char *pArea, std::ostringstream const &pStream) +{ + debugMsgPrint(pArea, "%s", pStream.str().c_str()); +} + +void OpenGLHelper::debugMsgPrint(const char *pArea, const char *pFormat, ...) +{ + va_list aArgs; + va_start (aArgs, pFormat); + + char pStr[1024]; +#ifdef _WIN32 +#define vsnprintf _vsnprintf +#endif + vsnprintf(pStr, sizeof(pStr), pFormat, aArgs); + pStr[sizeof(pStr)-1] = '\0'; + + SAL_INFO(pArea, pStr); + + OpenGLZone aZone; + + if (GLEW_KHR_debug) + glDebugMessageInsert(GL_DEBUG_SOURCE_APPLICATION, + GL_DEBUG_TYPE_OTHER, + 1, // one[sic] id is as good as another ? + // GL_DEBUG_SEVERITY_NOTIFICATION for >= GL4.3 ? + GL_DEBUG_SEVERITY_LOW, + strlen(pStr), pStr); + else if (GLEW_AMD_debug_output) + glDebugMessageInsertAMD(GL_DEBUG_CATEGORY_APPLICATION_AMD, + GL_DEBUG_SEVERITY_LOW_AMD, + 1, // one[sic] id is as good as another ? + strlen(pStr), pStr); + + va_end (aArgs); +} + #if defined UNX && !defined MACOSX && !defined IOS && !defined ANDROID && !defined(LIBO_HEADLESS) bool OpenGLHelper::GetVisualInfo(Display* pDisplay, int nScreen, XVisualInfo& rVI) |