summaryrefslogtreecommitdiffstats
path: root/video/out/gpu
diff options
context:
space:
mode:
authorJames Ross-Gowan <rossy@jrg.systems>2018-02-12 21:08:17 +1100
committerJames Ross-Gowan <rossy@jrg.systems>2018-02-13 21:25:15 +1100
commit1b80e124dbec1c4bb80b8ce4aaeb84ff841f9b6d (patch)
tree15afbd5e96cd783ee51bc55607d1c17da4fe76fc /video/out/gpu
parent7d2228c6738b8793bc616c9436cdc7a1cf149a79 (diff)
downloadmpv-1b80e124dbec1c4bb80b8ce4aaeb84ff841f9b6d.tar.bz2
mpv-1b80e124dbec1c4bb80b8ce4aaeb84ff841f9b6d.tar.xz
vo_gpu: d3d11: implement tex_download()
This allows the new GPU screenshot functionality introduced in 9f595f3a80ee to work with the D3D11 backend. It replaces the old window screenshot functionality, which was shared between D3D11 and ANGLE. The old code can be removed, since it's not needed by ANGLE anymore either.
Diffstat (limited to 'video/out/gpu')
-rw-r--r--video/out/gpu/d3d11_helpers.c81
-rw-r--r--video/out/gpu/d3d11_helpers.h2
2 files changed, 0 insertions, 83 deletions
diff --git a/video/out/gpu/d3d11_helpers.c b/video/out/gpu/d3d11_helpers.c
index 7bdd3c2eaa..d267ac3009 100644
--- a/video/out/gpu/d3d11_helpers.c
+++ b/video/out/gpu/d3d11_helpers.c
@@ -374,84 +374,3 @@ done:
SAFE_RELEASE(dxgi_dev);
return success;
}
-
-struct mp_image *mp_d3d11_screenshot(IDXGISwapChain *swapchain)
-{
- ID3D11Device *dev = NULL;
- ID3D11DeviceContext *ctx = NULL;
- ID3D11Texture2D *frontbuffer = NULL;
- ID3D11Texture2D *staging = NULL;
- struct mp_image *img = NULL;
- HRESULT hr;
-
- // Validate the swap chain. This screenshot method will only work on DXGI
- // 1.2+ flip/sequential swap chains. It's probably not possible at all with
- // discard swap chains, since by definition, the backbuffer contents is
- // discarded on Present().
- DXGI_SWAP_CHAIN_DESC scd;
- hr = IDXGISwapChain_GetDesc(swapchain, &scd);
- if (FAILED(hr))
- goto done;
- if (scd.SwapEffect != DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL)
- goto done;
-
- // Get the last buffer that was presented with Present(). This should be
- // the n-1th buffer for a swap chain of length n.
- hr = IDXGISwapChain_GetBuffer(swapchain, scd.BufferCount - 1,
- &IID_ID3D11Texture2D, (void**)&frontbuffer);
- if (FAILED(hr))
- goto done;
-
- ID3D11Texture2D_GetDevice(frontbuffer, &dev);
- ID3D11Device_GetImmediateContext(dev, &ctx);
-
- D3D11_TEXTURE2D_DESC td;
- ID3D11Texture2D_GetDesc(frontbuffer, &td);
- if (td.SampleDesc.Count > 1)
- goto done;
-
- // Validate the backbuffer format and convert to an mpv IMGFMT
- enum mp_imgfmt fmt;
- switch (td.Format) {
- case DXGI_FORMAT_B8G8R8A8_UNORM: fmt = IMGFMT_BGR0; break;
- case DXGI_FORMAT_R8G8B8A8_UNORM: fmt = IMGFMT_RGB0; break;
- default:
- goto done;
- }
-
- // Create a staging texture based on the frontbuffer with CPU access
- td.BindFlags = 0;
- td.MiscFlags = 0;
- td.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
- td.Usage = D3D11_USAGE_STAGING;
- hr = ID3D11Device_CreateTexture2D(dev, &td, 0, &staging);
- if (FAILED(hr))
- goto done;
-
- ID3D11DeviceContext_CopyResource(ctx, (ID3D11Resource*)staging,
- (ID3D11Resource*)frontbuffer);
-
- // Attempt to map the staging texture to CPU-accessible memory
- D3D11_MAPPED_SUBRESOURCE lock;
- hr = ID3D11DeviceContext_Map(ctx, (ID3D11Resource*)staging, 0,
- D3D11_MAP_READ, 0, &lock);
- if (FAILED(hr))
- goto done;
-
- img = mp_image_alloc(fmt, td.Width, td.Height);
- if (!img)
- return NULL;
- for (int i = 0; i < td.Height; i++) {
- memcpy(img->planes[0] + img->stride[0] * i,
- (char*)lock.pData + lock.RowPitch * i, td.Width * 4);
- }
-
- ID3D11DeviceContext_Unmap(ctx, (ID3D11Resource*)staging, 0);
-
-done:
- SAFE_RELEASE(frontbuffer);
- SAFE_RELEASE(staging);
- SAFE_RELEASE(ctx);
- SAFE_RELEASE(dev);
- return img;
-}
diff --git a/video/out/gpu/d3d11_helpers.h b/video/out/gpu/d3d11_helpers.h
index 481c183b4d..996b93494f 100644
--- a/video/out/gpu/d3d11_helpers.h
+++ b/video/out/gpu/d3d11_helpers.h
@@ -78,6 +78,4 @@ bool mp_d3d11_create_swapchain(ID3D11Device *dev, struct mp_log *log,
struct d3d11_swapchain_opts *opts,
IDXGISwapChain **swapchain_out);
-struct mp_image *mp_d3d11_screenshot(IDXGISwapChain *swapchain);
-
#endif