BgkNotifyDisplayOwnershipChange

__int64 __fastcall BgkNotifyDisplayOwnershipChange(VOID *a1, __int64 (__fastcall *a2)(_QWORD, _QWORD, _QWORD)){
  __int64 result; 
  int v3; 
  int v4; 
  UINT64 v5; 
  void *Interface; 
  __int64(*v7)(void); 
  INT64 v8[2]; 
  __int128 v9; 
  __int64 v10; 
  result = 0i64;
  *(_OWORD *)v8 = 0i64;
  v10 = 0i64;
  v9 = 0i64;
  if( byte_140C50390 && !(_BYTE)a1 )
  {
    BgkResumeFinished(a1);
    qword_140C508D8 = 0i64;
    result = 0i64;
    byte_140C508E1 = 0;
    return result;
  }
  if( (_BYTE)a1 != byte_140C508E1 )
  {
    if( !(_BYTE)a1 )
    {
      if( a2 )
      {
        qword_140C508C8 = a2;
      }
      else if( !qword_140C508C8 )
      {
        return 3221225712i64;
      }
      BgDisplayFade();
      byte_140C50485 = 0;
      byte_140C50484 = 0;
      ExWaitForRundownProtectionRelease(&stru_140C11248);
      ExRundownCompleted(&stru_140C11248);
      v3 = BgLibraryDisable();
      if( v3 < 0 )
      {
        BgkDestroy();
        InbvSetFunction(3);
        v3 = 0;
      }
      else
      {
        byte_140C508E1 = 0;
        byte_140C508D0 = 0;
        if( ConsoleInterface )
        {
          BgConsoleDestroyInterface(ConsoleInterface);
          ConsoleInterface = 0i64;
        }
      }
      BgSetFrameBufferAccess(0i64, 0i64, 0i64);
      BgkpUnlockBgfxCodeSection();
      if( qword_140C508D8 )
      {
        qword_140C508D8();
        qword_140C508D8 = 0i64;
      }
      return(unsigned int)v3;
    }
    if( !qword_140C508C8 )
      return 3221225473i64;
    v7 = 0i64;
    result = qword_140C508C8(0i64, v8, &v7);
    if( (int)result >= 0 )
    {
      qword_140C508D8 = v7;
      BgkpLockBgfxCodeSection();
      v4 = BgLibraryEnable((INT64)v8, 0);
      v5 = (unsigned __int8)byte_140C508E1;
      v3 = v4;
      if( v4 >= 0 )
        v5 = 1i64;
      byte_140C508E1 = v5;
      Interface = BgConsoleGetInterface(v5);
      ConsoleInterface = Interface;
      if( Interface )
        (*(void(__fastcall **)(_QWORD, __int64, _QWORD, _QWORD))Interface)(
          0i64,
          4291217094i64,
          (unsigned int)dword_140CF5080,
          0i64);
      BgkpTryEnableConsole();
      return(unsigned int)v3;
    }
  }
  return result;
}

Referenced by:

BgkNotifyDisplayOwnershipLost
BgkSetDisplayOwnership
BvgaNotifyDisplayOwnershipChange