1、oxr_xrDestroySwapchain
函数入口src/xrt/state_trackers/oxr/oxr_api_swapchain.c
XrResult
oxr_xrDestroySwapchain(XrSwapchain swapchain)
{
OXR_TRACE_MARKER();
struct oxr_swapchain *sc;
struct oxr_logger log;
OXR_VERIFY_SWAPCHAIN_AND_INIT_LOG(&log, swapchain, sc, "xrDestroySwapchain");
return oxr_handle_destroy(&log, &sc->handle);
}
oxr_handle_destroy
src/xrt/state_trackers/oxr/oxr_handle_base.c
XrResult
oxr_handle_destroy(struct oxr_logger *log, struct oxr_handle_base *hb)
{
XrResult result = oxr_handle_do_destroy(log, hb, 0);
}
下面递归销毁所有的oxr_handle_base
static XrResult
oxr_handle_do_destroy(struct oxr_logger *log, struct oxr_handle_base *hb, int level)
{
for (size_t i = 0; i < XRT_MAX_HANDLE_CHILDREN; ++i) {
struct oxr_handle_base *child = hb->children[i];
if (child != NULL) {
XrResult result = oxr_handle_do_destroy(log, child, level + 1);
//这一行真正执行销毁
XrResult result = hb->destroy(log, hb);
}
要想找到hb->destroy(log, hb); 对应的方法,需要回到上面oxr_xrDestroySwapchain
hb就是&sc->handle sc就是oxr_swapchain *sc
进入oxr_swapchain 看看初始化函数src/xrt/state_trackers/oxr/oxr_swapchain.c
XrResult
oxr_create_swapchain(struct oxr_logger *log,
struct oxr_session *sess,
const XrSwapchainCreateInfo *createInfo,
struct oxr_swapchain **out_swapchain)
{
//这里没直接指定destory函数指针,而是宏定义了一个
OXR_ALLOCATE_HANDLE_OR_RETURN(log, sc, OXR_XR_DEBUG_SWAPCHAIN, oxr_swapchain_destroy, &sess->handle);
}
宏定义OXR_ALLOCATE_HANDLE_OR_RETURN->
XrResult allocResult = OXR_ALLOCATE_HANDLE(LOG, OUT, DEBUG, DESTROY, PARENT);
继续看看
#define OXR_ALLOCATE_HANDLE(LOG, OUT, DEBUG, DESTROY, PARENT) \
oxr_handle_allocate_and_init(LOG, sizeof(*OUT), DEBUG, DESTROY, PARENT, (void **)&OUT)
看看oxr_handle_allocate_and_init 函数 又回到了base:src/xrt/state_trackers/oxr/oxr_handle_base.c
XrResult result = oxr_handle_init(log, hb, debug, destroy, parent);
XrResult
oxr_handle_init(struct oxr_logger *log,
struct oxr_handle_base *hb,
uint64_t debug,
oxr_handle_destroyer destroy,
struct oxr_handle_base *parent)
{
hb->destroy = destroy;
}
这里指定了hb->destroy = destroy;,上面我们还在找hb->destroy(log, hb);
综上oxr_handle_do_destroy 不就是oxr_swapchain.c 里面的oxr_swapchain_destroy
static XrResult
oxr_swapchain_destroy(struct oxr_logger *log, struct oxr_handle_base *hb)
{
struct oxr_swapchain *sc = (struct oxr_swapchain *)hb;
XrResult ret = sc->destroy(log, sc);
free(sc);
return ret;
}
接着我们要找sc->destroy
oxr_swapchain 文件里我们没找到sc->destroy 赋值的地方
我们搜搜oxr_create_swapchain 在哪
我们在src/xrt/state_trackers/oxr/oxr_swapchain_gl.c 里发现了他
//这个函数是赋值给sess->create_swapchain = oxr_swapchain_gl_create; 先于oxr_create_swapchain
XrResult
oxr_swapchain_gl_create(struct oxr_logger *log,
struct oxr_session *sess,
const XrSwapchainCreateInfo *createInfo,
struct oxr_swapchain **out_swapchain)
{
struct oxr_swapchain *sc;
XrResult ret;
ret = oxr_create_swapchain(log, sess, createInfo, &sc);
if (ret != XR_SUCCESS) {
return ret;
}
sc->destroy = oxr_swapchain_gl_destroy;
这里的oxr_swapchain_gl_destroy就是我们要找的sc->destroy
也把这个函数列出来吧
static XrResult
oxr_swapchain_gl_destroy(struct oxr_logger *log, struct oxr_swapchain *sc)
{
// Release any waited image.
if (sc->waited.yes) {
sc->release_image(log, sc, NULL);
}
// Release any acquired images.
XrSwapchainImageWaitInfo waitInfo = {0};
while (!u_index_fifo_is_empty(&sc->acquired.fifo)) {
sc->wait_image(log, sc, &waitInfo);
sc->release_image(log, sc, NULL);
}
// Drop our reference, does NULL checking.
xrt_swapchain_reference(&sc->swapchain, NULL);
return XR_SUCCESS;
}
综上oxr_xrDestroySwapchain - > oxr_swapchain_gl_destroy 就没然后了
网友评论