Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / ui / gl / test / gl_surface_test_support.cc
blobecc8015c5ef3fd320c17e4b591c9f9f2f94d3514
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ui/gl/test/gl_surface_test_support.h"
7 #include "base/command_line.h"
8 #include "base/logging.h"
9 #include "ui/gl/gl_context.h"
10 #include "ui/gl/gl_implementation.h"
11 #include "ui/gl/gl_surface.h"
12 #include "ui/gl/gl_switches.h"
14 #if defined(USE_X11)
15 #include <X11/Xlib.h>
16 #include "ui/platform_window/x11/x11_window.h"
17 #endif
19 namespace gfx {
21 // static
22 void GLSurfaceTestSupport::InitializeOneOff() {
23 DCHECK_EQ(kGLImplementationNone, GetGLImplementation());
25 #if defined(USE_X11)
26 XInitThreads();
27 ui::test::SetUseOverrideRedirectWindowByDefault(true);
28 #endif
30 bool use_osmesa = true;
32 // We usually use OSMesa as this works on all bots. The command line can
33 // override this behaviour to use hardware GL.
34 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
35 switches::kUseGpuInTests)) {
36 use_osmesa = false;
39 #if defined(OS_ANDROID)
40 // On Android we always use hardware GL.
41 use_osmesa = false;
42 #endif
44 std::vector<GLImplementation> allowed_impls;
45 GetAllowedGLImplementations(&allowed_impls);
46 DCHECK(!allowed_impls.empty());
48 GLImplementation impl = allowed_impls[0];
49 if (use_osmesa)
50 impl = kGLImplementationOSMesaGL;
52 DCHECK(!base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseGL))
53 << "kUseGL has not effect in tests";
55 bool fallback_to_osmesa = false;
56 bool gpu_service_logging = false;
57 bool disable_gl_drawing = true;
59 CHECK(GLSurface::InitializeOneOffImplementation(
60 impl, fallback_to_osmesa, gpu_service_logging, disable_gl_drawing));
63 // static
64 void GLSurfaceTestSupport::InitializeOneOffWithMockBindings() {
65 DCHECK(!base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseGL))
66 << "kUseGL has not effect in tests";
68 // This method may be called multiple times in the same process to set up
69 // mock bindings in different ways.
70 ClearGLBindings();
72 bool fallback_to_osmesa = false;
73 bool gpu_service_logging = false;
74 bool disable_gl_drawing = false;
76 CHECK(GLSurface::InitializeOneOffImplementation(
77 kGLImplementationMockGL, fallback_to_osmesa, gpu_service_logging,
78 disable_gl_drawing));
81 // static
82 void GLSurfaceTestSupport::InitializeDynamicMockBindings(GLContext* context) {
83 CHECK(InitializeDynamicGLBindings(kGLImplementationMockGL, context));
86 } // namespace gfx