| 62 | } |
| 63 | |
| 64 | Status EglEnvironment::Init() { |
| 65 | bool is_bound; |
| 66 | RETURN_IF_ERROR( |
| 67 | TFLITE_GPU_CALL_EGL(eglBindAPI, &is_bound, EGL_OPENGL_ES_API)); |
| 68 | if (!is_bound) { |
| 69 | return InternalError("No EGL error, but eglBindAPI failed"); |
| 70 | } |
| 71 | |
| 72 | // Re-use context and display if it was created on this thread. |
| 73 | if (eglGetCurrentContext() != EGL_NO_CONTEXT) { |
| 74 | display_ = eglGetCurrentDisplay(); |
| 75 | context_ = |
| 76 | EglContext(eglGetCurrentContext(), display_, EGL_NO_CONFIG_KHR, false); |
| 77 | } else { |
| 78 | RETURN_IF_ERROR(InitDisplay(&display_)); |
| 79 | |
| 80 | Status status = InitConfiglessContext(); |
| 81 | if (!status.ok()) { |
| 82 | status = InitSurfacelessContext(); |
| 83 | } |
| 84 | if (!status.ok()) { |
| 85 | status = InitPBufferContext(); |
| 86 | } |
| 87 | if (!status.ok()) { |
| 88 | return status; |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | if (gpu_info_.type == GpuType::UNKNOWN) { |
| 93 | RETURN_IF_ERROR(RequestGpuInfo(&gpu_info_)); |
| 94 | } |
| 95 | // TODO(akulik): when do we need ForceSyncTurning? |
| 96 | ForceSyncTurning(); |
| 97 | return OkStatus(); |
| 98 | } |
| 99 | |
| 100 | Status EglEnvironment::InitConfiglessContext() { |
| 101 | RETURN_IF_ERROR(CreateConfiglessContext(display_, EGL_NO_CONTEXT, &context_)); |
no test coverage detected