unsafe fn initialize_dx(
    present_trampoline: DXGISwapChainPresentType,
    p_this: *mut IDXGISwapChain,
    render_loop: Box<dyn RenderLoop>,
  ) -> Result<DxgiHook> {
    trace!("Initializing DXGI hook");

    let this = &*p_this;
    let mut p_device: *mut ID3D11Device = null_mut();
    let mut p_device_context: *mut ID3D11DeviceContext = null_mut();
    let mut sd: DXGI_SWAP_CHAIN_DESC = std::mem::zeroed();
    let mut back_buf: *mut ID3D11Texture2D = null_mut();
    let mut render_target_view: *mut ID3D11RenderTargetView = null_mut();

    let mut lpc: UINT = 0;
    this.GetLastPresentCount(&mut lpc);

    let result = this.GetDevice(&ID3D11Device::uuidof(), cast_dptr(&mut p_device));
    if result < 0 {
      return Err(Error(format!(
        "Get device + ctx from swap chain failed: {:?} {:?}",
        result, p_this
      )));
    };

    (*p_device).GetImmediateContext(&mut p_device_context);

    this.GetDesc(&mut sd as _);

    #[allow(clippy::fn_to_numeric_cast)]
    let default_wnd_proc = std::mem::transmute(SetWindowLongPtrA(
      sd.OutputWindow,
      GWLP_WNDPROC,
      wnd_proc as _,
    ));

    let mut imgui_ctx = imgui::Context::create();
    imgui_ctx.set_ini_filename(None);
    imgui_ctx
      .fonts()
      .add_font(&[imgui::FontSource::DefaultFontData {
        config: Some(imgui::FontConfig {
          ..imgui::FontConfig::default()
        }),
      }]);
    imgui_ctx
      .fonts()
      .add_font(&[imgui::FontSource::DefaultFontData {
        config: Some(imgui::FontConfig {
          size_pixels: 26.,
          ..imgui::FontConfig::default()
        }),
      }]);

    let renderer = imgui_impl::dx11::Renderer::new(p_device, p_device_context, &mut imgui_ctx)?;

    this.GetBuffer(
      0,
      &ID3D11Texture2D::uuidof(),
      &mut back_buf as *mut *mut _ as _,
    );
    (*p_device).CreateRenderTargetView(
      back_buf as _,
      null_mut(),
      &mut render_target_view as *mut *mut _ as _,
    );
    (*back_buf).Release();

    trace!("Initialization completed");
    Ok(DxgiHook {
      present_trampoline,
      default_wnd_proc,
      p_device_context,
      render_target_view,
      imgui_ctx,
      renderer,
      render_loop,
    })
  }
/// Initialize the DXGI hook.
// TODO URGENT if Result is Err, caller must call present_trampoline
Initialize the DXGI hook.
TODO URGENT if Result is Err, caller must call present_trampoline
Initialize the DXGI hook . TODO URGENT if Result is Err caller must call present_trampoline
unsafe fn initialize_dx(
    present_trampoline: DXGISwapChainPresentType,
    p_this: *mut IDXGISwapChain,
    render_loop: Box<dyn RenderLoop>,
  ) -> Result<DxgiHook> {
    trace!("Initializing DXGI hook");
    let this = &*p_this;
    let mut p_device: *mut ID3D11Device = null_mut();
    let mut p_device_context: *mut ID3D11DeviceContext = null_mut();
    let mut sd: DXGI_SWAP_CHAIN_DESC = std::mem::zeroed();
    let mut back_buf: *mut ID3D11Texture2D = null_mut();
    let mut render_target_view: *mut ID3D11RenderTargetView = null_mut();
    let mut lpc: UINT = 0;
    this.GetLastPresentCount(&mut lpc);
    let result = this.GetDevice(&ID3D11Device::uuidof(), cast_dptr(&mut p_device));
    if result < 0 {
      return Err(Error(format!(
        "Get device + ctx from swap chain failed: {:?} {:?}",
        result, p_this
      )));
    };
    (*p_device).GetImmediateContext(&mut p_device_context);
    this.GetDesc(&mut sd as _);
    #[allow(clippy::fn_to_numeric_cast)]
    let default_wnd_proc = std::mem::transmute(SetWindowLongPtrA(
      sd.OutputWindow,
      GWLP_WNDPROC,
      wnd_proc as _,
    ));
    let mut imgui_ctx = imgui::Context::create();
    imgui_ctx.set_ini_filename(None);
    imgui_ctx
      .fonts()
      .add_font(&[imgui::FontSource::DefaultFontData {
        config: Some(imgui::FontConfig {
          ..imgui::FontConfig::default()
        }),
      }]);
    imgui_ctx
      .fonts()
      .add_font(&[imgui::FontSource::DefaultFontData {
        config: Some(imgui::FontConfig {
          size_pixels: 26.,
          ..imgui::FontConfig::default()
        }),
      }]);
    let renderer = imgui_impl::dx11::Renderer::new(p_device, p_device_context, &mut imgui_ctx)?;
    this.GetBuffer(
      0,
      &ID3D11Texture2D::uuidof(),
      &mut back_buf as *mut *mut _ as _,
    );
    (*p_device).CreateRenderTargetView(
      back_buf as _,
      null_mut(),
      &mut render_target_view as *mut *mut _ as _,
    );
    (*back_buf).Release();
    trace!("Initialization completed");
    Ok(DxgiHook {
      present_trampoline,
      default_wnd_proc,
      p_device_context,
      render_target_view,
      imgui_ctx,
      renderer,
      render_loop,
    })
  }
unsafe fn initialize_dx ( present_trampoline : DXGISwapChainPresentType , p_this : * mut IDXGISwapChain , render_loop : Box < dyn RenderLoop > , ) -> Result < DxgiHook > { trace ! ( " " ) ; let this = & * p_this ; let mut p_device : * mut ID3D11Device = null_mut ( ) ; let mut p_device_context : * mut ID3D11DeviceContext = null_mut ( ) ; let mut sd : DXGI_SWAP_CHAIN_DESC = std :: mem :: zeroed ( ) ; let mut back_buf : * mut ID3D11Texture2D = null_mut ( ) ; let mut render_target_view : * mut ID3D11RenderTargetView = null_mut ( ) ; let mut lpc : UINT = 0 ; this . GetLastPresentCount ( & mut lpc ) ; let result = this . GetDevice ( & ID3D11Device :: uuidof ( ) , cast_dptr ( & mut p_device ) ) ; if result < 0 { return Err ( Error ( format ! ( " " result p_this ) ) ) ; } ; ( * p_device ) . GetImmediateContext ( & mut p_device_context ) ; this . GetDesc ( & mut sd as _ ) ; # [ allow ( clippy fn_to_numeric_cast ) ] let default_wnd_proc = std :: mem :: transmute ( SetWindowLongPtrA ( sd . OutputWindow , GWLP_WNDPROC , wnd_proc as _ , ) ) ; let mut imgui_ctx = imgui :: Context :: create ( ) ; imgui_ctx . set_ini_filename ( None ) ; imgui_ctx . fonts ( ) . add_font ( & [ imgui :: FontSource :: DefaultFontData { config : Some ( imgui :: FontConfig { .. imgui :: FontConfig :: default ( ) } ) , } ] ) ; imgui_ctx . fonts ( ) . add_font ( & [ imgui :: FontSource :: DefaultFontData { config : Some ( imgui :: FontConfig { size_pixels : 26. , .. imgui :: FontConfig :: default ( ) } ) , } ] ) ; let renderer = imgui_impl :: dx11 :: Renderer :: new ( p_device , p_device_context , & mut imgui_ctx ) ? ; this . GetBuffer ( 0 , & ID3D11Texture2D :: uuidof ( ) , & mut back_buf as * mut * mut _ as _ , ) ; ( * p_device ) . CreateRenderTargetView ( back_buf as _ , null_mut ( ) , & mut render_target_view as * mut * mut _ as _ , ) ; ( * back_buf ) . Release ( ) ; trace ! ( " " ) ; Ok ( DxgiHook { present_trampoline , default_wnd_proc , p_device_context , render_target_view , imgui_ctx , renderer , render_loop , } ) }
Initialize the DXGI hook.
Initialize the DXGI hook .
present_trampoline
DXGISwapChainPresentType
p_this
*mut IDXGISwapChain
render_loop
Box<dyn RenderLoop>
present_trampoline
DXGISwapChainPresentType
p_this
*mut IDXGISwapChain
render_loop
Box<dyn RenderLoop>