summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authordanakj@chromium.org <danakj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-03 19:53:15 +0000
committerdanakj@chromium.org <danakj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-03 19:53:15 +0000
commitaf7c5d96e7a34531cc8c9cbbe207013624c4c534 (patch)
treeaf753fc432af2a5aba96cfc9529accec0b062076 /ui
parent4e8809e57328d02157e06981a340a66e6a4a1390 (diff)
downloadchromium_src-af7c5d96e7a34531cc8c9cbbe207013624c4c534.zip
chromium_src-af7c5d96e7a34531cc8c9cbbe207013624c4c534.tar.gz
chromium_src-af7c5d96e7a34531cc8c9cbbe207013624c4c534.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=ben@chromium.org, piman@chromium.org, sievers@chromium.org, piman, sievers BUG=270918 Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=247793 Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=248049 Review URL: https://codereview.chromium.org/135213003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@248557 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r--ui/aura/bench/DEPS1
-rw-r--r--ui/aura/bench/bench_main.cc4
-rw-r--r--ui/aura/demo/DEPS3
-rw-r--r--ui/aura/demo/demo_main.cc3
-rw-r--r--ui/compositor/test/context_factories_for_test.cc7
-rw-r--r--ui/compositor/test/default_context_factory.cc10
-rw-r--r--ui/compositor/test/default_context_factory.h2
-rw-r--r--ui/compositor/test/test_suite.cc4
-rw-r--r--ui/gl/gl_gl_api_implementation.cc17
-rw-r--r--ui/gl/gl_implementation.h2
-rw-r--r--ui/gl/gl_implementation_android.cc3
-rw-r--r--ui/gl/gl_implementation_mac.cc3
-rw-r--r--ui/gl/gl_implementation_ozone.cc3
-rw-r--r--ui/gl/gl_implementation_win.cc3
-rw-r--r--ui/gl/gl_implementation_x11.cc3
-rw-r--r--ui/gl/gl_surface.cc93
-rw-r--r--ui/gl/gl_surface.h12
-rw-r--r--ui/gl/gl_surface_egl.cc16
-rw-r--r--ui/gl/gl_switches.cc3
-rw-r--r--ui/gl/gl_switches.h1
-rw-r--r--ui/keyboard/DEPS1
-rw-r--r--ui/keyboard/test/run_all_unittests.cc2
-rw-r--r--ui/views/examples/DEPS1
-rw-r--r--ui/views/examples/examples_main.cc3
24 files changed, 153 insertions, 47 deletions
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..9531fc4 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,99 @@ 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;
+
+ // We usually use OSMesa as this works on all bots. The command line can
+ // override this behaviour to use hardware GL.
+ if (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(!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/gl/gl_switches.cc b/ui/gl/gl_switches.cc
index b747d8f..c926d4b 100644
--- a/ui/gl/gl_switches.cc
+++ b/ui/gl/gl_switches.cc
@@ -71,6 +71,9 @@ const char kTestGLLib[] = "test-gl-lib";
// the GL output will not be correct but tests will run faster.
const char kDisableGLDrawingForTests[] = "disable-gl-drawing-for-tests";
+// Use hardware gpu, if available, for tests.
+const char kUseGpuInTests[] = "use-gpu-in-tests";
+
// This is the list of switches passed from this file that are passed from the
// GpuProcessHost to the GPU Process. Add your switch to this list if you need
// to read it in the GPU process, else don't add it.
diff --git a/ui/gl/gl_switches.h b/ui/gl/gl_switches.h
index bc27704..af7c3ce 100644
--- a/ui/gl/gl_switches.h
+++ b/ui/gl/gl_switches.h
@@ -45,6 +45,7 @@ GL_EXPORT extern const char kUseGL[];
GL_EXPORT extern const char kSwiftShaderPath[];
GL_EXPORT extern const char kTestGLLib[];
GL_EXPORT extern const char kDisableGLDrawingForTests[];
+GL_EXPORT extern const char kUseGpuInTests[];
GL_EXPORT extern const char* kGLSwitchesCopiedFromGpuProcessHost[];
GL_EXPORT extern const int kGLSwitchesCopiedFromGpuProcessHostNumSwitches;
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);