fbs/fontandbitmapserver/sfbs/SERVER.CPP
branchRCL_3
changeset 164 25ffed67c7ef
parent 163 bbf46f59e123
equal deleted inserted replaced
163:bbf46f59e123 164:25ffed67c7ef
     1 // Copyright (c) 1995-2010 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    20 #include "BackGroundCompression.h"
    20 #include "BackGroundCompression.h"
    21 #include "linkedfonts.h"
    21 #include "linkedfonts.h"
    22 #include "BitwiseBitmap.inl"
    22 #include "BitwiseBitmap.inl"
    23 
    23 
    24 const TInt KFbsPriority = 0;
    24 const TInt KFbsPriority = 0;
    25 const TInt KFbsGoomMonitorSid = 0x10207218;
    25 
    26 // Setup security policies
    26 // Setup security policies
    27 const TInt KRanges[] = 
    27 const TInt KRanges[] = 
    28 	{
    28 	{
    29 	0,
    29 	0,
    30 	EFbsMessShutdown,
    30 	EFbsMessShutdown,
    34 	EFbsMessUnused1,
    34 	EFbsMessUnused1,
    35 	EFbsMessUnused2,
    35 	EFbsMessUnused2,
    36 	EFbsMessRegisterLinkedTypeface,
    36 	EFbsMessRegisterLinkedTypeface,
    37 	EFbsMessFetchLinkedTypeface,
    37 	EFbsMessFetchLinkedTypeface,
    38 	EFbsMessUpdateLinkedTypeface,
    38 	EFbsMessUpdateLinkedTypeface,
    39 	EFbsMessGetFontTable,
       
    40     EFbsMessOogmNotification,
       
    41     EFbsMessGetGlyphCacheMetrics,
       
    42 	};
    39 	};
    43 
       
    44 const TUint KRangeCount = sizeof(KRanges)/sizeof(TInt);
    40 const TUint KRangeCount = sizeof(KRanges)/sizeof(TInt);
    45 const TUint8 KElementsIndex[KRangeCount] = 
    41 const TUint8 KElementsIndex[KRangeCount] = 
    46 	{
    42 	{
    47 	0,
    43 	0,
    48 	3, // For EFbsMessShutdown
    44 	3, // For EFbsMessShutdown
    52 	0, // ECapability_None for EFbsMessUnused1
    48 	0, // ECapability_None for EFbsMessUnused1
    53 	0, // ECapability_None for EFbsMessUnused2 and beyond
    49 	0, // ECapability_None for EFbsMessUnused2 and beyond
    54 	1, // ECapabilityWriteDeviceData for EFbsMessRegisterLinkedTypeface
    50 	1, // ECapabilityWriteDeviceData for EFbsMessRegisterLinkedTypeface
    55 	2, // ECapabilityReadDeviceData for EFbsMessFetchLinkedTypeface
    51 	2, // ECapabilityReadDeviceData for EFbsMessFetchLinkedTypeface
    56 	1, // ECapabilityWriteDeviceData for EFbsMessUpdateLinkedTypeface
    52 	1, // ECapabilityWriteDeviceData for EFbsMessUpdateLinkedTypeface
    57 	0, // ECapability_None for EFbsMessGetFontTable and beyond
       
    58     4, // SID for EFbsMessOogmNotification.
       
    59     0, // For EFbsMessGetGlyphCacheMetrics and on.
       
    60 	};
    53 	};
    61 
       
    62 const CPolicyServer::TPolicyElement KElements[] = 
    54 const CPolicyServer::TPolicyElement KElements[] = 
    63 	{
    55 	{
    64 	{_INIT_SECURITY_POLICY_C1(ECapability_None), CPolicyServer::EFailClient},
    56 	{_INIT_SECURITY_POLICY_C1(ECapability_None), CPolicyServer::EFailClient},
    65 	{_INIT_SECURITY_POLICY_C1(ECapabilityWriteDeviceData), CPolicyServer::EFailClient},
    57 	{_INIT_SECURITY_POLICY_C1(ECapabilityWriteDeviceData), CPolicyServer::EFailClient},
    66 	{_INIT_SECURITY_POLICY_C1(ECapabilityReadDeviceData), CPolicyServer::EFailClient},
    58 	{_INIT_SECURITY_POLICY_C1(ECapabilityReadDeviceData), CPolicyServer::EFailClient},
    67 	{_INIT_SECURITY_POLICY_C1(ECapabilityPowerMgmt), CPolicyServer::EFailClient},
    59 	{_INIT_SECURITY_POLICY_C1(ECapabilityPowerMgmt), CPolicyServer::EFailClient},	
    68 	{_INIT_SECURITY_POLICY_S0(KFbsGoomMonitorSid), CPolicyServer::EFailClient}
       
    69  	};
    60  	};
    70 
       
    71 const CPolicyServer::TPolicy KFbsPolicy =
    61 const CPolicyServer::TPolicy KFbsPolicy =
    72 	{
    62 	{
    73 	CPolicyServer::EAlwaysPass, //specifies all connect attempts should pass
    63 	CPolicyServer::EAlwaysPass, //specifies all connect attempts should pass
    74 	KRangeCount,
    64 	KRangeCount,
    75 	KRanges,
    65 	KRanges,
    76 	KElementsIndex,
    66 	KElementsIndex,
    77 	KElements,
    67 	KElements,
    78 	};
    68 	};
    79 
    69 
    80 CFontBitmapServer::CFontBitmapServer():
    70 CFontBitmapServer::CFontBitmapServer():
    81 	CPolicyServer(KFbsPriority, KFbsPolicy)
    71 	CPolicyServer(KFbsPriority, KFbsPolicy),
       
    72 	iConnectionId(0),
       
    73 	iTopLevelStore(NULL)
    82 	{
    74 	{
    83 	}
    75 	}
    84 
    76 
    85 CFontBitmapServer::~CFontBitmapServer()
    77 CFontBitmapServer::~CFontBitmapServer()
    86 	{
    78 	{
    89 							// it may be called inside CFontBitmapServer::~CFontBitmapServer
    81 							// it may be called inside CFontBitmapServer::~CFontBitmapServer
    90 	}
    82 	}
    91 
    83 
    92 CFontBitmapServer* CFontBitmapServer::NewL()
    84 CFontBitmapServer* CFontBitmapServer::NewL()
    93 	{
    85 	{
    94 	CFontBitmapServer* self = new(ELeave) CFontBitmapServer;
    86 	CFontBitmapServer* fbs=new(ELeave) CFontBitmapServer;
    95 	CleanupStack::PushL(self);
    87 	CleanupStack::PushL(fbs);
    96 	self->ConstructL();
    88 	fbs->iTopLevelStore=CFbTop::NewL();
    97 	CleanupStack::Pop(); //self
       
    98 	return self;
       
    99 	}
       
   100 
       
   101 /**
       
   102 Two-phase constructor.
       
   103 */
       
   104 void CFontBitmapServer::ConstructL()
       
   105 	{
       
   106 	iTopLevelStore=CFbTop::NewL();
       
   107 	
    89 	
   108 	// If fbserv data paging is configured as unpaged, automatically pin client descriptors 
    90 	// If fbserv data paging is configured as unpaged, automatically pin client descriptors 
   109 	if(!RProcess().DefaultDataPaged())
    91 	if(!RProcess().DefaultDataPaged())
   110 		{
    92 		{
   111 		SetPinClientDescriptors(ETrue);
    93 		fbs->SetPinClientDescriptors(ETrue);
   112 		}
    94 		}
   113 	StartL(KFBSERVGlobalThreadName);
    95 
       
    96 	fbs->StartL(KFBSERVGlobalThreadName);
       
    97 	CleanupStack::Pop();
       
    98 	return(fbs);
   114 	}
    99 	}
   115 
   100 
   116 CFbTop* CFontBitmapServer::TopLevelStore()
   101 CFbTop* CFontBitmapServer::TopLevelStore()
   117 	{
   102 	{
   118 	return(iTopLevelStore);
   103 	return(iTopLevelStore);
   119 	}
   104 	}
   120 
       
   121 CSession2* CFontBitmapServer::NewSessionL(const TVersion& aVersion,const RMessage2& /*aMessage*/ ) const
   105 CSession2* CFontBitmapServer::NewSessionL(const TVersion& aVersion,const RMessage2& /*aMessage*/ ) const
   122 	{
   106 	{
   123 	TVersion v(KFbsMajorVersionNumber,KFbsMinorVersionNumber,KFbsBuildVersionNumber);
   107 	TVersion v(KFbsMajorVersionNumber,KFbsMinorVersionNumber,KFbsBuildVersionNumber);
   124 	if(!User::QueryVersionSupported(v,aVersion))
   108 	if(!User::QueryVersionSupported(v,aVersion))
   125 		User::Leave(KErrNotSupported);
   109 		User::Leave(KErrNotSupported);
   139 	TTypefaceSupport tfi;
   123 	TTypefaceSupport tfi;
   140 	TPckgBuf<TTypefaceSupport> ttipckg(tfi);
   124 	TPckgBuf<TTypefaceSupport> ttipckg(tfi);
   141 	TPckgBuf<TSize> pixelSize;
   125 	TPckgBuf<TSize> pixelSize;
   142 	TInt index=aMessage.Int0();
   126 	TInt index=aMessage.Int0();
   143 	TInt limit=iTopLevelStore->FontStore()->NumTypefaces();
   127 	TInt limit=iTopLevelStore->FontStore()->NumTypefaces();
   144 	if(index < 0 || index > limit)
   128 	if(index<0 || index>limit)
   145 		{
   129 		{
   146 		return KErrArgument;
   130 		return KErrArgument;
   147 		}
   131 		}
   148 	TInt ret = aMessage.Read(2, pixelSize);
   132 	TInt ret = aMessage.Read(2, pixelSize);
   149 	if (ret != KErrNone)
   133 	if (ret != KErrNone)
   207 void CFontBitmapServer::ProcMessage(const RMessage2& aMessage, TInt aSession, TInt& aRet)
   191 void CFontBitmapServer::ProcMessage(const RMessage2& aMessage, TInt aSession, TInt& aRet)
   208 #else
   192 #else
   209 void CFontBitmapServer::ProcMessage(const RMessage2& aMessage, TInt aSession)
   193 void CFontBitmapServer::ProcMessage(const RMessage2& aMessage, TInt aSession)
   210 #endif
   194 #endif
   211 	{
   195 	{
   212     TInt ret=KErrNone;
   196 	TInt ret=KErrNone;
   213 	TBool clientPanicRequired = EFalse;
   197 	TBool clientPanicRequired = EFalse;
   214 #ifdef _DEBUG
   198 #ifdef _DEBUG
   215 	TInt num=0;
   199 	TInt num=0;
   216 #endif
   200 #endif
   217 	switch (aMessage.Function())
   201 	switch (aMessage.Function())
   358 		}
   342 		}
   359 
   343 
   360 #ifdef _DEBUG
   344 #ifdef _DEBUG
   361 	aRet=ret;
   345 	aRet=ret;
   362 #endif	
   346 #endif	
   363 
       
   364 	}
   347 	}
   365 
   348 
   366 /**
   349 /**
   367 Returns the current sizes of the FBServ default heap, the heap for large bitmaps, 
   350 Returns the current sizes of the FBServ default heap, the heap for large bitmaps, 
   368 and the heap for small bitmaps.
   351 and the heap for small bitmaps.
   376 */
   359 */
   377 #ifdef _DEBUG
   360 #ifdef _DEBUG
   378 void CFontBitmapServer::GetHeapSizesL(const RMessage2& aMessage)
   361 void CFontBitmapServer::GetHeapSizesL(const RMessage2& aMessage)
   379 	{
   362 	{
   380 	TPckgBuf<THeapSizes> data;
   363 	TPckgBuf<THeapSizes> data;
   381 	TInt defaultHeapSize = 0;
   364 	TInt defaultHeapSize;
   382 	TInt smallBmpHeapSize = 0;		
   365 	TInt smallBmpHeapSize;		
   383 	TInt bigBmpHeapSize = 0;		
   366 	TInt bigBmpHeapSize;		
   384 	
   367 	
   385 	User::Heap().AllocSize(defaultHeapSize);
   368 	User::Heap().AllocSize(defaultHeapSize);
   386 	bigBmpHeapSize = iTopLevelStore->iLargeBitmapChunk.Size();
   369 	bigBmpHeapSize = iTopLevelStore->iLargeBitmapChunk.Size();
   387 	iTopLevelStore->Heap()->AllocSize(smallBmpHeapSize);
   370 	iTopLevelStore->Heap()->AllocSize(smallBmpHeapSize);
   388 	
   371 	
   398 	User::Leave(KErrNotSupported);	
   381 	User::Leave(KErrNotSupported);	
   399 	}	
   382 	}	
   400 #endif
   383 #endif
   401 
   384 
   402 
   385 
   403 CFontObject::CFontObject(CFontStore* aFontStore, CGlyphAtlas* aGlyphAtlas):
   386 CFontObject::CFontObject(CFontStore* aFontStore):
   404 	CObject(),
   387 	CObject(),
   405 	iFontStore(aFontStore),
   388 	iAddressPointer(NULL),
   406 	iGlyphAtlas(aGlyphAtlas)
   389 	iFontStore(aFontStore)
   407 	{
   390 	{
   408 	}
   391 	}
   409 
   392 
   410 CFontObject::~CFontObject()
   393 CFontObject::~CFontObject()
   411 	{
   394 	{
   412 	if (AccessCount()==1)
   395 	if (AccessCount()==1)
   413 		{
       
   414 		Dec();
   396 		Dec();
   415 		}
       
   416 	iFontStore->ReleaseFont(iAddressPointer);
   397 	iFontStore->ReleaseFont(iAddressPointer);
   417 	if (iGlyphAtlas)
       
   418 		{
       
   419 		iGlyphAtlas->FontReleased(*iAddressPointer);
       
   420 		}
       
   421 	}
   398 	}
   422 
   399 
   423 // CBitmapObject constructor - takes ownership of aBmp
   400 // CBitmapObject constructor - takes ownership of aBmp
   424 CBitmapObject::CBitmapObject(CFbTop& aFbTop, CBitwiseBitmap* aBmp):
   401 CBitmapObject::CBitmapObject(CFbTop& aFbTop, CBitwiseBitmap* aBmp):
   425 	CObject(),
   402 	CObject(),
   445 	iFbTop->iBitmapCon->AddL(this);
   422 	iFbTop->iBitmapCon->AddL(this);
   446 	if (!aReplacement)
   423 	if (!aReplacement)
   447 		{
   424 		{
   448 		iHandle = reinterpret_cast<TInt>(this);
   425 		iHandle = reinterpret_cast<TInt>(this);
   449 		while (iFbTop->iBitmapObjectIndex.FindInOrder(this, Compare) != KErrNotFound)
   426 		while (iFbTop->iBitmapObjectIndex.FindInOrder(this, Compare) != KErrNotFound)
   450 			{
       
   451 			++iHandle;
   427 			++iHandle;
   452 			}
       
   453 		User::LeaveIfError(iFbTop->iBitmapObjectIndex.InsertInOrder(this, Compare));
   428 		User::LeaveIfError(iFbTop->iBitmapObjectIndex.InsertInOrder(this, Compare));
   454 		}
   429 		}
   455 	}
   430 	}
   456 
   431 
   457 void CleanupBitmapObject(TAny* aPtr)
   432 void CleanupBitmapObject(TAny* aPtr)
   492 			{
   467 			{
   493 			TInt index = iFbTop->iBitmapObjectIndex.FindInOrder(this, Compare);
   468 			TInt index = iFbTop->iBitmapObjectIndex.FindInOrder(this, Compare);
   494 			if (index != KErrNotFound)
   469 			if (index != KErrNotFound)
   495 				{
   470 				{
   496 				if (iCleanBitmap)
   471 				if (iCleanBitmap)
   497 					{
       
   498 					iFbTop->iBitmapObjectIndex[index] = iCleanBitmap;
   472 					iFbTop->iBitmapObjectIndex[index] = iCleanBitmap;
   499 					}
       
   500 				else
   473 				else
   501 					{
       
   502 					iFbTop->iBitmapObjectIndex.Remove(index);
   474 					iFbTop->iBitmapObjectIndex.Remove(index);
   503 					}
       
   504 				}
   475 				}
   505 			}
   476 			}
   506 		if (iCleanBitmap != NULL)
   477 		if (iCleanBitmap != NULL)
   507 			{
   478 			{
   508 			iCleanBitmap->SetOwner(NULL);
   479 			iCleanBitmap->SetOwner(NULL);
   527 	aNewBmpObj->iAddressPointer->Extra()->iTouchCount = iAddressPointer->Extra()->iTouchCount + 1;
   498 	aNewBmpObj->iAddressPointer->Extra()->iTouchCount = iAddressPointer->Extra()->iTouchCount + 1;
   528 	}
   499 	}
   529 
   500 
   530 void CBitmapObject::Close()
   501 void CBitmapObject::Close()
   531 	{
   502 	{
   532 	if ((iCleanBitmap != NULL) && (Owner() != NULL) && (AccessCount() == 2))
   503 	if (iCleanBitmap != NULL && Owner() != NULL && AccessCount() == 2)
   533 		{
   504 		{
   534 		static_cast<CBitmapObject*>(Owner())->iCleanBitmap = iCleanBitmap;
   505 		static_cast<CBitmapObject*>(Owner())->iCleanBitmap = iCleanBitmap;
   535 		iCleanBitmap->SetOwner(Owner());
   506 		iCleanBitmap->SetOwner(Owner());
   536 		iHandle = 0;
   507 		iHandle = 0;
   537 		Dec();
   508 		Dec();
   550 	}
   521 	}
   551 
   522 
   552 // CSharedBitmapObject constructor - takes ownership of aBmp and aKey
   523 // CSharedBitmapObject constructor - takes ownership of aBmp and aKey
   553 CSharedBitmapObject::CSharedBitmapObject(CFbTop& aFbTop, CBitwiseBitmap* aBmp, TDesC* aKey):
   524 CSharedBitmapObject::CSharedBitmapObject(CFbTop& aFbTop, CBitwiseBitmap* aBmp, TDesC* aKey):
   554 	CBitmapObject(aFbTop, aBmp),
   525 	CBitmapObject(aFbTop, aBmp),
   555 	iKey(aKey)
   526 	iKey(aKey),
       
   527 	iNext(NULL)
   556 	{
   528 	{
   557 	__ASSERT_DEBUG(iKey, User::Invariant());	
   529 	__ASSERT_DEBUG(iKey, User::Invariant());	
   558 	}
   530 	}
   559 
   531 
   560 /** Second-phase constructor of reference counting objects for bitmaps
   532 /** Second-phase constructor of reference counting objects for bitmaps