LRESULT TabCloseButton::WndProc(UINT msg, WPARAM wParam, LPARAM lParam) { RECT tmpRect; switch(msg) { case WM_MOUSEMOVE: if(state_) break; state_ = 1; TrackMouseEvent(TME_LEAVE); ImmediatelyUpdateWindow(); return 0; case WM_MOUSELEAVE: state_ = 0; mousePressed_ = false; tmpRect = getClientRect(); ::MapWindowPoints(getWindowHandle(), getParent(), (POINT *) &tmpRect, 2); SafeWindowFromHandle(getParent())->UpdateWindow(&tmpRect); ::UpdateWindow(getParent()); ImmediatelyUpdateWindow(); return 0; case WM_LBUTTONDOWN: state_ = 2; mousePressed_ = true; ImmediatelyUpdateWindow(); return 0; case WM_LBUTTONUP: state_ = 1; ImmediatelyUpdateWindow(); if(mousePressed_) onClick_(*this); return 0; } return Window::WndProc(msg, wParam, lParam); }
void D3D9RenderWindow::getCustomAttribute( const String& name, void* pData ) { // Valid attributes and their equvalent native functions: // D3DDEVICE : getD3DDevice // WINDOW : getWindowHandle if( name == "D3DDEVICE" ) { *(IDirect3DDevice9**)pData = getD3D9Device(); } else if( name == "WINDOW" ) { *(HWND*)pData = getWindowHandle(); } else if( name == "isTexture" ) { *(bool*)pData = false; } else if( name == "D3DZBUFFER" ) { *(IDirect3DSurface9**)pData = mDevice->getDepthBuffer(this); } else if( name == "DDBACKBUFFER" ) { *(IDirect3DSurface9**)pData = mDevice->getBackBuffer(this); } else if( name == "DDFRONTBUFFER" ) { *(IDirect3DSurface9**)pData = mDevice->getBackBuffer(this); } }
bool Surface::checkForOutOfDateSwapChain() { RECT client; if (!GetClientRect(getWindowHandle(), &client)) { ASSERT(false); return false; } // Grow the buffer now, if the window has grown. We need to grow now to avoid losing information. int clientWidth = client.right - client.left; int clientHeight = client.bottom - client.top; bool sizeDirty = clientWidth != getWidth() || clientHeight != getHeight(); if (sizeDirty || mPresentIntervalDirty) { resetSwapChain(clientWidth, clientHeight); if (static_cast<egl::Surface*>(getCurrentDrawSurface()) == this) { glMakeCurrent(glGetCurrentContext(), static_cast<egl::Display*>(getCurrentDisplay()), this); } return true; } return false; }
void Application::setWindowCoord(const MyGUI::IntCoord& _value) { #if MYGUI_PLATFORM == MYGUI_PLATFORM_WIN32 if (_value.empty()) return; MyGUI::IntCoord coord = _value; if (coord.left < 0) coord.left = 0; if (coord.top < 0) coord.top = 0; if (coord.width < 640) coord.width = 640; if (coord.height < 480) coord.height = 480; if (coord.width > GetSystemMetrics(SM_CXSCREEN)) coord.width = GetSystemMetrics(SM_CXSCREEN); if (coord.height > GetSystemMetrics(SM_CYSCREEN)) coord.height = GetSystemMetrics(SM_CYSCREEN); if (coord.right() > GetSystemMetrics(SM_CXSCREEN)) coord.left = GetSystemMetrics(SM_CXSCREEN) - coord.width; if (coord.bottom() > GetSystemMetrics(SM_CYSCREEN)) coord.top = GetSystemMetrics(SM_CYSCREEN) - coord.height; size_t handle = getWindowHandle(); ::MoveWindow((HWND)handle, coord.left, coord.top, coord.width, coord.height, true); #endif }
//--------------------------------------------------------------------- void D3D10RenderWindow::getCustomAttribute( const String& name, void* pData ) { // Valid attributes and their equvalent native functions: // D3DDEVICE : getD3DDevice // WINDOW : getWindowHandle if( name == "D3DDEVICE" ) { ID3D10Device **device = (ID3D10Device **)pData; *device = mDevice.get(); return; } else if( name == "WINDOW" ) { HWND *pHwnd = (HWND*)pData; *pHwnd = getWindowHandle(); return; } else if( name == "isTexture" ) { bool *b = reinterpret_cast< bool * >( pData ); *b = false; return; } else if( name == "ID3D10RenderTargetView" ) { ID3D10RenderTargetView * *pRTView = (ID3D10RenderTargetView **)pData; *pRTView = mRenderTargetView; return; } else if( name == "ID3D10DepthStencilView" ) { ID3D10DepthStencilView * *pRTDepthView = (ID3D10DepthStencilView **)pData; *pRTDepthView = mDepthStencilView; return; } /*else if( name == "D3DZBUFFER" ) { IDXGISurface * *pSurf = (IDXGISurface **)pData; *pSurf = mpRenderZBuffer; return; } else if( name == "DDBACKBUFFER" ) { IDXGISurface * *pSurf = (IDXGISurface **)pData; *pSurf = mpRenderSurface; return; } else if( name == "DDFRONTBUFFER" ) { IDXGISurface * *pSurf = (IDXGISurface **)pData; *pSurf = mpRenderSurface; return; } */ }
bool Application::getWindowMaximized() { bool result = false; #if MYGUI_PLATFORM == MYGUI_PLATFORM_WIN32 size_t handle = getWindowHandle(); result = ::IsZoomed((HWND)handle) != 0; #endif return result; }
bool Surface::checkForOutOfDateSwapChain() { RECT client; if (!GetClientRect(getWindowHandle(), &client)) { ASSERT(false); return false; } // Grow the buffer now, if the window has grown. We need to grow now to avoid losing information. int clientWidth = client.right - client.left; int clientHeight = client.bottom - client.top; bool sizeDirty = clientWidth != getWidth() || clientHeight != getHeight(); if (IsIconic(getWindowHandle())) { // The window is automatically resized to 150x22 when it's minimized, but the swapchain shouldn't be resized // because that's not a useful size to render to. sizeDirty = false; } bool wasDirty = (mSwapIntervalDirty || sizeDirty); if (mSwapIntervalDirty) { resetSwapChain(clientWidth, clientHeight); } else if (sizeDirty) { resizeSwapChain(clientWidth, clientHeight); } if (wasDirty) { if (static_cast<egl::Surface*>(getCurrentDrawSurface()) == this) { glMakeCurrent(glGetCurrentContext(), static_cast<egl::Display*>(getCurrentDisplay()), this); } return true; } return false; }
void Application::setWindowMaximized(bool _value) { #if MYGUI_PLATFORM == MYGUI_PLATFORM_WIN32 if (_value) { size_t handle = getWindowHandle(); ::ShowWindow((HWND)handle, SW_SHOWMAXIMIZED); } #endif }
void Win32Window::getCustomAttribute( const String& name, void* pData ) { if( name == "GLCONTEXT" ) { *static_cast<GLContext**>(pData) = mContext; return; } else if( name == "WINDOW" ) { HWND *pHwnd = (HWND*)pData; *pHwnd = getWindowHandle(); return; } }
MyGUI::IntCoord Application::getWindowCoord() { MyGUI::IntCoord result; #if MYGUI_PLATFORM == MYGUI_PLATFORM_WIN32 size_t handle = getWindowHandle(); ::RECT rect; ::GetWindowRect((HWND)handle, &rect); result.left = rect.left; result.top = rect.top; result.width = rect.right - rect.left; result.height = rect.bottom - rect.top; #endif return result; }
bool Surface::resetSwapChain() { ASSERT(!mSwapChain); int width; int height; if (mWindow) { #if defined(ANGLE_PLATFORM_WINRT) winrt::getCurrentWindowDimensions(width, height); #else RECT windowRect; if (!GetClientRect(getWindowHandle(), &windowRect)) { ASSERT(false); ERR("Could not retrieve the window dimensions"); return error(EGL_BAD_SURFACE, false); } width = windowRect.right - windowRect.left; height = windowRect.bottom - windowRect.top; #endif // #if defined(ANGLE_PLATFORM_WINRT) } else { // non-window surface - size is determined at creation width = mWidth; height = mHeight; } mSwapChain = mRenderer->createSwapChain(mWindow, mShareHandle, mConfig->mRenderTargetFormat, mConfig->mDepthStencilFormat); if (!mSwapChain) { return error(EGL_BAD_ALLOC, false); } if (!resetSwapChain(width, height)) { delete mSwapChain; mSwapChain = NULL; return false; } return true; }
bool gkWindowAndroid::setupInput(const gkUserDefs& prefs) { // OIS try { #if 0 size_t handle = getWindowHandle(); if (handle == 0) { gkPrintf("Window handle is null."); return false; } #else size_t handle = 0; #endif OIS::ParamList params; params.insert(std::make_pair("WINDOW", Ogre::StringConverter::toString(handle))); m_input = OIS::InputManager::createInputSystem(params); m_input->enableAddOnFactory(OIS::InputManager::AddOn_All); m_ikeyboard = (OIS::Keyboard*)m_input->createInputObject(OIS::OISKeyboard, true); GK_ASSERT(m_ikeyboard); m_ikeyboard->setEventCallback(this); // TODO: Option for disabling accelration! Performance... try{ m_iacc = (OIS::JoyStick*)m_input->createInputObject(OIS::OISJoyStick, true); m_iacc->setEventCallback(this); m_ijoysticks.push_back(m_iacc); gkJoystick* gkjs = new gkJoystick(0,0); m_joysticks.push_back(gkjs); } catch (OIS::Exception&){ m_iacc=0; } m_itouch = (OIS::MultiTouch*)m_input->createInputObject(OIS::OISMultiTouch, true); GK_ASSERT(m_itouch); m_itouch->setEventCallback(this); } catch (OIS::Exception& e) { gkPrintf("%s", e.what()); return false; } return true; }
void Surface::resetSwapChain() { if (!mWindow) { resetSwapChain(mWidth, mHeight); return; } RECT windowRect; if (!GetClientRect(getWindowHandle(), &windowRect)) { ASSERT(false); ERR("Could not retrieve the window dimensions"); return; } resetSwapChain(windowRect.right - windowRect.left, windowRect.bottom - windowRect.top); }
void D3D9RenderWindow::getCustomAttribute( const String& name, void* pData ) { // Valid attributes and their equvalent native functions: // D3DDEVICE : getD3DDevice // WINDOW : getWindowHandle if( name == "D3DDEVICE" ) { IDirect3DDevice9* *pDev = (IDirect3DDevice9**)pData; *pDev = getD3D9Device(); return; } else if( name == "WINDOW" ) { HWND *pHwnd = (HWND*)pData; *pHwnd = getWindowHandle(); return; } else if( name == "isTexture" ) { bool *b = reinterpret_cast< bool * >( pData ); *b = false; return; } else if( name == "D3DZBUFFER" ) { IDirect3DSurface9* *pSurf = (IDirect3DSurface9**)pData; *pSurf = mDevice->getDepthBuffer(this); return; } else if( name == "DDBACKBUFFER" ) { IDirect3DSurface9* *pSurf = (IDirect3DSurface9**)pData; *pSurf = mDevice->getBackBuffer(this); return; } else if( name == "DDFRONTBUFFER" ) { IDirect3DSurface9* *pSurf = (IDirect3DSurface9**)pData; *pSurf = mDevice->getBackBuffer(this); return; } }
void BaseManager::setWindowCaption(const std::wstring& _text) { #if MYGUI_PLATFORM == MYGUI_PLATFORM_WIN32 ::SetWindowTextW((HWND)getWindowHandle(), _text.c_str()); #elif MYGUI_PLATFORM == MYGUI_PLATFORM_LINUX Display* xDisplay = nullptr; unsigned long windowHandle = 0; mWindow->getCustomAttribute("XDISPLAY", &xDisplay); mWindow->getCustomAttribute("WINDOW", &windowHandle); Window win = (Window)windowHandle; XTextProperty windowName; windowName.value = (unsigned char *)(MyGUI::UString(_text).asUTF8_c_str()); windowName.encoding = XA_STRING; windowName.format = 8; windowName.nitems = strlen((char *)(windowName.value)); XSetWMName(xDisplay, win, &windowName); #endif }
bool Surface::checkForOutOfDateSwapChain() { #if defined(ANGLE_PLATFORM_WINRT) int clientWidth = 0; int clientHeight = 0; winrt::getCurrentWindowDimensions(clientWidth,clientHeight); #else RECT client; if (!GetClientRect(getWindowHandle(), &client)) { ASSERT(false); return false; } // Grow the buffer now, if the window has grown. We need to grow now to avoid losing information. int clientWidth = client.right - client.left; int clientHeight = client.bottom - client.top; #endif // #if defined(ANGLE_PLATFORM_WINRT) bool sizeDirty = clientWidth != getWidth() || clientHeight != getHeight(); if (mSwapIntervalDirty) { resetSwapChain(clientWidth, clientHeight); } else if (sizeDirty) { resizeSwapChain(clientWidth, clientHeight); } if (mSwapIntervalDirty || sizeDirty) { if (static_cast<egl::Surface*>(getCurrentDrawSurface()) == this) { glMakeCurrent(glGetCurrentContext(), static_cast<egl::Display*>(getCurrentDisplay()), this); } return true; } return false; }
//--------------------------------------------------------------------- void D3D11RenderWindow::getCustomAttribute( const String& name, void* pData ) { // Valid attributes and their equvalent native functions: // D3DDEVICE : getD3DDevice // WINDOW : getWindowHandle if( name == "D3DDEVICE" ) { ID3D11Device **device = (ID3D11Device **)pData; *device = mDevice.get(); return; } else if( name == "WINDOW" ) { HWND *pHwnd = (HWND*)pData; *pHwnd = getWindowHandle(); return; } else if( name == "isTexture" ) { bool *b = reinterpret_cast< bool * >( pData ); *b = false; return; } else if( name == "ID3D11RenderTargetView" ) { ID3D11RenderTargetView * *pRTView = (ID3D11RenderTargetView **)pData; *pRTView = mRenderTargetView; return; } else if( name == "ID3D11Texture2D" ) { ID3D11Texture2D **pBackBuffer = (ID3D11Texture2D**)pData; *pBackBuffer = mpBackBuffer; } }
bool Surface::checkForWindowResize() { RECT client; if (!GetClientRect(getWindowHandle(), &client)) { ASSERT(false); return false; } if (getWidth() != client.right - client.left || getHeight() != client.bottom - client.top) { resetSwapChain(); if (static_cast<egl::Surface*>(getCurrentDrawSurface()) == this) { glMakeCurrent(glGetCurrentContext(), static_cast<egl::Display*>(getCurrentDisplay()), this); } return true; } return false; }
bool Surface::resetSwapChain(int backbufferWidth, int backbufferHeight) { IDirect3DDevice9 *device = mDisplay->getDevice(); if (device == NULL) { return false; } // Evict all non-render target textures to system memory and release all resources // before reallocating them to free up as much video memory as possible. device->EvictManagedResources(); release(); D3DPRESENT_PARAMETERS presentParameters = {0}; HRESULT result; bool useFlipEx = (LOWORD(GetVersion()) >= 0x61) && mDisplay->isD3d9ExDevice(); // FlipEx causes unseemly stretching when resizing windows AND when one // draws outside of the WM_PAINT callback. While this is seldom a problem in // single process applications, it is particuarly noticeable in multiprocess // applications. Therefore, if the creator process of our window is not in // the current process, disable use of FlipEx. DWORD windowPID; GetWindowThreadProcessId(mWindow, &windowPID); if(windowPID != GetCurrentProcessId()) useFlipEx = false; presentParameters.AutoDepthStencilFormat = mConfig->mDepthStencilFormat; // We set BackBufferCount = 1 even when we use D3DSWAPEFFECT_FLIPEX. // We do this because DirectX docs are a bit vague whether to set this to 1 // or 2. The runtime seems to accept 1, so we speculate that either it is // forcing it to 2 without telling us, or better, doing something smart // behind the scenes knowing that we don't need more. presentParameters.BackBufferCount = 1; presentParameters.BackBufferFormat = mConfig->mRenderTargetFormat; presentParameters.EnableAutoDepthStencil = FALSE; presentParameters.Flags = 0; presentParameters.hDeviceWindow = getWindowHandle(); presentParameters.MultiSampleQuality = 0; // FIXME: Unimplemented presentParameters.MultiSampleType = D3DMULTISAMPLE_NONE; // FIXME: Unimplemented presentParameters.PresentationInterval = mPresentInterval; // Use flipEx on Win7 or greater. if(useFlipEx) presentParameters.SwapEffect = D3DSWAPEFFECT_FLIPEX; else presentParameters.SwapEffect = D3DSWAPEFFECT_DISCARD; presentParameters.Windowed = TRUE; presentParameters.BackBufferWidth = backbufferWidth; presentParameters.BackBufferHeight = backbufferHeight; if (mWindow) { result = device->CreateAdditionalSwapChain(&presentParameters, &mSwapChain); } else { HANDLE *pShareHandle = NULL; if (mDisplay->isD3d9ExDevice()) { pShareHandle = &mShareHandle; } result = device->CreateTexture(presentParameters.BackBufferWidth, presentParameters.BackBufferHeight, 1, D3DUSAGE_RENDERTARGET, presentParameters.BackBufferFormat, D3DPOOL_DEFAULT, &mOffscreenTexture, pShareHandle); } if (FAILED(result)) { ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY); ERR("Could not create additional swap chains or offscreen surfaces: %08lX", result); release(); return error(EGL_BAD_ALLOC, false); } if (mConfig->mDepthStencilFormat != D3DFMT_UNKNOWN) { result = device->CreateDepthStencilSurface(presentParameters.BackBufferWidth, presentParameters.BackBufferHeight, presentParameters.AutoDepthStencilFormat, presentParameters.MultiSampleType, presentParameters.MultiSampleQuality, FALSE, &mDepthStencil, NULL); } if (FAILED(result)) { ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY); ERR("Could not create depthstencil surface for new swap chain: %08lX", result); release(); return error(EGL_BAD_ALLOC, false); } if (mWindow) { mSwapChain->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &mRenderTarget); InvalidateRect(mWindow, NULL, FALSE); } else { mOffscreenTexture->GetSurfaceLevel(0, &mRenderTarget); } mWidth = presentParameters.BackBufferWidth; mHeight = presentParameters.BackBufferHeight; mPresentIntervalDirty = false; return true; }
bool BaseManager::create() { Ogre::String pluginsPath; #ifndef OGRE_STATIC_LIB pluginsPath = mResourcePath + mPluginCfgName; #endif mRoot = new Ogre::Root(pluginsPath, mResourcePath + "ogre.cfg", mResourcePath + "Ogre.log"); setupResources(); // попробуем завестись на дефолтных if (!mRoot->restoreConfig()) { // ничего не получилось, покажем диалог if (!mRoot->showConfigDialog()) return false; } mWindow = mRoot->initialise(true); // вытаскиваем дискриптор окна size_t handle = getWindowHandle(); #if MYGUI_PLATFORM == MYGUI_PLATFORM_WIN32 // берем имя нашего экзешника char buf[MAX_PATH]; ::GetModuleFileNameA(0, (LPCH)&buf, MAX_PATH); // берем инстанс нашего модуля HINSTANCE instance = ::GetModuleHandleA(buf); // побыстрому грузим иконку HICON hIcon = ::LoadIcon(instance, MAKEINTRESOURCE(1001)); if (hIcon) { ::SendMessageA((HWND)handle, WM_SETICON, 1, (LPARAM)hIcon); ::SendMessageA((HWND)handle, WM_SETICON, 0, (LPARAM)hIcon); } #endif mSceneManager = mRoot->createSceneManager(Ogre::ST_GENERIC, "BaseSceneManager"); mCamera = mSceneManager->createCamera("BaseCamera"); mCamera->setNearClipDistance(5); mCamera->setPosition(400, 400, 400); mCamera->lookAt(0, 150, 0); // Create one viewport, entire window Ogre::Viewport* vp = mWindow->addViewport(mCamera); // Alter the camera aspect ratio to match the viewport mCamera->setAspectRatio((float)vp->getActualWidth() / (float)vp->getActualHeight()); // Set default mipmap level (NB some APIs ignore this) Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5); mSceneManager->setAmbientLight(Ogre::ColourValue::White); Ogre::Light* light = mSceneManager->createLight("MainLight"); light->setType(Ogre::Light::LT_DIRECTIONAL); Ogre::Vector3 vec(-0.3f, -0.3f, -0.3f); vec.normalise(); light->setDirection(vec); // Load resources Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); mRoot->addFrameListener(this); Ogre::WindowEventUtilities::addWindowEventListener(mWindow, this); createGui(); createInput(handle); createPointerManager(handle); createScene(); windowResized(mWindow); return true; }
bool Surface::resetSwapChain(int backbufferWidth, int backbufferHeight) { IDirect3DDevice9 *device = mDisplay->getDevice(); if (device == NULL) { return false; } // Evict all non-render target textures to system memory and release all resources // before reallocating them to free up as much video memory as possible. device->EvictManagedResources(); HRESULT result; // Release specific resources to free up memory for the new render target, while the // old render target still exists for the purpose of preserving its contents. if (mSwapChain) { mSwapChain->Release(); mSwapChain = NULL; } if (mBackBuffer) { mBackBuffer->Release(); mBackBuffer = NULL; } if (mOffscreenTexture) { mOffscreenTexture->Release(); mOffscreenTexture = NULL; } if (mDepthStencil) { mDepthStencil->Release(); mDepthStencil = NULL; } mShareHandle = NULL; HANDLE *pShareHandle = NULL; if (!mWindow && mDisplay->shareHandleSupported()) { pShareHandle = &mShareHandle; } result = device->CreateTexture(backbufferWidth, backbufferHeight, 1, D3DUSAGE_RENDERTARGET, mConfig->mRenderTargetFormat, D3DPOOL_DEFAULT, &mOffscreenTexture, pShareHandle); if (FAILED(result)) { ERR("Could not create offscreen texture: %08lX", result); release(); if(isDeviceLostError(result)) { mDisplay->notifyDeviceLost(); return false; } else { return error(EGL_BAD_ALLOC, false); } } IDirect3DSurface9 *oldRenderTarget = mRenderTarget; result = mOffscreenTexture->GetSurfaceLevel(0, &mRenderTarget); ASSERT(SUCCEEDED(result)); if (oldRenderTarget) { RECT rect = { 0, 0, mWidth, mHeight }; if (rect.right > static_cast<LONG>(backbufferWidth)) { rect.right = backbufferWidth; } if (rect.bottom > static_cast<LONG>(backbufferHeight)) { rect.bottom = backbufferHeight; } mDisplay->endScene(); result = device->StretchRect(oldRenderTarget, &rect, mRenderTarget, &rect, D3DTEXF_NONE); ASSERT(SUCCEEDED(result)); oldRenderTarget->Release(); } if (mWindow) { D3DPRESENT_PARAMETERS presentParameters = {0}; presentParameters.AutoDepthStencilFormat = mConfig->mDepthStencilFormat; presentParameters.BackBufferCount = 1; presentParameters.BackBufferFormat = mConfig->mRenderTargetFormat; presentParameters.EnableAutoDepthStencil = FALSE; presentParameters.Flags = 0; presentParameters.hDeviceWindow = getWindowHandle(); presentParameters.MultiSampleQuality = 0; // FIXME: Unimplemented presentParameters.MultiSampleType = D3DMULTISAMPLE_NONE; // FIXME: Unimplemented presentParameters.PresentationInterval = mPresentInterval; presentParameters.SwapEffect = D3DSWAPEFFECT_DISCARD; presentParameters.Windowed = TRUE; presentParameters.BackBufferWidth = backbufferWidth; presentParameters.BackBufferHeight = backbufferHeight; // http://crbug.com/140239 // http://crbug.com/143434 // // Some AMD/Intel switchable systems / drivers appear to round swap chain surfaces to a multiple of 64 pixels in width // when using the integrated Intel. This rounds the width up rather than down. // // Some non-switchable AMD GPUs / drivers do not respect the source rectangle to Present. Therefore, when the vendor ID // is not Intel, the back buffer width must be exactly the same width as the window or horizontal scaling will occur. D3DADAPTER_IDENTIFIER9* adapterIdentifier = mDisplay->getAdapterIdentifier(); if (adapterIdentifier->VendorId == VENDOR_ID_INTEL) { presentParameters.BackBufferWidth = (presentParameters.BackBufferWidth + 63) / 64 * 64; } result = device->CreateAdditionalSwapChain(&presentParameters, &mSwapChain); if (FAILED(result)) { ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY || result == D3DERR_INVALIDCALL || result == D3DERR_DEVICELOST); ERR("Could not create additional swap chains or offscreen surfaces: %08lX", result); release(); if(isDeviceLostError(result)) { mDisplay->notifyDeviceLost(); return false; } else { return error(EGL_BAD_ALLOC, false); } } result = mSwapChain->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &mBackBuffer); ASSERT(SUCCEEDED(result)); } if (mConfig->mDepthStencilFormat != D3DFMT_UNKNOWN) { result = device->CreateDepthStencilSurface(backbufferWidth, backbufferHeight, mConfig->mDepthStencilFormat, D3DMULTISAMPLE_NONE, 0, FALSE, &mDepthStencil, NULL); if (FAILED(result)) { ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY || result == D3DERR_INVALIDCALL); ERR("Could not create depthstencil surface for new swap chain: 0x%08X", result); release(); if(isDeviceLostError(result)) { mDisplay->notifyDeviceLost(); return false; } else { return error(EGL_BAD_ALLOC, false); } } } mWidth = backbufferWidth; mHeight = backbufferHeight; mPresentIntervalDirty = false; return true; }
void Surface::resetSwapChain() { IDirect3DDevice9 *device = mDisplay->getDevice(); D3DPRESENT_PARAMETERS presentParameters = {0}; presentParameters.AutoDepthStencilFormat = mConfig->mDepthStencilFormat; presentParameters.BackBufferCount = 1; presentParameters.BackBufferFormat = mConfig->mRenderTargetFormat; presentParameters.EnableAutoDepthStencil = FALSE; presentParameters.Flags = 0; presentParameters.hDeviceWindow = getWindowHandle(); presentParameters.MultiSampleQuality = 0; // FIXME: Unimplemented presentParameters.MultiSampleType = D3DMULTISAMPLE_NONE; // FIXME: Unimplemented presentParameters.PresentationInterval = Display::convertInterval(mConfig->mMinSwapInterval); presentParameters.SwapEffect = D3DSWAPEFFECT_DISCARD; presentParameters.Windowed = TRUE; RECT windowRect; if (!GetClientRect(getWindowHandle(), &windowRect)) { ASSERT(false); return; } presentParameters.BackBufferWidth = windowRect.right - windowRect.left; presentParameters.BackBufferHeight = windowRect.bottom - windowRect.top; IDirect3DSwapChain9 *swapChain = NULL; HRESULT result = device->CreateAdditionalSwapChain(&presentParameters, &swapChain); if (FAILED(result)) { ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY); ERR("Could not create additional swap chains: %08lX", result); return error(EGL_BAD_ALLOC); } IDirect3DSurface9 *depthStencilSurface = NULL; result = device->CreateDepthStencilSurface(presentParameters.BackBufferWidth, presentParameters.BackBufferHeight, presentParameters.AutoDepthStencilFormat, presentParameters.MultiSampleType, presentParameters.MultiSampleQuality, FALSE, &depthStencilSurface, NULL); if (FAILED(result)) { ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY); swapChain->Release(); ERR("Could not create depthstencil surface for new swap chain: %08lX", result); return error(EGL_BAD_ALLOC); } IDirect3DSurface9 *renderTarget = NULL; result = device->CreateRenderTarget(presentParameters.BackBufferWidth, presentParameters.BackBufferHeight, presentParameters.BackBufferFormat, presentParameters.MultiSampleType, presentParameters.MultiSampleQuality, FALSE, &renderTarget, NULL); if (FAILED(result)) { ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY); swapChain->Release(); depthStencilSurface->Release(); ERR("Could not create render target surface for new swap chain: %08lX", result); return error(EGL_BAD_ALLOC); } ASSERT(SUCCEEDED(result)); IDirect3DTexture9 *flipTexture = NULL; result = device->CreateTexture(presentParameters.BackBufferWidth, presentParameters.BackBufferHeight, 1, D3DUSAGE_RENDERTARGET, presentParameters.BackBufferFormat, D3DPOOL_DEFAULT, &flipTexture, NULL); if (FAILED(result)) { ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY); swapChain->Release(); depthStencilSurface->Release(); renderTarget->Release(); ERR("Could not create flip texture for new swap chain: %08lX", result); return error(EGL_BAD_ALLOC); } IDirect3DSurface9 *backBuffer = NULL; swapChain->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &backBuffer); if (mSwapChain) mSwapChain->Release(); if (mDepthStencil) mDepthStencil->Release(); if (mBackBuffer) mBackBuffer->Release(); if (mRenderTarget) mRenderTarget->Release(); if (mFlipTexture) mFlipTexture->Release(); mWidth = presentParameters.BackBufferWidth; mHeight = presentParameters.BackBufferHeight; mSwapChain = swapChain; mDepthStencil = depthStencilSurface; mBackBuffer = backBuffer; mRenderTarget = renderTarget; mFlipTexture = flipTexture; // The flip state block recorded mFlipTexture so it is now invalid. releaseRecordedState(device); }
void GlDisplayService::handleWindowClose(GLFWwindow* window) { int windowHandle = getWindowHandle(window); m_windowCloseHandler.notifyListeners(windowHandle); }
TestMRPPWindow::TestMRPPWindow(HWND parent, std::string title) : MRPWindow(parent, title) { for (int i = 0; i < 8; ++i) { auto but = std::make_shared<WinButton>(this, std::to_string(i)); but->GenericNotifyCallback = [i](GenericNotifications) { readbg() << "you pressed " << i << "\n"; }; add_control(but); } // Button 0 toggless enabled state of button 1 m_controls[0]->GenericNotifyCallback = [this](GenericNotifications) { m_controls[1]->setEnabled(!m_controls[1]->isEnabled()); }; m_envcontrol1 = std::make_shared<EnvelopeControl>(this); // Button 3 toggless enabled state of envelope control m_controls[3]->GenericNotifyCallback = [this](GenericNotifications) { m_envcontrol1->setEnabled(!m_envcontrol1->isEnabled()); }; // Button 7 toggless visible state of button 0 m_controls[7]->GenericNotifyCallback = [this](GenericNotifications) { m_controls[0]->setVisible(!m_controls[0]->isVisible()); }; auto env = std::make_shared<breakpoint_envelope>("foo", LICE_RGBA(255, 255, 255, 255)); env->add_point({ 0.0, 0.5 , envbreakpoint::Power, 0.5 }, true); env->add_point({ 0.5, 0.0 , envbreakpoint::Power, 0.5 }, true); env->add_point({ 1.0, 0.5 }, true); m_envcontrol1->add_envelope(env); m_envcontrol1->GenericNotifyCallback = [this, env](GenericNotifications reason) { //if (reason == GenericNotifications::AfterManipulation) // generate_items_sequence(env, m_edit1->getText().c_str()); }; add_control(m_envcontrol1); // Button 5 does some Xenakios silliness m_controls[5]->GenericNotifyCallback = [this, env](GenericNotifications) { generate_items_sequence(env, m_edit1->getText().c_str()); }; m_label1 = std::make_shared<WinLabel>(this, "This is a label"); add_control(m_label1); m_edit1 = std::make_shared<WinLineEdit>(this, "C:/MusicAudio/pihla_ei/ei_mono_005.wav"); add_control(m_edit1); m_edit1->TextCallback = [this](std::string txt) { m_label1->setText(txt); }; // Button 6 launches bogus work in another thread to demo progress bar m_controls[6]->GenericNotifyCallback = [this](GenericNotifications) { m_progressbar1->setVisible(true); // we don't deal with multiple background tasks now, so disable the button to start the task m_controls[6]->setEnabled(false); static int rseed = 0; auto task = [this](int randseed) { std::mt19937 randgen(randseed); std::uniform_real_distribution<double> randdist(0.0, 1.0); double accum = 0.0; const int iterations = 50000000; double t0 = time_precise(); for (int i = 0; i < iterations; ++i) { accum += randdist(randgen); //accum += randdist(randgen); // Production code should not do this at this granularity, because setProgressValue deals with // an atomic value. but this is just a demo... m_progressbar1->setProgressValue(1.0 / iterations*i); } double t1 = time_precise(); auto finishtask = [=]() { m_edit1->setText(std::to_string(accum) + " elapsed time " + std::to_string(t1-t0)); m_progressbar1->setProgressValue(0.0); m_progressbar1->setVisible(false); m_controls[6]->setEnabled(true); }; execute_in_main_thread(finishtask); }; m_future1 = std::async(std::launch::async, task, rseed); ++rseed; }; // Button 1 shows popup menu m_controls[1]->GenericNotifyCallback = [this, env](GenericNotifications) { PopupMenu popmenu(getWindowHandle()); popmenu.add_menu_item("Menu entry 1", [](PopupMenu::CheckState) {}); popmenu.add_menu_item("Menu entry 2", m_menuitem2state, [this](PopupMenu::CheckState cs) { m_menuitem2state = cs; }); popmenu.add_menu_item("Menu entry 3", m_menuitem3state, [this](PopupMenu::CheckState cs) { m_menuitem3state = cs; }); PopupMenu submenu(getWindowHandle()); submenu.add_menu_item("Submenu entry 1", [](PopupMenu::CheckState) { readbg() << "submenu entry 1\n"; }); submenu.add_menu_item("Submenu entry 2", [](PopupMenu::CheckState) { readbg() << "submenu entry 2\n"; }); PopupMenu subsubmenu(getWindowHandle()); for (int i = 0; i < 8; ++i) { subsubmenu.add_menu_item(std::string("Subsubmenu entry ") + std::to_string(i + 1), [i](PopupMenu::CheckState) { readbg() << "subsubmenu entry " << i + 1 << "\n"; }); } submenu.add_submenu("Going still deeper", subsubmenu); popmenu.add_submenu("More stuff", submenu); popmenu.execute(m_controls[1]->getXPosition(), m_controls[1]->getYPosition()); }; // Button 4 removes envelope points with value over 0.5 m_controls[4]->GenericNotifyCallback = [this, env](GenericNotifications) { env->remove_points_conditionally([](const envbreakpoint& pt) { return pt.get_y() > 0.5; }); m_envcontrol1->repaint(); }; m_combo1 = std::make_shared<WinComboBox>(this); m_combo1->addItem("Apple", -9001); m_combo1->addItem("Pear", 666); m_combo1->addItem("Kiwi", 42); m_combo1->addItem("Banana", 100); m_combo1->SelectedChangedCallback = [this](int index) { int user_id = m_combo1->userIDfromIndex(index); readbg() << "combo index " << index << " userid " << user_id << "\n"; }; add_control(m_combo1); m_combo1->setSelectedUserID(42); m_combo2 = std::make_shared<WinComboBox>(this); m_combo2->addItem("Item 1", 100); m_combo2->addItem("Item 2", 101); m_combo2->addItem("Item 3", 102); m_combo2->addItem("Item 4", 103); m_combo2->SelectedChangedCallback = [this](int index) { int user_id = m_combo2->userIDfromIndex(index); readbg() << "combo index " << index << " userid " << user_id << "\n"; }; add_control(m_combo2); m_combo2->setSelectedIndex(0); m_slider1 = std::make_shared<ReaSlider>(this, 0.5); //m_slider1->setValueConverter(std::make_shared<FFTSizesValueConverter>()); m_slider1->SliderValueCallback = [this](GenericNotifications, double x) { m_label1->setText(std::to_string(x)); m_progressbar1->setProgressValue(x); }; add_control(m_slider1); m_zoomscroll1 = std::make_shared<ZoomScrollBar>(this); add_control(m_zoomscroll1); m_zoomscroll1->RangeChangedCallback = [this](double t0, double t1) { m_envcontrol1->setViewTimeRange(t0, t1); }; m_progressbar1 = std::make_shared<ProgressControl>(this); m_progressbar1->setVisible(false); }
void Surface::resetSwapChain(int backbufferWidth, int backbufferHeight) { IDirect3DDevice9 *device = mDisplay->getDevice(); if (device == NULL) { return; } // Evict all non-render target textures to system memory and release all resources // before reallocating them to free up as much video memory as possible. device->EvictManagedResources(); release(); D3DPRESENT_PARAMETERS presentParameters = {0}; HRESULT result; presentParameters.AutoDepthStencilFormat = mConfig->mDepthStencilFormat; presentParameters.BackBufferCount = 1; presentParameters.BackBufferFormat = mConfig->mRenderTargetFormat; presentParameters.EnableAutoDepthStencil = FALSE; presentParameters.Flags = 0; presentParameters.hDeviceWindow = getWindowHandle(); presentParameters.MultiSampleQuality = 0; // FIXME: Unimplemented presentParameters.MultiSampleType = D3DMULTISAMPLE_NONE; // FIXME: Unimplemented presentParameters.PresentationInterval = mPresentInterval; presentParameters.SwapEffect = D3DSWAPEFFECT_DISCARD; presentParameters.Windowed = TRUE; presentParameters.BackBufferWidth = backbufferWidth; presentParameters.BackBufferHeight = backbufferHeight; if (mWindow) { result = device->CreateAdditionalSwapChain(&presentParameters, &mSwapChain); } else { HANDLE *pShareHandle = NULL; if (mDisplay->isD3d9exDevice()) { pShareHandle = &mShareHandle; } result = device->CreateTexture(presentParameters.BackBufferWidth, presentParameters.BackBufferHeight, 1, D3DUSAGE_RENDERTARGET, presentParameters.BackBufferFormat, D3DPOOL_DEFAULT, &mOffscreenTexture, pShareHandle); } if (FAILED(result)) { ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY); ERR("Could not create additional swap chains or offscreen surfaces: %08lX", result); release(); return error(EGL_BAD_ALLOC); } result = device->CreateDepthStencilSurface(presentParameters.BackBufferWidth, presentParameters.BackBufferHeight, presentParameters.AutoDepthStencilFormat, presentParameters.MultiSampleType, presentParameters.MultiSampleQuality, FALSE, &mDepthStencil, NULL); if (FAILED(result)) { ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY); ERR("Could not create depthstencil surface for new swap chain: %08lX", result); release(); return error(EGL_BAD_ALLOC); } if (mWindow) { mSwapChain->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &mRenderTarget); InvalidateRect(mWindow, NULL, FALSE); } else { mOffscreenTexture->GetSurfaceLevel(0, &mRenderTarget); } mWidth = presentParameters.BackBufferWidth; mHeight = presentParameters.BackBufferHeight; mPresentIntervalDirty = false; }
clearContentComponent(); } bool wasClosedByUser() const noexcept { return fClosed; } void setTransientWinId(const uintptr_t winId) const { CARLA_SAFE_ASSERT_RETURN(winId != 0,); #ifdef HAVE_X11 CARLA_SAFE_ASSERT_RETURN(display != nullptr,); ::Window window = (::Window)getWindowHandle(); CARLA_SAFE_ASSERT_RETURN(window != 0,); XSetTransientForHint(display, window, static_cast<Window>(winId)); #endif } protected: void closeButtonPressed() override { fClosed = true; } private: volatile bool fClosed;
void GlDisplayService::handleWindowSize(GLFWwindow* window, int width, int height) { int windowHandle = getWindowHandle(window); m_windowSizeHandler.notifyListeners(windowHandle, width, height); }