app/src/main/jni/SDL/src/video/kmsdrm/SDL_kmsdrmmouse.c
static int
KMSDRM_ShowCursor(SDL_Cursor * cursor)
{
    SDL_VideoDevice *dev = SDL_GetVideoDevice();
    SDL_VideoData *vdata = ((SDL_VideoData *)dev->driverdata);
    SDL_Mouse *mouse;
    KMSDRM_CursorData *curdata;
    SDL_VideoDisplay *display = NULL;
    SDL_DisplayData *ddata = NULL;
    int ret;
    uint32_t bo_handle;

    mouse = SDL_GetMouse();
    if (mouse == NULL) {
        return SDL_SetError("No mouse.");
    }

    if (mouse->focus != NULL) {
        display = SDL_GetDisplayForWindow(mouse->focus);
        if (display != NULL) {
            ddata = (SDL_DisplayData*) display->driverdata;
        }
    }

    if (cursor == NULL) {
        /* Hide current cursor */
        if ( mouse->cur_cursor != NULL && mouse->cur_cursor->driverdata != NULL) {
            curdata = (KMSDRM_CursorData *) mouse->cur_cursor->driverdata;

            if (curdata->crtc_id != 0) {
                ret = KMSDRM_drmModeSetCursor(vdata->drm_fd, curdata->crtc_id, 0, 0, 0);
                if (ret) {
                    SDL_SetError("Could not hide current cursor with drmModeSetCursor().");
                    return ret;
                }
                /* Mark previous cursor as not-displayed */
                curdata->crtc_id = 0;

                return 0;
            }
        }
        /* otherwise if possible, hide global cursor */
        if (ddata != NULL && ddata->crtc_id != 0) {
            ret = KMSDRM_drmModeSetCursor(vdata->drm_fd, ddata->crtc_id, 0, 0, 0);
            if (ret) {
                SDL_SetError("Could not hide display's cursor with drmModeSetCursor().");
                return ret;
            }
            return 0;
        }

        return SDL_SetError("Couldn't find cursor to hide.");
    }
    /* If cursor != NULL, show new cursor on display */
    if (display == NULL) {
        return SDL_SetError("Could not get display for mouse.");
    }
    if (ddata == NULL) {
        return SDL_SetError("Could not get display driverdata.");
    }

    curdata = (KMSDRM_CursorData *) cursor->driverdata;
    if (curdata == NULL || curdata->bo == NULL) {
        return SDL_SetError("Cursor not initialized properly.");
    }

    bo_handle = KMSDRM_gbm_bo_get_handle(curdata->bo).u32;
    if (curdata->hot_x == 0 && curdata->hot_y == 0) {
        ret = KMSDRM_drmModeSetCursor(vdata->drm_fd, ddata->crtc_id, bo_handle,
                                      curdata->w, curdata->h);
    } else {
        ret = KMSDRM_drmModeSetCursor2(vdata->drm_fd, ddata->crtc_id, bo_handle,
                                       curdata->w, curdata->h,
                                       curdata->hot_x, curdata->hot_y);
    }
    if (ret) {
        SDL_SetError("drmModeSetCursor failed.");
        return ret;
    }

    curdata->crtc_id = ddata->crtc_id;

    return 0;
}
/* Show the specified cursor, or hide if cursor is NULL */
Show the specified cursor, or hide if cursor is NULL
Show the specified cursor or hide if cursor is NULL
static int
KMSDRM_ShowCursor(SDL_Cursor * cursor)
{
    SDL_VideoDevice *dev = SDL_GetVideoDevice();
    SDL_VideoData *vdata = ((SDL_VideoData *)dev->driverdata);
    SDL_Mouse *mouse;
    KMSDRM_CursorData *curdata;
    SDL_VideoDisplay *display = NULL;
    SDL_DisplayData *ddata = NULL;
    int ret;
    uint32_t bo_handle;
    mouse = SDL_GetMouse();
    if (mouse == NULL) {
        return SDL_SetError("No mouse.");
    }
    if (mouse->focus != NULL) {
        display = SDL_GetDisplayForWindow(mouse->focus);
        if (display != NULL) {
            ddata = (SDL_DisplayData*) display->driverdata;
        }
    }
    if (cursor == NULL) {
        if ( mouse->cur_cursor != NULL && mouse->cur_cursor->driverdata != NULL) {
            curdata = (KMSDRM_CursorData *) mouse->cur_cursor->driverdata;
            if (curdata->crtc_id != 0) {
                ret = KMSDRM_drmModeSetCursor(vdata->drm_fd, curdata->crtc_id, 0, 0, 0);
                if (ret) {
                    SDL_SetError("Could not hide current cursor with drmModeSetCursor().");
                    return ret;
                }
                curdata->crtc_id = 0;
                return 0;
            }
        }
        if (ddata != NULL && ddata->crtc_id != 0) {
            ret = KMSDRM_drmModeSetCursor(vdata->drm_fd, ddata->crtc_id, 0, 0, 0);
            if (ret) {
                SDL_SetError("Could not hide display's cursor with drmModeSetCursor().");
                return ret;
            }
            return 0;
        }
        return SDL_SetError("Couldn't find cursor to hide.");
    }
    if (display == NULL) {
        return SDL_SetError("Could not get display for mouse.");
    }
    if (ddata == NULL) {
        return SDL_SetError("Could not get display driverdata.");
    }
    curdata = (KMSDRM_CursorData *) cursor->driverdata;
    if (curdata == NULL || curdata->bo == NULL) {
        return SDL_SetError("Cursor not initialized properly.");
    }
    bo_handle = KMSDRM_gbm_bo_get_handle(curdata->bo).u32;
    if (curdata->hot_x == 0 && curdata->hot_y == 0) {
        ret = KMSDRM_drmModeSetCursor(vdata->drm_fd, ddata->crtc_id, bo_handle,
                                      curdata->w, curdata->h);
    } else {
        ret = KMSDRM_drmModeSetCursor2(vdata->drm_fd, ddata->crtc_id, bo_handle,
                                       curdata->w, curdata->h,
                                       curdata->hot_x, curdata->hot_y);
    }
    if (ret) {
        SDL_SetError("drmModeSetCursor failed.");
        return ret;
    }
    curdata->crtc_id = ddata->crtc_id;
    return 0;
}
static int KMSDRM_ShowCursor ( SDL_Cursor * cursor ) { SDL_VideoDevice * dev = SDL_GetVideoDevice ( ) ; SDL_VideoData * vdata = ( ( SDL_VideoData * ) dev -> driverdata ) ; SDL_Mouse * mouse ; KMSDRM_CursorData * curdata ; SDL_VideoDisplay * display = NULL ; SDL_DisplayData * ddata = NULL ; int ret ; uint32_t bo_handle ; mouse = SDL_GetMouse ( ) ; if ( mouse == NULL ) { return SDL_SetError ( " " ) ; } if ( mouse -> focus != NULL ) { display = SDL_GetDisplayForWindow ( mouse -> focus ) ; if ( display != NULL ) { ddata = ( SDL_DisplayData * ) display -> driverdata ; } } if ( cursor == NULL ) { if ( mouse -> cur_cursor != NULL && mouse -> cur_cursor -> driverdata != NULL ) { curdata = ( KMSDRM_CursorData * ) mouse -> cur_cursor -> driverdata ; if ( curdata -> crtc_id != 0 ) { ret = KMSDRM_drmModeSetCursor ( vdata -> drm_fd , curdata -> crtc_id , 0 , 0 , 0 ) ; if ( ret ) { SDL_SetError ( " " ) ; return ret ; } curdata -> crtc_id = 0 ; return 0 ; } } if ( ddata != NULL && ddata -> crtc_id != 0 ) { ret = KMSDRM_drmModeSetCursor ( vdata -> drm_fd , ddata -> crtc_id , 0 , 0 , 0 ) ; if ( ret ) { SDL_SetError ( " " ) ; return ret ; } return 0 ; } return SDL_SetError ( " " ) ; } if ( display == NULL ) { return SDL_SetError ( " " ) ; } if ( ddata == NULL ) { return SDL_SetError ( " " ) ; } curdata = ( KMSDRM_CursorData * ) cursor -> driverdata ; if ( curdata == NULL || curdata -> bo == NULL ) { return SDL_SetError ( " " ) ; } bo_handle = KMSDRM_gbm_bo_get_handle ( curdata -> bo ) . u32 ; if ( curdata -> hot_x == 0 && curdata -> hot_y == 0 ) { ret = KMSDRM_drmModeSetCursor ( vdata -> drm_fd , ddata -> crtc_id , bo_handle , curdata -> w , curdata -> h ) ; } else { ret = KMSDRM_drmModeSetCursor2 ( vdata -> drm_fd , ddata -> crtc_id , bo_handle , curdata -> w , curdata -> h , curdata -> hot_x , curdata -> hot_y ) ; } if ( ret ) { SDL_SetError ( " " ) ; return ret ; } curdata -> crtc_id = ddata -> crtc_id ; return 0 ; }
Show the specified cursor, or hide if cursor is NULL
Show the specified cursor or hide if cursor is NULL
/* Hide current cursor */ /* Mark previous cursor as not-displayed */ /* otherwise if possible, hide global cursor */ /* If cursor != NULL, show new cursor on display */