pub(crate) unsafe fn create_render_target_dxgi(
    d2d_factory: &D2DFactory,
    swap_chain: *mut IDXGISwapChain1,
    scale: Scale,
    transparent: bool,
) -> Result<DxgiSurfaceRenderTarget, Error> {
    let mut buffer: *mut IDXGISurface = null_mut();
    as_result((*swap_chain).GetBuffer(
        0,
        &IDXGISurface::uuidof(),
        &mut buffer as *mut _ as *mut *mut c_void,
    ))?;
    let props = D2D1_RENDER_TARGET_PROPERTIES {
        _type: D2D1_RENDER_TARGET_TYPE_DEFAULT,
        pixelFormat: D2D1_PIXEL_FORMAT {
            format: DXGI_FORMAT_B8G8R8A8_UNORM,
            alphaMode: if transparent {
                D2D1_ALPHA_MODE_PREMULTIPLIED
            } else {
                D2D1_ALPHA_MODE_IGNORE
            },
        },
        dpiX: (scale.x() * SCALE_TARGET_DPI) as f32,
        dpiY: (scale.y() * SCALE_TARGET_DPI) as f32,
        usage: D2D1_RENDER_TARGET_USAGE_NONE,
        minLevel: D2D1_FEATURE_LEVEL_DEFAULT,
    };

    let mut render_target: *mut ID2D1RenderTarget = null_mut();
    let res =
        (*d2d_factory.get_raw()).CreateDxgiSurfaceRenderTarget(buffer, &props, &mut render_target);
    (*buffer).Release();
    if SUCCEEDED(res) {
        // TODO: maybe use builder
        Ok(DxgiSurfaceRenderTarget::from_raw(render_target))
    } else {
        Err(res.into())
    }
}
/// Create a render target from a DXGI swapchain.
///
/// TODO: probably want to create a DeviceContext, it's more flexible.
Create a render target from a DXGI swapchain.
TODO: probably want to create a DeviceContext, it's more flexible.
Create a render target from a DXGI swapchain . TODO : probably want to create a DeviceContext it ' s more flexible .
pub(crate) unsafe fn create_render_target_dxgi(
    d2d_factory: &D2DFactory,
    swap_chain: *mut IDXGISwapChain1,
    scale: Scale,
    transparent: bool,
) -> Result<DxgiSurfaceRenderTarget, Error> {
    let mut buffer: *mut IDXGISurface = null_mut();
    as_result((*swap_chain).GetBuffer(
        0,
        &IDXGISurface::uuidof(),
        &mut buffer as *mut _ as *mut *mut c_void,
    ))?;
    let props = D2D1_RENDER_TARGET_PROPERTIES {
        _type: D2D1_RENDER_TARGET_TYPE_DEFAULT,
        pixelFormat: D2D1_PIXEL_FORMAT {
            format: DXGI_FORMAT_B8G8R8A8_UNORM,
            alphaMode: if transparent {
                D2D1_ALPHA_MODE_PREMULTIPLIED
            } else {
                D2D1_ALPHA_MODE_IGNORE
            },
        },
        dpiX: (scale.x() * SCALE_TARGET_DPI) as f32,
        dpiY: (scale.y() * SCALE_TARGET_DPI) as f32,
        usage: D2D1_RENDER_TARGET_USAGE_NONE,
        minLevel: D2D1_FEATURE_LEVEL_DEFAULT,
    };
    let mut render_target: *mut ID2D1RenderTarget = null_mut();
    let res =
        (*d2d_factory.get_raw()).CreateDxgiSurfaceRenderTarget(buffer, &props, &mut render_target);
    (*buffer).Release();
    if SUCCEEDED(res) {
        // TODO: maybe use builder
        Ok(DxgiSurfaceRenderTarget::from_raw(render_target))
    } else {
        Err(res.into())
    }
}
pub ( crate ) unsafe fn create_render_target_dxgi ( d2d_factory : & D2DFactory , swap_chain : * mut IDXGISwapChain1 , scale : Scale , transparent : bool , ) -> Result < DxgiSurfaceRenderTarget , Error > { let mut buffer : * mut IDXGISurface = null_mut ( ) ; as_result ( ( * swap_chain ) . GetBuffer ( 0 , & IDXGISurface :: uuidof ( ) , & mut buffer as * mut _ as * mut * mut c_void , ) ) ? ; let props = D2D1_RENDER_TARGET_PROPERTIES { _type : D2D1_RENDER_TARGET_TYPE_DEFAULT , pixelFormat : D2D1_PIXEL_FORMAT { format : DXGI_FORMAT_B8G8R8A8_UNORM , alphaMode : if transparent { D2D1_ALPHA_MODE_PREMULTIPLIED } else { D2D1_ALPHA_MODE_IGNORE } , } , dpiX : ( scale . x ( ) * SCALE_TARGET_DPI ) as f32 , dpiY : ( scale . y ( ) * SCALE_TARGET_DPI ) as f32 , usage : D2D1_RENDER_TARGET_USAGE_NONE , minLevel : D2D1_FEATURE_LEVEL_DEFAULT , } ; let mut render_target : * mut ID2D1RenderTarget = null_mut ( ) ; let res = ( * d2d_factory . get_raw ( ) ) . CreateDxgiSurfaceRenderTarget ( buffer , & props , & mut render_target ) ; ( * buffer ) . Release ( ) ; if SUCCEEDED ( res ) { // TODO: maybe use builder Ok ( DxgiSurfaceRenderTarget :: from_raw ( render_target ) ) } else { Err ( res . into ( ) ) } }
Create a render target from a DXGI swapchain.
Create a render target from a DXGI swapchain .
d2d_factory
&D2DFactory
swap_chain
*mut IDXGISwapChain1
scale
Scale
transparent
bool
d2d_factory
&D2DFactory
swap_chain
*mut IDXGISwapChain1
scale
Scale
transparent
bool