tflite/egl_sync: Return early if extensions are not supported
This commit is contained in:
parent
8aaf1a394e
commit
6e93f44f35
@ -28,23 +28,30 @@ bool HasExtension(EGLDisplay display, const char* extension) {
|
||||
return extensions && std::strstr(extensions, extension);
|
||||
}
|
||||
|
||||
bool IsEglFenceSyncSupported(EGLDisplay display) {
|
||||
absl::Status IsEglFenceSyncSupported(EGLDisplay display) {
|
||||
static bool supported = HasExtension(display, "EGL_KHR_fence_sync");
|
||||
return supported;
|
||||
if (supported) {
|
||||
return absl::OkStatus();
|
||||
}
|
||||
return absl::InternalError("Not supported: EGL_KHR_fence_sync");
|
||||
}
|
||||
|
||||
bool IsEglWaitSyncSupported(EGLDisplay display) {
|
||||
absl::Status IsEglWaitSyncSupported(EGLDisplay display) {
|
||||
static bool supported = HasExtension(display, "EGL_KHR_wait_sync");
|
||||
return supported;
|
||||
if (supported) {
|
||||
return absl::OkStatus();
|
||||
}
|
||||
return absl::InternalError("Not supported: EGL_KHR_wait_sync");
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
absl::Status EglSync::NewFence(EGLDisplay display, EglSync* sync) {
|
||||
RETURN_IF_ERROR(IsEglFenceSyncSupported(display));
|
||||
static auto* egl_create_sync_khr =
|
||||
reinterpret_cast<decltype(&eglCreateSyncKHR)>(
|
||||
eglGetProcAddress("eglCreateSyncKHR"));
|
||||
if (!IsEglFenceSyncSupported(display) || egl_create_sync_khr == nullptr) {
|
||||
if (egl_create_sync_khr == nullptr) {
|
||||
// Needs extension: EGL_KHR_fence_sync (EGL) / GL_OES_EGL_sync (OpenGL ES).
|
||||
return absl::InternalError(
|
||||
"Not supported / bad EGL implementation: eglCreateSyncKHR.");
|
||||
@ -74,7 +81,7 @@ void EglSync::Invalidate() {
|
||||
reinterpret_cast<decltype(&eglDestroySyncKHR)>(
|
||||
eglGetProcAddress("eglDestroySyncKHR"));
|
||||
// Needs extension: EGL_KHR_fence_sync (EGL) / GL_OES_EGL_sync (OpenGL ES).
|
||||
if (IsEglFenceSyncSupported(display_) && egl_destroy_sync_khr) {
|
||||
if (IsEglFenceSyncSupported(display_).ok() && egl_destroy_sync_khr) {
|
||||
// Note: we're doing nothing when the function pointer is nullptr, or the
|
||||
// call returns EGL_FALSE.
|
||||
(*egl_destroy_sync_khr)(display_, sync_);
|
||||
@ -84,9 +91,10 @@ void EglSync::Invalidate() {
|
||||
}
|
||||
|
||||
absl::Status EglSync::ServerWait() {
|
||||
RETURN_IF_ERROR(IsEglWaitSyncSupported(display_));
|
||||
static auto* egl_wait_sync_khr = reinterpret_cast<decltype(&eglWaitSyncKHR)>(
|
||||
eglGetProcAddress("eglWaitSyncKHR"));
|
||||
if (!IsEglWaitSyncSupported(display_) || egl_wait_sync_khr == nullptr) {
|
||||
if (egl_wait_sync_khr == nullptr) {
|
||||
// Needs extension: EGL_KHR_wait_sync
|
||||
return absl::InternalError("Not supported: eglWaitSyncKHR.");
|
||||
}
|
||||
@ -98,11 +106,11 @@ absl::Status EglSync::ServerWait() {
|
||||
}
|
||||
|
||||
absl::Status EglSync::ClientWait() {
|
||||
RETURN_IF_ERROR(IsEglFenceSyncSupported(display_));
|
||||
static auto* egl_client_wait_sync_khr =
|
||||
reinterpret_cast<decltype(&eglClientWaitSyncKHR)>(
|
||||
eglGetProcAddress("eglClientWaitSyncKHR"));
|
||||
if (!IsEglFenceSyncSupported(display_) ||
|
||||
egl_client_wait_sync_khr == nullptr) {
|
||||
if (egl_client_wait_sync_khr == nullptr) {
|
||||
// Needs extension: EGL_KHR_fence_sync (EGL) / GL_OES_EGL_sync (OpenGL ES).
|
||||
return absl::InternalError("Not supported: eglClientWaitSyncKHR.");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user