/// <summary> /// Load an image from a resource into a buffer /// </summary> /// <param name="resourceName">name of image resource to load</param> /// <param name="resourceType">type of resource to load</param> /// <param name="nOutputWidth">width (in pixels) of scaled output bitmap</param> /// <param name="nOutputHeight">height (in pixels) of scaled output bitmap</param> /// <param name="pOutputBuffer">buffer that will hold the loaded image</param> /// <returns>S_OK on success, otherwise failure code</returns> HRESULT CColorBasics::LoadResourceImage(PCWSTR resourceName, PCWSTR resourceType, UINT nOutputWidth, UINT nOutputHeight, RGBQUAD* pOutputBuffer) { IWICImagingFactory* pIWICFactory = NULL; IWICBitmapDecoder* pDecoder = NULL; IWICBitmapFrameDecode* pSource = NULL; IWICStream* pStream = NULL; IWICFormatConverter* pConverter = NULL; IWICBitmapScaler* pScaler = NULL; HRSRC imageResHandle = NULL; HGLOBAL imageResDataHandle = NULL; void *pImageFile = NULL; DWORD imageFileSize = 0; HRESULT hrCoInit = CoInitialize(NULL); HRESULT hr = hrCoInit; if (SUCCEEDED(hr)) { hr = CoCreateInstance(CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, IID_IWICImagingFactory, (LPVOID*)&pIWICFactory); } if (SUCCEEDED(hr)) { // Locate the resource imageResHandle = FindResourceW(HINST_THISCOMPONENT, resourceName, resourceType); hr = imageResHandle ? S_OK : E_FAIL; } if (SUCCEEDED(hr)) { // Load the resource imageResDataHandle = LoadResource(HINST_THISCOMPONENT, imageResHandle); hr = imageResDataHandle ? S_OK : E_FAIL; } if (SUCCEEDED(hr)) { // Lock it to get a system memory pointer. pImageFile = LockResource(imageResDataHandle); hr = pImageFile ? S_OK : E_FAIL; } if (SUCCEEDED(hr)) { // Calculate the size. imageFileSize = SizeofResource(HINST_THISCOMPONENT, imageResHandle); hr = imageFileSize ? S_OK : E_FAIL; } if (SUCCEEDED(hr)) { // Create a WIC stream to map onto the memory. hr = pIWICFactory->CreateStream(&pStream); } if (SUCCEEDED(hr)) { // Initialize the stream with the memory pointer and size. hr = pStream->InitializeFromMemory( reinterpret_cast<BYTE*>(pImageFile), imageFileSize); } if (SUCCEEDED(hr)) { // Create a decoder for the stream. hr = pIWICFactory->CreateDecoderFromStream( pStream, NULL, WICDecodeMetadataCacheOnLoad, &pDecoder); } if (SUCCEEDED(hr)) { // Create the initial frame. hr = pDecoder->GetFrame(0, &pSource); } if (SUCCEEDED(hr)) { // Convert the image format to 32bppPBGRA // (DXGI_FORMAT_B8G8R8A8_UNORM + D2D1_ALPHA_MODE_PREMULTIPLIED). hr = pIWICFactory->CreateFormatConverter(&pConverter); } if (SUCCEEDED(hr)) { hr = pIWICFactory->CreateBitmapScaler(&pScaler); } if (SUCCEEDED(hr)) { hr = pScaler->Initialize( pSource, nOutputWidth, nOutputHeight, WICBitmapInterpolationModeCubic ); } if (SUCCEEDED(hr)) { hr = pConverter->Initialize( pScaler, GUID_WICPixelFormat32bppPBGRA, WICBitmapDitherTypeNone, NULL, 0.f, WICBitmapPaletteTypeMedianCut); } UINT width = 0; UINT height = 0; if (SUCCEEDED(hr)) { hr = pConverter->GetSize(&width, &height); } // make sure the image scaled correctly so the output buffer is big enough if (SUCCEEDED(hr)) { if ((width != nOutputWidth) || (height != nOutputHeight)) { hr = E_FAIL; } } if (SUCCEEDED(hr)) { hr = pConverter->CopyPixels(NULL, width * sizeof(RGBQUAD), nOutputWidth * nOutputHeight * sizeof(RGBQUAD), reinterpret_cast<BYTE*>(pOutputBuffer)); } SafeRelease(pScaler); SafeRelease(pConverter); SafeRelease(pSource); SafeRelease(pDecoder); SafeRelease(pStream); SafeRelease(pIWICFactory); if (SUCCEEDED(hrCoInit)) { CoUninitialize(); } return hr; }
void DrawTimeFrequencyGrid::DiscardGraphicsResources() { SafeRelease(&pVGridBrush); SafeRelease(&pTextBackgroundBrush); SafeRelease(&pLabelBrush); }
template <class T> HRESULT SetInterface(T **ppT, IUnknown *punk) { SafeRelease(ppT); return punk ? punk->QueryInterface(ppT) : E_NOINTERFACE; }
void XD3DView::Release() { SafeRelease( &m_pd3dChain ); }
void OnStartRecord(HWND hwnd) { IFileSaveDialog *pFileSave = NULL; IShellItem *pItem = NULL; PWSTR pszFileName = NULL; HRESULT hr = CoCreateInstance(CLSID_FileSaveDialog, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pFileSave)); if (FAILED(hr)) { goto done; } hr = pFileSave->SetTitle(L"Select File Name"); if (FAILED(hr)) { goto done; } hr = pFileSave->SetFileName(L"MyVideo.mp4"); if (FAILED(hr)) { goto done; } hr = pFileSave->SetDefaultExtension(L"mp4"); if (FAILED(hr)) { goto done; } const COMDLG_FILTERSPEC rgSpec[] = { { L"MP4 (H.264/AAC)", L"*.mp4" }, { L"Windows Media Video", L"*.wmv" }, { L"All Files", L"*.*" }, }; hr = pFileSave->SetFileTypes(ARRAYSIZE(rgSpec), rgSpec); if (FAILED(hr)) { goto done; } hr = pFileSave->Show(hwnd); if (hr == HRESULT_FROM_WIN32(ERROR_CANCELLED)) { hr = S_OK; // The user canceled the dialog. goto done; } if (FAILED(hr)) { goto done; } hr = pFileSave->GetResult(&pItem); if (FAILED(hr)) { goto done; } hr = pItem->GetDisplayName(SIGDN_FILESYSPATH, &pszFileName); if (FAILED(hr)) { goto done; } hr = g_pEngine->StartRecord(pszFileName); if (FAILED(hr)) { goto done; } done: CoTaskMemFree(pszFileName); SafeRelease(&pItem); SafeRelease(&pFileSave); if (FAILED(hr)) { ShowError(hwnd, IDS_ERR_RECORD, hr); } UpdateUI(hwnd); }
~Direct2DRendererPrivate() { destroyDeviceResource(); SafeRelease(&d2d_factory);//vlc does not call this. why? bug? dll.unload(); }
Effect::~Effect() { SafeRelease(mEffect); }
Query9::~Query9() { SafeRelease(mQuery); }
void FlashWndInfo::Destroy() { SafeRelease( m_image.pTexture ); }
HRESULT CLAVSplitterSettingsProp::OnDisconnect() { SafeRelease(&m_pLAVF); return S_OK; }
CLAVSplitterFormatsProp::~CLAVSplitterFormatsProp(void) { SAFE_CO_FREE(m_bFormats); SafeRelease(&m_pLAVF); }
//加载信息 bool CUserInformation::LoadInformation() { //变量定义 IStream * pIStreamSub=NULL; IStorage * pIStorageSub=NULL; IStorage * pIStorageRoot=NULL; IEnumSTATSTG * pIEnumSTATSTG=NULL; //读取数据 try { //变量定义 STATSTG Statstg; tagCompanionInfo CompanionInfo; ZeroMemory(&Statstg,sizeof(Statstg)); ZeroMemory(&CompanionInfo,sizeof(CompanionInfo)); //工作目录 TCHAR szDirectory[MAX_PATH]=TEXT(""); CWHService::GetWorkDirectory(szDirectory,CountArray(szDirectory)); //打开文件 WCHAR szInfomationFile[MAX_PATH]=L""; _snwprintf(szInfomationFile,CountArray(szInfomationFile),L"%s\\%s",(LPCWSTR)(CT2CW(szDirectory)),INFORMATION_FILE); //打开文件 StgOpenStorage(szInfomationFile,NULL,STGM_READ|STGM_SHARE_EXCLUSIVE,0,0,&pIStorageRoot); if (pIStorageRoot==NULL) return false; //创建枚举 pIStorageRoot->EnumElements(0,NULL,0,&pIEnumSTATSTG); if (pIEnumSTATSTG==NULL) throw TEXT("EnumElements Create pIEnumSTATSTG Error"); //枚举对象 while (pIEnumSTATSTG->Next(1,&Statstg,NULL)==NOERROR) { //目录类型 if (Statstg.type==STGTY_STORAGE) { //打开存储 pIStorageRoot->OpenStorage(Statstg.pwcsName,NULL,STGM_READ|STGM_SHARE_EXCLUSIVE,0,0,&pIStorageSub); if (pIStorageSub==NULL) throw TEXT("CreateStorage Create pIStorageSub Error"); //打开数据 pIStorageSub->OpenStream(STREAM_COMPANION,NULL,STGM_READ|STGM_SHARE_EXCLUSIVE,0,&pIStreamSub); //读取数据 if (pIStreamSub!=NULL) { //读取关系 ULONG cbReadCount=0L; pIStreamSub->Read(&CompanionInfo,sizeof(CompanionInfo),&cbReadCount); //读取效验 ASSERT(cbReadCount==sizeof(CompanionInfo)); if (cbReadCount!=sizeof(CompanionInfo)) throw TEXT("Read Data CompanionInfo Error"); //创建对象 tagCompanionInfo * pCompanionInfo=CreateCompanionItem(); if (pCompanionInfo==NULL) throw TEXT("CreateCompanionItem Error"); //设置信息 CopyMemory(pCompanionInfo,&CompanionInfo,sizeof(CompanionInfo)); } //释放接口 SafeRelease(pIStreamSub); SafeRelease(pIStorageSub); } //释放内存 CoTaskMemFree(Statstg.pwcsName); } //释放接口 SafeRelease(pIEnumSTATSTG); SafeRelease(pIStreamSub); SafeRelease(pIStorageSub); SafeRelease(pIStorageRoot); return true; } catch (...) { //错误断言 ASSERT(FALSE); //释放接口 SafeRelease(pIEnumSTATSTG); SafeRelease(pIStreamSub); SafeRelease(pIStorageSub); SafeRelease(pIStorageRoot); } return false; }
//设置关系 tagCompanionInfo * CUserInformation::InsertCompanionInfo(IClientUserItem * pIClientUserItem, BYTE cbCompanion) { //效验参数 ASSERT(pIClientUserItem!=NULL); if (pIClientUserItem==NULL) return NULL; //用户搜索 DWORD dwUserID=pIClientUserItem->GetUserID(); tagCompanionInfo * pCompanionInfo=SearchCompanionInfo(dwUserID); //设置信息 if (pCompanionInfo==NULL) { //创建对象 pCompanionInfo=CreateCompanionItem(); if (pCompanionInfo==NULL) return NULL; //设置信息 pCompanionInfo->cbCompanion=cbCompanion; pCompanionInfo->dwGameID=pIClientUserItem->GetGameID(); pCompanionInfo->dwUserID=pIClientUserItem->GetUserID(); lstrcpyn(pCompanionInfo->szNickName,pIClientUserItem->GetNickName(),CountArray(pCompanionInfo->szNickName)); lstrcpyn(pCompanionInfo->szUserNote,pIClientUserItem->GetUserNoteInfo(),CountArray(pCompanionInfo->szUserNote)); //插入通知 if (m_pIUserCompanionSink!=NULL) m_pIUserCompanionSink->OnCompanionInsert(pCompanionInfo); } else { //修改判断 bool bModify=false; if (pCompanionInfo->cbCompanion!=cbCompanion) bModify=true; if ((bModify==false)&&(lstrcmp(pCompanionInfo->szNickName,pIClientUserItem->GetNickName())!=0)) bModify=true; if ((bModify==false)&&(lstrcmp(pCompanionInfo->szUserNote,pIClientUserItem->GetUserNoteInfo())!=0)) bModify=true; //修改判断 if (bModify=false) return pCompanionInfo; //设置信息 pCompanionInfo->cbCompanion=cbCompanion; pCompanionInfo->dwGameID=pIClientUserItem->GetGameID(); pCompanionInfo->dwUserID=pIClientUserItem->GetUserID(); lstrcpyn(pCompanionInfo->szNickName,pIClientUserItem->GetNickName(),CountArray(pCompanionInfo->szNickName)); lstrcpyn(pCompanionInfo->szUserNote,pIClientUserItem->GetUserNoteInfo(),CountArray(pCompanionInfo->szUserNote)); //更新通知 if (m_pIUserCompanionSink!=NULL) m_pIUserCompanionSink->OnCompanionUpdate(pCompanionInfo); } //变量定义 IStream * pIStreamSub=NULL; IStorage * pIStorageSub=NULL; IStorage * pIStorageRoot=NULL; //写入数据 try { //构造名字 WCHAR szStorageName[16]=L""; _snwprintf(szStorageName,CountArray(szStorageName),L"%ld",dwUserID); //工作目录 TCHAR szDirectory[MAX_PATH]=TEXT(""); CWHService::GetWorkDirectory(szDirectory,CountArray(szDirectory)); //打开文件 WCHAR szInfomationFile[MAX_PATH]=L""; _snwprintf(szInfomationFile,CountArray(szInfomationFile),L"%s\\%s",(LPCWSTR)(CT2CW(szDirectory)),INFORMATION_FILE); //打开文件 StgOpenStorage(szInfomationFile,NULL,STGM_READWRITE|STGM_SHARE_EXCLUSIVE,0,0,&pIStorageRoot); if (pIStorageRoot==NULL) StgCreateDocfile(szInfomationFile,STGM_CREATE|STGM_READWRITE|STGM_SHARE_EXCLUSIVE,0,&pIStorageRoot); //错误判断 if (pIStorageRoot==NULL) throw TEXT("StgCreateDocfile Create pIStorageRoot Error"); //打开存储 pIStorageRoot->CreateStorage(szStorageName,STGM_WRITE|STGM_SHARE_EXCLUSIVE,0,0,&pIStorageSub); if (pIStorageSub==NULL) pIStorageRoot->CreateStorage(szStorageName,STGM_CREATE|STGM_WRITE|STGM_SHARE_EXCLUSIVE,0,0,&pIStorageSub); //错误处理 if (pIStorageSub==NULL) throw TEXT("CreateStorage Create pIStorageSub Error"); //创建数据 pIStorageSub->CreateStream(STREAM_COMPANION,STGM_WRITE|STGM_SHARE_EXCLUSIVE,0,0,&pIStreamSub); if (pIStreamSub==NULL) pIStorageSub->CreateStream(STREAM_COMPANION,STGM_CREATE|STGM_WRITE|STGM_SHARE_EXCLUSIVE,0,0,&pIStreamSub); //错误处理 if (pIStreamSub==NULL) throw TEXT("CreateStream Create pIStreamSub Error"); //写入数据 ULONG cbWriteCount=0L; pIStreamSub->Write(pCompanionInfo,sizeof(tagCompanionInfo),&cbWriteCount); //释放接口 SafeRelease(pIStreamSub); SafeRelease(pIStorageSub); SafeRelease(pIStorageRoot); return pCompanionInfo; } catch (...) { //错误断言 ASSERT(FALSE); //释放接口 SafeRelease(pIStreamSub); SafeRelease(pIStorageSub); SafeRelease(pIStorageRoot); } return NULL; }
void Scene::DiscardDeviceDependentResources() { SafeRelease(&m_pFill); SafeRelease(&m_pStroke); SafeRelease(&m_pRenderTarget); }
DrawTimeFrequencyGrid::~DrawTimeFrequencyGrid() { SafeRelease( &pTextFormat ); SafeRelease( &pDWriteFactory ); SafeRelease( &pFactory ); }
BOOL CProcessMgrImpl::SetWin7Mute( BOOL bMute/* =TRUE */ ) { if ( m_bMute == bMute ) return S_OK; IMMDeviceEnumerator* pEnumerator; HRESULT hr = E_FAIL; CoInitialize( NULL ); hr = CoCreateInstance( __uuidof( MMDeviceEnumerator ), NULL, CLSCTX_ALL, __uuidof( IMMDeviceEnumerator ), ( void** )&pEnumerator ); IMMDevice* pDevice; hr = pEnumerator->GetDefaultAudioEndpoint( eRender, eConsole, &pDevice ); if ( FAILED( hr ) ) return hr; IAudioSessionManager2* pasm = NULL; hr = pDevice->Activate( __uuidof( IAudioSessionManager2 ), CLSCTX_ALL, NULL, ( void** )&pasm ); if ( FAILED( hr ) ) return hr; IAudioSessionEnumerator* audio_session_enumerator; if ( SUCCEEDED( pasm->GetSessionEnumerator( &audio_session_enumerator ) ) ) { int count; if ( SUCCEEDED( audio_session_enumerator->GetCount( &count ) ) ) { for ( int i = 0; i < count; i++ ) { IAudioSessionControl* audio_session_control; IAudioSessionControl2* audio_session_control2; if ( SUCCEEDED( audio_session_enumerator->GetSession( i, &audio_session_control ) ) ) { if ( SUCCEEDED( audio_session_control->QueryInterface( __uuidof( IAudioSessionControl2 ), ( void** )&audio_session_control2 ) ) ) { DWORD processid; if ( SUCCEEDED( audio_session_control2->GetProcessId( &processid ) ) ) { if ( processid == GetCurrentProcessId() ) { ISimpleAudioVolume* pSAV; hr = audio_session_control2->QueryInterface( __uuidof( ISimpleAudioVolume ), ( void** ) &pSAV ); if ( SUCCEEDED( hr ) ) { hr = pSAV->SetMute( bMute, NULL ); if ( SUCCEEDED( hr ) ) { m_bMute = bMute; } pSAV->Release(); } } audio_session_control->Release(); audio_session_control2->Release(); } } } } audio_session_enumerator->Release(); } } pasm->Release(); SafeRelease( &pEnumerator ); ::CoUninitialize(); return hr; }
TextureStorage9_2D::~TextureStorage9_2D() { SafeRelease(mTexture); SafeDelete(mRenderTarget); }
void FlashWndInfo::ReleaseTexture() { --m_iRef; if (m_iRef <= 0) SafeRelease( m_image.pTexture ); }
DepthStencilBuffer::~DepthStencilBuffer() { SafeRelease(depth_stencil_view); SafeRelease(depth_stencil_texture); }
/// <summary> /// Main processing function /// </summary> // この関数がループ処理される void CColorBasics::Update() { HRESULT hr = NULL; // (1) カラーフレーム(背景描画のみに使用) if (m_pColorFrameReader) { IColorFrame* pColorFrame = NULL; hr = m_pColorFrameReader->AcquireLatestFrame(&pColorFrame); if (SUCCEEDED(hr)) { INT64 nTime = 0; IFrameDescription* pFrameDescription = NULL; int nWidth = 0; int nHeight = 0; ColorImageFormat imageFormat = ColorImageFormat_None; UINT nBufferSize = 0; RGBQUAD *pBuffer = NULL; hr = pColorFrame->get_RelativeTime(&nTime); if (SUCCEEDED(hr)) { hr = pColorFrame->get_FrameDescription(&pFrameDescription); } if (SUCCEEDED(hr)) { hr = pFrameDescription->get_Width(&nWidth); } if (SUCCEEDED(hr)) { hr = pFrameDescription->get_Height(&nHeight); } if (SUCCEEDED(hr)) { hr = pColorFrame->get_RawColorImageFormat(&imageFormat); } if (SUCCEEDED(hr)) { if (imageFormat == ColorImageFormat_Bgra) { hr = pColorFrame->AccessRawUnderlyingBuffer(&nBufferSize, reinterpret_cast<BYTE**>(&pBuffer)); } else if (m_pColorRGBX) { pBuffer = m_pColorRGBX; nBufferSize = cColorWidth * cColorHeight * sizeof(RGBQUAD); hr = pColorFrame->CopyConvertedFrameDataToArray(nBufferSize, reinterpret_cast<BYTE*>(pBuffer), ColorImageFormat_Bgra); } else { hr = E_FAIL; } } if (SUCCEEDED(hr)) { ProcessColor(nTime, pBuffer, nWidth, nHeight); } SafeRelease(pFrameDescription); } SafeRelease(pColorFrame); } // これ以降にBody処理を実装 TIMESPAN nBodyTime = 0; if (m_pBodyFrameReader) { IBodyFrame* pBodyFrame = NULL; hr = m_pBodyFrameReader->AcquireLatestFrame(&pBodyFrame); if (SUCCEEDED(hr)) { hr = pBodyFrame->get_RelativeTime(&nBodyTime); // ここに、UI描画処理 ボタン等 // ゲームのステータスによって描画を設定 if (!m_pGame){ m_pGame = new CSemaphoreGame(m_pDrawColor, m_pCoordinateMapper); } if (m_pGame){ m_pGame->Display(nBodyTime); } IBody* ppBodies[BODY_COUNT] = { 0 }; if (SUCCEEDED(hr)) { hr = pBodyFrame->GetAndRefreshBodyData(_countof(ppBodies), ppBodies); } if (SUCCEEDED(hr)) { // ここに、UI処理->ProcessBody()内でOK // ボディデータにてUI処理を行う // ステータスの変更 if (m_pGame){ m_pGame->Play(nBodyTime, BODY_COUNT, ppBodies); } ProcessBody(nBodyTime, BODY_COUNT, ppBodies); } for (int i = 0; i < _countof(ppBodies); ++i) { SafeRelease(ppBodies[i]); } } SafeRelease(pBodyFrame); } return; }
SkyboxSystem::~SkyboxSystem() { SafeRelease(skyboxEntity); }
~CCandidateListGetTextExtEditSession() { SafeRelease(&_pCandidateWindow); SafeRelease(&_pRangeComposition); SafeRelease(&_pContextView); }
void destroyDeviceResource() { SafeRelease(&render_target); SafeRelease(&bitmap); }
~CCandidateWindowEditSession() { SafeRelease(&_pCandidateWindow); SafeRelease(&_pRangeComposition); }
CBaseBrushDraw::~CBaseBrushDraw(void) { SafeRelease(m_pTexture); SafeDelete(m_pBrushGridHepler); SafeDelete(m_pEditCurveRender); }
HRESULT CCandidateList::_StartCandidateList(TfClientId tfClientId, ITfDocumentMgr *pDocumentMgr, ITfContext *pContext, TfEditCookie ec, ITfRange *pRange, BOOL reg, BOOL comp) { HRESULT hr = E_FAIL; TfEditCookie ecTextStore; ITfContextView *pContextView; HWND hwnd = NULL; _EndCandidateList(); if(pDocumentMgr->CreateContext(tfClientId, 0, NULL, &_pContextCandidateWindow, &ecTextStore) != S_OK) { return E_FAIL; } if(pDocumentMgr->Push(_pContextCandidateWindow) != S_OK) { goto exit; } _pDocumentMgr = pDocumentMgr; _pDocumentMgr->AddRef(); _pContextDocument = pContext; _pContextDocument->AddRef(); _pRangeComposition = pRange; _pRangeComposition->AddRef(); _ec = ec; _comp = comp; if(_AdviseContextKeyEventSink() != S_OK) { goto exit; } if(_AdviseTextLayoutSink() != S_OK) { goto exit; } try { _pCandidateWindow = new CCandidateWindow(_pTextService, this); if(pContext->GetActiveView(&pContextView) == S_OK) { if(!_pTextService->_UILessMode && _pCandidateWindow->_CanShowUIElement()) { if(FAILED(pContextView->GetWnd(&hwnd)) || hwnd == NULL) { hwnd = GetFocus(); } } SafeRelease(&pContextView); } if(!_pCandidateWindow->_Create(hwnd, NULL, 0, 0, reg, comp)) { goto exit; } HRESULT hrSession = E_FAIL; try { CCandidateWindowEditSession *pEditSession = new CCandidateWindowEditSession(_pTextService, _pContextDocument, _pRangeComposition, _pCandidateWindow); // Asynchronous pContext->RequestEditSession(ec, pEditSession, TF_ES_ASYNC | TF_ES_READWRITE, &hrSession); SafeRelease(&pEditSession); } catch(...) { } if(hrSession != TF_S_ASYNC) { hr = E_FAIL; goto exit; } hr = S_OK; } catch(...) { } exit: if(hr != S_OK) { _EndCandidateList(); } return hr; }
ErrorNotifier::~ErrorNotifier() { SafeRelease(errorDialog); }
EGLint SwapChain9::reset(int backbufferWidth, int backbufferHeight, EGLint swapInterval) { IDirect3DDevice9 *device = mRenderer->getDevice(); if (device == NULL) { return EGL_BAD_ACCESS; } // 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. SafeRelease(mSwapChain); SafeRelease(mBackBuffer); SafeRelease(mOffscreenTexture); SafeRelease(mDepthStencil); HANDLE *pShareHandle = NULL; if (!mWindow && mRenderer->getShareHandleSupport()) { pShareHandle = &mShareHandle; } result = device->CreateTexture(backbufferWidth, backbufferHeight, 1, D3DUSAGE_RENDERTARGET, gl_d3d9::GetTextureFormat(mBackBufferFormat, mRenderer), D3DPOOL_DEFAULT, &mOffscreenTexture, pShareHandle); if (FAILED(result)) { ERR("Could not create offscreen texture: %08lX", result); release(); if (d3d9::isDeviceLostError(result)) { return EGL_CONTEXT_LOST; } else { return EGL_BAD_ALLOC; } } 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; } mRenderer->endScene(); result = device->StretchRect(oldRenderTarget, &rect, mRenderTarget, &rect, D3DTEXF_NONE); ASSERT(SUCCEEDED(result)); SafeRelease(oldRenderTarget); } if (mWindow) { D3DPRESENT_PARAMETERS presentParameters = {0}; presentParameters.AutoDepthStencilFormat = gl_d3d9::GetRenderFormat(mDepthBufferFormat, mRenderer); presentParameters.BackBufferCount = 1; presentParameters.BackBufferFormat = gl_d3d9::GetRenderFormat(mBackBufferFormat, mRenderer); presentParameters.EnableAutoDepthStencil = FALSE; presentParameters.Flags = 0; presentParameters.hDeviceWindow = mWindow; presentParameters.MultiSampleQuality = 0; // FIXME: Unimplemented presentParameters.MultiSampleType = D3DMULTISAMPLE_NONE; // FIXME: Unimplemented presentParameters.PresentationInterval = convertInterval(swapInterval); 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. if (mRenderer->getAdapterVendor() == 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 (d3d9::isDeviceLostError(result)) { return EGL_CONTEXT_LOST; } else { return EGL_BAD_ALLOC; } } result = mSwapChain->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &mBackBuffer); ASSERT(SUCCEEDED(result)); InvalidateRect(mWindow, NULL, FALSE); } if (mDepthBufferFormat != GL_NONE) { result = device->CreateDepthStencilSurface(backbufferWidth, backbufferHeight, gl_d3d9::GetRenderFormat(mDepthBufferFormat, mRenderer), 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 (d3d9::isDeviceLostError(result)) { return EGL_CONTEXT_LOST; } else { return EGL_BAD_ALLOC; } } } mWidth = backbufferWidth; mHeight = backbufferHeight; mSwapInterval = swapInterval; return EGL_SUCCESS; }
EIEdgeImage::~EIEdgeImage() { SafeRelease(); }
MongodbObject::~MongodbObject() { SafeRelease(objectData); }