admin管理员组

文章数量:1401673

Is there a way to get supported device specific formats when using ANativeWindow_setBuffersGeometry? My current approach to test each option seems awkward. I can use ANativeWindow_getFormat (window) to get the default format, but some devices support multiple and I would like to choose the one with simplest processing to convert a source image to a displayable format. If there is a Java-side option based on Surface/SurfaceTexture (that can be used in NDK side), that would work but I couldn't find one.

int checkGeometry (ANativeWindow *window, int width, int height, int format)
{
    int err_code = ANativeWindow_setBuffersGeometry(window,
                    width, height, format);
    if (err_code != 0)
        {
        LOGD ("setBuffersGeometry failed!");
        return err_code;
        }
    LOGD ("setBuffersGeometry: OK");
    //--------
    ANativeWindow_Buffer outBuffer;
    err_code = ANativeWindow_lock(window, &outBuffer, NULL);
    if (err_code != 0) {
       LOGD ("Failed to allocate buffer!");
        return err_code;
        }
    ANativeWindow_unlockAndPost(window);
    
    //If failed to set properties, exit with error
    if ( outBuffer.width  != width ) {return -EINVAL;}
    if ( outBuffer.height != height) {return -EINVAL;}
    if ( outBuffer.format != format) {return -EINVAL;}
return err_code;
}

本文标签: imageGet list of supported formats for ANativeWindowsetBuffersGeometryStack Overflow