diff options
author | danakj@chromium.org <danakj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-30 01:04:53 +0000 |
---|---|---|
committer | danakj@chromium.org <danakj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-30 01:04:53 +0000 |
commit | a3d4bda4805547161217ebc79c7305b525e8c38b (patch) | |
tree | 380dae77b9f0793c7524c46828f6714ede976a43 /gpu | |
parent | b773065a8fcd6d50575bf290836aa65a02ee0fa5 (diff) | |
download | chromium_src-a3d4bda4805547161217ebc79c7305b525e8c38b.zip chromium_src-a3d4bda4805547161217ebc79c7305b525e8c38b.tar.gz chromium_src-a3d4bda4805547161217ebc79c7305b525e8c38b.tar.bz2 |
Ensure GL initialization only happens once, and provide common init path
Currently tests initialize GL by calling into methods that should be
internal to the gl bindings code. Instead, everyone should go through
GLSurface::InitializeOneOff.
Also GLSurface::InitializeOneOff early outs if it was already called,
leading to a pattern of initializing GL all over the place just in case
and not having a clear idea of where it should be set up. Instead, DCHECK
that it is not called more than once, and move calls to this method to
be during process startup for unit test suites instead of mid-test.
This adds two test variants of InitializeOneOff for tests to call, that
set up OSMesa or Mock GL bindings, via GLSurface::InitializeOneOff.
R=piman, sievers
BUG=270918
Review URL: https://codereview.chromium.org/135213003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@247793 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gpu')
-rw-r--r-- | gpu/command_buffer/common/unittest_main.cc | 11 | ||||
-rw-r--r-- | gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.cc | 6 | ||||
-rw-r--r-- | gpu/config/gpu_info_collector.cc | 4 | ||||
-rw-r--r-- | gpu/config/gpu_info_collector_android.cc | 16 | ||||
-rw-r--r-- | gpu/config/gpu_info_collector_unittest.cc | 6 | ||||
-rw-r--r-- | gpu/tools/compositor_model_bench/compositor_model_bench.cc | 7 |
6 files changed, 20 insertions, 30 deletions
diff --git a/gpu/command_buffer/common/unittest_main.cc b/gpu/command_buffer/common/unittest_main.cc index c48b77d..358805a 100644 --- a/gpu/command_buffer/common/unittest_main.cc +++ b/gpu/command_buffer/common/unittest_main.cc @@ -11,6 +11,7 @@ #include "testing/gtest/include/gtest/gtest.h" #include "ui/gl/gl_implementation.h" #include "ui/gl/gl_mock.h" +#include "ui/gl/gl_surface.h" namespace { @@ -19,6 +20,13 @@ class NoAtExitBaseTestSuite : public base::TestSuite { NoAtExitBaseTestSuite(int argc, char** argv) : base::TestSuite(argc, argv, false) { } + + virtual void Initialize() OVERRIDE { + base::TestSuite::Initialize(); + gfx::SetGLGetProcAddressProc(gfx::MockGLInterface::GetGLProcAddress); + gfx::GLSurface::InitializeOneOffWithMockBindingsForTests(); + gfx::GLSurface::InitializeDynamicMockBindingsForTests(NULL); + } }; int RunTestSuite(int argc, char** argv) { @@ -35,9 +43,6 @@ int main(int argc, char** argv) { base::AtExitManager exit_manager; #endif CommandLine::Init(argc, argv); - gfx::SetGLGetProcAddressProc(gfx::MockGLInterface::GetGLProcAddress); - gfx::InitializeStaticGLBindings(gfx::kGLImplementationMockGL); - gfx::InitializeDynamicGLBindings(gfx::kGLImplementationMockGL, NULL); testing::InitGoogleMock(&argc, argv); return base::LaunchUnitTests(argc, argv, diff --git a/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.cc b/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.cc index 097d8cd..c41777a 100644 --- a/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.cc +++ b/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.cc @@ -22,6 +22,7 @@ #include "testing/gtest/include/gtest/gtest.h" #include "ui/gl/gl_implementation.h" #include "ui/gl/gl_mock.h" +#include "ui/gl/gl_surface.h" using ::gfx::MockGLInterface; using ::testing::_; @@ -115,9 +116,8 @@ void GLES2DecoderTestBase::InitDecoderWithCommandLine( const CommandLine* command_line) { Framebuffer::ClearFramebufferCompleteComboMap(); - gfx::ClearGLBindings(); gfx::SetGLGetProcAddressProc(gfx::MockGLInterface::GetGLProcAddress); - gfx::InitializeStaticGLBindings(gfx::kGLImplementationMockGL); + gfx::GLSurface::InitializeOneOffWithMockBindingsForTests(); gl_.reset(new StrictMock<MockGLInterface>()); ::gfx::MockGLInterface::SetGLInterface(gl_.get()); @@ -289,7 +289,7 @@ void GLES2DecoderTestBase::InitDecoderWithCommandLine( context_->SetGLVersionString(gl_version); context_->MakeCurrent(surface_.get()); - gfx::InitializeDynamicGLBindings(gfx::kGLImplementationMockGL, context_); + gfx::GLSurface::InitializeDynamicMockBindingsForTests(context_); int32 attributes[] = { EGL_ALPHA_SIZE, request_alpha ? 8 : 0, diff --git a/gpu/config/gpu_info_collector.cc b/gpu/config/gpu_info_collector.cc index 0bb83dd..9404f3a 100644 --- a/gpu/config/gpu_info_collector.cc +++ b/gpu/config/gpu_info_collector.cc @@ -82,10 +82,6 @@ namespace gpu { bool CollectGraphicsInfoGL(GPUInfo* gpu_info) { TRACE_EVENT0("startup", "gpu_info_collector::CollectGraphicsInfoGL"); - if (!gfx::GLSurface::InitializeOneOff()) { - LOG(ERROR) << "gfx::GLSurface::InitializeOneOff() failed"; - return false; - } scoped_refptr<gfx::GLSurface> surface(InitializeGLSurface()); if (!surface.get()) diff --git a/gpu/config/gpu_info_collector_android.cc b/gpu/config/gpu_info_collector_android.cc index 79428a1..03f357e 100644 --- a/gpu/config/gpu_info_collector_android.cc +++ b/gpu/config/gpu_info_collector_android.cc @@ -65,23 +65,19 @@ ScopedRestoreNonOwnedEGLContext::ScopedRestoreNonOwnedEGLContext() // Chromium native code, but created by Android system itself. DCHECK(!gfx::GLContext::GetCurrent()); - if (gfx::GLSurface::InitializeOneOff()) { - context_ = eglGetCurrentContext(); - display_ = eglGetCurrentDisplay(); - draw_surface_ = eglGetCurrentSurface(EGL_DRAW); - read_surface_ = eglGetCurrentSurface(EGL_READ); - } + context_ = eglGetCurrentContext(); + display_ = eglGetCurrentDisplay(); + draw_surface_ = eglGetCurrentSurface(EGL_DRAW); + read_surface_ = eglGetCurrentSurface(EGL_READ); } ScopedRestoreNonOwnedEGLContext::~ScopedRestoreNonOwnedEGLContext() { if (context_ == EGL_NO_CONTEXT || display_ == EGL_NO_DISPLAY || - draw_surface_ == EGL_NO_SURFACE || read_surface_ == EGL_NO_SURFACE) { + draw_surface_ == EGL_NO_SURFACE || read_surface_ == EGL_NO_SURFACE) return; - } - if (!eglMakeCurrent(display_, draw_surface_, read_surface_, context_)) { + if (!eglMakeCurrent(display_, draw_surface_, read_surface_, context_)) LOG(WARNING) << "Failed to restore EGL context"; - } } } diff --git a/gpu/config/gpu_info_collector_unittest.cc b/gpu/config/gpu_info_collector_unittest.cc index 9c0adbf..0629359 100644 --- a/gpu/config/gpu_info_collector_unittest.cc +++ b/gpu/config/gpu_info_collector_unittest.cc @@ -7,7 +7,6 @@ #include "gpu/config/gpu_info_collector.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" -#include "ui/gl/gl_implementation.h" #include "ui/gl/gl_mock.h" using ::gfx::MockGLInterface; @@ -21,11 +20,6 @@ class GPUInfoCollectorTest : public testing::Test { virtual ~GPUInfoCollectorTest() { } virtual void SetUp() { - // TODO(kbr): make this setup robust in the case where - // GLSurface::InitializeOneOff() has already been called by - // another unit test. http://crbug.com/100285 - gfx::SetGLGetProcAddressProc(gfx::MockGLInterface::GetGLProcAddress); - gfx::InitializeStaticGLBindings(gfx::kGLImplementationMockGL); gl_.reset(new ::testing::StrictMock< ::gfx::MockGLInterface>()); ::gfx::MockGLInterface::SetGLInterface(gl_.get()); #if defined(OS_WIN) diff --git a/gpu/tools/compositor_model_bench/compositor_model_bench.cc b/gpu/tools/compositor_model_bench/compositor_model_bench.cc index 44ce333..6c60382 100644 --- a/gpu/tools/compositor_model_bench/compositor_model_bench.cc +++ b/gpu/tools/compositor_model_bench/compositor_model_bench.cc @@ -31,11 +31,10 @@ #include "base/memory/scoped_ptr.h" #include "base/message_loop/message_loop.h" #include "base/time/time.h" - #include "gpu/tools/compositor_model_bench/render_model_utils.h" #include "gpu/tools/compositor_model_bench/render_models.h" #include "gpu/tools/compositor_model_bench/render_tree.h" - +#include "ui/gl/gl_surface.h" using base::TimeTicks; using base::DirectoryExists; @@ -186,8 +185,8 @@ class Simulator { // Initialize the OpenGL context. bool InitGLContext() { - if (!InitializeStaticGLBindings(gfx::kGLImplementationDesktopGL)) { - LOG(FATAL) << "InitializeStaticGLBindings failed"; + if (!gfx::GLSurface::InitializeOneOff()) { + LOG(FATAL) << "gfx::GLSurface::InitializeOneOff failed"; return false; } |