public int InitializeDevice(IntPtr dwUserID, ref VMR9AllocationInfo lpAllocInfo, ref int lpNumBuffers) { ASSERT(dwUserID.ToInt32() == g_ciUsedID); if ((object)lpAllocInfo == null) { return(E_FAIL); } if ((object)lpNumBuffers == null) { return(E_POINTER); } HRESULT hr; int dwWidth = 1; int dwHeight = 1; if ((int)(m_Device.Capabilities.TextureCaps & TextureCaps.CubeMapPow2) != 0) { while (dwWidth < lpAllocInfo.dwWidth) { dwWidth = dwWidth << 1; } while (dwHeight < lpAllocInfo.dwHeight) { dwHeight = dwHeight << 1; } lpAllocInfo.dwWidth = dwWidth; lpAllocInfo.dwHeight = dwHeight; } m_nWidth = lpAllocInfo.dwWidth; m_nHeight = lpAllocInfo.dwHeight; lpAllocInfo.dwFlags |= VMR9SurfaceAllocationFlags.TextureSurface; m_Surfaces.Clear(); IntPtr[] lplpSurfaces = new IntPtr[lpNumBuffers]; hr = (HRESULT)m_lpIVMRSurfAllocNotify.AllocateSurfaceHelper(ref lpAllocInfo, ref lpNumBuffers, lplpSurfaces); hr.Assert(); if (hr.Succeeded) //if (0) { for (int i = 0; i < lplpSurfaces.Length; i++) { Marshal.AddRef(lplpSurfaces[i]); Surface _surface = Surface.FromPointer(lplpSurfaces[i]); m_Surfaces.Add(_surface); } } else { int nYUV = (int)(((int)'0') << 24 + ((int)'0') << 16 + ((int)'0') << 8 + ((int)'0')); if (lpAllocInfo.Format > nYUV) { DisplayMode _mode = m_Device.GetDisplayMode(0); m_PrivateTexture = new Texture(m_Device, _mode.Width, _mode.Height, 1, Usage.RenderTarget, _mode.Format, Pool.Default); } lpAllocInfo.dwFlags &= ~VMR9SurfaceAllocationFlags.TextureSurface; lpAllocInfo.dwFlags |= VMR9SurfaceAllocationFlags.OffscreenSurface; hr = (HRESULT)m_lpIVMRSurfAllocNotify.AllocateSurfaceHelper(ref lpAllocInfo, ref lpNumBuffers, lplpSurfaces); hr.Assert(); for (int i = 0; i < lplpSurfaces.Length; i++) { Marshal.AddRef(lplpSurfaces[i]); Surface _surface = Surface.FromPointer(lplpSurfaces[i]); m_Surfaces.Add(_surface); } } return(hr); }
public int InitializeDevice(IntPtr dwUserID, ref VMR9AllocationInfo lpAllocInfo, ref int lpNumBuffers) { ASSERT(dwUserID.ToInt32() == g_ciUsedID); if ((object)lpAllocInfo == null) return E_FAIL; if ((object)lpNumBuffers == null) return E_POINTER; HRESULT hr; int dwWidth = 1; int dwHeight = 1; if ((int)(m_Device.Capabilities.TextureCaps & TextureCaps.CubeMapPow2) != 0) { while (dwWidth < lpAllocInfo.dwWidth) dwWidth = dwWidth << 1; while (dwHeight < lpAllocInfo.dwHeight) dwHeight = dwHeight << 1; lpAllocInfo.dwWidth = dwWidth; lpAllocInfo.dwHeight = dwHeight; } m_nWidth = lpAllocInfo.dwWidth; m_nHeight = lpAllocInfo.dwHeight; lpAllocInfo.dwFlags |= VMR9SurfaceAllocationFlags.TextureSurface; m_Surfaces.Clear(); IntPtr[] lplpSurfaces = new IntPtr[lpNumBuffers]; hr = (HRESULT)m_lpIVMRSurfAllocNotify.AllocateSurfaceHelper(ref lpAllocInfo, ref lpNumBuffers, lplpSurfaces); hr.Assert(); if (hr.Succeeded) //if (0) { for (int i = 0; i < lplpSurfaces.Length; i++) { Marshal.AddRef(lplpSurfaces[i]); Surface _surface = Surface.FromPointer(lplpSurfaces[i]); m_Surfaces.Add(_surface); } } else { int nYUV = (int)(((int)'0') << 24 + ((int)'0') << 16 + ((int)'0') << 8 + ((int)'0')); if (lpAllocInfo.Format > nYUV) { DisplayMode _mode = m_Device.GetDisplayMode(0); m_PrivateTexture = new Texture(m_Device, _mode.Width, _mode.Height, 1, Usage.RenderTarget, _mode.Format, Pool.Default); } lpAllocInfo.dwFlags &= ~VMR9SurfaceAllocationFlags.TextureSurface; lpAllocInfo.dwFlags |= VMR9SurfaceAllocationFlags.OffscreenSurface; hr = (HRESULT)m_lpIVMRSurfAllocNotify.AllocateSurfaceHelper(ref lpAllocInfo, ref lpNumBuffers, lplpSurfaces); hr.Assert(); for (int i = 0; i < lplpSurfaces.Length; i++) { Marshal.AddRef(lplpSurfaces[i]); Surface _surface = Surface.FromPointer(lplpSurfaces[i]); m_Surfaces.Add(_surface); } } return hr; }