diff options
40 files changed, 226 insertions, 114 deletions
diff --git a/cc/test/cc_test_suite.cc b/cc/test/cc_test_suite.cc index 62b5430..abe61cb 100644 --- a/cc/test/cc_test_suite.cc +++ b/cc/test/cc_test_suite.cc @@ -7,6 +7,7 @@ #include "base/message_loop/message_loop.h" #include "base/threading/thread_id_name_manager.h" #include "cc/test/paths.h" +#include "ui/gl/gl_surface.h" namespace cc { @@ -17,6 +18,7 @@ CCTestSuite::~CCTestSuite() {} void CCTestSuite::Initialize() { base::TestSuite::Initialize(); + gfx::GLSurface::InitializeOneOffForTests(); CCPaths::RegisterPathProvider(); message_loop_.reset(new base::MessageLoop); diff --git a/cc/test/layer_tree_pixel_test.cc b/cc/test/layer_tree_pixel_test.cc index c5d2125..2792f66 100644 --- a/cc/test/layer_tree_pixel_test.cc +++ b/cc/test/layer_tree_pixel_test.cc @@ -21,7 +21,6 @@ #include "cc/trees/layer_tree_impl.h" #include "gpu/command_buffer/client/gl_in_process_context.h" #include "gpu/command_buffer/client/gles2_implementation.h" -#include "ui/gl/gl_implementation.h" using gpu::gles2::GLES2Interface; @@ -55,8 +54,6 @@ scoped_ptr<OutputSurface> LayerTreePixelTest::CreateOutputSurface( case GL_WITH_DEFAULT: case GL_WITH_BITMAP: { - CHECK(gfx::InitializeStaticGLBindings(gfx::kGLImplementationOSMesaGL)); - output_surface = make_scoped_ptr( new PixelTestOutputSurface(new TestInProcessContextProvider)); break; @@ -316,8 +313,6 @@ void LayerTreePixelTest::CopyBitmapToTextureMailboxAsTexture( DCHECK_GT(bitmap.width(), 0); DCHECK_GT(bitmap.height(), 0); - CHECK(gfx::InitializeStaticGLBindings(gfx::kGLImplementationOSMesaGL)); - scoped_ptr<gpu::GLInProcessContext> context = CreateTestInProcessContext(); GLES2Interface* gl = context->GetImplementation(); diff --git a/cc/test/pixel_test.cc b/cc/test/pixel_test.cc index e84540e..38a2b54 100644 --- a/cc/test/pixel_test.cc +++ b/cc/test/pixel_test.cc @@ -23,7 +23,6 @@ #include "cc/test/pixel_test_utils.h" #include "cc/test/test_in_process_context_provider.h" #include "testing/gtest/include/gtest/gtest.h" -#include "ui/gl/gl_implementation.h" namespace cc { @@ -118,8 +117,6 @@ bool PixelTest::PixelsMatchReference(const base::FilePath& ref_file, } void PixelTest::SetUpGLRenderer(bool use_skia_gpu_backend) { - CHECK(gfx::InitializeStaticGLBindings(gfx::kGLImplementationOSMesaGL)); - output_surface_.reset( new PixelTestOutputSurface(new TestInProcessContextProvider)); output_surface_->BindToClient(output_surface_client_.get()); diff --git a/content/browser/browser_main_loop.cc b/content/browser/browser_main_loop.cc index cc8e6c5..a4c3b72 100644 --- a/content/browser/browser_main_loop.cc +++ b/content/browser/browser_main_loop.cc @@ -70,6 +70,7 @@ #include "base/android/jni_android.h" #include "content/browser/android/browser_startup_controller.h" #include "content/browser/android/surface_texture_peer_browser_impl.h" +#include "ui/gl/gl_surface.h" #endif #if defined(OS_MACOSX) && !defined(OS_IOS) @@ -947,6 +948,13 @@ int BrowserMainLoop::BrowserThreadsStarted() { #if !defined(OS_IOS) HistogramSynchronizer::GetInstance(); +#if defined(OS_ANDROID) + // On Android, GLSurface::InitializeOneOff() must be called before initalizing + // the GpuDataManagerImpl as it uses the GL bindings. crbug.com/326295 + if (!gfx::GLSurface::InitializeOneOff()) + LOG(FATAL) << "GLSurface::InitializeOneOff failed"; +#endif + // Initialize the GpuDataManager before we set up the MessageLoops because // otherwise we'll trigger the assertion about doing IO on the UI thread. GpuDataManagerImpl::GetInstance()->Initialize(); diff --git a/content/browser/compositor/software_browser_compositor_output_surface_unittest.cc b/content/browser/compositor/software_browser_compositor_output_surface_unittest.cc index 9bc2a01..047346f 100644 --- a/content/browser/compositor/software_browser_compositor_output_surface_unittest.cc +++ b/content/browser/compositor/software_browser_compositor_output_surface_unittest.cc @@ -9,7 +9,6 @@ #include "testing/gtest/include/gtest/gtest.h" #include "ui/compositor/test/context_factories_for_test.h" #include "ui/gfx/vsync_provider.h" -#include "ui/gl/gl_implementation.h" namespace { @@ -80,7 +79,6 @@ class SoftwareBrowserCompositorOutputSurfaceTest : public testing::Test { SoftwareBrowserCompositorOutputSurfaceTest:: SoftwareBrowserCompositorOutputSurfaceTest() { - CHECK(gfx::InitializeStaticGLBindings(gfx::kGLImplementationOSMesaGL)); message_loop_.reset(new base::MessageLoopForUI); } diff --git a/content/browser/compositor/software_output_device_ozone_unittest.cc b/content/browser/compositor/software_output_device_ozone_unittest.cc index 751e3ee..a7bb49f 100644 --- a/content/browser/compositor/software_output_device_ozone_unittest.cc +++ b/content/browser/compositor/software_output_device_ozone_unittest.cc @@ -81,7 +81,6 @@ class SoftwareOutputDeviceOzoneTest : public testing::Test { }; SoftwareOutputDeviceOzoneTest::SoftwareOutputDeviceOzoneTest() { - CHECK(gfx::InitializeStaticGLBindings(gfx::kGLImplementationOSMesaGL)); message_loop_.reset(new base::MessageLoopForUI); } diff --git a/content/common/gpu/client/gl_helper_unittest.cc b/content/common/gpu/client/gl_helper_unittest.cc index 68484972..72593ae 100644 --- a/content/common/gpu/client/gl_helper_unittest.cc +++ b/content/common/gpu/client/gl_helper_unittest.cc @@ -1571,7 +1571,6 @@ int main(int argc, char** argv) { #if defined(TOOLKIT_GTK) gfx::GtkInitFromCommandLine(*CommandLine::ForCurrentProcess()); #endif - gfx::GLSurface::InitializeOneOff(); gpu::ApplyGpuDriverBugWorkarounds(CommandLine::ForCurrentProcess()); content::UnitTestTestSuite runner(suite); diff --git a/content/gpu/gpu_child_thread.cc b/content/gpu/gpu_child_thread.cc index 170b364..63f850f 100644 --- a/content/gpu/gpu_child_thread.cc +++ b/content/gpu/gpu_child_thread.cc @@ -65,11 +65,14 @@ GpuChildThread::GpuChildThread(const std::string& channel_id) DCHECK( CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess) || CommandLine::ForCurrentProcess()->HasSwitch(switches::kInProcessGPU)); +#if !defined(OS_ANDROID) // For single process and in-process GPU mode, we need to load and // initialize the GL implementation and locate the GL entry points here. - if (!gfx::GLSurface::InitializeOneOff()) { - VLOG(1) << "gfx::GLSurface::InitializeOneOff()"; - } + // On Android, GLSurface::InitializeOneOff() is called from BrowserMainLoop + // before getting here. crbug.com/326295 + if (!gfx::GLSurface::InitializeOneOff()) + VLOG(1) << "gfx::GLSurface::InitializeOneOff failed"; +#endif g_thread_safe_sender.Get() = thread_safe_sender(); } diff --git a/content/gpu/gpu_main.cc b/content/gpu/gpu_main.cc index f7650e7..9e6160d 100644 --- a/content/gpu/gpu_main.cc +++ b/content/gpu/gpu_main.cc @@ -219,8 +219,25 @@ int GpuMain(const MainFunctionParams& parameters) { base::TimeTicks before_initialize_one_off = base::TimeTicks::Now(); + // Determine if we need to initialize GL here or it has already been done. + bool gl_already_initialized = false; +#if defined(OS_MACOSX) + // On Mac, GLSurface::InitializeOneOff() is called from the sandbox warmup + // code before getting here. + gl_already_initialized = true; +#endif + if (command_line.HasSwitch(switches::kInProcessGPU)) { + // With in-process GPU, GLSurface::InitializeOneOff() is called from + // GpuChildThread before getting here. + gl_already_initialized = true; + } + // Load and initialize the GL implementation and locate the GL entry points. - if (gfx::GLSurface::InitializeOneOff()) { + bool gl_initialized = + gl_already_initialized + ? gfx::GetGLImplementation() != gfx::kGLImplementationNone + : gfx::GLSurface::InitializeOneOff(); + if (gl_initialized) { // We need to collect GL strings (VENDOR, RENDERER) for blacklisting // purposes. However, on Mac we don't actually use them. As documented in // crbug.com/222934, due to some driver issues, glGetString could take diff --git a/content/test/content_test_suite.cc b/content/test/content_test_suite.cc index 3618365..71cec54 100644 --- a/content/test/content_test_suite.cc +++ b/content/test/content_test_suite.cc @@ -5,6 +5,8 @@ #include "content/test/content_test_suite.h" #include "base/base_paths.h" +#include "base/base_switches.h" +#include "base/command_line.h" #include "base/logging.h" #include "base/path_service.h" #include "content/public/test/test_content_client_initializer.h" @@ -12,6 +14,10 @@ #include "testing/gtest/include/gtest/gtest.h" #include "ui/base/resource/resource_bundle.h" +#if !defined(OS_IOS) +#include "ui/gl/gl_surface.h" +#endif + #if defined(OS_MACOSX) #include "base/mac/scoped_nsautorelease_pool.h" #endif @@ -65,6 +71,13 @@ void ContentTestSuite::Initialize() { ContentTestSuiteBase::Initialize(); +#if !defined(OS_IOS) + // When running in a child process for Mac sandbox tests, the sandbox exists + // to initialize GL, so don't do it here. + if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestChildProcess)) + gfx::GLSurface::InitializeOneOffForTests(); +#endif + testing::TestEventListeners& listeners = testing::UnitTest::GetInstance()->listeners(); listeners.Append(new TestInitializationListener); 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; } diff --git a/media/tools/player_x11/gl_video_renderer.cc b/media/tools/player_x11/gl_video_renderer.cc index 58d122a..e32a63c 100644 --- a/media/tools/player_x11/gl_video_renderer.cc +++ b/media/tools/player_x11/gl_video_renderer.cc @@ -11,7 +11,7 @@ #include "media/base/buffers.h" #include "media/base/video_frame.h" #include "media/base/yuv_convert.h" -#include "ui/gl/gl_implementation.h" +#include "ui/gl/gl_surface.h" enum { kNumYUVPlanes = 3 }; @@ -20,8 +20,8 @@ static GLXContext InitGLContext(Display* display, Window window) { // dlopen/dlsym, and so linking it into chrome breaks it. So we dynamically // load it, and use glew to dynamically resolve symbols. // See http://code.google.com/p/chromium/issues/detail?id=16800 - if (!InitializeStaticGLBindings(gfx::kGLImplementationDesktopGL)) { - LOG(ERROR) << "InitializeStaticGLBindings failed"; + if (!gfx::GLSurface::InitializeOneOff()) { + LOG(ERROR) << "GLSurface::InitializeOneOff failed"; return NULL; } diff --git a/ui/aura/bench/DEPS b/ui/aura/bench/DEPS index 319a251..7fa58f9 100644 --- a/ui/aura/bench/DEPS +++ b/ui/aura/bench/DEPS @@ -3,4 +3,5 @@ include_rules = [ "-cc/surfaces", "+gpu/command_buffer/client/gles2_interface.h", "+third_party/khronos", + "+ui/gl/gl_surface.h", # To initialize GL bindings. ] diff --git a/ui/aura/bench/bench_main.cc b/ui/aura/bench/bench_main.cc index 85d7b67..94a8f6f 100644 --- a/ui/aura/bench/bench_main.cc +++ b/ui/aura/bench/bench_main.cc @@ -29,6 +29,8 @@ #include "ui/gfx/canvas.h" #include "ui/gfx/rect.h" #include "ui/gfx/skia_util.h" +#include "ui/gl/gl_surface.h" + #ifndef GL_GLEXT_PROTOTYPES #define GL_GLEXT_PROTOTYPES 1 #endif @@ -290,6 +292,8 @@ int main(int argc, char** argv) { base::AtExitManager exit_manager; + gfx::GLSurface::InitializeOneOff(); + // The ContextFactory must exist before any Compositors are created. bool allow_test_contexts = false; ui::InitializeContextFactoryForTests(allow_test_contexts); diff --git a/ui/aura/demo/DEPS b/ui/aura/demo/DEPS new file mode 100644 index 0000000..07d8243 --- /dev/null +++ b/ui/aura/demo/DEPS @@ -0,0 +1,3 @@ +include_rules = [ + "+ui/gl/gl_surface.h", # To initialize GL bindings. +] diff --git a/ui/aura/demo/demo_main.cc b/ui/aura/demo/demo_main.cc index 3dcd7db..7739ed5 100644 --- a/ui/aura/demo/demo_main.cc +++ b/ui/aura/demo/demo_main.cc @@ -21,6 +21,7 @@ #include "ui/events/event.h" #include "ui/gfx/canvas.h" #include "ui/gfx/rect.h" +#include "ui/gl/gl_surface.h" #if defined(USE_X11) #include "base/message_loop/message_pump_x11.h" @@ -108,6 +109,8 @@ int DemoMain() { // Create the message-loop here before creating the root window. base::MessageLoopForUI message_loop; + gfx::GLSurface::InitializeOneOff(); + // The ContextFactory must exist before any Compositors are created. bool allow_test_contexts = false; ui::InitializeContextFactoryForTests(allow_test_contexts); diff --git a/ui/compositor/test/context_factories_for_test.cc b/ui/compositor/test/context_factories_for_test.cc index 795f56d..b03fa34 100644 --- a/ui/compositor/test/context_factories_for_test.cc +++ b/ui/compositor/test/context_factories_for_test.cc @@ -10,6 +10,7 @@ #include "ui/compositor/compositor_switches.h" #include "ui/compositor/test/default_context_factory.h" #include "ui/compositor/test/test_context_factory.h" +#include "ui/gl/gl_implementation.h" namespace ui { @@ -40,11 +41,9 @@ void InitializeContextFactoryForTests(bool allow_test_contexts) { if (use_test_contexts) { g_implicit_factory = new ui::TestContextFactory; } else { + DCHECK_NE(gfx::kGLImplementationNone, gfx::GetGLImplementation()); DVLOG(1) << "Using DefaultContextFactory"; - scoped_ptr<ui::DefaultContextFactory> instance( - new ui::DefaultContextFactory()); - if (instance->Initialize()) - g_implicit_factory = instance.release(); + g_implicit_factory = new ui::DefaultContextFactory(); } ContextFactory::SetInstance(g_implicit_factory); } diff --git a/ui/compositor/test/default_context_factory.cc b/ui/compositor/test/default_context_factory.cc index 4839e1f1..21c004d 100644 --- a/ui/compositor/test/default_context_factory.cc +++ b/ui/compositor/test/default_context_factory.cc @@ -15,20 +15,12 @@ namespace ui { DefaultContextFactory::DefaultContextFactory() { + DCHECK_NE(gfx::GetGLImplementation(), gfx::kGLImplementationNone); } DefaultContextFactory::~DefaultContextFactory() { } -bool DefaultContextFactory::Initialize() { - if (!gfx::GLSurface::InitializeOneOff() || - gfx::GetGLImplementation() == gfx::kGLImplementationNone) { - LOG(ERROR) << "Could not load the GL bindings"; - return false; - } - return true; -} - scoped_ptr<cc::OutputSurface> DefaultContextFactory::CreateOutputSurface( Compositor* compositor, bool software_fallback) { DCHECK(!software_fallback); diff --git a/ui/compositor/test/default_context_factory.h b/ui/compositor/test/default_context_factory.h index 7b8501b..f377f2f 100644 --- a/ui/compositor/test/default_context_factory.h +++ b/ui/compositor/test/default_context_factory.h @@ -37,8 +37,6 @@ class DefaultContextFactory : public ContextFactory { virtual void RemoveCompositor(Compositor* compositor) OVERRIDE; virtual bool DoesCreateTestContexts() OVERRIDE; - bool Initialize(); - private: scoped_refptr<webkit::gpu::ContextProviderInProcess> offscreen_compositor_contexts_; diff --git a/ui/compositor/test/test_suite.cc b/ui/compositor/test/test_suite.cc index aa21ece..18b4060 100644 --- a/ui/compositor/test/test_suite.cc +++ b/ui/compositor/test/test_suite.cc @@ -9,7 +9,7 @@ #include "ui/compositor/compositor.h" #include "ui/compositor/compositor_switches.h" #include "ui/gfx/gfx_paths.h" -#include "ui/gl/gl_implementation.h" +#include "ui/gl/gl_surface.h" #if defined(USE_X11) #include <X11/Xlib.h> @@ -31,8 +31,8 @@ void CompositorTestSuite::Initialize() { #if defined(USE_X11) XInitThreads(); #endif - CHECK(gfx::InitializeStaticGLBindings(gfx::kGLImplementationOSMesaGL)); base::TestSuite::Initialize(); + gfx::GLSurface::InitializeOneOffForTests(); gfx::RegisterPathProvider(); diff --git a/ui/gl/gl_gl_api_implementation.cc b/ui/gl/gl_gl_api_implementation.cc index ce8a711..9184fc3 100644 --- a/ui/gl/gl_gl_api_implementation.cc +++ b/ui/gl/gl_gl_api_implementation.cc @@ -148,16 +148,31 @@ static void GL_BINDING_CALL CustomRenderbufferStorageMultisampleEXT( void DriverGL::InitializeCustomDynamicBindings(GLContext* context) { InitializeDynamicBindings(context); - orig_fn = fn; + + DCHECK(orig_fn.glTexImage2DFn == NULL); + orig_fn.glTexImage2DFn = fn.glTexImage2DFn; fn.glTexImage2DFn = reinterpret_cast<glTexImage2DProc>(CustomTexImage2D); + + DCHECK(orig_fn.glTexSubImage2DFn == NULL); + orig_fn.glTexSubImage2DFn = fn.glTexSubImage2DFn; fn.glTexSubImage2DFn = reinterpret_cast<glTexSubImage2DProc>(CustomTexSubImage2D); + + DCHECK(orig_fn.glTexStorage2DEXTFn == NULL); + orig_fn.glTexStorage2DEXTFn = fn.glTexStorage2DEXTFn; fn.glTexStorage2DEXTFn = reinterpret_cast<glTexStorage2DEXTProc>(CustomTexStorage2DEXT); + + DCHECK(orig_fn.glRenderbufferStorageEXTFn == NULL); + orig_fn.glRenderbufferStorageEXTFn = fn.glRenderbufferStorageEXTFn; fn.glRenderbufferStorageEXTFn = reinterpret_cast<glRenderbufferStorageEXTProc>( CustomRenderbufferStorageEXT); + + DCHECK(orig_fn.glRenderbufferStorageMultisampleEXTFn == NULL); + orig_fn.glRenderbufferStorageMultisampleEXTFn = + fn.glRenderbufferStorageMultisampleEXTFn; fn.glRenderbufferStorageMultisampleEXTFn = reinterpret_cast<glRenderbufferStorageMultisampleEXTProc>( CustomRenderbufferStorageMultisampleEXT); diff --git a/ui/gl/gl_implementation.h b/ui/gl/gl_implementation.h index 628fc1f..0881e10 100644 --- a/ui/gl/gl_implementation.h +++ b/ui/gl/gl_implementation.h @@ -47,7 +47,7 @@ GL_EXPORT bool InitializeStaticGLBindings(GLImplementation implementation); // Initialize function bindings that depend on the context for a GL // implementation. GL_EXPORT bool InitializeDynamicGLBindings(GLImplementation implementation, - GLContext* context); + GLContext* context); // Initialize Debug logging wrappers for GL bindings. void InitializeDebugGLBindings(); diff --git a/ui/gl/gl_implementation_android.cc b/ui/gl/gl_implementation_android.cc index 31fec9a..190f669 100644 --- a/ui/gl/gl_implementation_android.cc +++ b/ui/gl/gl_implementation_android.cc @@ -52,8 +52,7 @@ bool InitializeStaticGLBindings(GLImplementation implementation) { // Prevent reinitialization with a different implementation. Once the gpu // unit tests have initialized with kGLImplementationMock, we don't want to // later switch to another GL implementation. - if (GetGLImplementation() != kGLImplementationNone) - return true; + DCHECK_EQ(kGLImplementationNone, GetGLImplementation()); switch (implementation) { case kGLImplementationEGLGLES2: { diff --git a/ui/gl/gl_implementation_mac.cc b/ui/gl/gl_implementation_mac.cc index 546a082f..1011406 100644 --- a/ui/gl/gl_implementation_mac.cc +++ b/ui/gl/gl_implementation_mac.cc @@ -31,8 +31,7 @@ bool InitializeStaticGLBindings(GLImplementation implementation) { // Prevent reinitialization with a different implementation. Once the gpu // unit tests have initialized with kGLImplementationMock, we don't want to // later switch to another GL implementation. - if (GetGLImplementation() != kGLImplementationNone) - return true; + DCHECK_EQ(kGLImplementationNone, GetGLImplementation()); // Allow the main thread or another to initialize these bindings // after instituting restrictions on I/O. Going forward they will diff --git a/ui/gl/gl_implementation_ozone.cc b/ui/gl/gl_implementation_ozone.cc index 3659a02..b8dd2c4 100644 --- a/ui/gl/gl_implementation_ozone.cc +++ b/ui/gl/gl_implementation_ozone.cc @@ -37,8 +37,7 @@ bool InitializeStaticGLBindings(GLImplementation implementation) { // Prevent reinitialization with a different implementation. Once the gpu // unit tests have initialized with kGLImplementationMock, we don't want to // later switch to another GL implementation. - if (GetGLImplementation() != kGLImplementationNone) - return true; + DCHECK_EQ(kGLImplementationNone, GetGLImplementation()); switch (implementation) { case kGLImplementationOSMesaGL: diff --git a/ui/gl/gl_implementation_win.cc b/ui/gl/gl_implementation_win.cc index ddc9c57..5269297 100644 --- a/ui/gl/gl_implementation_win.cc +++ b/ui/gl/gl_implementation_win.cc @@ -112,8 +112,7 @@ bool InitializeStaticGLBindings(GLImplementation implementation) { // Prevent reinitialization with a different implementation. Once the gpu // unit tests have initialized with kGLImplementationMock, we don't want to // later switch to another GL implementation. - if (GetGLImplementation() != kGLImplementationNone) - return true; + DCHECK_EQ(kGLImplementationNone, GetGLImplementation()); // Allow the main thread or another to initialize these bindings // after instituting restrictions on I/O. Going forward they will diff --git a/ui/gl/gl_implementation_x11.cc b/ui/gl/gl_implementation_x11.cc index 7588a37..c19b39e 100644 --- a/ui/gl/gl_implementation_x11.cc +++ b/ui/gl/gl_implementation_x11.cc @@ -43,8 +43,7 @@ bool InitializeStaticGLBindings(GLImplementation implementation) { // Prevent reinitialization with a different implementation. Once the gpu // unit tests have initialized with kGLImplementationMock, we don't want to // later switch to another GL implementation. - if (GetGLImplementation() != kGLImplementationNone) - return true; + DCHECK_EQ(kGLImplementationNone, GetGLImplementation()); // Allow the main thread or another to initialize these bindings // after instituting restrictions on I/O. Going forward they will diff --git a/ui/gl/gl_surface.cc b/ui/gl/gl_surface.cc index a52a3f7..e9c7ce9 100644 --- a/ui/gl/gl_surface.cc +++ b/ui/gl/gl_surface.cc @@ -14,6 +14,7 @@ #include "base/threading/thread_local.h" #include "ui/gl/gl_context.h" #include "ui/gl/gl_implementation.h" +#include "ui/gl/gl_switches.h" namespace gfx { @@ -24,9 +25,7 @@ base::LazyInstance<base::ThreadLocalPointer<GLSurface> >::Leaky // static bool GLSurface::InitializeOneOff() { - static bool initialized = false; - if (initialized) - return true; + DCHECK_EQ(kGLImplementationNone, GetGLImplementation()); TRACE_EVENT0("gpu", "GLSurface::InitializeOneOff"); @@ -34,12 +33,14 @@ bool GLSurface::InitializeOneOff() { GetAllowedGLImplementations(&allowed_impls); DCHECK(!allowed_impls.empty()); + CommandLine* cmd = CommandLine::ForCurrentProcess(); + // The default implementation is always the first one in list. GLImplementation impl = allowed_impls[0]; bool fallback_to_osmesa = false; - if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseGL)) { + if (cmd->HasSwitch(switches::kUseGL)) { std::string requested_implementation_name = - CommandLine::ForCurrentProcess()->GetSwitchValueASCII(switches::kUseGL); + cmd->GetSwitchValueASCII(switches::kUseGL); if (requested_implementation_name == "any") { fallback_to_osmesa = true; } else if (requested_implementation_name == "swiftshader") { @@ -55,27 +56,94 @@ bool GLSurface::InitializeOneOff() { } } - initialized = InitializeStaticGLBindings(impl) && InitializeOneOffInternal(); + bool gpu_service_logging = cmd->HasSwitch(switches::kEnableGPUServiceLogging); + bool disable_gl_drawing = cmd->HasSwitch(switches::kDisableGLDrawingForTests); + + return InitializeOneOffImplementation( + impl, fallback_to_osmesa, gpu_service_logging, disable_gl_drawing); +} + +// static +bool GLSurface::InitializeOneOffImplementation(GLImplementation impl, + bool fallback_to_osmesa, + bool gpu_service_logging, + bool disable_gl_drawing) { + bool initialized = + InitializeStaticGLBindings(impl) && InitializeOneOffInternal(); if (!initialized && fallback_to_osmesa) { ClearGLBindings(); initialized = InitializeStaticGLBindings(kGLImplementationOSMesaGL) && InitializeOneOffInternal(); } + if (!initialized) + ClearGLBindings(); if (initialized) { DVLOG(1) << "Using " << GetGLImplementationName(GetGLImplementation()) << " GL implementation."; - if (CommandLine::ForCurrentProcess()->HasSwitch( - switches::kEnableGPUServiceLogging)) + if (gpu_service_logging) InitializeDebugGLBindings(); - if (CommandLine::ForCurrentProcess()->HasSwitch( - switches::kDisableGLDrawingForTests)) + if (disable_gl_drawing) InitializeNullDrawGLBindings(); } return initialized; } +// static +void GLSurface::InitializeOneOffForTests() { + bool use_osmesa = true; + +#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(!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 = false; + // TODO(danakj): Unit tests do not produce pixel output by default. + // bool disable_gl_drawing = true; + + CHECK(InitializeOneOffImplementation( + impl, fallback_to_osmesa, gpu_service_logging, disable_gl_drawing)); +} + +// static +void GLSurface::InitializeOneOffWithMockBindingsForTests() { + DCHECK(!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 8eaf60d..f7a02f0 100644 --- a/ui/gl/gl_surface.h +++ b/ui/gl/gl_surface.h @@ -12,6 +12,7 @@ #include "ui/gfx/native_widget_types.h" #include "ui/gfx/size.h" #include "ui/gl/gl_export.h" +#include "ui/gl/gl_implementation.h" namespace gfx { @@ -69,8 +70,15 @@ class GL_EXPORT GLSurface : public base::RefCounted<GLSurface> { // Copy part of the backbuffer to the frontbuffer. virtual bool PostSubBuffer(int x, int y, int width, int height); + // 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); @@ -109,6 +117,10 @@ class GL_EXPORT GLSurface : public base::RefCounted<GLSurface> { protected: virtual ~GLSurface(); + static bool InitializeOneOffImplementation(GLImplementation impl, + bool fallback_to_osmesa, + bool gpu_service_logging, + bool disable_gl_drawing); static bool InitializeOneOffInternal(); static void SetCurrent(GLSurface* surface); diff --git a/ui/gl/gl_surface_egl.cc b/ui/gl/gl_surface_egl.cc index 0db2fc7..635595c 100644 --- a/ui/gl/gl_surface_egl.cc +++ b/ui/gl/gl_surface_egl.cc @@ -784,14 +784,14 @@ GLSurfaceOSMesaHeadless::~GLSurfaceOSMesaHeadless() { Destroy(); } // static bool GLSurface::InitializeOneOffInternal() { - if (GetGLImplementation() == kGLImplementationOSMesaGL) { - return true; - } - DCHECK(GetGLImplementation() == kGLImplementationEGLGLES2); - - if (!GLSurfaceEGL::InitializeOneOff()) { - LOG(ERROR) << "GLSurfaceEGL::InitializeOneOff failed."; - return false; + switch (GetGLImplementation()) { + case kGLImplementationEGLGLES2: + if (!GLSurfaceEGL::InitializeOneOff()) { + LOG(ERROR) << "GLSurfaceEGL::InitializeOneOff failed."; + return false; + } + default: + break; } return true; } diff --git a/ui/keyboard/DEPS b/ui/keyboard/DEPS index defb61d..ec5b911 100644 --- a/ui/keyboard/DEPS +++ b/ui/keyboard/DEPS @@ -6,6 +6,7 @@ include_rules = [ "+ui/base", "+ui/compositor", "+ui/gfx", + "+ui/gl/gl_surface.h", # To initialize GL for tests. "+ui/test", "+ui/wm", ] diff --git a/ui/keyboard/test/run_all_unittests.cc b/ui/keyboard/test/run_all_unittests.cc index e95dcbe..d5e5bc0 100644 --- a/ui/keyboard/test/run_all_unittests.cc +++ b/ui/keyboard/test/run_all_unittests.cc @@ -10,6 +10,7 @@ #include "base/test/test_suite.h" #include "ui/base/resource/resource_bundle.h" #include "ui/base/ui_base_paths.h" +#include "ui/gl/gl_surface.h" namespace { @@ -20,6 +21,7 @@ class KeyboardTestSuite : public base::TestSuite { protected: virtual void Initialize() OVERRIDE { base::TestSuite::Initialize(); + gfx::GLSurface::InitializeOneOffForTests(); ui::RegisterPathProvider(); base::FilePath pak_dir; diff --git a/ui/views/examples/DEPS b/ui/views/examples/DEPS index 1108a45..44d965d 100644 --- a/ui/views/examples/DEPS +++ b/ui/views/examples/DEPS @@ -2,4 +2,5 @@ include_rules = [ "+content/public", "+content/shell", "+sandbox", + "+ui/gl/gl_surface.h", # To initialize GL bindings. ] diff --git a/ui/views/examples/examples_main.cc b/ui/views/examples/examples_main.cc index 62a6405..53a206f 100644 --- a/ui/views/examples/examples_main.cc +++ b/ui/views/examples/examples_main.cc @@ -14,6 +14,7 @@ #include "ui/base/resource/resource_bundle.h" #include "ui/compositor/test/context_factories_for_test.h" #include "ui/gfx/screen.h" +#include "ui/gl/gl_surface.h" #include "ui/views/corewm/wm_state.h" #include "ui/views/examples/example_base.h" #include "ui/views/examples/examples_window.h" @@ -46,6 +47,8 @@ int main(int argc, char** argv) { ui::ResourceBundle::InitSharedInstanceWithPakPath(pak_file); + gfx::GLSurface::InitializeOneOff(); + // The ContextFactory must exist before any Compositors are created. bool allow_test_contexts = false; ui::InitializeContextFactoryForTests(allow_test_contexts); diff --git a/webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.cc b/webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.cc index d04a459..51cf45d 100644 --- a/webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.cc +++ b/webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.cc @@ -24,7 +24,7 @@ #include "gpu/command_buffer/client/gles2_lib.h" #include "gpu/skia_bindings/gl_bindings_skia_cmd_buffer.h" #include "ui/gfx/size.h" -#include "ui/gl/gl_surface.h" +#include "ui/gl/gl_implementation.h" using gpu::gles2::GLES2Implementation; using gpu::GLInProcessContext; @@ -74,12 +74,9 @@ scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> WebGraphicsContext3DInProcessCommandBufferImpl::CreateViewContext( const blink::WebGraphicsContext3D::Attributes& attributes, gfx::AcceleratedWidget window) { - scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> context; - if (gfx::GLSurface::InitializeOneOff()) { - context.reset(new WebGraphicsContext3DInProcessCommandBufferImpl( + DCHECK_NE(gfx::GetGLImplementation(), gfx::kGLImplementationNone); + return make_scoped_ptr(new WebGraphicsContext3DInProcessCommandBufferImpl( scoped_ptr< ::gpu::GLInProcessContext>(), attributes, false, window)); - } - return context.Pass(); } // static @@ -87,24 +84,21 @@ scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> WebGraphicsContext3DInProcessCommandBufferImpl::CreateOffscreenContext( const blink::WebGraphicsContext3D::Attributes& attributes) { return make_scoped_ptr(new WebGraphicsContext3DInProcessCommandBufferImpl( - scoped_ptr< ::gpu::GLInProcessContext>(), - attributes, - true, - gfx::kNullAcceleratedWidget)) - .Pass(); + scoped_ptr< ::gpu::GLInProcessContext>(), + attributes, + true, + gfx::kNullAcceleratedWidget)); } scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> WebGraphicsContext3DInProcessCommandBufferImpl::WrapContext( scoped_ptr< ::gpu::GLInProcessContext> context, const blink::WebGraphicsContext3D::Attributes& attributes) { - return make_scoped_ptr( - new WebGraphicsContext3DInProcessCommandBufferImpl( - context.Pass(), - attributes, - true /* is_offscreen. Not used. */, - gfx::kNullAcceleratedWidget /* window. Not used. */)) - .Pass(); + return make_scoped_ptr(new WebGraphicsContext3DInProcessCommandBufferImpl( + context.Pass(), + attributes, + true /* is_offscreen. Not used. */, + gfx::kNullAcceleratedWidget /* window. Not used. */)); } WebGraphicsContext3DInProcessCommandBufferImpl:: |