diff options
41 files changed, 114 insertions, 230 deletions
diff --git a/cc/test/cc_test_suite.cc b/cc/test/cc_test_suite.cc index abe61cb..62b5430 100644 --- a/cc/test/cc_test_suite.cc +++ b/cc/test/cc_test_suite.cc @@ -7,7 +7,6 @@ #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 { @@ -18,7 +17,6 @@ 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 2792f66..c5d2125 100644 --- a/cc/test/layer_tree_pixel_test.cc +++ b/cc/test/layer_tree_pixel_test.cc @@ -21,6 +21,7 @@ #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; @@ -54,6 +55,8 @@ 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; @@ -313,6 +316,8 @@ 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 38a2b54..e84540e 100644 --- a/cc/test/pixel_test.cc +++ b/cc/test/pixel_test.cc @@ -23,6 +23,7 @@ #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 { @@ -117,6 +118,8 @@ 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 a4c3b72..cc8e6c5 100644 --- a/content/browser/browser_main_loop.cc +++ b/content/browser/browser_main_loop.cc @@ -70,7 +70,6 @@ #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) @@ -948,13 +947,6 @@ 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 047346f..9bc2a01 100644 --- a/content/browser/compositor/software_browser_compositor_output_surface_unittest.cc +++ b/content/browser/compositor/software_browser_compositor_output_surface_unittest.cc @@ -9,6 +9,7 @@ #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 { @@ -79,6 +80,7 @@ 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 a7bb49f..751e3ee 100644 --- a/content/browser/compositor/software_output_device_ozone_unittest.cc +++ b/content/browser/compositor/software_output_device_ozone_unittest.cc @@ -81,6 +81,7 @@ 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 72593ae..68484972 100644 --- a/content/common/gpu/client/gl_helper_unittest.cc +++ b/content/common/gpu/client/gl_helper_unittest.cc @@ -1571,6 +1571,7 @@ 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 63f850f..170b364 100644 --- a/content/gpu/gpu_child_thread.cc +++ b/content/gpu/gpu_child_thread.cc @@ -65,14 +65,11 @@ 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. - // 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 + if (!gfx::GLSurface::InitializeOneOff()) { + VLOG(1) << "gfx::GLSurface::InitializeOneOff()"; + } g_thread_safe_sender.Get() = thread_safe_sender(); } diff --git a/content/gpu/gpu_main.cc b/content/gpu/gpu_main.cc index 9e6160d..f7650e7 100644 --- a/content/gpu/gpu_main.cc +++ b/content/gpu/gpu_main.cc @@ -219,25 +219,8 @@ 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. - bool gl_initialized = - gl_already_initialized - ? gfx::GetGLImplementation() != gfx::kGLImplementationNone - : gfx::GLSurface::InitializeOneOff(); - if (gl_initialized) { + if (gfx::GLSurface::InitializeOneOff()) { // 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 71cec54..3618365 100644 --- a/content/test/content_test_suite.cc +++ b/content/test/content_test_suite.cc @@ -5,8 +5,6 @@ #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" @@ -14,10 +12,6 @@ #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 @@ -71,13 +65,6 @@ 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 358805a..c48b77d 100644 --- a/gpu/command_buffer/common/unittest_main.cc +++ b/gpu/command_buffer/common/unittest_main.cc @@ -11,7 +11,6 @@ #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 { @@ -20,13 +19,6 @@ 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) { @@ -43,6 +35,9 @@ 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 c41777a..097d8cd 100644 --- a/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.cc +++ b/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.cc @@ -22,7 +22,6 @@ #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::_; @@ -116,8 +115,9 @@ void GLES2DecoderTestBase::InitDecoderWithCommandLine( const CommandLine* command_line) { Framebuffer::ClearFramebufferCompleteComboMap(); + gfx::ClearGLBindings(); gfx::SetGLGetProcAddressProc(gfx::MockGLInterface::GetGLProcAddress); - gfx::GLSurface::InitializeOneOffWithMockBindingsForTests(); + gfx::InitializeStaticGLBindings(gfx::kGLImplementationMockGL); 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::GLSurface::InitializeDynamicMockBindingsForTests(context_); + gfx::InitializeDynamicGLBindings(gfx::kGLImplementationMockGL, 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 9404f3a..0bb83dd 100644 --- a/gpu/config/gpu_info_collector.cc +++ b/gpu/config/gpu_info_collector.cc @@ -82,6 +82,10 @@ 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 03f357e..79428a1 100644 --- a/gpu/config/gpu_info_collector_android.cc +++ b/gpu/config/gpu_info_collector_android.cc @@ -65,19 +65,23 @@ ScopedRestoreNonOwnedEGLContext::ScopedRestoreNonOwnedEGLContext() // Chromium native code, but created by Android system itself. DCHECK(!gfx::GLContext::GetCurrent()); - context_ = eglGetCurrentContext(); - display_ = eglGetCurrentDisplay(); - draw_surface_ = eglGetCurrentSurface(EGL_DRAW); - read_surface_ = eglGetCurrentSurface(EGL_READ); + if (gfx::GLSurface::InitializeOneOff()) { + 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 0629359..9c0adbf 100644 --- a/gpu/config/gpu_info_collector_unittest.cc +++ b/gpu/config/gpu_info_collector_unittest.cc @@ -7,6 +7,7 @@ #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; @@ -20,6 +21,11 @@ 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 6c60382..44ce333 100644 --- a/gpu/tools/compositor_model_bench/compositor_model_bench.cc +++ b/gpu/tools/compositor_model_bench/compositor_model_bench.cc @@ -31,10 +31,11 @@ #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; @@ -185,8 +186,8 @@ class Simulator { // Initialize the OpenGL context. bool InitGLContext() { - if (!gfx::GLSurface::InitializeOneOff()) { - LOG(FATAL) << "gfx::GLSurface::InitializeOneOff failed"; + if (!InitializeStaticGLBindings(gfx::kGLImplementationDesktopGL)) { + LOG(FATAL) << "InitializeStaticGLBindings failed"; return false; } diff --git a/media/tools/player_x11/gl_video_renderer.cc b/media/tools/player_x11/gl_video_renderer.cc index e32a63c..58d122a 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_surface.h" +#include "ui/gl/gl_implementation.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 (!gfx::GLSurface::InitializeOneOff()) { - LOG(ERROR) << "GLSurface::InitializeOneOff failed"; + if (!InitializeStaticGLBindings(gfx::kGLImplementationDesktopGL)) { + LOG(ERROR) << "InitializeStaticGLBindings failed"; return NULL; } diff --git a/ui/aura/bench/DEPS b/ui/aura/bench/DEPS index 7fa58f9..319a251 100644 --- a/ui/aura/bench/DEPS +++ b/ui/aura/bench/DEPS @@ -3,5 +3,4 @@ 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 58dbde9..077afd4 100644 --- a/ui/aura/bench/bench_main.cc +++ b/ui/aura/bench/bench_main.cc @@ -29,8 +29,6 @@ #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 @@ -293,8 +291,6 @@ 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 deleted file mode 100644 index 07d8243..0000000 --- a/ui/aura/demo/DEPS +++ /dev/null @@ -1,3 +0,0 @@ -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 7739ed5..3dcd7db 100644 --- a/ui/aura/demo/demo_main.cc +++ b/ui/aura/demo/demo_main.cc @@ -21,7 +21,6 @@ #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" @@ -109,8 +108,6 @@ 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 b03fa34..795f56d 100644 --- a/ui/compositor/test/context_factories_for_test.cc +++ b/ui/compositor/test/context_factories_for_test.cc @@ -10,7 +10,6 @@ #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 { @@ -41,9 +40,11 @@ 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"; - g_implicit_factory = new ui::DefaultContextFactory(); + scoped_ptr<ui::DefaultContextFactory> instance( + new ui::DefaultContextFactory()); + if (instance->Initialize()) + g_implicit_factory = instance.release(); } ContextFactory::SetInstance(g_implicit_factory); } diff --git a/ui/compositor/test/default_context_factory.cc b/ui/compositor/test/default_context_factory.cc index 21c004d..4839e1f1 100644 --- a/ui/compositor/test/default_context_factory.cc +++ b/ui/compositor/test/default_context_factory.cc @@ -15,12 +15,20 @@ 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 f377f2f..7b8501b 100644 --- a/ui/compositor/test/default_context_factory.h +++ b/ui/compositor/test/default_context_factory.h @@ -37,6 +37,8 @@ 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 18b4060..aa21ece 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_surface.h" +#include "ui/gl/gl_implementation.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_bindings.h b/ui/gl/gl_bindings.h index 510596a..74e20fe 100644 --- a/ui/gl/gl_bindings.h +++ b/ui/gl/gl_bindings.h @@ -225,8 +225,6 @@ typedef uint64 EGLuint64CHROMIUM; namespace gfx { struct GL_EXPORT DriverGL { - DriverGL(); - void InitializeStaticBindings(); void InitializeCustomDynamicBindings(GLContext* context); void InitializeDebugBindings(); diff --git a/ui/gl/gl_gl_api_implementation.cc b/ui/gl/gl_gl_api_implementation.cc index 1f9a06d..ce8a711 100644 --- a/ui/gl/gl_gl_api_implementation.cc +++ b/ui/gl/gl_gl_api_implementation.cc @@ -146,35 +146,18 @@ static void GL_BINDING_CALL CustomRenderbufferStorageMultisampleEXT( } // anonymous namespace -DriverGL::DriverGL() { ClearBindings(); } - void DriverGL::InitializeCustomDynamicBindings(GLContext* context) { InitializeDynamicBindings(context); - - DCHECK(orig_fn.glTexImage2DFn == NULL); - orig_fn.glTexImage2DFn = fn.glTexImage2DFn; + orig_fn = fn; 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 0881e10..628fc1f 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 190f669..31fec9a 100644 --- a/ui/gl/gl_implementation_android.cc +++ b/ui/gl/gl_implementation_android.cc @@ -52,7 +52,8 @@ 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. - DCHECK_EQ(kGLImplementationNone, GetGLImplementation()); + if (GetGLImplementation() != kGLImplementationNone) + return true; switch (implementation) { case kGLImplementationEGLGLES2: { diff --git a/ui/gl/gl_implementation_mac.cc b/ui/gl/gl_implementation_mac.cc index 1011406..546a082f 100644 --- a/ui/gl/gl_implementation_mac.cc +++ b/ui/gl/gl_implementation_mac.cc @@ -31,7 +31,8 @@ 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. - DCHECK_EQ(kGLImplementationNone, GetGLImplementation()); + if (GetGLImplementation() != kGLImplementationNone) + return true; // 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 b8dd2c4..3659a02 100644 --- a/ui/gl/gl_implementation_ozone.cc +++ b/ui/gl/gl_implementation_ozone.cc @@ -37,7 +37,8 @@ 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. - DCHECK_EQ(kGLImplementationNone, GetGLImplementation()); + if (GetGLImplementation() != kGLImplementationNone) + return true; switch (implementation) { case kGLImplementationOSMesaGL: diff --git a/ui/gl/gl_implementation_win.cc b/ui/gl/gl_implementation_win.cc index 5269297..ddc9c57 100644 --- a/ui/gl/gl_implementation_win.cc +++ b/ui/gl/gl_implementation_win.cc @@ -112,7 +112,8 @@ 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. - DCHECK_EQ(kGLImplementationNone, GetGLImplementation()); + if (GetGLImplementation() != kGLImplementationNone) + return true; // 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 c19b39e..7588a37 100644 --- a/ui/gl/gl_implementation_x11.cc +++ b/ui/gl/gl_implementation_x11.cc @@ -43,7 +43,8 @@ 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. - DCHECK_EQ(kGLImplementationNone, GetGLImplementation()); + if (GetGLImplementation() != kGLImplementationNone) + return true; // 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 e9c7ce9..a52a3f7 100644 --- a/ui/gl/gl_surface.cc +++ b/ui/gl/gl_surface.cc @@ -14,7 +14,6 @@ #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 { @@ -25,7 +24,9 @@ base::LazyInstance<base::ThreadLocalPointer<GLSurface> >::Leaky // static bool GLSurface::InitializeOneOff() { - DCHECK_EQ(kGLImplementationNone, GetGLImplementation()); + static bool initialized = false; + if (initialized) + return true; TRACE_EVENT0("gpu", "GLSurface::InitializeOneOff"); @@ -33,14 +34,12 @@ 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 (cmd->HasSwitch(switches::kUseGL)) { + if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseGL)) { std::string requested_implementation_name = - cmd->GetSwitchValueASCII(switches::kUseGL); + CommandLine::ForCurrentProcess()->GetSwitchValueASCII(switches::kUseGL); if (requested_implementation_name == "any") { fallback_to_osmesa = true; } else if (requested_implementation_name == "swiftshader") { @@ -56,94 +55,27 @@ bool GLSurface::InitializeOneOff() { } } - 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(); + 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 (gpu_service_logging) + if (CommandLine::ForCurrentProcess()->HasSwitch( + switches::kEnableGPUServiceLogging)) InitializeDebugGLBindings(); - if (disable_gl_drawing) + if (CommandLine::ForCurrentProcess()->HasSwitch( + switches::kDisableGLDrawingForTests)) 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 f7a02f0..8eaf60d 100644 --- a/ui/gl/gl_surface.h +++ b/ui/gl/gl_surface.h @@ -12,7 +12,6 @@ #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 { @@ -70,15 +69,8 @@ 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); @@ -117,10 +109,6 @@ 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 635595c..0db2fc7 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() { - switch (GetGLImplementation()) { - case kGLImplementationEGLGLES2: - if (!GLSurfaceEGL::InitializeOneOff()) { - LOG(ERROR) << "GLSurfaceEGL::InitializeOneOff failed."; - return false; - } - default: - break; + if (GetGLImplementation() == kGLImplementationOSMesaGL) { + return true; + } + DCHECK(GetGLImplementation() == kGLImplementationEGLGLES2); + + if (!GLSurfaceEGL::InitializeOneOff()) { + LOG(ERROR) << "GLSurfaceEGL::InitializeOneOff failed."; + return false; } return true; } diff --git a/ui/keyboard/DEPS b/ui/keyboard/DEPS index ec5b911..defb61d 100644 --- a/ui/keyboard/DEPS +++ b/ui/keyboard/DEPS @@ -6,7 +6,6 @@ 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 d5e5bc0..e95dcbe 100644 --- a/ui/keyboard/test/run_all_unittests.cc +++ b/ui/keyboard/test/run_all_unittests.cc @@ -10,7 +10,6 @@ #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 { @@ -21,7 +20,6 @@ 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 44d965d..1108a45 100644 --- a/ui/views/examples/DEPS +++ b/ui/views/examples/DEPS @@ -2,5 +2,4 @@ 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 53a206f..62a6405 100644 --- a/ui/views/examples/examples_main.cc +++ b/ui/views/examples/examples_main.cc @@ -14,7 +14,6 @@ #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" @@ -47,8 +46,6 @@ 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 51cf45d..d04a459 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_implementation.h" +#include "ui/gl/gl_surface.h" using gpu::gles2::GLES2Implementation; using gpu::GLInProcessContext; @@ -74,9 +74,12 @@ scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> WebGraphicsContext3DInProcessCommandBufferImpl::CreateViewContext( const blink::WebGraphicsContext3D::Attributes& attributes, gfx::AcceleratedWidget window) { - DCHECK_NE(gfx::GetGLImplementation(), gfx::kGLImplementationNone); - return make_scoped_ptr(new WebGraphicsContext3DInProcessCommandBufferImpl( + scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> context; + if (gfx::GLSurface::InitializeOneOff()) { + context.reset(new WebGraphicsContext3DInProcessCommandBufferImpl( scoped_ptr< ::gpu::GLInProcessContext>(), attributes, false, window)); + } + return context.Pass(); } // static @@ -84,21 +87,24 @@ scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> WebGraphicsContext3DInProcessCommandBufferImpl::CreateOffscreenContext( const blink::WebGraphicsContext3D::Attributes& attributes) { return make_scoped_ptr(new WebGraphicsContext3DInProcessCommandBufferImpl( - scoped_ptr< ::gpu::GLInProcessContext>(), - attributes, - true, - gfx::kNullAcceleratedWidget)); + scoped_ptr< ::gpu::GLInProcessContext>(), + attributes, + true, + gfx::kNullAcceleratedWidget)) + .Pass(); } 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. */)); + return make_scoped_ptr( + new WebGraphicsContext3DInProcessCommandBufferImpl( + context.Pass(), + attributes, + true /* is_offscreen. Not used. */, + gfx::kNullAcceleratedWidget /* window. Not used. */)) + .Pass(); } WebGraphicsContext3DInProcessCommandBufferImpl:: |