#include "ui/gl/test/gl_test_support.h"
#include <vector>
#include "base/check_op.h"
#include "build/build_config.h"
#include "gpu/config/gpu_util.h"
#include "ui/gl/init/gl_factory.h"
#include "ui/gl/test/gl_surface_test_support.h"
#if BUILDFLAG(IS_OZONE)
#include "base/run_loop.h"
#include "ui/ozone/public/ozone_platform.h"
#endif
namespace gl {
GLDisplay* GLTestSupport::InitializeGL(
std::optional<GLImplementationParts> prefered_impl) {
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC)
gpu::TrySetNonSoftwareDevicePreferenceForTesting(
gl::GpuPreference ::kDefault);
#endif
#if BUILDFLAG(IS_OZONE)
ui::OzonePlatform::InitParams params;
params.single_process = true;
ui::OzonePlatform::InitializeForGPU(params);
#endif
std::vector<GLImplementationParts> allowed_impls =
init::GetAllowedGLImplementations();
DCHECK(!allowed_impls.empty());
GLImplementationParts impl =
prefered_impl ? *prefered_impl : allowed_impls[0];
DCHECK(impl.IsAllowed(allowed_impls));
GLDisplay* display =
GLSurfaceTestSupport::InitializeOneOffImplementation(impl);
#if BUILDFLAG(IS_OZONE)
base::RunLoop().RunUntilIdle();
#endif
return display;
}
void GLTestSupport::CleanupGL(GLDisplay* display) {
GLSurfaceTestSupport::ShutdownGL(display);
}
}