diff options
author | sadrul <sadrul@chromium.org> | 2015-07-20 15:34:26 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-07-20 22:35:29 +0000 |
commit | ba162cdaf95c99b67da214be4cc8117db9ad2a5f (patch) | |
tree | 814ef1c3c6d82f7193494ffece674371b68e8bfc /ui/gl | |
parent | c2e5ab72a5cc817cdb86189670c9f535ed67bd4e (diff) | |
download | chromium_src-ba162cdaf95c99b67da214be4cc8117db9ad2a5f.zip chromium_src-ba162cdaf95c99b67da214be4cc8117db9ad2a5f.tar.gz chromium_src-ba162cdaf95c99b67da214be4cc8117db9ad2a5f.tar.bz2 |
gl/test: Move some initialization code used in tests to a separate component.
Moving test-code to a separete component, so that adding more test-only
dependencies does not affect non-test code.
BUG=none
CQ_INCLUDE_TRYBOTS=tryserver.blink:linux_blink_rel
TBR=jam@ for non-ui/gl/ changes, since trivial #include/gyp-gn updates
Review URL: https://codereview.chromium.org/1238443004
Cr-Commit-Position: refs/heads/master@{#339539}
Diffstat (limited to 'ui/gl')
-rw-r--r-- | ui/gl/BUILD.gn | 19 | ||||
-rw-r--r-- | ui/gl/gl.gyp | 23 | ||||
-rw-r--r-- | ui/gl/gl_implementation.h | 3 | ||||
-rw-r--r-- | ui/gl/gl_surface.cc | 64 | ||||
-rw-r--r-- | ui/gl/gl_surface.h | 7 | ||||
-rw-r--r-- | ui/gl/gl_tests.gyp | 1 | ||||
-rw-r--r-- | ui/gl/gpu_timing_unittest.cc | 6 | ||||
-rw-r--r-- | ui/gl/test/gl_surface_test_support.cc | 84 | ||||
-rw-r--r-- | ui/gl/test/gl_surface_test_support.h | 21 |
9 files changed, 154 insertions, 74 deletions
diff --git a/ui/gl/BUILD.gn b/ui/gl/BUILD.gn index f5f4134..8d20112 100644 --- a/ui/gl/BUILD.gn +++ b/ui/gl/BUILD.gn @@ -280,6 +280,24 @@ source_set("gl_unittest_utils") { ] } +source_set("test_support") { + sources = [ + "test/gl_surface_test_support.cc", + "test/gl_surface_test_support.h", + ] + + configs += [ "//third_party/khronos:khronos_headers" ] + + deps = [ + ":gl", + ] + + if (use_x11) { + configs += [ "//build/config/linux:x11" ] + deps += [ "//ui/gfx/x" ] + } +} + test("gl_unittests") { sources = [ "gl_api_unittest.cc", @@ -299,6 +317,7 @@ test("gl_unittests") { deps = [ ":gl", ":gl_unittest_utils", + ":test_support", "//base", "//base/test:test_support", "//testing/gmock", diff --git a/ui/gl/gl.gyp b/ui/gl/gl.gyp index 6d4d1f9..3edd4d4 100644 --- a/ui/gl/gl.gyp +++ b/ui/gl/gl.gyp @@ -291,6 +291,29 @@ 'gpu_timing_fake.h', ], }, + { + 'target_name': 'gl_test_support', + 'type': 'static_library', + 'dependencies': [ + '../../third_party/khronos/khronos.gyp:khronos_headers', + 'gl', + ], + 'include_dirs': [ + '../..', + ], + 'sources': [ + 'test/gl_surface_test_support.cc', + 'test/gl_surface_test_support.h', + ], + 'conditions': [ + ['use_x11==1', { + 'dependencies': [ + '../../build/linux/system.gyp:x11', + '../gfx/x/gfx_x11.gyp:gfx_x11', + ], + }], + ], + }, ], 'conditions': [ ['OS=="android"' , { diff --git a/ui/gl/gl_implementation.h b/ui/gl/gl_implementation.h index c0ac42e..d76f438 100644 --- a/ui/gl/gl_implementation.h +++ b/ui/gl/gl_implementation.h @@ -36,7 +36,8 @@ struct GL_EXPORT GLWindowSystemBindingInfo { bool direct_rendering; }; -void GetAllowedGLImplementations(std::vector<GLImplementation>* impls); +void GL_EXPORT +GetAllowedGLImplementations(std::vector<GLImplementation>* impls); #if defined(OS_WIN) typedef void* (WINAPI *GLGetProcAddressProc)(const char* name); diff --git a/ui/gl/gl_surface.cc b/ui/gl/gl_surface.cc index 8a60ca5..a4a6035 100644 --- a/ui/gl/gl_surface.cc +++ b/ui/gl/gl_surface.cc @@ -97,70 +97,6 @@ bool GLSurface::InitializeOneOffImplementation(GLImplementation impl, return initialized; } -// static -void GLSurface::InitializeOneOffForTests() { - DCHECK_EQ(kGLImplementationNone, GetGLImplementation()); - -#if defined(USE_X11) - XInitThreads(); -#endif - - bool use_osmesa = true; - - // We usually use OSMesa as this works on all bots. The command line can - // override this behaviour to use hardware GL. - if (base::CommandLine::ForCurrentProcess()->HasSwitch( - switches::kUseGpuInTests)) - use_osmesa = false; - -#if defined(OS_ANDROID) - // On Android we always use hardware GL. - use_osmesa = false; -#endif - - std::vector<GLImplementation> allowed_impls; - GetAllowedGLImplementations(&allowed_impls); - DCHECK(!allowed_impls.empty()); - - GLImplementation impl = allowed_impls[0]; - if (use_osmesa) - impl = kGLImplementationOSMesaGL; - - DCHECK(!base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseGL)) - << "kUseGL has not effect in tests"; - - bool fallback_to_osmesa = false; - bool gpu_service_logging = false; - bool disable_gl_drawing = true; - - CHECK(InitializeOneOffImplementation( - impl, fallback_to_osmesa, gpu_service_logging, disable_gl_drawing)); -} - -// static -void GLSurface::InitializeOneOffWithMockBindingsForTests() { - DCHECK(!base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseGL)) - << "kUseGL has not effect in tests"; - - // This method may be called multiple times in the same process to set up - // mock bindings in different ways. - ClearGLBindings(); - - bool fallback_to_osmesa = false; - bool gpu_service_logging = false; - bool disable_gl_drawing = false; - - CHECK(InitializeOneOffImplementation(kGLImplementationMockGL, - fallback_to_osmesa, - gpu_service_logging, - disable_gl_drawing)); -} - -// static -void GLSurface::InitializeDynamicMockBindingsForTests(GLContext* context) { - CHECK(InitializeDynamicGLBindings(kGLImplementationMockGL, context)); -} - GLSurface::GLSurface() {} bool GLSurface::Initialize() { diff --git a/ui/gl/gl_surface.h b/ui/gl/gl_surface.h index 9fee0a3..2f9ad84 100644 --- a/ui/gl/gl_surface.h +++ b/ui/gl/gl_surface.h @@ -99,12 +99,6 @@ class GL_EXPORT GLSurface : public base::RefCounted<GLSurface> { // Initialize GL bindings. static bool InitializeOneOff(); - // Unit tests should call these instead of InitializeOneOff() to set up - // GL bindings appropriate for tests. - static void InitializeOneOffForTests(); - static void InitializeOneOffWithMockBindingsForTests(); - static void InitializeDynamicMockBindingsForTests(GLContext* context); - // Called after a context is made current with this surface. Returns false // on error. virtual bool OnMakeCurrent(GLContext* context); @@ -189,6 +183,7 @@ class GL_EXPORT GLSurface : public base::RefCounted<GLSurface> { private: friend class base::RefCounted<GLSurface>; friend class GLContext; + friend class GLSurfaceTestSupport; DISALLOW_COPY_AND_ASSIGN(GLSurface); }; diff --git a/ui/gl/gl_tests.gyp b/ui/gl/gl_tests.gyp index 37dec4f..4f7e2dd 100644 --- a/ui/gl/gl_tests.gyp +++ b/ui/gl/gl_tests.gyp @@ -24,6 +24,7 @@ '<(DEPTH)/testing/gmock.gyp:gmock', '<(DEPTH)/testing/gtest.gyp:gtest', '<(DEPTH)/ui/gl/gl.gyp:gl', + '<(DEPTH)/ui/gl/gl.gyp:gl_test_support', '<(DEPTH)/ui/gl/gl.gyp:gl_unittest_utils', ], 'conditions': [ diff --git a/ui/gl/gpu_timing_unittest.cc b/ui/gl/gpu_timing_unittest.cc index 946d231..2b95574 100644 --- a/ui/gl/gpu_timing_unittest.cc +++ b/ui/gl/gpu_timing_unittest.cc @@ -8,10 +8,10 @@ #include "ui/gl/gl_context_stub_with_extensions.h" #include "ui/gl/gl_implementation.h" #include "ui/gl/gl_mock.h" -#include "ui/gl/gl_surface.h" #include "ui/gl/gpu_preference.h" #include "ui/gl/gpu_timing.h" #include "ui/gl/gpu_timing_fake.h" +#include "ui/gl/test/gl_surface_test_support.h" namespace gfx { @@ -38,7 +38,7 @@ class GPUTimingTest : public testing::Test { void SetupGLContext(const char* gl_version, const char* gl_extensions) { ASSERT_FALSE(setup_) << "Cannot setup GL context twice."; SetGLGetProcAddressProc(MockGLInterface::GetGLProcAddress); - GLSurface::InitializeOneOffWithMockBindingsForTests(); + GLSurfaceTestSupport::InitializeOneOffWithMockBindings(); gl_.reset(new ::testing::StrictMock<MockGLInterface>()); MockGLInterface::SetGLInterface(gl_.get()); @@ -46,7 +46,7 @@ class GPUTimingTest : public testing::Test { context_->AddExtensionsString(gl_extensions); context_->SetGLVersionString(gl_version); gpu_timing_fake_queries_.Reset(); - GLSurface::InitializeDynamicMockBindingsForTests(context_.get()); + GLSurfaceTestSupport::InitializeDynamicMockBindings(context_.get()); setup_ = true; } diff --git a/ui/gl/test/gl_surface_test_support.cc b/ui/gl/test/gl_surface_test_support.cc new file mode 100644 index 0000000..fde1a1b --- /dev/null +++ b/ui/gl/test/gl_surface_test_support.cc @@ -0,0 +1,84 @@ +// Copyright 2015 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/test/gl_surface_test_support.h" + +#include "base/command_line.h" +#include "base/logging.h" +#include "ui/gl/gl_context.h" +#include "ui/gl/gl_implementation.h" +#include "ui/gl/gl_surface.h" +#include "ui/gl/gl_switches.h" + +#if defined(USE_X11) +#include <X11/Xlib.h> +#endif + +namespace gfx { + +// static +void GLSurfaceTestSupport::InitializeOneOff() { + DCHECK_EQ(kGLImplementationNone, GetGLImplementation()); + +#if defined(USE_X11) + XInitThreads(); +#endif + + bool use_osmesa = true; + + // We usually use OSMesa as this works on all bots. The command line can + // override this behaviour to use hardware GL. + if (base::CommandLine::ForCurrentProcess()->HasSwitch( + switches::kUseGpuInTests)) { + use_osmesa = false; + } + +#if defined(OS_ANDROID) + // On Android we always use hardware GL. + use_osmesa = false; +#endif + + std::vector<GLImplementation> allowed_impls; + GetAllowedGLImplementations(&allowed_impls); + DCHECK(!allowed_impls.empty()); + + GLImplementation impl = allowed_impls[0]; + if (use_osmesa) + impl = kGLImplementationOSMesaGL; + + DCHECK(!base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseGL)) + << "kUseGL has not effect in tests"; + + bool fallback_to_osmesa = false; + bool gpu_service_logging = false; + bool disable_gl_drawing = true; + + CHECK(GLSurface::InitializeOneOffImplementation( + impl, fallback_to_osmesa, gpu_service_logging, disable_gl_drawing)); +} + +// static +void GLSurfaceTestSupport::InitializeOneOffWithMockBindings() { + DCHECK(!base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseGL)) + << "kUseGL has not effect in tests"; + + // This method may be called multiple times in the same process to set up + // mock bindings in different ways. + ClearGLBindings(); + + bool fallback_to_osmesa = false; + bool gpu_service_logging = false; + bool disable_gl_drawing = false; + + CHECK(GLSurface::InitializeOneOffImplementation( + kGLImplementationMockGL, fallback_to_osmesa, gpu_service_logging, + disable_gl_drawing)); +} + +// static +void GLSurfaceTestSupport::InitializeDynamicMockBindings(GLContext* context) { + CHECK(InitializeDynamicGLBindings(kGLImplementationMockGL, context)); +} + +} // namespace gfx diff --git a/ui/gl/test/gl_surface_test_support.h b/ui/gl/test/gl_surface_test_support.h new file mode 100644 index 0000000..6e53c69 --- /dev/null +++ b/ui/gl/test/gl_surface_test_support.h @@ -0,0 +1,21 @@ +// Copyright 2015 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_TEST_GL_SURFACE_TEST_SUPPORT_H_ +#define UI_GL_TEST_GL_SURFACE_TEST_SUPPORT_H_ + +namespace gfx { + +class GLContext; + +class GLSurfaceTestSupport { + public: + static void InitializeOneOff(); + static void InitializeOneOffWithMockBindings(); + static void InitializeDynamicMockBindings(GLContext* context); +}; + +} // namespace gfx + +#endif // UI_GL_TEST_GL_SURFACE_TEST_SUPPORT_H_ |