Update contrib.
1 // Copyright (c) 1995-2010 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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
21 #include "fbshelper.h"
22 #include "FbsMessage.H"
23 #include <graphics/fbsoogmmessage.h>
24 #include "OstTraceDefinitions.h"
26 #ifdef OST_TRACE_COMPILER_IN_USE
27 #include "SESSIONTraces.h"
30 GLDEF_C void Panic(TFbsPanic aPanic)
32 _LIT(KFBSERVClientPanicCategory,"FBSCLI");
33 User::Panic(KFBSERVClientPanicCategory,aPanic);
36 EXPORT_C TInt FbsStartup()
39 TInt ret = sharedchunk.OpenGlobal(KFBSERVSharedChunkName,EFalse);
47 _LIT(KFBSERVServerExe,"z:\\sys\\bin\\fbserv.exe");
48 ret = fbs.Create(KFBSERVServerExe,KNullDesC);
56 if (stat!=KRequestPending)
57 fbs.Kill(0); // abort startup
59 fbs.Resume(); // logon OK - start the server
60 User::WaitForRequest(stat); // wait for start or death
61 // we can't use the 'exit reason' if the server panicked as this
62 // is the panic 'reason' and may be '0' which cannot be distinguished
64 ret=(fbs.ExitType()==EExitPanic) ? KErrGeneral : stat.Int();
71 // Fontbitmap server client side session
78 EXPORT_C RFbsSession::RFbsSession():
84 iRomFileAddrCache(NULL),
85 iDecompressionBuffer(NULL),
86 iScanLineBuffer(NULL),
90 /** Creates a session with the Font and Bitmap server.
91 @param aFileServer A fuly constructed file server session
92 @return KErrNone, if successful; KErrNoMemory if there is not enough memory
93 to create the session; otherwise another of the system-wide error codes.
97 EXPORT_C TInt RFbsSession::Connect(RFs& aFileServer)
100 RFbsSession* thisptr = (RFbsSession*)Dll::Tls();
101 FBS_OST(OstTrace1(GRAPHICS_CONTROL_FUNCTIONS, RFBSSESSION_CONNECT_ENTRY, "> this=0x%08x;", (TUint)thisptr);)
104 thisptr->iConnections++;
105 FBS_OST(OstTraceExt2(GRAPHICS_CONTROL_SEMANTICS, RFBSSESSION_CONNECT_INFO, "# Connected to existing session; this=0x%08x; iConnections=%d;", (TInt)thisptr, thisptr->iConnections);)
109 ret = RFbsSession::DoAlloc(thisptr);
112 FBS_OST(OstTrace1(TRACE_ERROR, RFBSSESSION_CONNECT_ERROR, "! DoAlloc returned %d", ret);)
116 ret = thisptr->DoConnect(aFileServer);
119 FBS_OST(OstTraceExt2(TRACE_ERROR, RFBSSESSION_CONNECT_ERROR2, "! this=0x%08x; DoConnect returned %d", (TInt)thisptr, ret);)
124 FBS_OST(OstTraceExt2(GRAPHICS_CONTROL_FUNCTIONS, RFBSSESSION_CONNECT_EXIT, "< this=0x%08x; ret=%d", (TUint)thisptr, ret);)
128 /** Creates a session with the Font and Bitmap server.
129 @return KErrNone, if successful; KErrNoMemory if there is not enough memory
130 to create the session; otherwise another of the system-wide error codes.
134 EXPORT_C TInt RFbsSession::Connect()
137 RFbsSession* thisptr = (RFbsSession*)Dll::Tls();
138 FBS_OST(OstTrace1(GRAPHICS_CONTROL_FUNCTIONS, RFBSSESSION_CONNECT2_ENTRY, "> this=0x%08x;", (TUint)thisptr);)
141 thisptr->iConnections++;
142 FBS_OST(OstTraceExt2(GRAPHICS_CONTROL_SEMANTICS, RFBSSESSION_CONNECT2_INFO, "# Connected to existing session; this=0x%08x; iConnections=%d;", (TInt)thisptr, thisptr->iConnections);)
146 TInt ret = RFbsSession::DoAlloc(thisptr);
149 FBS_OST(OstTrace1(TRACE_ERROR, RFBSSESSION_CONNECT2_ERROR, "! DoAlloc returned %d", ret);)
153 ret = thisptr->iFileServer.Connect();
156 thisptr->Disconnect();
157 FBS_OST(OstTraceExt2(TRACE_ERROR, RFBSSESSION_CONNECT2_ERROR2, "! this=0x%08x; RFs::Connect() returned %d", (TInt)thisptr, ret);)
161 ret = thisptr->DoConnect(thisptr->iFileServer);
164 FBS_OST(OstTraceExt2(TRACE_ERROR, RFBSSESSION_CONNECT2_ERROR3, "! this=0x%08x; DoConnect returned %d", (TInt)thisptr, ret);)
168 FBS_OST(OstTraceExt2(GRAPHICS_CONTROL_FUNCTIONS, RFBSSESSION_CONNECT2_EXIT, "< this=0x%08x; ret=%d", (TUint)thisptr, ret);)
172 /** Closes the session with the Font and Bitmap server.
176 EXPORT_C void RFbsSession::Disconnect()
178 RFbsSession* thisptr=(RFbsSession*)Dll::Tls();
179 FBS_OST(OstTrace1(GRAPHICS_CONTROL_FUNCTIONS, RFBSSESSION_DISCONNECT_ENTRY, "> this=0x%08x;", (TUint)thisptr);)
182 TInt tempServerSessionHandle = thisptr->ServerSessionHandle();
183 if(thisptr->iConnections>0)
185 thisptr->iCallBack.iPtr=NULL;
186 thisptr->iCallBack.CallBack();
187 // Destructor of CFbsSessionHelper may call SendCommand to cancel an
188 // outstanding request, therefore destruction must be done before
189 // iConnections is 0 to avoid an assertion going off.
190 if(thisptr->iConnections==1)
192 delete thisptr->iHelper;
194 thisptr->iConnections--;
196 if(thisptr->iConnections==0)
198 thisptr->iSharedChunk.Close();
199 thisptr->iLargeBitmapChunk.Close();
200 // Call close on the iFileServer regardless of whether this session owns it:
201 // if we don't own it, close will do nothing if there are still open files,
202 // so always calling close introduces extra safety
203 thisptr->iFileServer.Close();
204 delete thisptr->iRomFileAddrCache;
205 delete thisptr->iScanLineBuffer;
206 delete thisptr->iDecompressionBuffer;
211 FBS_OST(OstTraceExt3(GRAPHICS_CONTROL_SEMANTICS, RFBSSESSION_DISCONNECT_INFO, "# Disconnected from session; this=0x%08x; iConnections=%d; iSSH=0x%08x", (TInt)thisptr, thisptr->iConnections, tempServerSessionHandle);)
213 FBS_OST(OstTrace1(GRAPHICS_CONTROL_FUNCTIONS, RFBSSESSION_DISCONNECT_EXIT2, "< this=0x%08x;", (TUint)thisptr);)
216 /** Gets the current Font and Bitmap server session.
217 @return A pointer to the current session or NULL if Connect() has not been
222 EXPORT_C RFbsSession* RFbsSession::GetSession()
224 return((RFbsSession*)Dll::Tls());
227 /** Triggers the most recently registered callback. This is mainly called by
228 bitmaps when their twips size changes and when any FBSERV objects are closed
229 to notify clients of a change that may affect their operation.
233 EXPORT_C void RFbsSession::CallBack()
235 iCallBack.CallBack();
239 void RFbsSession::SetCallBackPtr(TInt* aBitmapHandle)const
241 iCallBack.iPtr=aBitmapHandle;
244 /** Sets the callback.
245 @param aCallBack callback object to be called by CallBack(). Only one may be
246 in use at a time and subsequent calls will displace previous calls.
250 EXPORT_C void RFbsSession::SetCallBack(TCallBack aCallBack)
255 /** Resets the callback.
259 EXPORT_C void RFbsSession::ResetCallBack()
265 /** Returns the number of Font and Bitmap Server objects currently in
267 @return The number of resources in use: bitmaps, fonts, typeface stores.
271 EXPORT_C TInt RFbsSession::ResourceCount()
273 return(SendCommand(EFbsMessResourceCount));
276 /** Utility function for passing commands to the server.
277 @param aMessage Integer code for the message to pass - see TFbsMessage.
278 @param aInt0 Parameter 0 for the message.
279 @param aInt1 Parameter 1 for the message.
280 @param aInt2 Parameter 2 for the message.
281 @param aInt3 Parameter 3 for the message.
282 @return Return code from RSessionBase::SendReceive().
285 EXPORT_C TInt RFbsSession::SendCommand(TInt aMessage,TInt aInt0,TInt aInt1,TInt aInt2,TInt aInt3) const
287 __ASSERT_ALWAYS(iConnections>0,Panic(EFbsPanicBadConnection));
291 case EFbsMessShutdown:
293 SetCallBackPtr(aMessage==EFbsMessClose ? &aInt1 : 0);
294 iCallBack.CallBack();
299 TInt ret = SendReceive(aMessage, TIpcArgs(aInt0,aInt1,aInt2,aInt3));
304 TInt RFbsSession::SendCommand(TInt aMessage, const TIpcArgs& aArgs) const
306 __ASSERT_ALWAYS(iConnections>0,Panic(EFbsPanicBadConnection));
307 return SendReceive(aMessage,aArgs);
310 void RFbsSession::SendCommand(TInt aMessage, const TIpcArgs& aArgs, TRequestStatus &aStatus) const
312 __ASSERT_ALWAYS(iConnections>0,Panic(EFbsPanicBadConnection));
313 SendReceive(aMessage,aArgs,aStatus);
316 /** Gets the current Font and Bitmap server version.
317 @return The current version of the server.
321 EXPORT_C TVersion RFbsSession::Version()
323 TVersion v(KFbsMajorVersionNumber,KFbsMinorVersionNumber,KFbsBuildVersionNumber);
327 /** Gets the address of first location in the global shared heap containing
329 @return Pointer to the base of the shared heap.
333 EXPORT_C TUint8* RFbsSession::HeapBase() const
335 return(iSharedChunk.Base());
338 TBool RFbsSession::LookupBitmapInROM(const TDesC& aFilename, TAny*& aAddr)
340 aAddr = iRomFileAddrCache->Lookup(aFilename);
346 TInt RFbsSession::DoAlloc(RFbsSession*& aNewSession)
348 aNewSession = (RFbsSession*)User::Alloc(sizeof(RFbsSession));
351 new(aNewSession) RFbsSession;
352 aNewSession->iConnections = 1;
353 TInt ret = Dll::SetTls(aNewSession);
363 Do actual connect as common to both Connect() and Connect(RFs& aFileServer). Store fully constructed
364 file server session to iSpare member variable
366 @return KErrNone, if successful; KErrNoMemory if there is not enough memory
367 to create the session; otherwise another of the system-wide error codes.
370 TInt RFbsSession::DoConnect(RFs& aFileServer)
372 //Allow this session to be accessed by other process to lead bitmap in server
373 TInt ret = aFileServer.ShareProtected();
379 iRomFileAddrCache = CFbsRalCache::New(4, aFileServer);
380 if (!iRomFileAddrCache)
386 ret = CreateSession(KFBSERVGlobalThreadName,Version(),-1);
392 const TInt serverAssignedHandle = SendReceive(EFbsMessInit);
393 if(serverAssignedHandle <= 0)
396 return serverAssignedHandle;
398 ret = iSharedChunk.OpenGlobal(KFBSERVSharedChunkName,EFalse);
400 Panic(EFbsPanicChunkError);
401 iHelper = new CFbsSessionHelper(*this);
407 iHelper->iServerSessionHandle = serverAssignedHandle;
409 ret = iLargeBitmapChunk.OpenGlobal(KFBSERVLargeChunkName,EFalse);
411 Panic(EFbsPanicChunkError);
413 iSpare = (TUint32*)&aFileServer;
415 FBS_OST(OstTraceExt2(GRAPHICS_CONTROL_SEMANTICS, RFBSSESSION_DOCONNECT_INFO, "# New FBS Session created; this=0x%08x; iSSH=0x%08x;", (TInt)this, serverAssignedHandle);)
420 Allocates the buffer for decoding compressed rom bitmaps.
424 @param aSize Minimum size of the buffer required.
425 If the buffer is too small an attempt to resize it will be made.
426 @return KErrNone if successful,
427 KErrNoMemory if the buffer was too small and could
432 TInt RFbsSession::AllocScanLineBuffer(TInt aSize)
434 if (iScanLineBuffer && iScanLineBuffer->Des().MaxSize() >= aSize)
439 HBufC8* newBuffer = HBufC8::New(aSize);
443 delete iScanLineBuffer;
444 iScanLineBuffer = newBuffer;
452 Gets a reference to the buffer currently in use for decoding
453 compressed rom bitmaps.
457 @return The buffer area currently in use,
461 HBufC8* RFbsSession::GetScanLineBuffer()
463 return iScanLineBuffer;
467 Gets a pointer to the buffer currently in use for decoding
468 compressed mask bitmaps.
471 @param aSize Minimum size of the buffer required.
472 If the buffer is too small an attempt to resize it will be made.
473 @return The buffer area currently in use or NULL if there is no memory.
476 HBufC8* RFbsSession::GetDecompressionBuffer(TInt aSize)
478 if (iDecompressionBuffer)
480 if (iDecompressionBuffer->Des().MaxSize() < aSize)
482 HBufC8* tempBuffer = iDecompressionBuffer->ReAlloc(aSize);
487 iDecompressionBuffer = tempBuffer;
492 iDecompressionBuffer = HBufC8::New(aSize);
495 return iDecompressionBuffer;
499 Gets a pointer to an extra buffer for general use.
502 @param aSize Minimum size of the buffer required.
503 If the buffer is too small an attempt to resize it will be made.
504 @return The buffer area currently in use or NULL if there is no memory.
507 HBufC8* RFbsSession::GetExtraBuffer(TInt aSize)
509 if (iHelper->iExtraBuffer)
511 if (iHelper->iExtraBuffer->Des().MaxSize() < aSize)
513 HBufC8* tempBuffer = iHelper->iExtraBuffer->ReAlloc(aSize);
518 iHelper->iExtraBuffer = tempBuffer;
523 iHelper->iExtraBuffer = HBufC8::New(aSize);
526 return iHelper->iExtraBuffer;
530 Returns a handle assigned to this session by the server upon connection.
531 This method should be used instead of SessionHandle() when passing a session
532 handle to FbServ APIs that require Session handles.
533 @return A handle representing this session on the server.
534 @pre The session has successfully connected to the server.
536 TInt RFbsSession::ServerSessionHandle() const
538 __ASSERT_ALWAYS(iConnections>0,Panic(EFbsPanicBadConnection));
539 return iHelper->iServerSessionHandle;
542 EXPORT_C TInt RFbsSession::GetGlyphCacheMetrics( TGlyphCacheMetrics& aGlyphCacheMetrics )
544 TPckgBuf<TGlyphCacheMetrics> metrics;
545 TIpcArgs args( &metrics );
547 TInt ret = SendReceive( EFbsMessGetGlyphCacheMetrics, args );
548 aGlyphCacheMetrics = metrics();
554 Perform the IPC to convey the desired OoGM action to the glyph atlas.
556 @return KErrNone if IPC was successful. One of the system-wide error
557 codes, as described for RSessionBase::SendReceive(), if not.
559 @note The server-side platform security policy applied to this method is such that it is only useable by the GOoM framework.
561 @param aOogmMessage. A reference to the class encapsulating the OoGM action required of the glyph atlas.
563 EXPORT_C TInt RFbsSession::ConveyOogmMessage( TFbsOogmMessage& aOogmMessage )
565 TPckgBuf<TFbsOogmMessage> oogmMessage;
566 oogmMessage() = aOogmMessage;
567 TIpcArgs args( &oogmMessage );
569 return SendReceive( EFbsMessOogmNotification, args );
573 Returns the current sizes of the FBServ default heap, the heap for large bitmaps,
574 and the heap for small bitmaps.
576 Not supported in release builds.
580 @param aDefaultHeapSize A reference to an integer supplied by the caller. On return from this function, contains the size of the FBServ default heap.
581 @param aSmallBmpHeapSize A reference to an integer supplied by the caller. On return from this function, contains the size of the FBServ heap for small bitmaps
582 @param aBigBmpHeapSize A reference to an integer supplied by the caller. On return from this function, contains the size of the FBServ heap for large bitmaps
583 @return KErrNone or one of the system wide error codes in debug mode, or KErrNotSupported in release mode.
586 EXPORT_C TInt RFbsSession::GetHeapSizes(TInt& aDefaultHeapSize, TInt& aSmallBmpHeapSize, TInt& aBigBmpHeapSize)
588 TPckgBuf<THeapSizes> data;
589 TIpcArgs args(&data);
590 TInt ret = SendReceive(EFbsMessGetHeapSizes, args);
593 aDefaultHeapSize = data().iDefault;
594 aSmallBmpHeapSize = data().iSmall;
595 aBigBmpHeapSize = data().iBig;
600 EXPORT_C TInt RFbsSession::GetHeapSizes(TInt&, TInt&, TInt&)
602 return KErrNotSupported;