#pragma once
#include <d3d11.h>
#include <dxgi1_2.h>
#include <string>
#include <vector>
#pragma comment(lib, "d3d11.lib")
#pragma comment(lib, "dxgi.lib")


class DXGIDuplicator
{
public:
    DXGIDuplicator();
    ~DXGIDuplicator();
    bool InitD3D11Device(ID3D11Device* g_pd3dDevice,ID3D11DeviceContext* g_pImmediateContext);
    bool InitDuplication();
    HRESULT GetDesktopFrame(ID3D11Texture2D*& texture);
    ID3D11Texture2D* ConvertFormat(ID3D11Texture2D* pSrcTexture, DXGI_FORMAT fmt = DXGI_FORMAT_R8G8B8A8_UNORM);
    std::vector<uint8_t> GenerateBitmapFile(ID3D11Texture2D* texture2D);

    void* MapBuffer(ID3D11Texture2D* texture2D);
    void UnMapBuffer(ID3D11Texture2D* texture2D);
    HRESULT FreeFrame();
private:
    int frameRef = 0;
    ID3D11Device* device_ = nullptr;
    ID3D11DeviceContext* deviceContext_ = nullptr;
    IDXGIOutputDuplication* duplication_ = nullptr;
};

