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