blob: a3b8ad7a325d307105e4a968891466085902e7df [file] [log] [blame]
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/ozone/common/egl_util.h"
#include "base/files/file_path.h"
#include "ui/gl/egl_util.h"
#include "ui/gl/gl_bindings.h"
#include "ui/gl/gl_implementation.h"
namespace ui {
namespace {
const char kDefaultEglSoname[] = "libEGL.so.1";
const char kDefaultGlesSoname[] = "libGLESv2.so.2";
} // namespace
bool LoadDefaultEGLGLES2Bindings() {
return LoadEGLGLES2Bindings(kDefaultEglSoname, kDefaultGlesSoname);
}
bool LoadEGLGLES2Bindings(
const char* egl_library_name,
const char* gles_library_name) {
base::NativeLibraryLoadError error;
base::NativeLibrary gles_library =
base::LoadNativeLibrary(base::FilePath(gles_library_name), &error);
if (!gles_library) {
LOG(WARNING) << "Failed to load GLES library: " << error.ToString();
return false;
}
base::NativeLibrary egl_library =
base::LoadNativeLibrary(base::FilePath(egl_library_name), &error);
if (!egl_library) {
LOG(WARNING) << "Failed to load EGL library: " << error.ToString();
base::UnloadNativeLibrary(gles_library);
return false;
}
gl::GLGetProcAddressProc get_proc_address =
reinterpret_cast<gl::GLGetProcAddressProc>(
base::GetFunctionPointerFromNativeLibrary(egl_library,
"eglGetProcAddress"));
if (!get_proc_address) {
LOG(ERROR) << "eglGetProcAddress not found.";
base::UnloadNativeLibrary(egl_library);
base::UnloadNativeLibrary(gles_library);
return false;
}
gl::SetGLGetProcAddressProc(get_proc_address);
gl::AddGLNativeLibrary(egl_library);
gl::AddGLNativeLibrary(gles_library);
return true;
}
EGLConfig ChooseEGLConfig(EGLDisplay display, const int32_t* attributes) {
int32_t num_configs;
if (!eglChooseConfig(display, attributes, nullptr, 0, &num_configs)) {
LOG(ERROR) << "eglChooseConfig failed with error "
<< GetLastEGLErrorString();
return nullptr;
}
if (num_configs == 0) {
LOG(ERROR) << "No suitable EGL configs found.";
return nullptr;
}
EGLConfig config;
if (!eglChooseConfig(display, attributes, &config, 1, &num_configs)) {
LOG(ERROR) << "eglChooseConfig failed with error "
<< GetLastEGLErrorString();
return nullptr;
}
return config;
}
} // namespace ui