/** * * Initializes a specific XFlash instance. * The initialization entails: * - Check the Device family type. * - Issuing the CFI query command. * - Get and translate relevant CFI query information. * - Set default options for the instance. * - Setup the VTable. * - Call the family initialize function of the instance. * - Initialize the Xilinx Platform Flash XL to Async mode if the user * selects to use the Platform Flash XL in the MLD. The Platform Flash XL * is an Intel CFI complaint device. * * @param InstancePtr is a pointer to the XFlash instance. * @param BaseAddress is the base address of the flash memory. * @param BusWidth is the total width of the flash memory, in bytes. * @param IsPlatformFlash is used to specify if the flash is a platform * flash. * * @return * - XST_SUCCESS if successful. * - XFLASH_PART_NOT_SUPPORTED if the command set algorithm or * Layout is not supported by any flash family compiled into * the system. * - XFLASH_CFI_QUERY_ERROR if the device would not enter CFI * query mode. Either the device(s) do not support CFI, the wrong * BaseAddress param was used, an unsupported part layout exists, * or a hardware problem exists with the part. * * @note BusWidth is not the width of an individual part. Its the total * operating width. For example, if there are two 16-bit parts, * with one tied to data lines D0-D15 and other tied to D15-D31, * BusWidth would be (32 / 8) = 4. If a single 16-bit flash is in * 8-bit mode, then BusWidth should be (8 / 8) = 1. * ******************************************************************************/ int XFlash_Initialize(XFlash * InstancePtr, u32 BaseAddress, u8 BusWidth, int IsPlatformFlash) { int Status = XST_FAILURE; /* * Validate parameters. */ if(InstancePtr == NULL) { return XST_FAILURE; } if (BusWidth > 8) { return XFLASH_PART_NOT_SUPPORTED; } InstancePtr->IsReady = 0; InstancePtr->Geometry.BaseAddress = BaseAddress; InstancePtr->IsPlatformFlash = IsPlatformFlash; #ifdef XPAR_XFL_DEVICE_FAMILY_INTEL if (IsPlatformFlash == 1) { /* * Set Async mode for platform flash */ WRITE_FLASH_16(InstancePtr->Geometry.BaseAddress + XFL_INTEL_CMD_CONFIG_REG_ASYNC_ADDR, XFL_INTEL_CMD_CONFIG_REG_SETUP); WRITE_FLASH_16(InstancePtr->Geometry.BaseAddress + XFL_INTEL_CMD_CONFIG_REG_ASYNC_ADDR, XFL_INTEL_CMD_CONFIG_REG_CONFIRM); } #endif /* XPAR_XFL_DEVICE_FAMILY_INTEL */ /* * Get CFI data. */ Status = XFlashCFI_ReadCommon(InstancePtr, BusWidth); if (Status != XST_SUCCESS) { return (XFLASH_CFI_QUERY_ERROR); } /* * Set the VTable function pointer based on the command set algorithm * discovered in the CFI query. */ Status = SetVTable(InstancePtr); if (Status != XST_SUCCESS) { return Status; } /* * Initialize the specific flash family device. * If it initializes successfully set the IsReady flag to indicate the * device is ready. */ Status = InstancePtr->VTable.Initialize(InstancePtr); if (Status == XST_SUCCESS) { InstancePtr->IsReady = XIL_COMPONENT_IS_READY; } return Status; }
HRESULT STDMETHODCALLTYPE SwapPresentHook(UINT syncInterval, UINT flags) { IDXGISwapChain *swap = (IDXGISwapChain*)this; if(lpCurrentSwap == NULL && !bTargetAcquired) { lpCurrentSwap = swap; SetupD3D11(swap); bTargetAcquired = true; } if(lpCurrentSwap == swap) { ID3D11Device *device = NULL; HRESULT chi; if(SUCCEEDED(chi = swap->GetDevice(__uuidof(ID3D11Device), (void**)&device))) { if(!lpCurrentDevice) { lpCurrentDevice = device; oldD3D11Release = GetVTable(device, (8/4)); newD3D11Release = ConvertClassProcToFarproc((CLASSPROC)&D3D11Override::DeviceReleaseHook); SetVTable(device, (8/4), newD3D11Release); } ID3D11DeviceContext *context; device->GetImmediateContext(&context); if(!bHasTextures && bCapturing) { if(dxgiFormat) { if(!hwndReceiver) hwndReceiver = FindWindow(RECEIVER_WINDOWCLASS, NULL); if(hwndReceiver) { D3D11_TEXTURE2D_DESC texDesc; ZeroMemory(&texDesc, sizeof(texDesc)); texDesc.Width = d3d11CaptureInfo.cx; texDesc.Height = d3d11CaptureInfo.cy; texDesc.MipLevels = 1; texDesc.ArraySize = 1; texDesc.Format = dxgiFormat; texDesc.SampleDesc.Count = 1; texDesc.Usage = D3D11_USAGE_STAGING; texDesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ; bool bSuccess = true; UINT pitch; for(UINT i=0; i<2; i++) { HRESULT ching; if(FAILED(ching = device->CreateTexture2D(&texDesc, NULL, &d3d11Textures[i]))) { bSuccess = false; break; } if(i == 0) { ID3D11Resource *resource; if(FAILED(d3d11Textures[i]->QueryInterface(__uuidof(ID3D11Resource), (void**)&resource))) { bSuccess = false; break; } D3D11_MAPPED_SUBRESOURCE map; if(FAILED(context->Map(resource, 0, D3D11_MAP_READ, 0, &map))) { bSuccess = false; break; } pitch = map.RowPitch; context->Unmap(resource, 0); resource->Release(); } } if(bSuccess) { d3d11CaptureInfo.mapID = InitializeSharedMemory(pitch*d3d11CaptureInfo.cy, &d3d11CaptureInfo.mapSize, ©Data, textureBuffers); if(!d3d11CaptureInfo.mapID) bSuccess = false; } if(bSuccess) { bHasTextures = true; d3d11CaptureInfo.captureType = CAPTURETYPE_MEMORY; d3d11CaptureInfo.hwndSender = hwndSender; d3d11CaptureInfo.pitch = pitch; d3d11CaptureInfo.bFlip = FALSE; PostMessage(hwndReceiver, RECEIVER_NEWCAPTURE, 0, (LPARAM)&d3d11CaptureInfo); } else { for(UINT i=0; i<2; i++) { SafeRelease(d3d11Textures[i]); if(textureBuffers[i]) { free(textureBuffers[i]); textureBuffers[i] = NULL; } } } } } } if(bHasTextures) { if(bCapturing) { DWORD nextCapture = curCapture == 0 ? 1 : 0; ID3D11Texture2D *texture = d3d11Textures[curCapture]; ID3D11Resource *backBuffer = NULL; if(SUCCEEDED(swap->GetBuffer(0, IID_ID3D11Resource, (void**)&backBuffer))) { if(bIsMultisampled) context->ResolveSubresource(texture, 0, backBuffer, 0, dxgiFormat); else context->CopyResource(texture, backBuffer); backBuffer->Release(); ID3D11Texture2D *lastTexture = d3d11Textures[nextCapture]; ID3D11Resource *resource; if(SUCCEEDED(lastTexture->QueryInterface(__uuidof(ID3D11Resource), (void**)&resource))) { D3D11_MAPPED_SUBRESOURCE map; if(SUCCEEDED(context->Map(resource, 0, D3D11_MAP_READ, 0, &map))) { LPBYTE *pTextureBuffer = NULL; int lastRendered = -1; //under no circumstances do we -ever- allow a stall if(WaitForSingleObject(textureMutexes[curCapture], 0) == WAIT_OBJECT_0) lastRendered = (int)curCapture; else if(WaitForSingleObject(textureMutexes[nextCapture], 0) == WAIT_OBJECT_0) lastRendered = (int)nextCapture; if(lastRendered != -1) { SSECopy(textureBuffers[lastRendered], map.pData, map.RowPitch*d3d11CaptureInfo.cy); ReleaseMutex(textureMutexes[lastRendered]); } context->Unmap(resource, 0); copyData->lastRendered = (UINT)lastRendered; } resource->Release(); } } curCapture = nextCapture; } else ClearD3D11Data(); } device->Release(); context->Release(); } } gi11swapPresent.Unhook(); HRESULT hRes = swap->Present(syncInterval, flags); gi11swapPresent.Rehook(); return hRes; }