Как я могу представить владельца и время жизни типов EGL, которые будут храниться в локальном потоке? - PullRequest
0 голосов
/ 01 февраля 2019

Вот основные прототипы основных функций EGL.

typedef void *EGLContext;

EGLContext eglCreateContext(EGLDisplay display,
    EGLConfig config,
    EGLContext share_context,
    EGLint const * attrib_list);

EGLBoolean eglMakeCurrent(EGLDisplay display,
    EGLSurface draw,
    EGLSurface read,
    EGLContext context);

EGLBoolean eglDestroyContext(EGLDisplay display,
    EGLContext context);

Экземпляр EGLContext, возвращаемый из eglCreateContext(), будет установлен в локальное хранилище потока с помощью eglMakeCurrent().После этого все функции OpenGL или ES OpenGL изменят состояния, хранящиеся в этом экземпляре.

Когда я переписываю эти функции EGL в Rust, как правильно обращаться с владением и временем жизни?

#[no_mangle]
pub extern "C" fn eglCreateContext() -> EGLContext {
    // init instance of EGLContext
    // Rc::new(RefCell::new(instance of EGLContext));
    // return that instance of Rc?
}

#[no_mangle]
pub extern "C" fn eglMakeCurrent() -> EGLBoolean {
    // Clone a new Rc instance of the value returned by eglCreateContext?
    // How to set the new Rc instance to Thread Local Storage variable properly?
    // TLS can be None if eglMakeCurrent() pass a nullptr as actual value of EGLContext
}

#[no_mangle]
pub extern "C" fn eglDestroyContext(display: EGLDisplay, context: EGLContext) -> EGLBoolean {
    // Set TLS variable to None if context is already store in it
    // Dispose all the related resource.
}
...