os/graphics/graphicshwdrivers/surfacemgr/src/surfacemanagerdriver.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
sl@0
    17
#include <kernel/kern_priv.h>
sl@0
    18
#include <graphics/surfacemanager.h>
sl@0
    19
#include "surfacemanager_dev.h"
sl@0
    20
sl@0
    21
sl@0
    22
sl@0
    23
sl@0
    24
DECLARE_EXTENSION_LDD()
sl@0
    25
	{
sl@0
    26
	return new DSurfaceManagerFactory;
sl@0
    27
	}
sl@0
    28
sl@0
    29
static DSurfaceManager Manager;
sl@0
    30
sl@0
    31
sl@0
    32
sl@0
    33
DSurfaceManagerFactory::DSurfaceManagerFactory()
sl@0
    34
	{
sl@0
    35
	// Set version number for this device
sl@0
    36
	iVersion=RSurfaceManagerDriver::VersionRequired();
sl@0
    37
sl@0
    38
	iParseMask=0;
sl@0
    39
	}
sl@0
    40
sl@0
    41
TInt DSurfaceManagerFactory::Install()
sl@0
    42
	{
sl@0
    43
	return SetName(&RSurfaceManagerDriver::Name());
sl@0
    44
	}
sl@0
    45
sl@0
    46
sl@0
    47
/**
sl@0
    48
  Called by the kernel's device driver framework to create a Logical Channel.
sl@0
    49
  This is called in the context of the user thread (client) which requested the creation of a Logical Channel
sl@0
    50
  (E.g. through a call to RBusLogicalChannel::DoCreate)
sl@0
    51
  The thread is in a critical section.
sl@0
    52
sl@0
    53
  @param aChannel  Set to point to the created Logical Channel
sl@0
    54
sl@0
    55
  @return KErrNone if successful, otherwise one of the other system wide error codes.
sl@0
    56
*/
sl@0
    57
TInt DSurfaceManagerFactory::Create(DLogicalChannelBase*& aChannel)
sl@0
    58
	{
sl@0
    59
	aChannel=new DSurfaceManagerChannel();
sl@0
    60
	if(!aChannel)
sl@0
    61
		return KErrNoMemory;
sl@0
    62
	return KErrNone;
sl@0
    63
	}
sl@0
    64
sl@0
    65
sl@0
    66
sl@0
    67
/**
sl@0
    68
  Return the drivers capabilities.
sl@0
    69
  Called in the response to an RDevice::GetCaps() request.
sl@0
    70
sl@0
    71
  @param aDes  User-side descriptor to write capabilities information into
sl@0
    72
*/
sl@0
    73
void DSurfaceManagerFactory::GetCaps(TDes8& aDes) const
sl@0
    74
	{
sl@0
    75
	// Create a capabilities object
sl@0
    76
	RSurfaceManagerDriver::TCaps caps;
sl@0
    77
	caps.iVersion = iVersion;
sl@0
    78
	// Write it back to user memory
sl@0
    79
	Kern::InfoCopy(aDes,reinterpret_cast<TUint8*>(&caps),sizeof(caps));
sl@0
    80
	}
sl@0
    81
sl@0
    82
sl@0
    83
sl@0
    84
DSurfaceManagerChannel::DSurfaceManagerChannel()
sl@0
    85
	{
sl@0
    86
	TRACE(Kern::Printf("SurfaceManagerChannel Creation");)
sl@0
    87
	}
sl@0
    88
sl@0
    89
sl@0
    90
/**
sl@0
    91
Channel destructor.
sl@0
    92
Called when the process owning the channel has died or closed the channel.
sl@0
    93
Calls the manager object to indicate that the process has closed a session so it 
sl@0
    94
can cleanup the surfaces which are only owned by that process if it has no further connections.
sl@0
    95
*/
sl@0
    96
DSurfaceManagerChannel::~DSurfaceManagerChannel()
sl@0
    97
	{
sl@0
    98
	Manager.RemoveConnection(iOwner);
sl@0
    99
	}
sl@0
   100
sl@0
   101
sl@0
   102
/**
sl@0
   103
  Second stage constructor called by the kernel's device driver framework.
sl@0
   104
  This is called in the context of the user thread (client) which requested the creation of a Logical Channel
sl@0
   105
  (E.g. through a call to RBusLogicalChannel::DoCreate)
sl@0
   106
  The thread is in a critical section.
sl@0
   107
sl@0
   108
  @param aUnit  The unit argument supplied by the client to RBusLogicalChannel::DoCreate
sl@0
   109
  @param aInfo  The info argument supplied by the client to RBusLogicalChannel::DoCreate
sl@0
   110
  @param aVer  The version argument supplied by the client to RBusLogicalChannel::DoCreate
sl@0
   111
sl@0
   112
  @return KErrNone if successful, otherwise one of the other system wide error codes.
sl@0
   113
*/
sl@0
   114
TInt DSurfaceManagerChannel::DoCreate(TInt /*aUnit*/, const TDesC8* /*aInfo*/, const TVersion& aVer)
sl@0
   115
	{
sl@0
   116
	// Check version
sl@0
   117
	if (!Kern::QueryVersionSupported(RSurfaceManagerDriver::VersionRequired(),aVer))
sl@0
   118
		return KErrNotSupported;
sl@0
   119
	
sl@0
   120
	iOwner = &Kern::CurrentProcess();
sl@0
   121
	TInt ret = Manager.AddConnection(iOwner);
sl@0
   122
	if (ret != KErrNone)
sl@0
   123
		iOwner = NULL;
sl@0
   124
	
sl@0
   125
	return ret;
sl@0
   126
	}
sl@0
   127
	
sl@0
   128
sl@0
   129
sl@0
   130
/**
sl@0
   131
  Process a request on this logical channel.
sl@0
   132
sl@0
   133
  @param aReqNo Request number:
sl@0
   134
  	            ==KMaxTInt, a 'DoCancel' message
sl@0
   135
	            >=0, a 'DoControl' message with function number equal to iValue
sl@0
   136
	            <0, a 'DoRequest' message with function number equal to ~iValue
sl@0
   137
  @param a1     First argument. For DoRequest requests this is a pointer to the TRequestStatus.
sl@0
   138
  @param a2     Second argument. For DoRequest this is a pointer to the 2 actual TAny* arguments.
sl@0
   139
sl@0
   140
  @return       Result ignored by device driver framework for DoRequest requests.
sl@0
   141
*/
sl@0
   142
TInt DSurfaceManagerChannel::Request(TInt aReqNo, TAny* a1, TAny* a2)
sl@0
   143
	{
sl@0
   144
	// Decode the message type and dispatch it to the relevent handler function...
sl@0
   145
	// only using synchronous control messages
sl@0
   146
	if (static_cast<TUint>(aReqNo) < static_cast<TUint>(KMaxTInt))
sl@0
   147
		{
sl@0
   148
		return DoControl(aReqNo, a1, a2);
sl@0
   149
		}
sl@0
   150
sl@0
   151
	return KErrNotSupported;
sl@0
   152
	}
sl@0
   153
sl@0
   154
/**
sl@0
   155
  Process synchronous 'control' requests
sl@0
   156
*/
sl@0
   157
TInt DSurfaceManagerChannel::DoControl(TInt aFunction, TAny* a1, TAny* a2)
sl@0
   158
	{
sl@0
   159
	TRACE(Kern::Printf(">DSurfaceManagerChannel::DoControl fn=%d process = %u\n",aFunction, iOwner);)
sl@0
   160
sl@0
   161
	TInt r;
sl@0
   162
	switch(aFunction)
sl@0
   163
		{
sl@0
   164
		case RSurfaceManagerDriver::EControlCreateSurface:
sl@0
   165
			r = Manager.CreateSurface(reinterpret_cast<const TDesC8*>(a1), reinterpret_cast<TSurfaceId*>(a2));
sl@0
   166
			break;
sl@0
   167
			
sl@0
   168
		case RSurfaceManagerDriver::EControlOpenSurface:
sl@0
   169
			r = Manager.OpenSurface(reinterpret_cast<TSurfaceId*>(a1));
sl@0
   170
			break;
sl@0
   171
			
sl@0
   172
		case RSurfaceManagerDriver::EControlCloseSurface:
sl@0
   173
			r = Manager.CloseSurface(reinterpret_cast<TSurfaceId*>(a1));
sl@0
   174
			break;
sl@0
   175
			
sl@0
   176
		case RSurfaceManagerDriver::EControlAccessSurfaceData:
sl@0
   177
			r = Manager.MapSurface(reinterpret_cast<TSurfaceId*>(a1));
sl@0
   178
			break;
sl@0
   179
			
sl@0
   180
		case RSurfaceManagerDriver::EControlSurfaceInfo:
sl@0
   181
			r = Manager.SurfaceInfo(reinterpret_cast<TSurfaceId*>(a1), reinterpret_cast<TDes8*>(a2));
sl@0
   182
			break;
sl@0
   183
sl@0
   184
		case RSurfaceManagerDriver::EControlCreateSurfaceEx:
sl@0
   185
			r = Manager.CreateSurface(reinterpret_cast<RSurfaceManagerDriver::TDeviceParam*>(a1), (TInt)a2);
sl@0
   186
			break;
sl@0
   187
			
sl@0
   188
		case RSurfaceManagerDriver::EControlSynchronizeCache:
sl@0
   189
			r = Manager.SynchronizeCache(reinterpret_cast<RSurfaceManagerDriver::TDeviceParam*>(a1), (RSurfaceManager::TSyncOperation&)a2);
sl@0
   190
			break;
sl@0
   191
sl@0
   192
		case RSurfaceManagerDriver::EControlGetSurfaceHint:
sl@0
   193
			r = Manager.GetSurfaceHint(reinterpret_cast<TSurfaceId*>(a1), reinterpret_cast<RSurfaceManager::THintPair*>(a2));
sl@0
   194
			break;
sl@0
   195
sl@0
   196
		case RSurfaceManagerDriver::EControlSetSurfaceHint:
sl@0
   197
			r = Manager.SetSurfaceHint(reinterpret_cast<TSurfaceId*>(a1), reinterpret_cast<const RSurfaceManager::THintPair*>(a2));
sl@0
   198
			break;
sl@0
   199
sl@0
   200
		case RSurfaceManagerDriver::EControlAddSurfaceHint:
sl@0
   201
			r = Manager.AddSurfaceHint(reinterpret_cast<TSurfaceId*>(a1), reinterpret_cast<const RSurfaceManager::THintPair*>(a2));
sl@0
   202
			break;
sl@0
   203
		case RSurfaceManagerDriver::EControlGetBufferOffset:
sl@0
   204
			r = Manager.GetBufferOffset(reinterpret_cast<RSurfaceManagerDriver::TDeviceParam*>(a1),reinterpret_cast<TUint*>(a2));
sl@0
   205
			break;
sl@0
   206
		case RSurfaceManagerDriver::EControlGetSurfaceManagerAttrib:
sl@0
   207
			r = Manager.GetSurfaceManagerAttrib(reinterpret_cast<RSurfaceManager::TSurfaceManagerAttrib*>(a1),reinterpret_cast<TInt*>(a2));
sl@0
   208
			break;			
sl@0
   209
		default:
sl@0
   210
			r = KErrNotSupported;
sl@0
   211
			break;
sl@0
   212
		}
sl@0
   213
	TRACE(Kern::Printf("<SurfaceManagerChannel::DoControl result=%d\n",r);)
sl@0
   214
	return r;
sl@0
   215
	}
sl@0
   216
sl@0
   217
sl@0
   218
sl@0
   219
DECLARE_STANDARD_EXTENSION()
sl@0
   220
	{
sl@0
   221
	//called when kernel extension is loaded
sl@0
   222
	//initialise the kernel extension
sl@0
   223
	TRACE(Kern::Printf("<SurfaceManager Extension entry point\n");)
sl@0
   224
	return KErrNone;
sl@0
   225
	}
sl@0
   226