guestrendering/guestvideodriver/ldd/src/virtualvideohwchannel.cpp
branchbug235_bringup_0
changeset 1 d8d95053303a
child 2 e8ccf068ac7f
equal deleted inserted replaced
0:013716db5021 1:d8d95053303a
       
     1 /*
       
     2  * =============================================================================
       
     3  *  Name        : virtualvideohwchannel.cpp
       
     4  *  Part of     : 
       
     5  *  Description : Implementation of the class DVirtualVideoHwChannel.
       
     6  *  Version     : %version:2 %
       
     7  *
       
     8  *  Copyright © 2002-2010 Nokia. All rights reserved.
       
     9  *  This material, including documentation and any related
       
    10  *  computer programs, is protected by copyright controlled by
       
    11  *  Nokia. All rights are reserved. Copying, including
       
    12  *  reproducing, storing, adapting or translating, any
       
    13  *  or all of this material requires the prior written consent of
       
    14  *  Nokia. This material also contains confidential
       
    15  *  information which may not be disclosed to others without the
       
    16  *  prior written consent of Nokia.
       
    17  * =============================================================================
       
    18  */
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <kernel/kernel.h>
       
    22 #include <assp.h>
       
    23 
       
    24 #include "virtualvideohwchannel.h"
       
    25 #include "virtualvideohwdeviceinterface.h"
       
    26 #include "platsimvideodriverprotocol.h"
       
    27 #include "platsimvideodrivercommon.h"
       
    28 #include "devicereqhandler.h"
       
    29 #include "serializedfunctioncall.h"
       
    30 
       
    31 
       
    32 // CONSTANTS
       
    33 // ============================ MEMBER FUNCTIONS ===============================
       
    34 
       
    35 // -----------------------------------------------------------------------------
       
    36 // DVirtualVideoHwChannel::DVirtualVideoHwChannel
       
    37 // -----------------------------------------------------------------------------
       
    38 //
       
    39 DVirtualVideoHwChannel::DVirtualVideoHwChannel(
       
    40     MVirtualVideoHwDeviceInterface& aDeviceInterface,
       
    41     DVirtualVideoHwInterface& aHwInterface,
       
    42     DDeviceReqHandler& aDeviceReqHandler,
       
    43     TDfcQue* aQueue ) :
       
    44     iDeviceInterface( aDeviceInterface ),
       
    45     iHwInterface( aHwInterface ),
       
    46     iReqHandler( aDeviceReqHandler )
       
    47     {    
       
    48     SetDfcQ( aQueue );
       
    49     }
       
    50 
       
    51 // -----------------------------------------------------------------------------
       
    52 // DVirtualVideoHwChannel::~DVirtualVideoHwChannel
       
    53 // -----------------------------------------------------------------------------
       
    54 //
       
    55 DVirtualVideoHwChannel::~DVirtualVideoHwChannel()
       
    56     {
       
    57     // Enter critical section
       
    58     NKern::ThreadEnterCS();
       
    59     iMsgQ.CompleteAll( KErrAbort );
       
    60     // Leave critical section
       
    61     NKern::ThreadLeaveCS();
       
    62     }
       
    63 
       
    64 // -----------------------------------------------------------------------------
       
    65 // DVirtualVideoHwChannel::Request
       
    66 // -----------------------------------------------------------------------------
       
    67 //
       
    68 TInt DVirtualVideoHwChannel::Request( TInt aReqNo, TAny *a1, TAny *a2 )
       
    69     {
       
    70     TInt result = DLogicalChannel::Request( aReqNo, a1, a2 );
       
    71     return result;
       
    72     }
       
    73 
       
    74 // -----------------------------------------------------------------------------
       
    75 // DVirtualVideoHwChannel::HandleMsg
       
    76 // -----------------------------------------------------------------------------
       
    77 //
       
    78 void DVirtualVideoHwChannel::HandleMsg( TMessageBase* aMsgRequest )
       
    79     {
       
    80     DThread* userThread = aMsgRequest->Client();
       
    81     TThreadMessage& msg = *(TThreadMessage*)aMsgRequest;
       
    82     // Default error condition
       
    83     TInt err = KErrNone; 
       
    84 
       
    85     if ( msg.iValue == ECloseMsg )
       
    86         {
       
    87         iReqHandler.HandleClientShutdown( userThread->iOwningProcess->iId, userThread->iId );
       
    88         msg.Complete( KErrNone, EFalse );
       
    89         return;
       
    90         }
       
    91     
       
    92     if ( msg.iValue < 0 )
       
    93         {
       
    94         TRequestStatus* status = (TRequestStatus*)msg.Ptr0();
       
    95         err = DoRequest( userThread, ~msg.iValue, status, msg.Ptr1(), msg.Ptr2() );
       
    96         if( err != KErrNone )
       
    97             {
       
    98             Kern::RequestComplete( userThread, status, err );
       
    99             }
       
   100         err = KErrNone;
       
   101         }
       
   102     else
       
   103         {
       
   104         err = DoControl( userThread, msg.iValue, msg.Ptr0(), msg.Ptr1() );
       
   105         }
       
   106 
       
   107     msg.Complete( err, ETrue );
       
   108     }
       
   109 
       
   110 // -----------------------------------------------------------------------------
       
   111 // DVirtualVideoHwChannel::DoCreate
       
   112 // -----------------------------------------------------------------------------
       
   113 //
       
   114 TInt DVirtualVideoHwChannel::DoCreate( TInt /*aUnit*/, const TDesC* /*aInfo*/, const TVersion& aVer )
       
   115     {
       
   116     using namespace PlatsimVideoDriver;
       
   117     TInt err = KErrNone;
       
   118     
       
   119     if ( ! Kern::QueryVersionSupported(
       
   120             TVersion(
       
   121                     KMajorVer,
       
   122                     KMinorVer,
       
   123                     KBuildVer ),
       
   124             aVer ) )
       
   125         {
       
   126         return KErrNotSupported; 
       
   127         }
       
   128 
       
   129     iMsgQ.Receive();
       
   130     return err;
       
   131     }
       
   132 
       
   133 // -----------------------------------------------------------------------------
       
   134 // DVirtualVideoHwChannel::DoRequest
       
   135 // -----------------------------------------------------------------------------
       
   136 //
       
   137 TInt DVirtualVideoHwChannel::DoRequest(
       
   138         DThread*& aUserThread,
       
   139         TInt aReqNo,
       
   140         TRequestStatus* aStatus,
       
   141         TAny* a1,
       
   142         TAny* a2 )
       
   143     {
       
   144     using namespace PlatsimVideoDriver;
       
   145 
       
   146     // Default error condition
       
   147     TInt err = KErrNone; 
       
   148 
       
   149     switch( aReqNo )
       
   150         {
       
   151         case ERequestExecuteCommand:
       
   152             {
       
   153             err = iReqHandler.HandleExecuteAsync(
       
   154                     aUserThread,
       
   155                     aStatus,
       
   156                     a1);
       
   157             break;
       
   158             }
       
   159         case ERequestLoadCommands:
       
   160             {
       
   161             err = iReqHandler.HandleLoadCommands(
       
   162                     aUserThread, 
       
   163                     aStatus,
       
   164                     a1 );
       
   165             break;
       
   166             }
       
   167         default:
       
   168             {
       
   169             // Other requests are not supported
       
   170             err = KErrNotSupported;
       
   171             }
       
   172             break;
       
   173         }
       
   174     return err;
       
   175     }
       
   176 
       
   177 
       
   178 
       
   179 TInt DVirtualVideoHwChannel::GetSgImageMetaData(TSgImageMetaData& aSgInfo, const TUint64 aId)
       
   180 	{
       
   181 	VVHW_TRACE("DVirtualVideoHwChannel::OpenSgImageMetaData 0x%lx", aId );
       
   182 	DSgResource* sgResource = NULL;
       
   183 	TInt metaDataErr = SgExtension::FindAndOpenResource( aId, sgResource );//Open the sgimage resource
       
   184 	
       
   185 	if ( metaDataErr == KErrNone )
       
   186 		{
       
   187 		TPckgBuf<TSgImageMetaData> metaDataPckg;
       
   188 		
       
   189 		metaDataErr = sgResource->GetMetaData( metaDataPckg );
       
   190 		if ( metaDataErr == KErrNone )
       
   191 			{
       
   192 			aSgInfo = metaDataPckg();
       
   193 			}
       
   194 
       
   195 		sgResource->Close();
       
   196 		}
       
   197 	return metaDataErr;
       
   198 	}
       
   199 
       
   200 
       
   201 // -----------------------------------------------------------------------------
       
   202 // DVirtualVideoHwChannel::DoControl
       
   203 // -----------------------------------------------------------------------------
       
   204 //
       
   205 TInt DVirtualVideoHwChannel::DoControl(
       
   206         DThread*& aUserThread,
       
   207         TInt aFunction,
       
   208         TAny* a1,
       
   209         TAny* a2 )
       
   210     {
       
   211     using namespace PlatsimVideoDriver;
       
   212     
       
   213     // Default error condition
       
   214     TInt err = KErrNone; 
       
   215 
       
   216     switch( aFunction )
       
   217         {
       
   218         case ERequestMapAddress:
       
   219             {
       
   220             TPckgBuf<TInt> handle;
       
   221             err = Kern::ThreadDesRead( aUserThread, a1, handle, 0, 0 );
       
   222             if ( KErrNone == err )
       
   223                 {
       
   224                 DChunk* chunk = Kern::OpenSharedChunk( aUserThread, handle(), EFalse );
       
   225                 if ( chunk )
       
   226                     {
       
   227                     TLinAddr kernelAddress;
       
   228                     TUint32 mapAttr;
       
   229                     TUint32 physicalAddress( 0 );
       
   230                     TInt ret = Kern::ChunkPhysicalAddress( chunk, 0, chunk->Size(), 
       
   231                             kernelAddress, mapAttr, physicalAddress );
       
   232                     
       
   233                     TPckgC<TUint32> address( physicalAddress );
       
   234                     err = Kern::ThreadDesWrite( aUserThread, a2, address, 0, 0, aUserThread );
       
   235                     Kern::ChunkClose( chunk );
       
   236                     chunk = NULL;
       
   237                     }
       
   238                 else
       
   239                     {
       
   240                     err = KErrGeneral;
       
   241                     }
       
   242                 }
       
   243             break;
       
   244             }
       
   245         case ERequestSgHandles:
       
   246             {
       
   247             VVHW_TRACE("DVirtualVideoHwChannel::DoControl - ERequestSgHandles" );
       
   248             TPckgBuf<TUint64> sgId;
       
   249             err = Kern::ThreadDesRead( aUserThread, a1, sgId, 0, 0 );
       
   250             if( KErrNone == err )
       
   251                 {
       
   252 				TSgImageMetaData sgInfo;
       
   253 				err = GetSgImageMetaData( sgInfo, sgId());
       
   254 				if ( KErrNone == err )
       
   255 					{
       
   256 					// package the handles into 64-bit value, since there's only one parameter (a2) available
       
   257 					TUint64 sgHandles = (((TUint64)sgInfo.iPbufferHandle)&0xFFFFFFFF) + (((TUint64)sgInfo.iVGImageHandle)<<32);
       
   258 					TPckg<TUint64> handles(sgHandles);
       
   259 					err = Kern::ThreadDesWrite( aUserThread, a2, handles, 0, 0);
       
   260 					if(err)
       
   261 					    VVHW_TRACE("DVirtualVideoHwChannel::DoControl - ThreadDesWrite error=%d", err);
       
   262 					}
       
   263 				else
       
   264 					{
       
   265 					VVHW_TRACE("DVirtualVideoHwChannel::DoControl - OpenSgImageMetaData failed" );
       
   266 					}
       
   267                 }
       
   268             else
       
   269             	{
       
   270 				VVHW_TRACE("DVirtualVideoHwChannel::DoControl - ThreadDesRead err=%i", err );
       
   271                 }
       
   272             break;
       
   273             }
       
   274         default:
       
   275             {
       
   276             // Other functions are not supported
       
   277             err = KErrNotSupported;
       
   278             }
       
   279             break;
       
   280         }
       
   281 
       
   282     return err;
       
   283     }
       
   284