diff options
Diffstat (limited to 'ui')
-rwxr-xr-x | ui/gl/generate_bindings.py | 75 | ||||
-rw-r--r-- | ui/gl/gl.gyp | 18 | ||||
-rw-r--r-- | ui/gl/gl_bindings.h | 3 | ||||
-rw-r--r-- | ui/gl/gl_implementation.h | 3 | ||||
-rw-r--r-- | ui/gl/gl_implementation_android.cc | 1 | ||||
-rw-r--r-- | ui/gl/gl_implementation_mac.cc | 1 | ||||
-rw-r--r-- | ui/gl/gl_implementation_ozone.cc | 1 | ||||
-rw-r--r-- | ui/gl/gl_implementation_win.cc | 1 | ||||
-rw-r--r-- | ui/gl/gl_implementation_x11.cc | 1 | ||||
-rw-r--r-- | ui/gl/gl_interface.cc | 20 | ||||
-rw-r--r-- | ui/gl/gl_interface.h | 35 | ||||
-rw-r--r-- | ui/gl/gl_mock.cc | 6 | ||||
-rw-r--r-- | ui/gl/gl_mock.h | 26 |
13 files changed, 67 insertions, 124 deletions
diff --git a/ui/gl/generate_bindings.py b/ui/gl/generate_bindings.py index ed42225..3bcfb54e 100755 --- a/ui/gl/generate_bindings.py +++ b/ui/gl/generate_bindings.py @@ -1405,30 +1405,6 @@ def GenerateMockHeader(file, functions, set_name): file.write('\n') -def GenerateInterfaceHeader(file, functions, set_name): - """Generates gl_interface_autogen_x.h""" - - # Write file header. - file.write( -"""// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// This file is automatically generated. - -""" % {'name': set_name.upper()}) - - # Write API declaration. - for func in functions: - args = func['arguments'] - if args == 'void': - args = '' - file.write(' virtual %s %s(%s) = 0;\n' % - (func['return_type'], func['known_as'][2:], args)) - - file.write('\n') - - def GenerateSource( file, functions, nulldraw_functions, set_name, used_extensions): """Generates gl_bindings_autogen_x.cc""" @@ -1748,8 +1724,24 @@ namespace gfx { file.write('} // namespace gfx\n') -def GenerateMockSource(file, functions): - """Generates functions that invoke a mock GLInterface""" +def GenerateMockBindingsHeader(file, functions): + """Headers for functions that invoke MockGLInterface members""" + + file.write( +"""// Copyright (c) 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// This file is automatically generated. + +""") + for func in functions: + file.write('static %s GL_BINDING_CALL Mock_%s(%s);\n' % + (func['return_type'], func['known_as'], func['arguments'])) + +def GenerateMockBindingsSource(file, functions): + """Generates functions that invoke MockGLInterface members and a + GetGLProcAddress function that returns addresses to those functions.""" file.write( """// Copyright (c) 2011 The Chromium Authors. All rights reserved. @@ -1760,14 +1752,14 @@ def GenerateMockSource(file, functions): #include <string.h> -#include "ui/gl/gl_interface.h" +#include "ui/gl/gl_mock.h" namespace gfx { """) - # Write function that trampoline into the GLInterface. + # Write functions that trampoline into the set MockGLInterface instance. for func in functions: file.write('\n') - file.write('%s GL_BINDING_CALL Mock_%s(%s) {\n' % + file.write('%s GL_BINDING_CALL MockGLInterface::Mock_%s(%s) {\n' % (func['return_type'], func['known_as'], func['arguments'])) arg_re = r'(const )?[a-zA-Z0-9]+((\s*const\s*)?\*)* ([a-zA-Z0-9]+)' argument_names = re.sub(arg_re, r'\4', func['arguments']) @@ -1775,10 +1767,10 @@ namespace gfx { argument_names = '' function_name = func['known_as'][2:] if func['return_type'] == 'void': - file.write(' GLInterface::GetGLInterface()->%s(%s);\n' % + file.write(' interface_->%s(%s);\n' % (function_name, argument_names)) else: - file.write(' return GLInterface::GetGLInterface()->%s(%s);\n' % + file.write(' return interface_->%s(%s);\n' % (function_name, argument_names)) file.write('}\n') @@ -1792,7 +1784,8 @@ namespace gfx { # 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') + file.write('void* GL_BINDING_CALL ' + + 'MockGLInterface::GetGLProcAddress(const char* name) {\n') for func in functions: unique_names = set([version['name'] for version in func['versions']]) for name in unique_names: @@ -2010,19 +2003,19 @@ def main(argv): used_extensions) source_file.close() - header_file = open( - os.path.join(directory, 'gl_interface_autogen_%s.h' % set_name), 'wb') - GenerateInterfaceHeader(header_file, functions, set_name) - header_file.close() + header_file = open( + os.path.join(directory, 'gl_mock_autogen_gl.h'), 'wb') + GenerateMockHeader(header_file, GL_FUNCTIONS, 'gl') + header_file.close() - header_file = open( - os.path.join(directory, 'gl_mock_autogen_%s.h' % set_name), 'wb') - GenerateMockHeader(header_file, functions, set_name) - header_file.close() + header_file = open(os.path.join(directory, 'gl_bindings_autogen_mock.h'), + 'wb') + GenerateMockBindingsHeader(header_file, GL_FUNCTIONS) + header_file.close() source_file = open(os.path.join(directory, 'gl_bindings_autogen_mock.cc'), 'wb') - GenerateMockSource(source_file, GL_FUNCTIONS) + GenerateMockBindingsSource(source_file, GL_FUNCTIONS) source_file.close() return 0 diff --git a/ui/gl/gl.gyp b/ui/gl/gl.gyp index 5e1c4d40..fad0091 100644 --- a/ui/gl/gl.gyp +++ b/ui/gl/gl.gyp @@ -40,7 +40,7 @@ 'export_dependent_settings': [ '<(DEPTH)/third_party/mesa/mesa.gyp:mesa_headers', ], - 'sources': [ + 'sources': [ 'android/gl_jni_registrar.cc', 'android/gl_jni_registrar.h', 'android/scoped_java_surface.cc', @@ -90,8 +90,6 @@ 'gl_implementation_mac.cc', 'gl_implementation_win.cc', 'gl_implementation_x11.cc', - 'gl_interface.cc', - 'gl_interface.h', 'gl_osmesa_api_implementation.cc', 'gl_osmesa_api_implementation.h', 'gl_share_group.cc', @@ -123,10 +121,8 @@ 'sync_control_vsync_provider.h', '<(gl_binding_output_dir)/gl_bindings_autogen_gl.cc', '<(gl_binding_output_dir)/gl_bindings_autogen_gl.h', - '<(gl_binding_output_dir)/gl_bindings_autogen_mock.cc', '<(gl_binding_output_dir)/gl_bindings_autogen_osmesa.cc', '<(gl_binding_output_dir)/gl_bindings_autogen_osmesa.h', - '<(gl_binding_output_dir)/gl_interface_autogen_gl.h', ], # hard_dependency is necessary for this target because it has actions # that generate header files included by dependent targets. The header @@ -156,22 +152,14 @@ '<(gl_binding_output_dir)/gl_bindings_autogen_glx.h', '<(gl_binding_output_dir)/gl_bindings_api_autogen_glx.h', '<(gl_binding_output_dir)/gl_bindings_autogen_mock.cc', + '<(gl_binding_output_dir)/gl_bindings_autogen_mock.h', '<(gl_binding_output_dir)/gl_bindings_autogen_osmesa.cc', '<(gl_binding_output_dir)/gl_bindings_autogen_osmesa.h', '<(gl_binding_output_dir)/gl_bindings_api_autogen_osmesa.h', '<(gl_binding_output_dir)/gl_bindings_autogen_wgl.cc', '<(gl_binding_output_dir)/gl_bindings_autogen_wgl.h', '<(gl_binding_output_dir)/gl_bindings_api_autogen_wgl.h', - '<(gl_binding_output_dir)/gl_interface_autogen_egl.h', - '<(gl_binding_output_dir)/gl_interface_autogen_gl.h', - '<(gl_binding_output_dir)/gl_interface_autogen_glx.h', - '<(gl_binding_output_dir)/gl_interface_autogen_osmesa.h', - '<(gl_binding_output_dir)/gl_interface_autogen_wgl.h', - '<(gl_binding_output_dir)/gl_mock_autogen_egl.h', '<(gl_binding_output_dir)/gl_mock_autogen_gl.h', - '<(gl_binding_output_dir)/gl_mock_autogen_glx.h', - '<(gl_binding_output_dir)/gl_mock_autogen_osmesa.h', - '<(gl_binding_output_dir)/gl_mock_autogen_wgl.h', ], 'action': [ 'python', @@ -329,6 +317,8 @@ 'sources': [ 'gl_mock.h', 'gl_mock.cc', + '<(gl_binding_output_dir)/gl_bindings_autogen_mock.cc', + '<(gl_binding_output_dir)/gl_bindings_autogen_mock.h', '<(gl_binding_output_dir)/gl_mock_autogen_gl.h', ], }, diff --git a/ui/gl/gl_bindings.h b/ui/gl/gl_bindings.h index fd24c42..74e20fe 100644 --- a/ui/gl/gl_bindings.h +++ b/ui/gl/gl_bindings.h @@ -324,9 +324,6 @@ GL_EXPORT extern DriverEGL g_driver_egl; #endif -// Find an entry point to the mock GL implementation. -void* GL_BINDING_CALL GetMockGLProcAddress(const char* name); - } // namespace gfx #endif // UI_GL_GL_BINDINGS_H_ diff --git a/ui/gl/gl_implementation.h b/ui/gl/gl_implementation.h index 045101c..628fc1f 100644 --- a/ui/gl/gl_implementation.h +++ b/ui/gl/gl_implementation.h @@ -80,7 +80,8 @@ void AddGLNativeLibrary(base::NativeLibrary library); void UnloadGLNativeLibraries(); // Set an additional function that will be called to find GL entry points. -void SetGLGetProcAddressProc(GLGetProcAddressProc proc); +// Exported so that tests may set the function used in the mock implementation. +GL_EXPORT void SetGLGetProcAddressProc(GLGetProcAddressProc proc); // Find an entry point in the current GL implementation. Note that the function // may return a non-null pointer to something else than the GL function if an diff --git a/ui/gl/gl_implementation_android.cc b/ui/gl/gl_implementation_android.cc index 0b01133..31fec9a 100644 --- a/ui/gl/gl_implementation_android.cc +++ b/ui/gl/gl_implementation_android.cc @@ -92,7 +92,6 @@ bool InitializeStaticGLBindings(GLImplementation implementation) { break; } case kGLImplementationMockGL: { - SetGLGetProcAddressProc(GetMockGLProcAddress); SetGLImplementation(kGLImplementationMockGL); InitializeStaticGLBindingsGL(); break; diff --git a/ui/gl/gl_implementation_mac.cc b/ui/gl/gl_implementation_mac.cc index e768970..546a082f 100644 --- a/ui/gl/gl_implementation_mac.cc +++ b/ui/gl/gl_implementation_mac.cc @@ -98,7 +98,6 @@ bool InitializeStaticGLBindings(GLImplementation implementation) { break; } case kGLImplementationMockGL: { - SetGLGetProcAddressProc(GetMockGLProcAddress); SetGLImplementation(kGLImplementationMockGL); InitializeStaticGLBindingsGL(); break; diff --git a/ui/gl/gl_implementation_ozone.cc b/ui/gl/gl_implementation_ozone.cc index 0d9fe6b..3659a02 100644 --- a/ui/gl/gl_implementation_ozone.cc +++ b/ui/gl/gl_implementation_ozone.cc @@ -59,7 +59,6 @@ bool InitializeStaticGLBindings(GLImplementation implementation) { ::gfx::g_driver_gl.fn.glDepthRangeFn = MarshalDepthRangeToDepthRangef; break; case kGLImplementationMockGL: { - SetGLGetProcAddressProc(GetMockGLProcAddress); SetGLImplementation(kGLImplementationMockGL); InitializeStaticGLBindingsGL(); break; diff --git a/ui/gl/gl_implementation_win.cc b/ui/gl/gl_implementation_win.cc index 02f6dc1..ddc9c57 100644 --- a/ui/gl/gl_implementation_win.cc +++ b/ui/gl/gl_implementation_win.cc @@ -311,7 +311,6 @@ bool InitializeStaticGLBindings(GLImplementation implementation) { break; } case kGLImplementationMockGL: { - SetGLGetProcAddressProc(GetMockGLProcAddress); SetGLImplementation(kGLImplementationMockGL); InitializeStaticGLBindingsGL(); break; diff --git a/ui/gl/gl_implementation_x11.cc b/ui/gl/gl_implementation_x11.cc index f85dff3..7588a37 100644 --- a/ui/gl/gl_implementation_x11.cc +++ b/ui/gl/gl_implementation_x11.cc @@ -128,7 +128,6 @@ bool InitializeStaticGLBindings(GLImplementation implementation) { break; } case kGLImplementationMockGL: { - SetGLGetProcAddressProc(GetMockGLProcAddress); SetGLImplementation(kGLImplementationMockGL); InitializeStaticGLBindingsGL(); break; diff --git a/ui/gl/gl_interface.cc b/ui/gl/gl_interface.cc deleted file mode 100644 index 0cb61e7..0000000 --- a/ui/gl/gl_interface.cc +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ui/gl/gl_interface.h" - -namespace gfx { - -GLInterface* GLInterface::interface_; - -void GLInterface::SetGLInterface(GLInterface* gl_interface) { - interface_ = gl_interface; -} - -GLInterface* GLInterface::GetGLInterface() { - return interface_; -} - -} // namespace gfx - diff --git a/ui/gl/gl_interface.h b/ui/gl/gl_interface.h deleted file mode 100644 index 7f1ba8f..0000000 --- a/ui/gl/gl_interface.h +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef UI_GL_GL_INTERFACE_H_ -#define UI_GL_GL_INTERFACE_H_ - -// This file implements glue to a GL interface so we can mock it for unit -// testing. It has to be Desktop GL, not GLES2 as it is used to test the service -// side code. - -#include "ui/gl/gl_bindings.h" - -namespace gfx { - -class GL_EXPORT GLInterface { - public: - virtual ~GLInterface() {} - - static void SetGLInterface(GLInterface* gl_interface); - - static GLInterface* GetGLInterface(); - - // Include the auto-generated part of this class. We split this because - // it means we can easily edit the non-auto generated parts right here in - // this file instead of having to edit some template or the code generator. - #include "gl_interface_autogen_gl.h" - - private: - static GLInterface* interface_; -}; - -} // namespace gfx - -#endif // UI_GL_GL_INTERFACE_H_ diff --git a/ui/gl/gl_mock.cc b/ui/gl/gl_mock.cc index f145c77..3b83579 100644 --- a/ui/gl/gl_mock.cc +++ b/ui/gl/gl_mock.cc @@ -12,4 +12,10 @@ MockGLInterface::MockGLInterface() { MockGLInterface::~MockGLInterface() { } +MockGLInterface* MockGLInterface::interface_; + +void MockGLInterface::SetGLInterface(MockGLInterface* gl_interface) { + interface_ = gl_interface; +} + } // namespace gfx diff --git a/ui/gl/gl_mock.h b/ui/gl/gl_mock.h index 39ccb5f..b678a5e 100644 --- a/ui/gl/gl_mock.h +++ b/ui/gl/gl_mock.h @@ -2,26 +2,42 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// This file implements mock GL Interface for unit testing. It has to mock -// Desktop GL, not GLES2 as it is used to test the service side code. +// This file implements mock GL Interface for unit testing. The interface +// corresponds to the set of functionally distinct GL functions defined in +// generate_bindings.py, which may originate from either desktop GL or GLES. #ifndef UI_GL_GL_MOCK_H_ #define UI_GL_GL_MOCK_H_ #include "testing/gmock/include/gmock/gmock.h" -#include "ui/gl/gl_interface.h" +#include "ui/gl/gl_bindings.h" namespace gfx { -class MockGLInterface : public GLInterface { +class MockGLInterface { public: MockGLInterface(); virtual ~MockGLInterface(); - // Include the auto-generated part of this class. We split this because + // Set the functions called from the mock GL implementation for the purposes + // of testing. + static void SetGLInterface(MockGLInterface* gl_interface); + + // Find an entry point to the mock GL implementation. + static void* GL_BINDING_CALL GetGLProcAddress(const char* name); + + // Include the auto-generated parts of this class. We split this because // it means we can easily edit the non-auto generated parts right here in // this file instead of having to edit some template or the code generator. + + // Member functions #include "gl_mock_autogen_gl.h" + + private: + static MockGLInterface* interface_; + + // Static mock functions that invoke the member functions of interface_. + #include "gl_bindings_autogen_mock.h" }; } // namespace gfx |