HRESULT SetAllocatorPresenter( IBaseFilter *filter, HWND window )
{
    if( filter == NULL )
    {
        return E_FAIL;
    }

    HRESULT hr;

    SmartPtr<IVMRSurfaceAllocatorNotify9> lpIVMRSurfAllocNotify;
    FAIL_RET( filter->QueryInterface(IID_IVMRSurfaceAllocatorNotify9, reinterpret_cast<void**>(&lpIVMRSurfAllocNotify)) );

    // create our surface allocator
    g_allocator.Attach(new CAllocator( hr, window ));
    if( FAILED( hr ) )
    {
        g_allocator = NULL;
        return hr;
    }

    // let the allocator and the notify know about each other
    FAIL_RET( lpIVMRSurfAllocNotify->AdviseSurfaceAllocator( g_userId, g_allocator ) );
    FAIL_RET( g_allocator->AdviseNotify(lpIVMRSurfAllocNotify) );
    
    return hr;
}
HRESULT ConfigureVMR9(HWND window)
{
    assert(g_graph != NULL);

    HRESULT hr = S_OK;
    RECT rect;

    SmartPtr<IVMRFilterConfig9> filterConfig;

    // Create the VMR-9.
    FAIL_RET( CoCreateInstance(CLSID_VideoMixingRenderer9, NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void**)&g_filter) );

    // Configure the VMR-9.
    // Set the maximum number of video streams, and set windowless mode. 
    FAIL_RET( g_filter->QueryInterface(IID_IVMRFilterConfig9, reinterpret_cast<void**>(&filterConfig)) );

    FAIL_RET( filterConfig->SetNumberOfStreams( MAX_VIDEO_STREAMS ) );
    FAIL_RET( filterConfig->SetRenderingMode( VMR9Mode_Windowless ) );

    FAIL_RET( g_filter->QueryInterface(IID_IVMRWindowlessControl9, reinterpret_cast<void**>(&g_windowlessControl)) );
    FAIL_RET( g_windowlessControl->SetVideoClippingWindow( window ) );

    GetClientRect( window, & rect );
    FAIL_RET( g_windowlessControl->SetVideoPosition(NULL, & rect) );

    // Set the custom compositor on the VMR-9.

    g_compositor.Attach( new CMyCompositor9() );
    FAIL_RET( filterConfig->SetImageCompositor( g_compositor ));

    // Add the VMR-9 to the filter graph.
    FAIL_RET( g_graph->AddFilter(g_filter, L"Video Mixing Renderer 9") );

    return hr;
}
HRESULT CMyCompositor9::SetUpFog( IDirect3DDevice9* d3ddev )
{
    HRESULT hr;
    float fogStart = 2.0;
    float fogEnd = 6.0;

    FAIL_RET( d3ddev->SetRenderState( D3DRS_FOGENABLE, TRUE ));
    FAIL_RET( d3ddev->SetRenderState( D3DRS_FOGCOLOR, 0x00001020));
    FAIL_RET( d3ddev->SetRenderState( D3DRS_FOGSTART, DWORD( fogStart ) ));
    FAIL_RET( d3ddev->SetRenderState( D3DRS_FOGEND, DWORD( fogEnd ) ));
    return hr;
}
Ejemplo n.º 4
0
bool Path::LoadPath(const QString& path){
	mPath.clear();
	QDir rootDir(path);
	FAIL_RET(rootDir.exists());
	if(!rootDir.exists(ASSET_INNER_PATH)){
		FAIL_RET(rootDir.mkpath(ASSET_INNER_PATH));
	}
    if(!rootDir.exists(OBJECT_INNER_PATH)){
        FAIL_RET(rootDir.mkpath(OBJECT_INNER_PATH));
    }
	if(!rootDir.exists(MAP_INNER_PATH)){
		FAIL_RET(rootDir.mkpath(MAP_INNER_PATH));
	}
    if(!rootDir.exists(MAP_INNER_PATH_JSON)){
        FAIL_RET(rootDir.mkpath(MAP_INNER_PATH_JSON));
    }
	if(!rootDir.exists(ZIP_INNER_PATH)){
		FAIL_RET(rootDir.mkpath(ZIP_INNER_PATH));
	}
	mAssetDir.setPath(rootDir.absoluteFilePath(ASSET_INNER_PATH));
	FAIL_RET(mAssetDir.exists());
    mObjectDir.setPath(rootDir.absoluteFilePath(OBJECT_INNER_PATH));
    FAIL_RET(mObjectDir.exists());
	mPath = rootDir.absolutePath();
	AddRecentProject(mPath);
	return true;
}
HRESULT CMyCompositor9::AdjustViewMatrix( IDirect3DDevice9* d3ddev )
{
    ASSERT( d3ddev );
    HRESULT hr;

    if( m_needTurn == false ) {
        return S_FALSE;
    }

    //
    // view matrix
    //
    float x, y;
    x = float( m_x ) / 100 ;
    y = float( m_y ) / 100 ;
    D3DVECTOR from = { x, y, -4.0f };
    D3DVECTOR at = { 0.0f, 1.0f, 0.0f };
    D3DVECTOR up = { 0.0f, 1.0f, 0.0f };

    D3DMATRIX matView;
    MatrixLookAtLH(&matView, &from, &at, &up);
    FAIL_RET( d3ddev->SetTransform( D3DTS_VIEW, &matView ) );

    m_needTurn = false;
    return hr;
}
HRESULT CMyCompositor9::CreateTexture( IDirect3DDevice9* d3ddev, DWORD x, DWORD y )
{
    ASSERT( d3ddev );
    HRESULT hr;
    D3DDISPLAYMODE dm; 
    FAIL_RET( d3ddev->GetDisplayMode(NULL,  & dm ) );

    m_texture = NULL;
    // create the private texture
    FAIL_RET( d3ddev->CreateTexture(x, y,
        1, 
        D3DUSAGE_RENDERTARGET, 
        dm.Format, 
        D3DPOOL_DEFAULT /* default pool - usually video memory */, 
        & m_texture, NULL ) );
    return hr;
}
Ejemplo n.º 7
0
int
do_test (void)
{
  void *sstk = xalloc_sigstack (0);
  struct sigaction sa;

  sa.sa_handler = handler;
  sa.sa_flags   = SA_RESTART | SA_ONSTACK;
  sigfillset (&sa.sa_mask);
  if (sigaction (SIGUSR1, &sa, 0))
    FAIL_RET ("sigaction (SIGUSR1, handler): %m\n");

  raise (SIGUSR1);

  xfree_sigstack (sstk);
  FAIL_RET ("test process was not terminated by quick_exit in signal handler");
}
Ejemplo n.º 8
0
bool Path::NewPath(const QString& path,const QString& folderName){
	mPath.clear();
	QDir rootDir(path);
	FAIL_RET(rootDir.exists());
	FAIL_RET(rootDir.mkdir(folderName));
	FAIL_RET(rootDir.cd(folderName));
	FAIL_RET(rootDir.mkpath(ASSET_INNER_PATH));
    FAIL_RET(rootDir.mkpath(OBJECT_INNER_PATH));
	FAIL_RET(rootDir.mkpath(MAP_INNER_PATH));
    FAIL_RET(rootDir.mkpath(MAP_INNER_PATH_JSON));
	FAIL_RET(rootDir.mkpath(ZIP_INNER_PATH));
	mAssetDir.setPath(rootDir.absoluteFilePath(ASSET_INNER_PATH));
	FAIL_RET(mAssetDir.exists());
    mObjectDir.setPath(rootDir.absoluteFilePath(OBJECT_INNER_PATH));
    FAIL_RET(mObjectDir.exists());
	mPath = rootDir.absolutePath();
	AddRecentProject(mPath);
	return true;
}
Ejemplo n.º 9
0
HRESULT CAllocator::PresentImage( 
    /* [in] */ DWORD_PTR dwUserID,
    /* [in] */ VMR9PresentationInfo *lpPresInfo)
{
    HRESULT hr;
//    CAutoLock Lock(&m_ObjectLock);

    // if we are in the middle of the display change
    if( NeedToHandleDisplayChange() )
    {
        // NOTE: this piece of code is left as a user exercise.  
        // The D3DDevice here needs to be switched
        // to the device that is using another adapter
    }

    hr = PresentHelper( lpPresInfo );

#if 0
    // IMPORTANT: device can be lost when user changes the resolution
    // or when (s)he presses Ctrl + Alt + Delete.
    // We need to restore our video memory after that
    if( hr == D3DERR_DEVICELOST)
    {
        if (m_D3DDev->TestCooperativeLevel() == D3DERR_DEVICENOTRESET) 
        {
            DeleteSurfaces();
            FAIL_RET( CreateDevice() );

            HMONITOR hMonitor = m_D3D->GetAdapterMonitor( D3DADAPTER_DEFAULT );

            FAIL_RET( m_lpIVMRSurfAllocNotify->ChangeD3DDevice( m_D3DDev, hMonitor ) );

        }

        hr = S_OK;
    }
#endif

    return hr;
}
Ejemplo n.º 10
0
bool GSScreen::Clear(SelItem& item) const{
	QList<QGraphicsItem*> childList = childItems();
	FAIL_RET(!childList.isEmpty());
	if(childList.last()->zValue() > 0){
		item.isSelect = true;
		item.pItem = childList.last();
		item.pItem->setZValue(0);
	}else{
		item.isSelect = false;
		item.pItem = 0;
	}
	return true;
}
Ejemplo n.º 11
0
bool FolderDelThread::RmFolder(const QDir& dir){
	if(!dir.exists()) return true;
	
	QFileInfoList fileList = dir.entryInfoList();
	foreach(QFileInfo info,fileList)
	{
		QString fileName = info.fileName();
		if(fileName == "." || fileName==".."){
			//暂时先不处理
		}else if(info.isFile() || info.isSymLink()){
			QFile file(info.filePath());
			FAIL_RET( file.setPermissions(QFile::WriteOwner) );
			FAIL_RET( file.remove() );
			emit Increase();
			emit Name(fileName);
		}else if(info.isDir()){	
			FAIL_RET(RmFolder(info.filePath()));	
		}else{
			//不存在其他类型的情况
			assert(false); 
			return false;
		}
	}
static void
create_arp_response(ip_addr_t *adr)
{
  int k;
  struct eth_hdr *ethhdr;
  struct etharp_hdr *etharphdr;
  struct pbuf *p = pbuf_alloc(PBUF_RAW, sizeof(struct eth_hdr) + sizeof(struct etharp_hdr), PBUF_RAM);
  if(p == NULL) {
    FAIL_RET();
  }
  ethhdr = (struct eth_hdr*)p->payload;
  etharphdr = (struct etharp_hdr*)(ethhdr + 1);

  ethhdr->dest = test_ethaddr;
  ethhdr->src = test_ethaddr2;
  ethhdr->type = htons(ETHTYPE_ARP);

  etharphdr->hwtype = htons(/*HWTYPE_ETHERNET*/ 1);
  etharphdr->proto = htons(ETHTYPE_IP);
  etharphdr->hwlen = ETHARP_HWADDR_LEN;
  etharphdr->protolen = sizeof(ip_addr_t);
  etharphdr->opcode = htons(ARP_REPLY);

  SMEMCPY(&etharphdr->sipaddr, adr, sizeof(ip_addr_t));
  SMEMCPY(&etharphdr->dipaddr, &test_ipaddr, sizeof(ip_addr_t));

  k = 6;
  while(k > 0) {
    k--;
    /* Write the ARP MAC-Addresses */
    etharphdr->shwaddr.addr[k] = test_ethaddr2.addr[k];
    etharphdr->dhwaddr.addr[k] = test_ethaddr.addr[k];
    /* Write the Ethernet MAC-Addresses */
    ethhdr->dest.addr[k] = test_ethaddr.addr[k];
    ethhdr->src.addr[k]  = test_ethaddr2.addr[k];
  }

  ethernet_input(p, &test_netif);
}
// IVMRImageCompositor9
HRESULT STDMETHODCALLTYPE CMyCompositor9::InitCompositionDevice( 
    /* [in] */ IUnknown *pD3DDevice)
{
    HRESULT hr;
    SmartPtr<IDirect3DDevice9> d3ddev;
    
    hr = pD3DDevice->QueryInterface(__uuidof(IDirect3DDevice9), (void**)&d3ddev);
    ASSERT( d3ddev );

    //FAIL_RET( SetUpFog( d3ddev ) );
    //
    // Set the projection matrix
    //
    SmartPtr<IDirect3DSurface9> backBuffer;
    FAIL_RET( d3ddev->GetRenderTarget( 0, &backBuffer ) );

    D3DSURFACE_DESC backBufferDesc;
    backBuffer->GetDesc( & backBufferDesc );

    FAIL_RET( AdjustViewMatrix( d3ddev ) );

    D3DMATRIX matProj;
    FLOAT fAspect = backBufferDesc.Width / 
                    (float)backBufferDesc.Height;
    MatrixPerspectiveFovLH( &matProj, (float)M_PI_4, fAspect, 
                                1.0f, 100.0f );
    FAIL_RET( d3ddev->SetTransform( D3DTS_PROJECTION, &matProj ) );

    // 
    // vertex buffer
    // 
    m_vertexBuffer = NULL;
    FAIL_RET( d3ddev->CreateVertexBuffer(sizeof(m_vertices),D3DUSAGE_WRITEONLY,
         D3DFVF_CUSTOMVERTEX,D3DPOOL_MANAGED,& m_vertexBuffer, NULL ) );

    if( m_createTexture ) {
        FAIL_RET( CreateTexture( d3ddev, backBufferDesc.Width, backBufferDesc.Height ) );
    }

	m_zSurface = NULL;
	FAIL_RET(  d3ddev->CreateDepthStencilSurface( backBufferDesc.Width, backBufferDesc.Height,
        D3DFMT_D16, D3DMULTISAMPLE_NONE, 0, TRUE, &m_zSurface, NULL )  ); 

    return S_OK;
}
Ejemplo n.º 14
0
HRESULT CAllocator::PresentHelper(VMR9PresentationInfo *lpPresInfo)
{

#if 0
    // parameter validation
    if( lpPresInfo == NULL )
    {
        return E_POINTER;
    }
    else if( lpPresInfo->lpSurf == NULL )
    {
        return E_POINTER;
    }

//    CAutoLock Lock(&m_ObjectLock);
    HRESULT hr;

    m_D3DDev->SetRenderTarget( 0, m_renderTarget );
    // if we created a  private texture
    // blt the decoded image onto the texture.
    if( m_privateTexture != NULL )
    {   
        CComPtr<IDirect3DSurface9> surface;
        FAIL_RET( m_privateTexture->GetSurfaceLevel( 0 , & surface.p ) );

        // copy the full surface onto the texture's surface
        FAIL_RET( m_D3DDev->StretchRect( lpPresInfo->lpSurf, NULL,
                             surface, NULL,
                             D3DTEXF_NONE ) );

        FAIL_RET( m_scene.DrawScene(m_D3DDev, m_privateTexture ) );
    }
    else // this is the case where we have got the textures allocated by VMR
         // all we need to do is to get them from the surface
    {
        CComPtr<IDirect3DTexture9> texture;
        FAIL_RET( lpPresInfo->lpSurf->GetContainer( IID_IDirect3DTexture9, (LPVOID*) & texture.p ) );    
        FAIL_RET( m_scene.DrawScene(m_D3DDev, texture ) );
    }

    FAIL_RET( m_D3DDev->Present( NULL, NULL, NULL, NULL ) );

#endif
    return S_OK;
}
HRESULT STDMETHODCALLTYPE CMyCompositor9::CompositeImage( 
    /* [in] */ IUnknown *pD3DDevice,
    /* [in] */ IDirect3DSurface9 *pddsRenderTarget,
    /* [in] */ AM_MEDIA_TYPE *pmtRenderTarget,
    /* [in] */ REFERENCE_TIME rtStart,
    /* [in] */ REFERENCE_TIME rtEnd,
    /* [in] */ D3DCOLOR dwClrBkGnd,
    /* [in] */ VMR9VideoStreamInfo *pVideoStreamInfo,
    /* [in] */ UINT cStreams)
{
    ASSERT( pD3DDevice );
    if( pD3DDevice == NULL ) {
        return E_POINTER;
    }

    HRESULT hr;
    SmartPtr<IDirect3DDevice9> d3ddev;
    
    pD3DDevice->QueryInterface(__uuidof(IDirect3DDevice9), (void**)&d3ddev);
    ASSERT( d3ddev );

    FAIL_RET( d3ddev->SetRenderState( D3DRS_AMBIENT, 0x00202020 ) );
    FAIL_RET( d3ddev->SetRenderState( D3DRS_LIGHTING, FALSE ) );
    FAIL_RET( d3ddev->SetRenderState( D3DRS_CULLMODE,D3DCULL_NONE)); 
    FAIL_RET( d3ddev->SetRenderState( D3DRS_ZENABLE,TRUE)); 

    FAIL_RET( AdjustViewMatrix( d3ddev ) );

    // write the new vertex information into the buffer
    void* pData;
    FAIL_RET( m_vertexBuffer->Lock(0, sizeof m_vertices, &pData,0) );
    memcpy(pData,m_vertices,sizeof(m_vertices));                            
    FAIL_RET( m_vertexBuffer->Unlock() );  

	FAIL_RET( d3ddev->SetDepthStencilSurface( m_zSurface) );

    // clear the scene so we don't have any articats left
    d3ddev->Clear( 0L, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 
                   D3DCOLOR_XRGB(128,128,255), 1.0f, 0L );

    FAIL_RET( d3ddev->BeginScene() );
    FAIL_RET( d3ddev->SetStreamSource(0, m_vertexBuffer, 0, sizeof( CUSTOMVERTEX)  ) );
    FAIL_RET( d3ddev->SetFVF( D3DFVF_CUSTOMVERTEX ) );
    FAIL_RET( d3ddev->SetTexture( 0, GetTexture( d3ddev, pVideoStreamInfo + 0 % cStreams ) ) );
    FAIL_RET( d3ddev->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2) );  
    FAIL_RET( d3ddev->SetTexture( 0, GetTexture( d3ddev, pVideoStreamInfo + 1 % cStreams ) ) );
    FAIL_RET( d3ddev->DrawPrimitive(D3DPT_TRIANGLESTRIP,4,2) );  
    FAIL_RET( d3ddev->SetTexture( 0, GetTexture( d3ddev, pVideoStreamInfo + 2 % cStreams ) ) );
    FAIL_RET( d3ddev->DrawPrimitive(D3DPT_TRIANGLESTRIP,8,2) );  
    FAIL_RET( d3ddev->EndScene());
    return S_OK;
}
Ejemplo n.º 16
0
HRESULT 
CPlaneScene::Init(IDirect3DDevice9* d3ddev)
{
    HRESULT hr;

    if( ! d3ddev )
        return E_POINTER;

    FAIL_RET(hr = d3ddev->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE));
    FAIL_RET(hr = d3ddev->SetRenderState(D3DRS_LIGHTING, FALSE));
    FAIL_RET(hr = d3ddev->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE));
    FAIL_RET(hr = d3ddev->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA));
    FAIL_RET(hr = d3ddev->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA));
    FAIL_RET(hr = d3ddev->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE));
    FAIL_RET(hr = d3ddev->SetRenderState(D3DRS_ALPHAREF, 0x10));
    FAIL_RET(hr = d3ddev->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATER));

    FAIL_RET(hr = d3ddev->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP));
    FAIL_RET(hr = d3ddev->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP));
    FAIL_RET(hr = d3ddev->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR));
    FAIL_RET(hr = d3ddev->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR));
    FAIL_RET(hr = d3ddev->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR));

    m_vertexBuffer = NULL;

    d3ddev->CreateVertexBuffer(sizeof(m_vertices),D3DUSAGE_WRITEONLY,D3DFVF_CUSTOMVERTEX,D3DPOOL_MANAGED,& m_vertexBuffer.p, NULL );

    CComPtr<IDirect3DSurface9> backBuffer;
    FAIL_RET( d3ddev->GetBackBuffer( 0, 0,
                                    D3DBACKBUFFER_TYPE_MONO,
                                    & backBuffer.p ) );

    D3DSURFACE_DESC backBufferDesc;
    backBuffer->GetDesc( & backBufferDesc );

    // Set the projection matrix
    D3DXMATRIX matProj;
    FLOAT fAspect = backBufferDesc.Width / 
                    (float)backBufferDesc.Height;
    D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4, fAspect, 
                                1.0f, 100.0f );
    FAIL_RET( d3ddev->SetTransform( D3DTS_PROJECTION, &matProj ) );

    
    D3DXVECTOR3 from( 1.0f, 1.0f, -3.0f );
    D3DXVECTOR3 at( 0.0f, 0.0f, 0.0f );
    D3DXVECTOR3 up( 0.0f, 1.0f, 0.0f );

    D3DXMATRIX matView;
    D3DXMatrixLookAtLH( &matView, & from, & at, & up);
    FAIL_RET( d3ddev->SetTransform( D3DTS_VIEW, &matView ) );

    m_time = GetTickCount();

    return hr;
}
Ejemplo n.º 17
0
HRESULT 
CPlaneScene::DrawScene( IDirect3DDevice9* d3ddev,
                        IDirect3DTexture9* texture ) 
{
    HRESULT hr;

    if( !( d3ddev && texture ) )
    {
        return E_POINTER;
    }

    if( m_vertexBuffer == NULL )
    {
        return D3DERR_INVALIDCALL;
    }

    // get the difference in time
    DWORD dwCurrentTime;
    dwCurrentTime = GetTickCount();
    double difference = m_time - dwCurrentTime ;
    
    // figure out the rotation of the plane
    float x = (float) ( -cos(difference / 2000.0 ) ) ;
    float y = (float) ( cos(difference / 2000.0 ) ) ;
    float z = (float) ( sin(difference / 2000.0 ) ) ;

    // update the two rotating vertices with the new position
    m_vertices[0].position = CUSTOMVERTEX::Position(x,  y, z);   // top left
    m_vertices[3].position = CUSTOMVERTEX::Position(-x, -y, -z); // bottom right

    // Adjust the color so the blue is always on the bottom.
    // As the corner approaches the bottom, get rid of all the other
    // colors besides blue
    DWORD mask0 = (DWORD) (255 * ( ( y + 1.0  )/ 2.0 ));
    DWORD mask3 = (DWORD) (255 * ( ( -y + 1.0  )/ 2.0 ));
    m_vertices[0].color = 0xff0000ff | ( mask0 << 16 ) | ( mask0 << 8 );
    m_vertices[3].color = 0xff0000ff | ( mask3 << 16 ) | ( mask3 << 8 );

    // write the new vertex information into the buffer
    void* pData;
    FAIL_RET( m_vertexBuffer->Lock(0,sizeof(pData), &pData,0) );
    memcpy(pData,m_vertices,sizeof(m_vertices));                            
    FAIL_RET( m_vertexBuffer->Unlock() );  

    // clear the scene so we don't have any articats left
    d3ddev->Clear( 0L, NULL, D3DCLEAR_TARGET, 
                   D3DCOLOR_XRGB(255,255,255), 1.0f, 0L );

    FAIL_RET( d3ddev->BeginScene() );
    FAIL_RET( d3ddev->SetTexture( 0, texture));

    FAIL_RET(hr = d3ddev->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE));
    FAIL_RET(hr = d3ddev->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE));
    FAIL_RET(hr = d3ddev->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE));
    FAIL_RET(hr = d3ddev->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE));

    FAIL_RET( d3ddev->SetStreamSource(0, m_vertexBuffer.p, 0, sizeof(CPlaneScene::CUSTOMVERTEX)  ) );            //set next source ( NEW )
    FAIL_RET( d3ddev->SetFVF( D3DFVF_CUSTOMVERTEX ) );
    FAIL_RET( d3ddev->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2) );  //draw quad 
    FAIL_RET( d3ddev->SetTexture( 0, NULL));
    FAIL_RET( d3ddev->EndScene());

    return hr;
}
Ejemplo n.º 18
0
//IVMRSurfaceAllocator9
HRESULT CAllocator::InitializeDevice( 
            /* [in] */ DWORD_PTR dwUserID,
            /* [in] */ VMR9AllocationInfo *lpAllocInfo,
            /* [out][in] */ DWORD *lpNumBuffers)
{
    DWORD dwWidth = 1;
    DWORD dwHeight = 1;
    float fTU = 1.f;
    float fTV = 1.f;

    if( lpNumBuffers == NULL )
    {
        return E_POINTER;
    }

    if( m_lpIVMRSurfAllocNotify == NULL )
    {
        return E_FAIL;
    }

    HRESULT hr = S_OK;

//	lpAllocInfo->dwWidth = dwWidth;
//	lpAllocInfo->dwHeight = dwHeight;

    // NOTE:
    // we need to make sure that we create textures because
    // surfaces can not be textured onto a primitive.
    lpAllocInfo->dwFlags |= VMR9AllocFlag_TextureSurface;

    hr = m_lpIVMRSurfAllocNotify->AllocateSurfaceHelper(lpAllocInfo, lpNumBuffers, &m_surfaces );

#if 0
    // If we couldn't create a texture surface and 
    // the format is not an alpha format,
    // then we probably cannot create a texture.
    // So what we need to do is create a private texture
    // and copy the decoded images onto it.
    if(FAILED(hr) && !(lpAllocInfo->dwFlags & VMR9AllocFlag_3DRenderTarget))
    {
        DeleteSurfaces();            

        // is surface YUV ?
        if (lpAllocInfo->Format > '0000') 
        {           
            D3DDISPLAYMODE dm; 
            FAIL_RET( m_D3DDev->GetDisplayMode(NULL,  & dm ) );

            // create the private texture
            FAIL_RET( m_D3DDev->CreateTexture(lpAllocInfo->dwWidth, lpAllocInfo->dwHeight,
                                    1, 
                                    D3DUSAGE_RENDERTARGET, 
                                    dm.Format, 
                                    D3DPOOL_DEFAULT /* default pool - usually video memory */, 
                                    & m_privateTexture.p, NULL ) );
        }

        
        lpAllocInfo->dwFlags &= ~VMR9AllocFlag_TextureSurface;
        lpAllocInfo->dwFlags |= VMR9AllocFlag_OffscreenSurface;

        FAIL_RET( m_lpIVMRSurfAllocNotify->AllocateSurfaceHelper(lpAllocInfo, lpNumBuffers, & m_surfaces.at(0) ) );
    }
#endif

    return hr;
}
HRESULT StartGraph(HWND window)
{
    HRESULT hr = S_OK;

    const DWORD BUFFER_SIZE = MAX_PATH * MAX_VIDEO_STREAMS;

    MultiSelectFileList<BUFFER_SIZE> selectList;

    OPENFILENAME ofn;
    ZeroMemory(&ofn, sizeof(ofn));

    ofn.lStructSize         = sizeof(OPENFILENAME);
    ofn.hwndOwner           = g_hWnd;
    ofn.lpstrFilter         = TEXT("Video Files (.AVI, .MPG, .MPEG, .VOB, .WMV)\0*.AVI;*.MPG;*.MPEG;*.VOB;*.WMV\0") 
                              TEXT("All Files (*.*)\0*.*\0\0");
    ofn.nFilterIndex        = 1;
    ofn.lpstrFile           = selectList.BufferPtr();
    ofn.nMaxFile            = selectList.BufferSizeCch();
    ofn.lpstrTitle          = TEXT("Select a video file to play...");
    ofn.Flags               = OFN_HIDEREADONLY | OFN_ALLOWMULTISELECT | OFN_FILEMUSTEXIST | OFN_EXPLORER;
    ofn.lpstrDefExt         = TEXT("AVI");
    
    // Launch the Open File dialog.
	DWORD result = GetOpenFileName(&ofn);

    // Check for errors.
    if (CommDlgExtendedError() != 0)
    {

        // NOTE: For mult-selection, CommDlgExtendedError can return FNERR_BUFFERTOOSMALL even when
        // GetOpenFileName returns TRUE.

        MessageBox(NULL, TEXT( "Could not open files." ), NULL, MB_OK | MB_ICONERROR);
        return E_FAIL;
    }
    else if (!result)
    {
        // The user cancelled. (No error occurred.)
        return S_OK;
    }

    FAIL_RET(hr = selectList.ParseBuffer());

    // Clear all DirectShow interfaces (COM smart pointers)
    g_compositor            = NULL;
    g_windowlessControl     = NULL;
    g_mediaControl          = NULL;
    g_filter                = NULL;
    g_graph                 = NULL;

    // Create the Filter Graph Manager.
    FAIL_RET( CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void**)&g_graph) );

    // Configure the VMR-9.
    FAIL_RET( ConfigureVMR9(window) );

    // Render every file that the user selected.
    for (DWORD i = 0; i < MAX_VIDEO_STREAMS; i++)
    {
        TCHAR *pFileName = NULL;

        FAIL_RET(hr = selectList.Next(&pFileName));
        if (hr == S_FALSE)
        {
            hr = S_OK;
            break;
        }

		hr = g_graph->RenderFile( pFileName, NULL );

        CoTaskMemFree(pFileName);

        FAIL_RET(hr);

	}

    // Run the graph.

    FAIL_RET( g_graph->QueryInterface(IID_IMediaControl, reinterpret_cast<void**>(&g_mediaControl)) );

    FAIL_RET( g_mediaControl->Run() );

    return hr;
}
Ejemplo n.º 20
0
HRESULT dx_player::init_gpu(int width, int height, IDirect3DDevice9 *device)
{
	invalidate_gpu();

	HRESULT hr;
	if (!m_ui_logo_gpu)
	{
		FAIL_RET(m_Device->CreateTexture(512, 512, 1, D3DUSAGE_AUTOGENMIPMAP, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &m_ui_logo_gpu, NULL));
		FAIL_RET(m_ui_logo_cpu->AddDirtyRect(NULL));
		FAIL_RET(m_Device->UpdateTexture(m_ui_logo_cpu, m_ui_logo_gpu));
	}
	if (!m_ui_tex_gpu)
	{
		FAIL_RET(m_Device->CreateTexture(222, 14, 1, NULL, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &m_ui_tex_gpu, NULL));
		FAIL_RET(m_ui_tex_cpu->AddDirtyRect(NULL));
		FAIL_RET(m_Device->UpdateTexture(m_ui_tex_cpu, m_ui_tex_gpu));
	}
	if (!m_ui_background_gpu)
	{
		FAIL_RET(m_Device->CreateTexture(64, 64, 1, NULL, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &m_ui_background_gpu, NULL));
		FAIL_RET(m_ui_background_cpu->AddDirtyRect(NULL));
		FAIL_RET(m_Device->UpdateTexture(m_ui_background_cpu, m_ui_background_gpu));
	}


	m_Device = device;
	m_width = width;
	m_height = height;
	vertex_from_element convert(width, height);

	// back ground
	back_ground.anchor1 = BOTTOMLEFT;
	back_ground.x1 = back_ground.y1 = 0;
	back_ground.anchor2 = BOTTOMRIGHT;
	back_ground.x2 = 0; back_ground.y2 = -64;
	back_ground.tx = 64; back_ground.ty = 64;

	// progress bar
	progressbar.anchor1 = BOTTOMLEFT;
	progressbar.x1 = 113; progressbar.y1 = -8;
	progressbar.anchor2 = BOTTOMRIGHT;
	progressbar.x2 = -161; progressbar.y2 = -22;
	progressbar.tx = 222; progressbar.ty = 14;

	// volume
	volume.anchor1 = BOTTOMRIGHT;
	volume.x1 = -42; volume.y1 = -8;
	volume.anchor2 = BOTTOMRIGHT;
	volume.x2 = -76; volume.y2 = -22;
	volume.tx = 222; volume.ty = 14;

	// play button
	playbutton.anchor = BOTTOMLEFT;
	playbutton.width = playbutton.height = 0;
	playbutton.x = 14; playbutton.y = -8;
	playbutton.sx = 96;
	playbutton.sy = 0;
	playbutton.cx = 14;
	playbutton.cy = 14;
	playbutton.tx = 222;
	playbutton.ty = 14;
	pausebutton = playbutton;
	pausebutton.sx += 14;

	// full button
	fullbutton = playbutton;
	fullbutton.anchor = BOTTOMRIGHT;
	fullbutton.x = -14; fullbutton.y = -8;
	fullbutton.sx = 192;

	// test button
	test_button = playbutton;
	test_button.sx = test_button.sy = 0;
	test_button.cx = test_button.cy = 512;
	test_button.tx = test_button.ty = 512;
	test_button.anchor = CENTER;
	test_button.width = test_button.height = min(512, min(width,height-40) *3/5);
	test_button.x = test_button.width / 40; test_button.y = -20;

	test_button2 = test_button;
	test_button.x = 0;


	int xmap0[4] = {51, 75, -107, -131};
	for(int i = 0; i<4; i++)
	{
		colon[i].width = colon[i].height = 0;
		colon[i].anchor = i<2 ? BOTTOMLEFT : BOTTOMRIGHT;
		colon[i].x = xmap0[i];
		colon[i].y = -8;
		colon[i].sx = 0;
		colon[i].sy = 0;
		colon[i].cx = 6;
		colon[i].cy = 14;
		colon[i].tx = 222;
		colon[i].ty = 14;
	}


	// times
	int xmap1[5] = {42,57,66,81,90};
	int xmap2[5] = {-138,-123,-114,-99,-90};
	for(int i=0; i<5; i++)
		for(int j=0; j<10; j++)
		{
			current_time[i][j].width = current_time[i][j].height = 0;
			current_time[i][j].anchor = BOTTOMLEFT;
			current_time[i][j].sx = 6+9*j;
			current_time[i][j].sy = 0;
			current_time[i][j].cx = 9;
			current_time[i][j].cy = 14;
			current_time[i][j].tx = 222;
			current_time[i][j].ty = 14;

			current_time[i][j].y = -8;
			current_time[i][j].x = xmap1[i];

			total_time[i][j] = current_time[i][j];
			total_time[i][j].anchor = BOTTOMRIGHT;
			total_time[i][j].x = xmap2[i];
		}


		m_vertex = NULL;
		for(int i=0; i<50; i++)
		{
			quad[i] = convert.tovertex(current_time[i/10][i%10]);
			quad[i+50] = convert.tovertex(total_time[i/10][i%10]);
		}
		quad[PLAYBUTTON] = convert.tovertex(playbutton);
		quad[PAUSEBUTTON] = convert.tovertex(pausebutton);
		quad[FULLBUTTON] = convert.tovertex(fullbutton);
		quad[BACKGROUND] = convert.tovertex(back_ground);
		quad[PROGRESSBAR] = convert.tovertex(progressbar);
		quad[VOLUME] = convert.tovertex(volume);
		quad[TESTBUTTON] = convert.tovertex(test_button);
		quad[TESTBUTTON2] = convert.tovertex(test_button2);
		for (int i=0; i<4; i++)
			quad[150+i] = convert.tovertex(colon[i]);

		m_Device->CreateVertexBuffer( sizeof(quad), D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, FVF_Flags, D3DPOOL_DEFAULT, &m_vertex, NULL );
		m_Device->CreatePixelShader((DWORD*)g_code_UI, &m_ps_UI);

		void *pVertices = NULL;
		m_vertex->Lock( 0, sizeof(quad), (void**)&pVertices, D3DLOCK_DISCARD );
		memcpy( pVertices, quad, sizeof(quad));
		m_vertex->Unlock();

		return S_OK;
}