HRESULT CGraphics::Reset(void) { m_NeedReset = FALSE; // If the device can be restored, the application prepares the // device by destroying all video-memory resources and any // swap chains if(FAILED(Invalidate())) { TRACE(TEXT("Error: Failed to invalidate device.\n")); return E_FAIL; } // Try to reset the device HRESULT hr = m_Device->Reset(&m_PresentParameters); if(FAILED(hr)) { // Check if error other than device lost if(hr != D3DERR_DEVICELOST) { HWND hWnd = GetWindowHandle(); UINT width = GetWidth(); UINT height = GetHeight(); BOOL blur = GetBlur(); UninitializeRenderer(); UninitializeDisplay(); InitializeDisplay(hWnd,width,height,blur); InitializeRenderer(); TRACE(TEXT("Warning: Failed to reset the display device, reinitialized graphics.\n")); return S_FALSE; } // The device was lost again, so continue waiting until it can be reset TRACE(TEXT("Error: Failed to reset the display device.\n")); return S_FALSE; } // Finally, a lost device must re-create resources (including // video memory resources) after it has been reset if(FAILED(Restore())) { HWND hWnd = GetWindowHandle(); UINT width = GetWidth(); UINT height = GetHeight(); BOOL blur = GetBlur(); UninitializeRenderer(); UninitializeDisplay(); InitializeDisplay(hWnd,width,height,blur); InitializeRenderer(); TRACE(TEXT("Warning: Failed to restore device, reinitialized graphics.\n")); return false; } return S_OK; }
CGraphics::~CGraphics(void) { UninitializeRenderer(); UninitializeDisplay(); UninitializeTimer(); Uninitialize(); }
HRESULT CGraphics::InitializeDisplay(HWND hWnd,UINT width,UINT height,BOOL blur) { // Check if windowed visualization (skin mode not supported) if(!hWnd) return E_FAIL; // Safe to assume that if device is not null display is initialized if(m_Device) UninitializeDisplay(); // Get the address of the create function if(!m_Direct3DCreate9) { TRACE(TEXT("Error: Failed to find \"Direct3DCreate9\" in \"%s\".\n"),D3DDLL); return E_FAIL; } // Reset audio data if(IsProcessorFeaturePresent(PF_XMMI_INSTRUCTIONS_AVAILABLE)) { TRACE(TEXT("Info: Using SSE instruction set.\n")); m_Levels = (PFLOAT)_aligned_malloc(sizeof(FLOAT) * VISUALIZATION_BARCOUNT,16); m_LevelsBuffer = (PFLOAT)_aligned_malloc(sizeof(FLOAT) * VISUALIZATION_BARCOUNT,16); m_Waveform = (PFLOAT)_aligned_malloc(sizeof(FLOAT) * SA_BUFFER_SIZE,16); m_WaveformBuffer = (PFLOAT)_aligned_malloc(sizeof(FLOAT) * SA_BUFFER_SIZE,16); } else { m_Levels = (PFLOAT)malloc(sizeof(FLOAT) * VISUALIZATION_BARCOUNT); m_LevelsBuffer = (PFLOAT)malloc(sizeof(FLOAT) * VISUALIZATION_BARCOUNT); m_Waveform = (PFLOAT)malloc(sizeof(FLOAT) * SA_BUFFER_SIZE); m_WaveformBuffer = (PFLOAT)malloc(sizeof(FLOAT) * SA_BUFFER_SIZE); } ZeroMemory(m_Levels,sizeof(FLOAT) * VISUALIZATION_BARCOUNT); ZeroMemory(m_LevelsBuffer,sizeof(FLOAT) * VISUALIZATION_BARCOUNT); ZeroMemory(m_Waveform,sizeof(FLOAT) * SA_BUFFER_SIZE); ZeroMemory(m_WaveformBuffer,sizeof(FLOAT) * SA_BUFFER_SIZE); ZeroMemory(m_Peaks,sizeof(m_Peaks)); m_Hwnd = hWnd; m_Blur = blur; m_Direct3D = m_Direct3DCreate9(D3D_SDK_VERSION); if(!m_Direct3D) { TRACE(TEXT("Error: Failed to create direct 3d.\n")); return E_FAIL; } m_Direct3D->GetDeviceCaps(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,&m_Caps); m_Direct3D->GetAdapterIdentifier(D3DADAPTER_DEFAULT,NULL,&m_AdapterIdentifier); ZeroMemory(&m_PresentParameters,sizeof(m_PresentParameters)); m_PresentParameters.Windowed = TRUE; m_PresentParameters.SwapEffect = D3DSWAPEFFECT_DISCARD; m_PresentParameters.BackBufferFormat = D3DFMT_X8R8G8B8; //m_PresentParameters.EnableAutoDepthStencil = TRUE; m_PresentParameters.AutoDepthStencilFormat = D3DFMT_D16; m_PresentParameters.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT; //m_PresentParameters.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; m_PresentParameters.BackBufferWidth = width; m_PresentParameters.BackBufferHeight = height; //m_PresentParameters.MultiSampleType = D3DMULTISAMPLE_4_SAMPLES; DWORD vp = NULL; if(m_Caps.DevCaps & D3DDEVCAPS_PUREDEVICE) { vp |= D3DCREATE_PUREDEVICE; TRACE(TEXT("Info: Using pure device.\n")); } if(m_Caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) { vp |= D3DCREATE_HARDWARE_VERTEXPROCESSING; TRACE(TEXT("Info: Using hardware vertex processing.\n")); } else { vp |= D3DCREATE_SOFTWARE_VERTEXPROCESSING; TRACE(TEXT("Info: Using software vertex processing.\n")); } if(FAILED(m_Direct3D->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,m_Hwnd,vp|D3DCREATE_MULTITHREADED,&m_PresentParameters,&m_Device))) { TRACE(TEXT("Error: Failed to create direct 3d device.\n")); return E_FAIL; } if(FAILED(Restore())) { TRACE(TEXT("Error: Failed to initaly restore device.\n")); return E_FAIL; } return S_OK; }
void CWinEGLPlatformGeneric::DestroyWindowSystem(EGLNativeWindowType native_window) { UninitializeDisplay(); }
CWinEGLPlatformGeneric::~CWinEGLPlatformGeneric() { UninitializeDisplay(); }