async fn allocate_image_buffer(
    ctrl: Controller,
    params: &ImageParameters,
) -> Result<BufferCollection> {
    let allocator =
        connect_to_protocol::<AllocatorMarker>().map_err(|_| Error::SysmemConnection)?;
    {
        let name = fuchsia_runtime::process_self().get_name()?;
        let koid = fuchsia_runtime::process_self().get_koid()?;
        allocator.set_debug_client_info(name.to_str()?, koid.raw_koid())?;
    }
    let collection_token = {
        let (proxy, remote) = create_proxy::<BufferCollectionTokenMarker>()?;
        allocator.allocate_shared_collection(remote)?;
        proxy
    };
    // TODO(armansito): The priority number here is arbitrary but I don't expect there to be
    // contention for the assigned name as this client library should be the collection's sole
    // owner. Still, come up with a better way to assign this.
    if let Some(ref name) = params.name {
        collection_token.set_name(100, name.as_str())?;
    }

    // Duplicate of `collection_token` to be transferred to the display driver.
    let display_duplicate = {
        let (local, remote) = create_endpoints::<BufferCollectionTokenMarker>()?;
        collection_token.duplicate(std::u32::MAX, remote)?;
        collection_token.sync().await?;
        local
    };

    // Register the collection with the display driver.
    let id = ctrl.import_buffer_collection(display_duplicate).await?;

    // Tell sysmem to perform the buffer allocation and wait for the result. Clean up on error.
    match allocate_image_buffer_helper(params, allocator, collection_token).await {
        Ok((info, proxy)) => Ok(BufferCollection { id, info, proxy, ctrl, released: false }),
        Err(error) => {
            let _ = ctrl.release_buffer_collection(id);
            Err(error)
        }
    }
}
// Allocate a sysmem buffer collection and register it with the display driver. The allocated
// buffer can be used to construct a display layer image.
Allocate a sysmem buffer collection and register it with the display driver. The allocated
buffer can be used to construct a display layer image.
Allocate a sysmem buffer collection and register it with the display driver . The allocated buffer can be used to construct a display layer image .
async fn allocate_image_buffer(
    ctrl: Controller,
    params: &ImageParameters,
) -> Result<BufferCollection> {
    let allocator =
        connect_to_protocol::<AllocatorMarker>().map_err(|_| Error::SysmemConnection)?;
    {
        let name = fuchsia_runtime::process_self().get_name()?;
        let koid = fuchsia_runtime::process_self().get_koid()?;
        allocator.set_debug_client_info(name.to_str()?, koid.raw_koid())?;
    }
    let collection_token = {
        let (proxy, remote) = create_proxy::<BufferCollectionTokenMarker>()?;
        allocator.allocate_shared_collection(remote)?;
        proxy
    };
    // TODO(armansito): The priority number here is arbitrary but I don't expect there to be
    // contention for the assigned name as this client library should be the collection's sole
    // owner. Still, come up with a better way to assign this.
    if let Some(ref name) = params.name {
        collection_token.set_name(100, name.as_str())?;
    }
    // Duplicate of `collection_token` to be transferred to the display driver.
    let display_duplicate = {
        let (local, remote) = create_endpoints::<BufferCollectionTokenMarker>()?;
        collection_token.duplicate(std::u32::MAX, remote)?;
        collection_token.sync().await?;
        local
    };
    // Register the collection with the display driver.
    let id = ctrl.import_buffer_collection(display_duplicate).await?;
    // Tell sysmem to perform the buffer allocation and wait for the result. Clean up on error.
    match allocate_image_buffer_helper(params, allocator, collection_token).await {
        Ok((info, proxy)) => Ok(BufferCollection { id, info, proxy, ctrl, released: false }),
        Err(error) => {
            let _ = ctrl.release_buffer_collection(id);
            Err(error)
        }
    }
}
async fn allocate_image_buffer ( ctrl : Controller , params : & ImageParameters , ) -> Result < BufferCollection > { let allocator = connect_to_protocol :: < AllocatorMarker > ( ) . map_err ( | _ | Error :: SysmemConnection ) ? ; { let name = fuchsia_runtime :: process_self ( ) . get_name ( ) ? ; let koid = fuchsia_runtime :: process_self ( ) . get_koid ( ) ? ; allocator . set_debug_client_info ( name . to_str ( ) ? , koid . raw_koid ( ) ) ? ; } let collection_token = { let ( proxy , remote ) = create_proxy :: < BufferCollectionTokenMarker > ( ) ? ; allocator . allocate_shared_collection ( remote ) ? ; proxy } ; // TODO(armansito): The priority number here is arbitrary but I don't expect there to be // contention for the assigned name as this client library should be the collection's sole // owner. Still, come up with a better way to assign this. if let Some ( ref name ) = params . name { collection_token . set_name ( 100 , name . as_str ( ) ) ? ; } // Duplicate of `collection_token` to be transferred to the display driver. let display_duplicate = { let ( local , remote ) = create_endpoints :: < BufferCollectionTokenMarker > ( ) ? ; collection_token . duplicate ( std :: u32 :: MAX , remote ) ? ; collection_token . sync ( ) . await ? ; local } ; // Register the collection with the display driver. let id = ctrl . import_buffer_collection ( display_duplicate ) . await ? ; // Tell sysmem to perform the buffer allocation and wait for the result. Clean up on error. match allocate_image_buffer_helper ( params , allocator , collection_token ) . await { Ok ( ( info , proxy ) ) => Ok ( BufferCollection { id , info , proxy , ctrl , released : false } ) , Err ( error ) => { let _ = ctrl . release_buffer_collection ( id ) ; Err ( error ) } } }
Allocate a sysmem buffer collection and register it with the display driver.
Allocate a sysmem buffer collection and register it with the display driver .
ctrl
Controller
params
&ImageParameters
ctrl
Controller
params
&ImageParameters