diff options
author | gman@chromium.org <gman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-04 19:27:49 +0000 |
---|---|---|
committer | gman@chromium.org <gman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-04 19:27:49 +0000 |
commit | 218a5a204661ad6185f01d6233b35b2d5f86027b (patch) | |
tree | 39406b87d8e6c7430a82d60856f68981b9abd087 /app | |
parent | 843dad82c9915bb0057c4bffc379fdd245f27731 (diff) | |
download | chromium_src-218a5a204661ad6185f01d6233b35b2d5f86027b.zip chromium_src-218a5a204661ad6185f01d6233b35b2d5f86027b.tar.gz chromium_src-218a5a204661ad6185f01d6233b35b2d5f86027b.tar.bz2 |
Add service side GL call logging to the DEBUG
build of Chrome.
For now you need to call InitDebugGLBindings.
It seems like it would be nice to add a flag
or check an environment variable but it also
seems strange to add a flag just for debugging.
Then again I guess we have --gpu-startup-dialog.
Also, to really make this work will require
both an special ostream and adding a bunch
more type info the generate_bindings.py
so it can cast values appropriately.
For example it would be nice if it cast GLenum
to an object that printed the enum name. It would
also be nice if it cast const GLubyte* and void*
to appropriate things depending on usage so
the stream can write the correct stuff.
For now though it does show all the calls which
is useful in and of itself.
Any idea how to get base/logging.h working on mac?
TEST=ran it in the opengl es 2.0 conformance tests.
BUG=none
Review URL: http://codereview.chromium.org/4464002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@65096 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app')
-rw-r--r-- | app/gfx/gl/generate_bindings.py | 126 | ||||
-rw-r--r-- | app/gfx/gl/gl_bindings.h | 9 | ||||
-rw-r--r-- | app/gfx/gl/gl_implementation.h | 3 | ||||
-rw-r--r-- | app/gfx/gl/gl_implementation_linux.cc | 7 | ||||
-rw-r--r-- | app/gfx/gl/gl_implementation_mac.cc | 5 | ||||
-rw-r--r-- | app/gfx/gl/gl_implementation_win.cc | 7 |
6 files changed, 122 insertions, 35 deletions
diff --git a/app/gfx/gl/generate_bindings.py b/app/gfx/gl/generate_bindings.py index 8208cd9..f63293d 100644 --- a/app/gfx/gl/generate_bindings.py +++ b/app/gfx/gl/generate_bindings.py @@ -424,7 +424,7 @@ FUNCTION_SETS = [ [GLX_FUNCTIONS, 'glx'], ] -def GenerateHeader(file, functions, setName): +def GenerateHeader(file, functions, set_name): """Generates gl_binding_autogen_x.h""" # Write file header. @@ -434,26 +434,27 @@ def GenerateHeader(file, functions, setName): file.write('\n') file.write('// This file is automatically generated.\n') file.write('\n') - file.write('#ifndef APP_GFX_GL_GL_BINDINGS_AUTOGEN_%s_H_\n' % setName.upper()) - file.write('#define APP_GFX_GL_GL_BINDINGS_AUTOGEN_%s_H_\n' % setName.upper()) + file.write('#ifndef APP_GFX_GL_GL_BINDINGS_AUTOGEN_%s_H_\n' % set_name.upper()) + file.write('#define APP_GFX_GL_GL_BINDINGS_AUTOGEN_%s_H_\n' % set_name.upper()) # Write prototype for initialization function. file.write('\n') file.write('namespace gfx {\n') file.write('\n') - file.write('void InitializeGLBindings%s();\n' % setName.upper()) + file.write('void InitializeGLBindings%s();\n' % set_name.upper()) + file.write('void InitializeDebugGLBindings%s();\n' % set_name.upper()) # Write typedefs for function pointer types. Always use the GL name for the # typedef. file.write('\n') - for [returnType, names, arguments] in functions: + for [return_type, names, arguments] in functions: file.write('typedef %s (GL_BINDING_CALL *%sProc)(%s);\n' % - (returnType, names[0], arguments)) + (return_type, names[0], arguments)) # Write declarations for function pointers. Always use the GL name for the # declaration. file.write('\n') - for [returnType, names, arguments] in functions: + for [return_type, names, arguments] in functions: file.write('extern %sProc g_%s;\n' % (names[0], names[0])) file.write('\n') file.write( '} // namespace gfx\n') @@ -461,15 +462,16 @@ def GenerateHeader(file, functions, setName): # Write macros to invoke function pointers. Always use the GL name for the # macro. file.write('\n') - for [returnType, names, arguments] in functions: + for [return_type, names, arguments] in functions: file.write('#define %s ::gfx::g_%s\n' % (names[0], names[0])) file.write('\n') file.write('#endif // APP_GFX_GL_GL_BINDINGS_AUTOGEN_%s_H_\n' % - setName.upper()) + set_name.upper()) -def GenerateSource(file, functions, setName): + +def GenerateSource(file, functions, set_name): """Generates gl_binding_autogen_x.cc""" # Write file header. @@ -486,13 +488,17 @@ def GenerateSource(file, functions, setName): file.write('\n') file.write('namespace gfx {\n') file.write('\n') - for [returnType, names, arguments] in functions: + for [return_type, names, arguments] in functions: file.write('%sProc g_%s;\n' % (names[0], names[0])) + file.write('\n') + for [return_type, names, arguments] in functions: + file.write('static %sProc g_debug_%s;\n' % (names[0], names[0])) + # Write function to initialize the function pointers. file.write('\n') - file.write('void InitializeGLBindings%s() {\n' % setName.upper()) - for [returnType, names, arguments] in functions: + file.write('void InitializeGLBindings%s() {\n' % set_name.upper()) + for [return_type, names, arguments] in functions: for name in names: file.write(' if (!g_%s)\n' % names[0]) file.write( @@ -500,8 +506,56 @@ def GenerateSource(file, functions, setName): (names[0], names[0], name)) file.write('}\n') file.write('\n') + + # Write logging wrappers for each function. + file.write('extern "C" {\n') + for [return_type, names, arguments] in functions: + file.write('\n') + file.write('static %s GL_BINDING_CALL Debug_%s(%s) {\n' % + (return_type, names[0], arguments)) + argument_names = re.sub(r'(const )?[a-zA-Z0-9]+\** ([a-zA-Z0-9]+)', r'\2', + arguments) + argument_names = re.sub(r'(const )?[a-zA-Z0-9]+\** ([a-zA-Z0-9]+)', r'\2', + argument_names) + log_argument_names = argument_names.replace(',', ' << ", " <<'); + if argument_names == 'void' or argument_names == '': + argument_names = '' + log_argument_names = '' + else: + log_argument_names = " << " + log_argument_names + function_name = names[0] + if return_type == 'void': + file.write(' GL_SERVICE_LOG("%s" << "(" %s << ")");\n' % + (function_name, log_argument_names)) + file.write(' g_debug_%s(%s);\n' % + (function_name, argument_names)) + else: + file.write(' GL_SERVICE_LOG("%s" << "(" %s << ")");\n' % + (function_name, log_argument_names)) + file.write(' %s result = g_debug_%s(%s);\n' % + (return_type, function_name, argument_names)) + file.write(' GL_SERVICE_LOG("GL_RESULT: " << result);\n'); + file.write(' return result;\n') + file.write('}\n') + file.write('} // extern "C"\n') + + # Write function to initialize the function pointers. + file.write('\n') + file.write('void InitializeDebugGLBindings%s() {\n' % set_name.upper()) + for [return_type, names, arguments] in functions: + for name in names: + file.write(' if (!g_debug_%s) {\n' % names[0]) + file.write(' g_debug_%s = g_%s;\n' % (names[0], names[0])) + #file.write(' g_%s = reinterpret_cast<%sProc>(Debug_%s);\n' % + # (names[0], names[0], names[0])) + file.write(' g_%s = Debug_%s;\n' % (names[0], names[0])) + file.write(' }\n') + file.write('}\n') + file.write('\n') + file.write( '} // namespace gfx\n') + def GenerateMockSource(file, functions): """Generates functions that invoke a mock GLInterface""" @@ -519,27 +573,27 @@ def GenerateMockSource(file, functions): file.write('namespace gfx {\n') # Write function that trampoline into the GLInterface. - for [returnType, names, arguments] in functions: + for [return_type, names, arguments] in functions: file.write('\n') file.write('%s GL_BINDING_CALL Mock_%s(%s) {\n' % - (returnType, names[0], arguments)) - argumentNames = re.sub(r'(const )?[a-zA-Z0-9]+\** ([a-zA-Z0-9]+)', r'\2', + (return_type, names[0], arguments)) + argument_names = re.sub(r'(const )?[a-zA-Z0-9]+\** ([a-zA-Z0-9]+)', r'\2', arguments) - if argumentNames == 'void': - argumentNames = '' - functionName = names[0][2:] - if returnType == 'void': + if argument_names == 'void': + argument_names = '' + function_name = names[0][2:] + if return_type == 'void': file.write(' GLInterface::GetGLInterface()->%s(%s);\n' % - (functionName, argumentNames)) + (function_name, argument_names)) else: file.write(' return GLInterface::GetGLInterface()->%s(%s);\n' % - (functionName, argumentNames)) + (function_name, argument_names)) file.write('}\n') # Write a function to lookup a mock GL function based on its name. file.write('\n') file.write('void* GL_BINDING_CALL GetMockGLProcAddress(const char* name) {\n') - for [returnType, names, arguments] in functions: + for [return_type, names, arguments] in functions: file.write(' if (strcmp(name, "%s") == 0)\n' % names[0]) file.write(' return reinterpret_cast<void*>(Mock_%s);\n' % names[0]) file.write(' return NULL;\n') @@ -548,6 +602,7 @@ def GenerateMockSource(file, functions): file.write('\n') file.write('} // namespace gfx\n') + def main(argv): """This is the main function.""" @@ -556,20 +611,21 @@ def main(argv): else: dir = '.' - for [functions, setName] in FUNCTION_SETS: - headerFile = open( - os.path.join(dir, 'gl_bindings_autogen_%s.h' % setName), 'wb') - GenerateHeader(headerFile, functions, setName) - headerFile.close() + for [functions, set_name] in FUNCTION_SETS: + header_file = open( + os.path.join(dir, 'gl_bindings_autogen_%s.h' % set_name), 'wb') + GenerateHeader(header_file, functions, set_name) + header_file.close() + + source_file = open( + os.path.join(dir, 'gl_bindings_autogen_%s.cc' % set_name), 'wb') + GenerateSource(source_file, functions, set_name) + source_file.close() - sourceFile = open( - os.path.join(dir, 'gl_bindings_autogen_%s.cc' % setName), 'wb') - GenerateSource(sourceFile, functions, setName) - sourceFile.close() + source_file = open(os.path.join(dir, 'gl_bindings_autogen_mock.cc'), 'wb') + GenerateMockSource(source_file, GL_FUNCTIONS) + source_file.close() - sourceFile = open(os.path.join(dir, 'gl_bindings_autogen_mock.cc'), 'wb') - GenerateMockSource(sourceFile, GL_FUNCTIONS) - sourceFile.close() if __name__ == '__main__': main(sys.argv[1:]) diff --git a/app/gfx/gl/gl_bindings.h b/app/gfx/gl/gl_bindings.h index 6f37a42..6b1d22c 100644 --- a/app/gfx/gl/gl_bindings.h +++ b/app/gfx/gl/gl_bindings.h @@ -15,6 +15,9 @@ #include <GL/glext.h> #include "build/build_config.h" +#if defined(OS_WIN) +#include "base/logging.h" +#endif // The standard OpenGL native extension headers are also included. #if defined(OS_WIN) @@ -39,6 +42,12 @@ #define GL_BINDING_CALL #endif +#if defined(OS_WIN) +#define GL_SERVICE_LOG(args) DLOG(INFO) << args; +#else +#define GL_SERVICE_LOG(args) +#endif + // Forward declare OSMesa types. typedef struct osmesa_context *OSMesaContext; typedef void (*OSMESAproc)(); diff --git a/app/gfx/gl/gl_implementation.h b/app/gfx/gl/gl_implementation.h index 91dd617..dba4277 100644 --- a/app/gfx/gl/gl_implementation.h +++ b/app/gfx/gl/gl_implementation.h @@ -37,6 +37,9 @@ typedef void* (*GLGetProcAddressProc)(const char* name); // Initialize a particular GL implementation. bool InitializeGLBindings(GLImplementation implementation); +// Initialize a particular GL implementation. +void InitializeDebugGLBindings(); + // Set the current GL implementation. void SetGLImplementation(GLImplementation implementation); diff --git a/app/gfx/gl/gl_implementation_linux.cc b/app/gfx/gl/gl_implementation_linux.cc index 09e0c71..74fd21e 100644 --- a/app/gfx/gl/gl_implementation_linux.cc +++ b/app/gfx/gl/gl_implementation_linux.cc @@ -151,4 +151,11 @@ bool InitializeGLBindings(GLImplementation implementation) { return true; } +void InitializeDebugGLBindings() { + InitializeDebugGLBindingsEGL(); + InitializeDebugGLBindingsGL(); + InitializeDebugGLBindingsGLX(); + InitializeDebugGLBindingsOSMESA(); +} + } // namespace gfx diff --git a/app/gfx/gl/gl_implementation_mac.cc b/app/gfx/gl/gl_implementation_mac.cc index 66562ca..0a1d5a5 100644 --- a/app/gfx/gl/gl_implementation_mac.cc +++ b/app/gfx/gl/gl_implementation_mac.cc @@ -84,4 +84,9 @@ bool InitializeGLBindings(GLImplementation implementation) { return true; } +void InitializeDebugGLBindings() { + InitializeDebugGLBindingsGL(); + InitializeDebugGLBindingsOSMESA(); +} + } // namespace gfx diff --git a/app/gfx/gl/gl_implementation_win.cc b/app/gfx/gl/gl_implementation_win.cc index 42cd9eb..c3869b1 100644 --- a/app/gfx/gl/gl_implementation_win.cc +++ b/app/gfx/gl/gl_implementation_win.cc @@ -158,4 +158,11 @@ bool InitializeGLBindings(GLImplementation implementation) { return true; } +void InitializeDebugGLBindings() { + InitializeDebugGLBindingsEGL(); + InitializeDebugGLBindingsGL(); + InitializeDebugGLBindingsOSMESA(); + InitializeDebugGLBindingsWGL(); +} + } // namespace gfx |