Advertisement
Guest User

Untitled

a guest
Dec 2nd, 2020
334
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.16 KB | None | 0 0
  1. __int64 __fastcall AcquireNextFrame(void* pThis, unsigned int timeout, void* pFrameInfo, IDXGIResource** ppDesktopResource)
  2. {
  3.     __int64 ret = pAcquireNextFrame(pThis, timeout, pFrameInfo, ppDesktopResource);
  4.  
  5.     if (*ppDesktopResource == 0)
  6.     {
  7.         return ret;
  8.     }
  9.  
  10.     ID3D11Texture2D *AcquiredDesktopImage;
  11.     HRESULT res = (*ppDesktopResource)->QueryInterface(__uuidof(ID3D11Texture2D), reinterpret_cast<void**>(&AcquiredDesktopImage));
  12.  
  13.     if (res != S_OK)
  14.     {
  15.         char* nDbg = new char[255];
  16.         sprintf(nDbg, "Query Interface Failed: %08X", res);
  17.         MessageBoxA(NULL, nDbg, "ERROR", MB_OK);
  18.         return ret;
  19.     }
  20.  
  21.     ID3D11Device* pDevice;
  22.     AcquiredDesktopImage->GetDevice(&pDevice);
  23.  
  24.     D3D11_TEXTURE2D_DESC desc;
  25.     AcquiredDesktopImage->GetDesc(&desc);
  26.  
  27.     D3D11_SUBRESOURCE_DATA tbsd;
  28.  
  29.     int w = desc.Width;
  30.     int h = desc.Height;
  31.     int bpp = 4;
  32.     int* buf = new int[w * h];
  33.  
  34.     // filling the image
  35.     for (int i = 0; i < h; i++)
  36.         for (int j = 0; j < w; j++)
  37.         {
  38.             if ((i & 32) == (j & 32))
  39.                 buf[i * w + j] = 0x00000000;
  40.             else
  41.                 buf[i * w + j] = 0xffffffff;
  42.         }
  43.  
  44.     // setting up D3D11_SUBRESOURCE_DATA
  45.     tbsd.pSysMem = (void*)buf;
  46.     tbsd.SysMemPitch = w * bpp;
  47.     tbsd.SysMemSlicePitch = w * h * bpp; // Not needed since this is a 2d texture
  48.  
  49.     if (tex2d == NULL)
  50.     {
  51.  
  52.         if (FAILED(pDevice->CreateTexture2D(&desc, &tbsd, &tex2d)))
  53.         {
  54.             char* nDbg = new char[255];
  55.             sprintf(nDbg, "CreateTexture2D Failed %08X", GetLastError());
  56.             MessageBoxA(NULL, nDbg, "ERROR", MB_OK);
  57.             return ret;
  58.         }
  59.     }
  60.  
  61. if (FAILED(tex2d->QueryInterface(__uuidof(IDXGIResource), reinterpret_cast<void**>(ppDesktopResource))))
  62.     {
  63.         char* nDbg = new char[255];
  64.         sprintf(nDbg, "QueryInterface Failed: %08X", GetLastError());
  65.         MessageBoxA(NULL, nDbg, "ERROR", MB_OK);
  66.         tex2d->Release();
  67.         AcquiredDesktopImage->Release();
  68.         return ret;
  69.     }
  70.     else
  71.     {
  72.         AcquiredDesktopImage->Release();
  73.     }
  74.  
  75.     return ret;
  76. }
  77.  
  78.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement