IDirect3DCubeTexture9 * TextureCache::_addCubeTex( const char * srcFile, uint _usage ) { uint pool = D3DPOOL_MANAGED; if ( _usage & D3DUSAGE_RENDERTARGET ) // The resource will be a render target. D3DUSAGE_RENDERTARGET can only be used with D3DPOOL_DEFAULT. pool = D3DPOOL_DEFAULT; uint usage = _usage; // | D3DUSAGE_AUTOGENMIPMAP; printf( "%s %s\n", __FUNCTION__, srcFile ); IDirect3DCubeTexture9 * pTexture = 0; uint mipLevels = 0; D3DXIMAGE_INFO imgInfo; HRESULT hr = D3DXCreateCubeTextureFromFileEx( device, //LPDIRECT3DDEVICE9 pDevice, srcFile, //LPCTSTR pSrcFile, D3DX_DEFAULT, //UINT Size, mipLevels, //UINT MipLevels, usage,//_usage & (D3DUSAGE_DYNAMIC | D3DUSAGE_RENDERTARGET), // DWORD Usage, D3DFMT_FROM_FILE, //_format, // D3DFORMAT Format, (D3DPOOL) pool, //D3DPOOL Pool, D3DX_DEFAULT , //DWORD Filter, D3DX_DEFAULT , //DWORD MipFilter, 0, //D3DCOLOR ColorKey, & imgInfo, // D3DXIMAGE_INFO 0, //PALETTEENTRY *pPalette, & pTexture //LPDIRECT3DCUBETEXTURE9 *ppCubeTexture ); E_TRACE(hr); if ( FAILED( hr ) ) { return 0; } return pTexture; }
// ----------------------------------------------------------------------------- // DIscQueue::Remove // Removes first element from the queue // ( other items were commented in a header ). // ----------------------------------------------------------------------------- // EXPORT_C TAny* DIscQueue::RemoveFirst() { E_TRACE( ( _T( "IQ:R %d %d" ), iCount, iSize ) ); TAny* result = NULL; TInt irqLevel = DisableIrqs(); if ( iCount == 0 || iSize == 0 ) { RestoreIrqs( irqLevel ); return NULL; } // Get an element from the queue. result = ( TAny* )iQueue[ iHead ]; iQueue[ iHead ] = NULL; // Adjust the head of the queue. iHead = ++iHead % iSize; // Decrease counter. iCount--; RestoreIrqs( irqLevel ); return result; }
// ----------------------------------------------------------------------------- // DIscQueue::Add // Function to add element to queue // ( other items were commented in a header ). // ----------------------------------------------------------------------------- // EXPORT_C TInt DIscQueue::Add( TAny* anEntry ) { E_TRACE( ( _T( "IQ:A %d 0x%x" ), iCount, iQueue ) ); TInt irqLevel = DisableIrqs(); if ( iCount == iSize || iSize == 0 ) { RestoreIrqs( irqLevel ); return KErrNoMemory;//EFalse; } /* place the buffer into the queue */ iQueue[ iTail ] = ( TUint32* )( anEntry ); if ( iSize > 0 ) { /* adjust tail pointer */ iTail = ++iTail % iSize; /* remember the amount of the requests in the queue */ iCount++; } else { ASSERT_RESET_ALWAYS( 0, "IscDriver", EIscBufferAllocationFailure ) } RestoreIrqs( irqLevel ); return KErrNone; }
// ----------------------------------------------------------------------------- // DIscSendQueue::Add // Function to add element to queue // ( other items were commented in a header ). // ----------------------------------------------------------------------------- // EXPORT_C TInt DIscSendQueue::Add( TAny* anEntry, TUint16 aId, DIscChannel* aChannelPtr, TAny* aFrameInfo ) { E_TRACE( ( _T( "ISQ:A %d, 0x%x" ), iCount, iQueue ) ); TInt irqLevel = DisableIrqs(); if ( iCount == iSize || iSize == 0 ) { RestoreIrqs( irqLevel ); return KErrNoMemory;//EFalse; } /* place the buffer into the queue */ iQueue[ iTail ] = ( TUint32* )( anEntry ); TIscSendFrameInfo* tmp = iParameterQueue[ iTail ]; // Set additional info for send frame tmp->iChannelId = aId; tmp->iChannelPtr = aChannelPtr; tmp->iFrameInfo = aFrameInfo; /* adjust tail pointer */ iTail = ++iTail % iSize; /* remember the amount of the requests in the queue */ iCount++; RestoreIrqs( irqLevel ); return KErrNone; }
uint copyFromSurface( uint dst_w, uint dst_h, uint dst_bpp, unsigned char *dst_pix, IDirect3DSurface9 *surf ) { D3DLOCKED_RECT lockedRect; HRESULT hr; hr = surf->LockRect( &lockedRect, NULL, // const RECT *pRect, 0 //D3DLOCK_READONLY // DWORD Flags ); if ( hr != S_OK ) { LOG_ERROR(hr); return 0; } D3DSURFACE_DESC desc; surf->GetDesc( &desc ); uint src_w = min(dst_w,desc.Width ); uint src_h = min(dst_h,desc.Height ); uint dst_row = dst_w * dst_bpp; uint pitch = lockedRect.Pitch; unsigned char *src_pix = (unsigned char *) lockedRect.pBits; if ( dst_bpp == 3 ) // copy single pixels: { for ( uint j = 0; j < src_h; j++ ) { unsigned char * d = dst_pix + j * dst_row; unsigned char * pPixel = src_pix + j *pitch; for ( uint i = 0; i < src_w; i++ ) { *d++ = *pPixel++; *d++ = *pPixel++; *d++ = *pPixel++; pPixel++; } } } else if ( dst_bpp == 4 ) // copy whole lines: { for ( uint j=0, scan_in=(src_h-1)*pitch, scan_out=0; j<src_h; j++, scan_in-=pitch, scan_out+=dst_row ) { unsigned char *pix_in = src_pix + scan_in; unsigned char *pix_out = dst_pix + scan_out; memcpy( pix_out, pix_in, dst_row ); } } hr = surf->UnlockRect(); E_TRACE(hr); return hr == S_OK; }
IDirect3DTexture9 * TextureCache::createTexture( uint width, uint height, uint format , uint usage, uint pool ) { IDirect3DTexture9 * pTexture = 0; uint levels = (usage & D3DUSAGE_AUTOGENMIPMAP) ? 0 : 1; printf( "%s %i %i %x %x %x %x\n", __FUNCTION__, width, height, levels, usage, format, pool ); HRESULT hr = device->CreateTexture( width, height, levels, usage, (D3DFORMAT)format, (D3DPOOL)pool, & pTexture, 0 ); E_TRACE(hr); return pTexture; }
// ----------------------------------------------------------------------------- // DIscSendQueue::DIscSendQueue // C++ default constructor can NOT contain any code, that // might leave. // ----------------------------------------------------------------------------- // EXPORT_C DIscSendQueue::DIscSendQueue( TUint32** aQueue, TIscSendFrameInfo** aParameterQueue, TUint16 aSize ) :iParameterQueue( aParameterQueue ) { iHead = 0; iTail = 0; iCount = 0; iQueue = aQueue; iSize = aSize; for ( TInt i( 0 ); i < aSize; i++ ) { iParameterQueue[i]->iChannelId = KImpossibleChannelId; iParameterQueue[i]->iChannelPtr = NULL; iParameterQueue[i]->iFrameInfo = NULL; } E_TRACE( ( _T( "ISQ:ISQ %d 0x%x" ), iSize, iQueue ) ); }
// ----------------------------------------------------------------------------- // DIscQueue::GetFirst // Fetches first element from the queue // ( other items were commented in a header ). // ----------------------------------------------------------------------------- // EXPORT_C TAny* DIscQueue::GetFirst() { E_TRACE( ( _T( "IQ:G %d %d" ), iCount, iSize ) ); TAny* result; TInt irqLevel = DisableIrqs(); if ( iCount == 0 || iSize == 0 ) { RestoreIrqs( irqLevel ); return NULL; } // Get an element from the queue. result = ( TAny* )iQueue[ iHead ]; RestoreIrqs( irqLevel ); return result; }
// ----------------------------------------------------------------------------- // DIscSendQueue::GetFirstFrameInfo // Returns a frist frame info from list. // (other items were commented in a header). // ----------------------------------------------------------------------------- // EXPORT_C TIscSendFrameInfo* DIscSendQueue::GetFirstFrameInfo() { E_TRACE( ( _T( "ISQ:G(%d, 0x%x)" ), iCount, iQueue ) ); TIscSendFrameInfo* result; TInt irqLevel = DisableIrqs(); if ( iCount == 0 || iSize == 0 ) { RestoreIrqs( irqLevel ); return NULL; } result = iParameterQueue[ iHead ]; RestoreIrqs( irqLevel ); return result; }
IDirect3DTexture9 * TextureCache::_addTex( uint fmt, uint w, uint h, uint c, const unsigned char * pixel, uint _usage ) { uint usage = _usage; uint pool = D3DPOOL_MANAGED; if ( usage & D3DUSAGE_DYNAMIC ) // The resource will be a render target. D3DUSAGE_RENDERTARGET can only be used with D3DPOOL_DEFAULT. { pool = D3DPOOL_DEFAULT; } if ( usage & D3DUSAGE_RENDERTARGET ) // The resource will be a render target. D3DUSAGE_RENDERTARGET can only be used with D3DPOOL_DEFAULT. { pool = D3DPOOL_DEFAULT; } else // no usage { usage |= D3DUSAGE_AUTOGENMIPMAP; } //printf( "%s %s %x\n", __FUNCTION__, ("nil"), fmt); IDirect3DTexture9 * tx = createTexture( w, h, getPixelFormat(fmt), usage, pool ); if ( ! tx ) { printf( __FUNCTION__ " ERROR : could not create tex \n" ); return 0; } if ( pixel ) { IDirect3DSurface9 *surf = 0; HRESULT hr = tx->GetSurfaceLevel( 0, & surf ); E_TRACE(hr); uint r = SurfaceHelper::copyToSurface( w, h, c, pixel, surf ); COM_RELEASE( surf ); } return tx; }
// ----------------------------------------------------------------------------- // DIscQueue::DeleteFirst // Deletes first element from the queue // ( other items were commented in a header ). // ----------------------------------------------------------------------------- // EXPORT_C void DIscQueue::DeleteFirst() { E_TRACE( ( _T( "IQ:D %d %d" ), iCount, iSize ) ); TInt irqLevel = DisableIrqs(); iQueue[ iHead ] = NULL; if ( iSize > 0 ) { // Adjust the head of the queue. iHead = ++iHead % iSize; // decrease counter. iCount--; } else { ASSERT_RESET_ALWAYS( 0, "IscDriver", EIscBufferAllocationFailure ) } RestoreIrqs( irqLevel ); }
IDirect3DVolumeTexture9 * TextureCache::_addVolumeTex( const char * srcFile, uint _usage ) { HRESULT hr = 0; IDirect3DVolumeTexture9 * pTexture = 0; uint pool = D3DPOOL_MANAGED; if ( _usage & D3DUSAGE_RENDERTARGET ) // The resource will be a render target. D3DUSAGE_RENDERTARGET can only be used with D3DPOOL_DEFAULT. pool = D3DPOOL_DEFAULT; uint usage = _usage ; //;| D3DUSAGE_AUTOGENMIPMAP; printf( "%s %s\n", __FUNCTION__, srcFile ); D3DXIMAGE_INFO srcInfo; uint levels = 1; hr = D3DXCreateVolumeTextureFromFileEx( device, //LPDIRECT3DDEVICE9 pDevice, srcFile, // LPCTSTR pSrcFile, 0, //UINT Width, 0, //UINT Height, 0, //UINT Depth, 0, //UINT MipLevels, usage, //DWORD Usage, D3DFMT_UNKNOWN, //D3DFORMAT Format, (D3DPOOL) pool, //D3DPOOL Pool, D3DX_DEFAULT , //DWORD Filter, D3DX_DEFAULT , //DWORD MipFilter, 0, //D3DCOLOR ColorKey, &srcInfo, //D3DXIMAGE_INFO *pSrcInfo, 0, //PALETTEENTRY *pPalette, & pTexture //LPDIRECT3DVOLUMETEXTURE9 *ppTexture ); E_TRACE(hr); if ( FAILED( hr ) ) { return 0; } return pTexture; }
uint copyToSurface( uint src_w, uint src_h, uint src_bpp, const unsigned char *src_pix, IDirect3DSurface9 *surf ) { D3DLOCKED_RECT lockedRect; HRESULT hr; hr = surf->LockRect( &lockedRect, NULL, // const RECT *pRect, 0 //D3DLOCK_DISCARD // DWORD Flags ); if ( hr != D3D_OK ) { LOG_ERROR(hr); return 0; } D3DSURFACE_DESC desc; surf->GetDesc( &desc ); uint dst_w = min(src_w,desc.Width ); uint dst_h = min(src_h,desc.Height ); uint src_row = src_w * src_bpp; uint pitch = lockedRect.Pitch; unsigned char *dst_pix = (unsigned char *) lockedRect.pBits; if ( src_bpp == 3 ) { uint r,g,b, a=0xff; for ( uint j = 0; j < dst_h; j++ ) { unsigned char * pPixel = dst_pix + j *pitch; unsigned char * s = (unsigned char*)src_pix + j * src_row; for ( uint i = 0; i < dst_w; i++ ) { b = *s++; g = *s++; r = *s++; *pPixel++ = r; *pPixel++ = g; *pPixel++ = b; *pPixel++ = a; } } } else if ( src_bpp == 4 ) { uint r,g,b, a=0xff; for ( uint j = 0; j < dst_h; j++ ) { unsigned char * pPixel = dst_pix + j *pitch; unsigned char * s = (unsigned char*)src_pix + j * src_row; for ( uint i = 0; i < dst_w; i++ ) { b = *s++; g = *s++; r = *s++; a = *s++; *pPixel++ = r; *pPixel++ = g; *pPixel++ = b; *pPixel++ = a; } } //for ( uint j=0, src_scan=0, dst_scan=0; j<(uint)src_h; j++, dst_scan+=pitch, src_scan+=src_row ) //{ // unsigned char *pix_in = (unsigned char*)src_pix + src_scan; // unsigned char *pix_out = dst_pix + dst_scan; // memcpy( pix_out, pix_in, src_row ); //} } hr = surf->UnlockRect(); E_TRACE(hr); return hr == S_OK; }
// ----------------------------------------------------------------------------- // DIscQueue::DIscQueue // C++ default constructor can NOT contain any code, that // might leave. // ----------------------------------------------------------------------------- // EXPORT_C DIscQueue::DIscQueue( TUint32** aQueue, TUint16 Size ) :iHead( 0 ),iTail( 0 ),iCount( 0 ),iSize( Size ),iQueue( aQueue ) { E_TRACE( ( _T( "IQ:IQ %d 0x%x" ), iSize, iQueue ) ); }
// ----------------------------------------------------------------------------- // RUsbPnClient::ConnectL // (other items were commented in a header). // ----------------------------------------------------------------------------- // EXPORT_C void RUsbPnClient::ConnectL() { OstTrace0( TRACE_BORDER, RUSBPNCLIENT_CONNECTL_ENTRY, "RUsbPnClient::ConnectL" ); A_TRACE( ( _T( "RUsbPnClient::ConnectL()" ) ) ); TInt err( KErrNone ); // Create USB Phonet Link Server session err = CreateSession( KUsbPnServerName, TVersion(1,0,0)); if ( err == KErrNotFound ) { // Session not created // Find lock semaphore for server process creation TFindSemaphore lock( KUsbPnServerName ); TFullName semaphoreName; err = lock.Next( semaphoreName ); if ( err == KErrNotFound ) { // Lock is not enabled OstTrace0( TRACE_INTERNALS, RUSBPNCLIENT_CONNECTL, "RUsbPnClient::ConnectL() - semaphore not found, start server" ); E_TRACE( ( _L( "RUsbPnClient::ConnectL() - semaphore not found, start server" ) ) ); RSemaphore startLock; // Create lock User::LeaveIfError( startLock.CreateGlobal( KUsbPnServerName, 0, EOwnerProcess ) ); /********************************************/ /* Start the USB Phonet Link process process */ TRequestStatus status; RProcess server; User::LeaveIfError( server.Create( KUsbPnServerName, TPtrC( NULL, 0), EOwnerThread ) ); server.Rendezvous( status ); if( status != KRequestPending ) { server.Kill(0); // Abort startup } else { server.Resume(); // Logon OK -> start the server } OstTrace0( TRACE_INTERNALS, RUSBPNCLIENT_CONNECTL_DUP1, "RUsbPnClient::ConnectL() - waiting server response" ); E_TRACE( ( _T( "RUsbPnClient::ConnectL() - waiting server response" ) ) ); User::WaitForRequest( status ); // Wait for start or death // we can't use the 'exit reason' if the server panicked as this // is the panic 'reason' and may be '0' which cannot be distinguished // from KErrNone TInt err = status.Int(); if (err == KErrNone && (server.ExitType() == EExitPanic || server.ExitType() == EExitKill)) { err = KErrServerTerminated; } server.Close(); if( err ) { OstTrace1( TRACE_INTERNALS, RUSBPNCLIENT_CONNECTL_DUP2, "RUsbPnClient::ConnectL() - waiting server response status; err=%d", err ); E_TRACE( ( _T( "RUsbPnClient::ConnectL() - waiting server response status: %d" ), err ) ); TRACE_ASSERT_ALWAYS; User::LeaveIfError( err ); } /* End of starting process */ /********************************************/ OstTrace0( TRACE_INTERNALS, RUSBPNCLIENT_CONNECTL_DUP3, "RUsbPnClient::ConnectL() - server is started, signal other clients" ); E_TRACE( ( _L( "RUsbPnClient::ConnectL() - server is started, signal other clients" ) ) ); // Signal other clients startLock.Signal( KMaxTInt ); // Close semaphore startLock.Close(); } else { // Lock is enabled RSemaphore startLock; // Open lock semaphore User::LeaveIfError( startLock.Open( lock ) ); OstTrace0( TRACE_INTERNALS, RUSBPNCLIENT_CONNECTL_DUP4, "RUsbPnClient::ConnectL() - server is starting, wait for signal" ); E_TRACE( ( _L( "RUsbPnClient::ConnectL() - server is starting, wait for signal" ) ) ); // Wait for signal startLock.Wait(); OstTrace0( TRACE_INTERNALS, RUSBPNCLIENT_CONNECTL_DUP5, "RUsbPnClient::ConnectL() - signal received" ); E_TRACE( ( _L( "RUsbPnClient::ConnectL() - signal received" ) ) ); // Close semaphore startLock.Close(); } // Create USB Phonet Link server session OstTrace0( TRACE_INTERNALS, RUSBPNCLIENT_CONNECTL_DUP6, "RUsbPnClient::ConnectL() - Create session" ); E_TRACE( ( _L( "RUsbPnClient::ConnectL() - Create session" ) ) ); User::LeaveIfError( CreateSession( KUsbPnServerName, TVersion(1,0,0) ) ); OstTrace0( TRACE_INTERNALS, RUSBPNCLIENT_CONNECTL_DUP7, "RUsbPnClient::ConnectL() - session created1" ); E_TRACE( ( _L( "RUsbPnClient::ConnectL() - session created1" ) ) ); } else if ( err ) { OstTrace0( TRACE_INTERNALS, RUSBPNCLIENT_CONNECTL_DUP8, "RUsbPnClient::ConnectL() - session not created, reason uknown" ); E_TRACE( ( _L( "RUsbPnClient::ConnectL() - session not created, reason uknown" ) ) ); TRACE_ASSERT_ALWAYS; User::Leave( err ); } else { OstTrace0( TRACE_INTERNALS, RUSBPNCLIENT_CONNECTL_DUP9, "RUsbPnClient::ConnectL() - session created2" ); E_TRACE( ( _T( "RUsbPnClient::ConnectL() - session created2" ) ) ); } OstTrace0( TRACE_BORDER, RUSBPNCLIENT_CONNECTL_EXIT, "RUsbPnClient::ConnectL() - return void" ); A_TRACE( ( _T( "RUsbPnClient::ConnectL() - return void" ) ) ); }