1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
|
// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/gl/test/gl_surface_test_support.h"
#include <vector>
#include "base/check_op.h"
#include "base/command_line.h"
#include "build/build_config.h"
#include "ui/gl/gl_context.h"
#include "ui/gl/gl_features.h"
#include "ui/gl/gl_implementation.h"
#include "ui/gl/gl_switches.h"
#include "ui/gl/init/gl_factory.h"
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
#include "ui/platform_window/common/platform_window_defaults.h" // nogncheck
#endif
#if BUILDFLAG(IS_OZONE)
#include "ui/ozone/public/ozone_platform.h"
#endif
namespace gl {
namespace {
GLDisplay* InitializeOneOffHelper(bool init_extensions) {
DCHECK_EQ(kGLImplementationNone, GetGLImplementation());
#if BUILDFLAG(IS_OZONE)
ui::OzonePlatform::InitParams params;
params.single_process = true;
ui::OzonePlatform::InitializeForGPU(params);
#endif
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
ui::test::EnableTestConfigForPlatformWindows();
#endif
bool use_software_gl = true;
// We usually use software GL as this works on all bots. The
// command line can override this behaviour to use hardware GL.
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kUseGpuInTests)) {
use_software_gl = false;
}
#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_IOS)
// On Android and iOS we always use hardware GL.
use_software_gl = false;
#endif
std::vector<GLImplementationParts> allowed_impls =
init::GetAllowedGLImplementations();
DCHECK(!allowed_impls.empty());
GLImplementationParts impl = allowed_impls[0];
if (use_software_gl) {
impl = gl::GetSoftwareGLImplementation();
}
DCHECK(!base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseGL))
<< "kUseGL has not effect in tests";
bool disable_gl_drawing = true;
CHECK(gl::init::InitializeStaticGLBindingsImplementation(impl));
GLDisplay* display = gl::init::InitializeGLOneOffPlatformImplementation(
disable_gl_drawing, init_extensions, gl::GpuPreference::kDefault);
CHECK(display);
return display;
}
} // namespace
// static
GLDisplay* GLSurfaceTestSupport::InitializeOneOff() {
return InitializeOneOffHelper(true);
}
// static
GLDisplay* GLSurfaceTestSupport::InitializeNoExtensionsOneOff() {
return InitializeOneOffHelper(false);
}
// static
GLDisplay* GLSurfaceTestSupport::InitializeOneOffImplementation(
GLImplementationParts impl) {
DCHECK(!base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseGL))
<< "kUseGL has not effect in tests";
bool disable_gl_drawing = false;
bool init_extensions = true;
CHECK(gl::init::InitializeStaticGLBindingsImplementation(impl));
GLDisplay* display = gl::init::InitializeGLOneOffPlatformImplementation(
disable_gl_drawing, init_extensions, gl::GpuPreference::kDefault);
CHECK(display);
return display;
}
// static
GLDisplay* GLSurfaceTestSupport::InitializeOneOffWithMockBindings() {
#if BUILDFLAG(IS_OZONE)
ui::OzonePlatform::InitParams params;
params.single_process = true;
ui::OzonePlatform::InitializeForGPU(params);
#endif
return InitializeOneOffImplementation(
GLImplementationParts(kGLImplementationMockGL));
}
// static
GLDisplay* GLSurfaceTestSupport::InitializeOneOffWithStubBindings() {
#if BUILDFLAG(IS_OZONE)
ui::OzonePlatform::InitParams params;
params.single_process = true;
ui::OzonePlatform::InitializeForGPU(params);
#endif
return InitializeOneOffImplementation(
GLImplementationParts(kGLImplementationStubGL));
}
// static
GLDisplay* GLSurfaceTestSupport::InitializeOneOffWithNullAngleBindings() {
#if BUILDFLAG(IS_OZONE)
ui::OzonePlatform::InitParams params;
params.single_process = true;
ui::OzonePlatform::InitializeForGPU(params);
#endif
auto* display = InitializeOneOffImplementation(
GLImplementationParts(gl::ANGLEImplementation::kNull));
DCHECK_EQ(gl::GetANGLEImplementation(), gl::ANGLEImplementation::kNull);
return display;
}
// static
void GLSurfaceTestSupport::ShutdownGL(GLDisplay* display) {
init::ShutdownGL(display, false);
}
} // namespace gl
|