Path: blob/21.2-virgl/src/gallium/frontends/d3d10umd/Dxgi.cpp
4565 views
/**************************************************************************1*2* Copyright 2012-2021 VMware, Inc.3* All Rights Reserved.4*5* Permission is hereby granted, free of charge, to any person obtaining a6* copy of this software and associated documentation files (the7* "Software"), to deal in the Software without restriction, including8* without limitation the rights to use, copy, modify, merge, publish,9* distribute, sub license, and/or sell copies of the Software, and to10* permit persons to whom the Software is furnished to do so, subject to11* the following conditions:12*13* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR14* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,15* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL16* THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,17* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR18* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE19* USE OR OTHER DEALINGS IN THE SOFTWARE.20*21* The above copyright notice and this permission notice (including the22* next paragraph) shall be included in all copies or substantial portions23* of the Software.24*25**************************************************************************/2627/*28* Dxgi.cpp --29* DXGI related functions.30*/3132#include <stdio.h>3334#include "Dxgi.h"35#include "Format.h"36#include "State.h"3738#include "Debug.h"3940#include "util/format/u_format.h"414243/*44* ----------------------------------------------------------------------45*46* _Present --47*48* This is turned into kernel callbacks rather than directly emitted49* as fifo packets.50*51* ----------------------------------------------------------------------52*/5354HRESULT APIENTRY55_Present(DXGI_DDI_ARG_PRESENT *pPresentData)56{5758LOG_ENTRYPOINT();5960struct pipe_context *pipe = CastPipeDevice(pPresentData->hDevice);61Resource *pSrcResource = CastResource(pPresentData->hSurfaceToPresent);6263D3DKMT_PRESENT *pPresentInfo = (D3DKMT_PRESENT *)pPresentData->pDXGIContext;6465HWND hWnd = pPresentInfo->hWindow;6667if (0) {68DebugPrintf(" hWindow = 0x%08lx\n", pPresentInfo->hWindow);69if (pPresentInfo->Flags.SrcRectValid) {70DebugPrintf(" SrcRect.left = %li\n", pPresentInfo->SrcRect.left);71DebugPrintf(" SrcRect.top = %li\n", pPresentInfo->SrcRect.top);72DebugPrintf(" SrcRect.right = %li\n", pPresentInfo->SrcRect.right);73DebugPrintf(" SrcRect.bottom = %li\n", pPresentInfo->SrcRect.bottom);74}75if (pPresentInfo->Flags.DstRectValid) {76DebugPrintf(" DstRect.left = %li\n", pPresentInfo->DstRect.left);77DebugPrintf(" DstRect.top = %li\n", pPresentInfo->DstRect.top);78DebugPrintf(" DstRect.right = %li\n", pPresentInfo->DstRect.right);79DebugPrintf(" DstRect.bottom = %li\n", pPresentInfo->DstRect.bottom);80}81}8283RECT rect;84if (!GetClientRect(hWnd, &rect)) {85DebugPrintf("Invalid window.\n");86return S_OK;87}8889int windowWidth = rect.right - rect.left;90int windowHeight = rect.bottom - rect.top;9192HDC hDC = GetDC(hWnd);9394unsigned w = pSrcResource->resource->width0;95unsigned h = pSrcResource->resource->height0;9697void *map;98struct pipe_transfer *transfer;99map = pipe_transfer_map(pipe,100pSrcResource->resource,1010, 0, PIPE_MAP_READ,1020, 0, w, h,103&transfer);104if (map) {105106BITMAPINFO bmi;107108memset(&bmi, 0, sizeof bmi);109bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);110bmi.bmiHeader.biWidth = w;111bmi.bmiHeader.biHeight= -(long)h;112bmi.bmiHeader.biPlanes = 1;113bmi.bmiHeader.biBitCount = 32;114bmi.bmiHeader.biCompression = BI_RGB;115bmi.bmiHeader.biSizeImage = 0;116bmi.bmiHeader.biXPelsPerMeter = 0;117bmi.bmiHeader.biYPelsPerMeter = 0;118bmi.bmiHeader.biClrUsed = 0;119bmi.bmiHeader.biClrImportant = 0;120121DWORD *pixels = NULL;122123// http://www.daniweb.com/software-development/cpp/code/241875/fast-animation-with-the-windows-gdi124125HBITMAP hBmp = CreateDIBSection(hDC, &bmi, DIB_RGB_COLORS, (void**)&pixels, NULL, 0);126127util_format_translate(128PIPE_FORMAT_B8G8R8X8_UNORM,129(void *)pixels, w * 4,1300, 0,131pSrcResource->resource->format,132map, transfer->stride,1330, 0, w, h);134135if (0) {136/*137* Save a BMP for debugging.138*/139140FILE *fp = fopen("present.bmp", "wb");141if (fp) {142BITMAPFILEHEADER bmf;143bmf.bfType = 0x4d42;144bmf.bfSize = sizeof bmf + sizeof bmi + h * w * 4;145bmf.bfReserved1 = 0;146bmf.bfReserved2 = 0;147bmf.bfOffBits = sizeof bmf + sizeof bmi;148149fwrite(&bmf, sizeof bmf, 1, fp);150fwrite(&bmi, sizeof bmi, 1, fp);151fwrite(pixels, h, w * 4, fp);152fclose(fp);153}154}155156HDC hdcMem;157hdcMem = CreateCompatibleDC(hDC);158HBITMAP hbmOld = (HBITMAP)SelectObject(hdcMem, hBmp);159160int iStretchMode = SetStretchBltMode(hDC, HALFTONE);161162StretchBlt(hDC, 0, 0, windowWidth, windowHeight,163hdcMem, 0, 0, w, h,164SRCCOPY);165166if (iStretchMode) {167SetStretchBltMode(hDC, iStretchMode);168}169170SelectObject(hdcMem, hbmOld);171DeleteDC(hdcMem);172DeleteObject(hBmp);173174pipe_transfer_unmap(pipe, transfer);175}176177ReleaseDC(hWnd, hDC);178179return S_OK;180}181182183/*184* ----------------------------------------------------------------------185*186* _GetGammaCaps --187*188* Return gamma capabilities.189*190* ----------------------------------------------------------------------191*/192193HRESULT APIENTRY194_GetGammaCaps( DXGI_DDI_ARG_GET_GAMMA_CONTROL_CAPS *GetCaps )195{196LOG_ENTRYPOINT();197198DXGI_GAMMA_CONTROL_CAPABILITIES *pCaps;199200pCaps = GetCaps->pGammaCapabilities;201202pCaps->ScaleAndOffsetSupported = FALSE;203pCaps->MinConvertedValue = 0.0;204pCaps->MaxConvertedValue = 1.0;205pCaps->NumGammaControlPoints = 17;206207for (UINT i = 0; i < pCaps->NumGammaControlPoints; i++) {208pCaps->ControlPointPositions[i] = (float)i / (float)(pCaps->NumGammaControlPoints - 1);209}210211return S_OK;212}213214215/*216* ----------------------------------------------------------------------217*218* _SetDisplayMode --219*220* Set the resource that is used to scan out to the display.221*222* ----------------------------------------------------------------------223*/224225HRESULT APIENTRY226_SetDisplayMode( DXGI_DDI_ARG_SETDISPLAYMODE *SetDisplayMode )227{228LOG_UNSUPPORTED_ENTRYPOINT();229230return S_OK;231}232233234/*235* ----------------------------------------------------------------------236*237* _SetResourcePriority --238*239* ----------------------------------------------------------------------240*/241242HRESULT APIENTRY243_SetResourcePriority( DXGI_DDI_ARG_SETRESOURCEPRIORITY *SetResourcePriority )244{245LOG_ENTRYPOINT();246247/* ignore */248249return S_OK;250}251252253/*254* ----------------------------------------------------------------------255*256* _QueryResourceResidency --257*258* ----------------------------------------------------------------------259*/260261HRESULT APIENTRY262_QueryResourceResidency( DXGI_DDI_ARG_QUERYRESOURCERESIDENCY *QueryResourceResidency )263{264LOG_ENTRYPOINT();265266for (UINT i = 0; i < QueryResourceResidency->Resources; ++i) {267QueryResourceResidency->pStatus[i] = DXGI_DDI_RESIDENCY_FULLY_RESIDENT;268}269270return S_OK;271}272273274/*275* ----------------------------------------------------------------------276*277* _RotateResourceIdentities --278*279* Rotate a list of resources by recreating their views with280* the updated rotations.281*282* ----------------------------------------------------------------------283*/284285HRESULT APIENTRY286_RotateResourceIdentities( DXGI_DDI_ARG_ROTATE_RESOURCE_IDENTITIES *RotateResourceIdentities )287{288LOG_ENTRYPOINT();289290if (RotateResourceIdentities->Resources <= 1) {291return S_OK;292}293294struct pipe_context *pipe = CastPipeDevice(RotateResourceIdentities->hDevice);295struct pipe_screen *screen = pipe->screen;296297struct pipe_resource *resource0 = CastPipeResource(RotateResourceIdentities->pResources[0]);298299assert(resource0);300LOG_UNSUPPORTED(resource0->last_level);301302/*303* XXX: Copying is not very efficient, but it is much simpler than the304* alternative of recreating all views.305*/306307struct pipe_resource *temp_resource;308temp_resource = screen->resource_create(screen, resource0);309assert(temp_resource);310if (!temp_resource) {311return E_OUTOFMEMORY;312}313314struct pipe_box src_box;315src_box.x = 0;316src_box.y = 0;317src_box.z = 0;318src_box.width = resource0->width0;319src_box.height = resource0->height0;320src_box.depth = resource0->depth0;321322for (UINT i = 0; i < RotateResourceIdentities->Resources + 1; ++i) {323struct pipe_resource *src_resource;324struct pipe_resource *dst_resource;325326if (i < RotateResourceIdentities->Resources) {327src_resource = CastPipeResource(RotateResourceIdentities->pResources[i]);328} else {329src_resource = temp_resource;330}331332if (i > 0) {333dst_resource = CastPipeResource(RotateResourceIdentities->pResources[i - 1]);334} else {335dst_resource = temp_resource;336}337338assert(dst_resource);339assert(src_resource);340341pipe->resource_copy_region(pipe,342dst_resource,3430, // dst_level3440, 0, 0, // dst_x,y,z345src_resource,3460, // src_level347&src_box);348}349350pipe_resource_reference(&temp_resource, NULL);351352return S_OK;353}354355356/*357* ----------------------------------------------------------------------358*359* _Blt --360*361* Do a blt between two subresources. Apply MSAA resolve, format362* conversion and stretching.363*364* ----------------------------------------------------------------------365*/366367HRESULT APIENTRY368_Blt(DXGI_DDI_ARG_BLT *Blt)369{370LOG_UNSUPPORTED_ENTRYPOINT();371372return S_OK;373}374375376