sl@0: // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: sl@0: #include sl@0: #include sl@0: #include "surfacemanager_dev.h" sl@0: sl@0: sl@0: sl@0: sl@0: DECLARE_EXTENSION_LDD() sl@0: { sl@0: return new DSurfaceManagerFactory; sl@0: } sl@0: sl@0: static DSurfaceManager Manager; sl@0: sl@0: sl@0: sl@0: DSurfaceManagerFactory::DSurfaceManagerFactory() sl@0: { sl@0: // Set version number for this device sl@0: iVersion=RSurfaceManagerDriver::VersionRequired(); sl@0: sl@0: iParseMask=0; sl@0: } sl@0: sl@0: TInt DSurfaceManagerFactory::Install() sl@0: { sl@0: return SetName(&RSurfaceManagerDriver::Name()); sl@0: } sl@0: sl@0: sl@0: /** sl@0: Called by the kernel's device driver framework to create a Logical Channel. sl@0: This is called in the context of the user thread (client) which requested the creation of a Logical Channel sl@0: (E.g. through a call to RBusLogicalChannel::DoCreate) sl@0: The thread is in a critical section. sl@0: sl@0: @param aChannel Set to point to the created Logical Channel sl@0: sl@0: @return KErrNone if successful, otherwise one of the other system wide error codes. sl@0: */ sl@0: TInt DSurfaceManagerFactory::Create(DLogicalChannelBase*& aChannel) sl@0: { sl@0: aChannel=new DSurfaceManagerChannel(); sl@0: if(!aChannel) sl@0: return KErrNoMemory; sl@0: return KErrNone; sl@0: } sl@0: sl@0: sl@0: sl@0: /** sl@0: Return the drivers capabilities. sl@0: Called in the response to an RDevice::GetCaps() request. sl@0: sl@0: @param aDes User-side descriptor to write capabilities information into sl@0: */ sl@0: void DSurfaceManagerFactory::GetCaps(TDes8& aDes) const sl@0: { sl@0: // Create a capabilities object sl@0: RSurfaceManagerDriver::TCaps caps; sl@0: caps.iVersion = iVersion; sl@0: // Write it back to user memory sl@0: Kern::InfoCopy(aDes,reinterpret_cast(&caps),sizeof(caps)); sl@0: } sl@0: sl@0: sl@0: sl@0: DSurfaceManagerChannel::DSurfaceManagerChannel() sl@0: { sl@0: TRACE(Kern::Printf("SurfaceManagerChannel Creation");) sl@0: } sl@0: sl@0: sl@0: /** sl@0: Channel destructor. sl@0: Called when the process owning the channel has died or closed the channel. sl@0: Calls the manager object to indicate that the process has closed a session so it sl@0: can cleanup the surfaces which are only owned by that process if it has no further connections. sl@0: */ sl@0: DSurfaceManagerChannel::~DSurfaceManagerChannel() sl@0: { sl@0: Manager.RemoveConnection(iOwner); sl@0: } sl@0: sl@0: sl@0: /** sl@0: Second stage constructor called by the kernel's device driver framework. sl@0: This is called in the context of the user thread (client) which requested the creation of a Logical Channel sl@0: (E.g. through a call to RBusLogicalChannel::DoCreate) sl@0: The thread is in a critical section. sl@0: sl@0: @param aUnit The unit argument supplied by the client to RBusLogicalChannel::DoCreate sl@0: @param aInfo The info argument supplied by the client to RBusLogicalChannel::DoCreate sl@0: @param aVer The version argument supplied by the client to RBusLogicalChannel::DoCreate sl@0: sl@0: @return KErrNone if successful, otherwise one of the other system wide error codes. sl@0: */ sl@0: TInt DSurfaceManagerChannel::DoCreate(TInt /*aUnit*/, const TDesC8* /*aInfo*/, const TVersion& aVer) sl@0: { sl@0: // Check version sl@0: if (!Kern::QueryVersionSupported(RSurfaceManagerDriver::VersionRequired(),aVer)) sl@0: return KErrNotSupported; sl@0: sl@0: iOwner = &Kern::CurrentProcess(); sl@0: TInt ret = Manager.AddConnection(iOwner); sl@0: if (ret != KErrNone) sl@0: iOwner = NULL; sl@0: sl@0: return ret; sl@0: } sl@0: sl@0: sl@0: sl@0: /** sl@0: Process a request on this logical channel. sl@0: sl@0: @param aReqNo Request number: sl@0: ==KMaxTInt, a 'DoCancel' message sl@0: >=0, a 'DoControl' message with function number equal to iValue sl@0: <0, a 'DoRequest' message with function number equal to ~iValue sl@0: @param a1 First argument. For DoRequest requests this is a pointer to the TRequestStatus. sl@0: @param a2 Second argument. For DoRequest this is a pointer to the 2 actual TAny* arguments. sl@0: sl@0: @return Result ignored by device driver framework for DoRequest requests. sl@0: */ sl@0: TInt DSurfaceManagerChannel::Request(TInt aReqNo, TAny* a1, TAny* a2) sl@0: { sl@0: // Decode the message type and dispatch it to the relevent handler function... sl@0: // only using synchronous control messages sl@0: if (static_cast(aReqNo) < static_cast(KMaxTInt)) sl@0: { sl@0: return DoControl(aReqNo, a1, a2); sl@0: } sl@0: sl@0: return KErrNotSupported; sl@0: } sl@0: sl@0: /** sl@0: Process synchronous 'control' requests sl@0: */ sl@0: TInt DSurfaceManagerChannel::DoControl(TInt aFunction, TAny* a1, TAny* a2) sl@0: { sl@0: TRACE(Kern::Printf(">DSurfaceManagerChannel::DoControl fn=%d process = %u\n",aFunction, iOwner);) sl@0: sl@0: TInt r; sl@0: switch(aFunction) sl@0: { sl@0: case RSurfaceManagerDriver::EControlCreateSurface: sl@0: r = Manager.CreateSurface(reinterpret_cast(a1), reinterpret_cast(a2)); sl@0: break; sl@0: sl@0: case RSurfaceManagerDriver::EControlOpenSurface: sl@0: r = Manager.OpenSurface(reinterpret_cast(a1)); sl@0: break; sl@0: sl@0: case RSurfaceManagerDriver::EControlCloseSurface: sl@0: r = Manager.CloseSurface(reinterpret_cast(a1)); sl@0: break; sl@0: sl@0: case RSurfaceManagerDriver::EControlAccessSurfaceData: sl@0: r = Manager.MapSurface(reinterpret_cast(a1)); sl@0: break; sl@0: sl@0: case RSurfaceManagerDriver::EControlSurfaceInfo: sl@0: r = Manager.SurfaceInfo(reinterpret_cast(a1), reinterpret_cast(a2)); sl@0: break; sl@0: sl@0: case RSurfaceManagerDriver::EControlCreateSurfaceEx: sl@0: r = Manager.CreateSurface(reinterpret_cast(a1), (TInt)a2); sl@0: break; sl@0: sl@0: case RSurfaceManagerDriver::EControlSynchronizeCache: sl@0: r = Manager.SynchronizeCache(reinterpret_cast(a1), (RSurfaceManager::TSyncOperation&)a2); sl@0: break; sl@0: sl@0: case RSurfaceManagerDriver::EControlGetSurfaceHint: sl@0: r = Manager.GetSurfaceHint(reinterpret_cast(a1), reinterpret_cast(a2)); sl@0: break; sl@0: sl@0: case RSurfaceManagerDriver::EControlSetSurfaceHint: sl@0: r = Manager.SetSurfaceHint(reinterpret_cast(a1), reinterpret_cast(a2)); sl@0: break; sl@0: sl@0: case RSurfaceManagerDriver::EControlAddSurfaceHint: sl@0: r = Manager.AddSurfaceHint(reinterpret_cast(a1), reinterpret_cast(a2)); sl@0: break; sl@0: case RSurfaceManagerDriver::EControlGetBufferOffset: sl@0: r = Manager.GetBufferOffset(reinterpret_cast(a1),reinterpret_cast(a2)); sl@0: break; sl@0: case RSurfaceManagerDriver::EControlGetSurfaceManagerAttrib: sl@0: r = Manager.GetSurfaceManagerAttrib(reinterpret_cast(a1),reinterpret_cast(a2)); sl@0: break; sl@0: default: sl@0: r = KErrNotSupported; sl@0: break; sl@0: } sl@0: TRACE(Kern::Printf("