os/graphics/fbs/fontandbitmapserver/sfbs/SERVER.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) 1995-2010 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
#include <fntstore.h>
sl@0
    17
#include <bitmap.h>
sl@0
    18
#include "FBSVER.H"
sl@0
    19
#include "SERVER.H"
sl@0
    20
#include "BackGroundCompression.h"
sl@0
    21
#include "linkedfonts.h"
sl@0
    22
#include "BitwiseBitmap.inl"
sl@0
    23
sl@0
    24
const TInt KFbsPriority = 0;
sl@0
    25
const TInt KFbsGoomMonitorSid = 0x10207218;
sl@0
    26
// Setup security policies
sl@0
    27
const TInt KRanges[] = 
sl@0
    28
	{
sl@0
    29
	0,
sl@0
    30
	EFbsMessShutdown,
sl@0
    31
	EFbsMessClose,
sl@0
    32
	EFbsSetSystemDefaultTypefaceName,
sl@0
    33
	EFbsGetAllBitmapHandles,
sl@0
    34
	EFbsMessUnused1,
sl@0
    35
	EFbsMessUnused2,
sl@0
    36
	EFbsMessRegisterLinkedTypeface,
sl@0
    37
	EFbsMessFetchLinkedTypeface,
sl@0
    38
	EFbsMessUpdateLinkedTypeface,
sl@0
    39
	EFbsMessGetFontTable,
sl@0
    40
    EFbsMessOogmNotification,
sl@0
    41
    EFbsMessGetGlyphCacheMetrics,
sl@0
    42
	};
sl@0
    43
sl@0
    44
const TUint KRangeCount = sizeof(KRanges)/sizeof(TInt);
sl@0
    45
const TUint8 KElementsIndex[KRangeCount] = 
sl@0
    46
	{
sl@0
    47
	0,
sl@0
    48
	3, // For EFbsMessShutdown
sl@0
    49
	0,
sl@0
    50
	1, // For EFbsSetSystemDefaultTypefaceName
sl@0
    51
	2, // For EFbsGetAllBitmapHandles
sl@0
    52
	0, // ECapability_None for EFbsMessUnused1
sl@0
    53
	0, // ECapability_None for EFbsMessUnused2 and beyond
sl@0
    54
	1, // ECapabilityWriteDeviceData for EFbsMessRegisterLinkedTypeface
sl@0
    55
	2, // ECapabilityReadDeviceData for EFbsMessFetchLinkedTypeface
sl@0
    56
	1, // ECapabilityWriteDeviceData for EFbsMessUpdateLinkedTypeface
sl@0
    57
	0, // ECapability_None for EFbsMessGetFontTable and beyond
sl@0
    58
    4, // SID for EFbsMessOogmNotification.
sl@0
    59
    0, // For EFbsMessGetGlyphCacheMetrics and on.
sl@0
    60
	};
sl@0
    61
sl@0
    62
const CPolicyServer::TPolicyElement KElements[] = 
sl@0
    63
	{
sl@0
    64
	{_INIT_SECURITY_POLICY_C1(ECapability_None), CPolicyServer::EFailClient},
sl@0
    65
	{_INIT_SECURITY_POLICY_C1(ECapabilityWriteDeviceData), CPolicyServer::EFailClient},
sl@0
    66
	{_INIT_SECURITY_POLICY_C1(ECapabilityReadDeviceData), CPolicyServer::EFailClient},
sl@0
    67
	{_INIT_SECURITY_POLICY_C1(ECapabilityPowerMgmt), CPolicyServer::EFailClient},
sl@0
    68
	{_INIT_SECURITY_POLICY_S0(KFbsGoomMonitorSid), CPolicyServer::EFailClient}
sl@0
    69
 	};
sl@0
    70
sl@0
    71
const CPolicyServer::TPolicy KFbsPolicy =
sl@0
    72
	{
sl@0
    73
	CPolicyServer::EAlwaysPass, //specifies all connect attempts should pass
sl@0
    74
	KRangeCount,
sl@0
    75
	KRanges,
sl@0
    76
	KElementsIndex,
sl@0
    77
	KElements,
sl@0
    78
	};
sl@0
    79
sl@0
    80
CFontBitmapServer::CFontBitmapServer():
sl@0
    81
	CPolicyServer(KFbsPriority, KFbsPolicy)
sl@0
    82
	{
sl@0
    83
	}
sl@0
    84
sl@0
    85
CFontBitmapServer::~CFontBitmapServer()
sl@0
    86
	{
sl@0
    87
	delete iTopLevelStore;
sl@0
    88
	iTopLevelStore = NULL;	// so that CFBClient::~CFbClient can avoid using this pointer;
sl@0
    89
							// it may be called inside CFontBitmapServer::~CFontBitmapServer
sl@0
    90
	}
sl@0
    91
sl@0
    92
CFontBitmapServer* CFontBitmapServer::NewL()
sl@0
    93
	{
sl@0
    94
	CFontBitmapServer* self = new(ELeave) CFontBitmapServer;
sl@0
    95
	CleanupStack::PushL(self);
sl@0
    96
	self->ConstructL();
sl@0
    97
	CleanupStack::Pop(); //self
sl@0
    98
	return self;
sl@0
    99
	}
sl@0
   100
sl@0
   101
/**
sl@0
   102
Two-phase constructor.
sl@0
   103
*/
sl@0
   104
void CFontBitmapServer::ConstructL()
sl@0
   105
	{
sl@0
   106
	iTopLevelStore=CFbTop::NewL();
sl@0
   107
	
sl@0
   108
	// If fbserv data paging is configured as unpaged, automatically pin client descriptors 
sl@0
   109
	if(!RProcess().DefaultDataPaged())
sl@0
   110
		{
sl@0
   111
		SetPinClientDescriptors(ETrue);
sl@0
   112
		}
sl@0
   113
	StartL(KFBSERVGlobalThreadName);
sl@0
   114
	}
sl@0
   115
sl@0
   116
CFbTop* CFontBitmapServer::TopLevelStore()
sl@0
   117
	{
sl@0
   118
	return(iTopLevelStore);
sl@0
   119
	}
sl@0
   120
sl@0
   121
CSession2* CFontBitmapServer::NewSessionL(const TVersion& aVersion,const RMessage2& /*aMessage*/ ) const
sl@0
   122
	{
sl@0
   123
	TVersion v(KFbsMajorVersionNumber,KFbsMinorVersionNumber,KFbsBuildVersionNumber);
sl@0
   124
	if(!User::QueryVersionSupported(v,aVersion))
sl@0
   125
		User::Leave(KErrNotSupported);
sl@0
   126
sl@0
   127
	CSession2* pSession2 = CFbClient::NewL(iTopLevelStore->Heap());
sl@0
   128
	return pSession2;
sl@0
   129
	}
sl@0
   130
sl@0
   131
TInt CFontBitmapServer::Init()
sl@0
   132
	{
sl@0
   133
	return(iConnectionId++);
sl@0
   134
	}
sl@0
   135
sl@0
   136
sl@0
   137
TInt CFontBitmapServer::HandleMesgTypefaceSupport(const RMessage2& aMessage, TBool& aClientPanicRequired)
sl@0
   138
	{
sl@0
   139
	TTypefaceSupport tfi;
sl@0
   140
	TPckgBuf<TTypefaceSupport> ttipckg(tfi);
sl@0
   141
	TPckgBuf<TSize> pixelSize;
sl@0
   142
	TInt index=aMessage.Int0();
sl@0
   143
	TInt limit=iTopLevelStore->FontStore()->NumTypefaces();
sl@0
   144
	if(index < 0 || index > limit)
sl@0
   145
		{
sl@0
   146
		return KErrArgument;
sl@0
   147
		}
sl@0
   148
	TInt ret = aMessage.Read(2, pixelSize);
sl@0
   149
	if (ret != KErrNone)
sl@0
   150
		{
sl@0
   151
		return ret;
sl@0
   152
		}
sl@0
   153
	iTopLevelStore->FontStore()->iKPixelHeightInTwips = pixelSize().iHeight;
sl@0
   154
	iTopLevelStore->FontStore()->iKPixelWidthInTwips = pixelSize().iWidth;
sl@0
   155
	iTopLevelStore->FontStore()->TypefaceSupport(ttipckg(),index);
sl@0
   156
	ret = aMessage.Write(1,ttipckg);
sl@0
   157
	if(ret!=KErrNone)
sl@0
   158
		{
sl@0
   159
		aClientPanicRequired = ETrue;
sl@0
   160
		}
sl@0
   161
	return ret;
sl@0
   162
	}
sl@0
   163
sl@0
   164
sl@0
   165
TInt CFontBitmapServer::HandleMesgFontHeight(const RMessage2& aMessage, TBool aInTwips)
sl@0
   166
	{
sl@0
   167
	TInt typefaceindex = aMessage.Int0();
sl@0
   168
	TInt fontsize = aMessage.Int1();
sl@0
   169
sl@0
   170
	if(typefaceindex < 0)
sl@0
   171
		{
sl@0
   172
		aMessage.Panic(KFBSERVPanicCategory,KErrArgument);
sl@0
   173
		return KErrArgument;
sl@0
   174
		}
sl@0
   175
	
sl@0
   176
	// pixel size (used to be set in a separate call)
sl@0
   177
	TPckgBuf<TSize> size;
sl@0
   178
	TInt ret = aMessage.Read(2, size);
sl@0
   179
	if (ret != KErrNone)
sl@0
   180
		{
sl@0
   181
		return ret;
sl@0
   182
		}
sl@0
   183
		
sl@0
   184
	if(size().iHeight <=  0 || size().iWidth < 0)
sl@0
   185
		{
sl@0
   186
		aMessage.Panic(KFBSERVPanicCategory,KErrArgument);
sl@0
   187
		return KErrArgument;
sl@0
   188
		}
sl@0
   189
			
sl@0
   190
	iTopLevelStore->FontStore()->iKPixelHeightInTwips = size().iHeight;
sl@0
   191
	iTopLevelStore->FontStore()->iKPixelWidthInTwips = size().iWidth;
sl@0
   192
	if (aInTwips)
sl@0
   193
		{
sl@0
   194
		return iTopLevelStore->FontStore()->FontHeightInTwips(typefaceindex,fontsize);
sl@0
   195
		}
sl@0
   196
	else
sl@0
   197
		{
sl@0
   198
		return iTopLevelStore->FontStore()->FontHeightInPixels(typefaceindex,fontsize);
sl@0
   199
		}
sl@0
   200
	}
sl@0
   201
sl@0
   202
sl@0
   203
#ifdef _DEBUG
sl@0
   204
//aRet is used in debug builds to allow the server to know if the call was successful.
sl@0
   205
//On success there should be no panics from out of memory testing, since memory
sl@0
   206
//may have been genuinely allocated.
sl@0
   207
void CFontBitmapServer::ProcMessage(const RMessage2& aMessage, TInt aSession, TInt& aRet)
sl@0
   208
#else
sl@0
   209
void CFontBitmapServer::ProcMessage(const RMessage2& aMessage, TInt aSession)
sl@0
   210
#endif
sl@0
   211
	{
sl@0
   212
    TInt ret=KErrNone;
sl@0
   213
	TBool clientPanicRequired = EFalse;
sl@0
   214
#ifdef _DEBUG
sl@0
   215
	TInt num=0;
sl@0
   216
#endif
sl@0
   217
	switch (aMessage.Function())
sl@0
   218
		{
sl@0
   219
	case EFbsMessShutdown:
sl@0
   220
		CActiveScheduler::Stop();
sl@0
   221
		break;
sl@0
   222
	case EFbsMessNumTypefaces:
sl@0
   223
		ret=iTopLevelStore->FontStore()->NumTypefaces();
sl@0
   224
		break;
sl@0
   225
	case EFbsMessTypefaceSupport:
sl@0
   226
		ret = HandleMesgTypefaceSupport(aMessage, clientPanicRequired);
sl@0
   227
		break;
sl@0
   228
sl@0
   229
	case EFbsMessFontHeightInTwips:
sl@0
   230
		ret = HandleMesgFontHeight(aMessage, ETrue);
sl@0
   231
		break;
sl@0
   232
sl@0
   233
	case EFbsMessFontHeightInPixels:
sl@0
   234
		ret = HandleMesgFontHeight(aMessage, EFalse);
sl@0
   235
		break;
sl@0
   236
sl@0
   237
	case EFbsMessSetPixelHeight:
sl@0
   238
		iTopLevelStore->FontStore()->iKPixelWidthInTwips=aMessage.Int0();
sl@0
   239
		iTopLevelStore->FontStore()->iKPixelHeightInTwips=aMessage.Int1();
sl@0
   240
		break;
sl@0
   241
#ifdef _DEBUG
sl@0
   242
	case EFbsMessDefaultAllocFail:
sl@0
   243
		num=aMessage.Int0();
sl@0
   244
		if(num) __UHEAP_FAILNEXT(num);
sl@0
   245
		else __UHEAP_RESET;
sl@0
   246
		break;
sl@0
   247
	case EFbsMessDefaultMark:
sl@0
   248
		__UHEAP_MARK;
sl@0
   249
		break;
sl@0
   250
	case EFbsMessDefaultMarkEnd:
sl@0
   251
		num=aMessage.Int0();
sl@0
   252
		if(num) __UHEAP_MARKENDC(num);
sl@0
   253
		else __UHEAP_MARKEND;
sl@0
   254
		break;
sl@0
   255
	case EFbsMessUserAllocFail:
sl@0
   256
		num=aMessage.Int0();
sl@0
   257
		if(num) __RHEAP_FAILNEXT(iTopLevelStore->Heap(),num);
sl@0
   258
		else __RHEAP_RESET(iTopLevelStore->Heap());
sl@0
   259
		break;
sl@0
   260
	case EFbsMessUserMark:
sl@0
   261
		__RHEAP_MARK(iTopLevelStore->Heap());
sl@0
   262
		break;
sl@0
   263
	case EFbsMessUserMarkEnd:
sl@0
   264
		num=aMessage.Int0();
sl@0
   265
		if(num) __RHEAP_MARKENDC(iTopLevelStore->Heap(),num);
sl@0
   266
		else __RHEAP_MARKEND(iTopLevelStore->Heap());
sl@0
   267
		break;
sl@0
   268
#endif
sl@0
   269
	case EFbsMessHeapCheck:
sl@0
   270
		iTopLevelStore->Heap()->Check();
sl@0
   271
		User::Heap().Check();
sl@0
   272
		break;
sl@0
   273
	case EFbsMessSetDefaultGlyphBitmapType:
sl@0
   274
		iTopLevelStore->FontStore()->SetDefaultBitmapType((TGlyphBitmapType)aMessage.Int0());
sl@0
   275
		break;
sl@0
   276
	case EFbsMessGetDefaultGlyphBitmapType:
sl@0
   277
		ret = iTopLevelStore->FontStore()->DefaultBitmapType();
sl@0
   278
		break;
sl@0
   279
	case EFbsMessFontNameAlias:
sl@0
   280
		TRAP(ret, iTopLevelStore->SetFontNameAliasL(aMessage));
sl@0
   281
		break;
sl@0
   282
	case EFbsMessGetHeapSizes:
sl@0
   283
		TRAP(ret, GetHeapSizesL(aMessage));
sl@0
   284
		break;
sl@0
   285
	case EFbsMessDefaultLanguageForMetrics:
sl@0
   286
		iTopLevelStore->SetDefaultLanguageForMetrics(aMessage);
sl@0
   287
		break;
sl@0
   288
	case EFbsCompress:
sl@0
   289
		iTopLevelStore->BackgroundCompression()->CompressAll();
sl@0
   290
		break;
sl@0
   291
	case EFbsMessRegisterLinkedTypeface:
sl@0
   292
		{
sl@0
   293
		TPckgBuf<TLinkedTypefaceSpecificationArgs> buf;
sl@0
   294
		ret=aMessage.Read(0,buf);
sl@0
   295
		if (ret==KErrNone)
sl@0
   296
			{
sl@0
   297
			//Id used by original font linking; now unused.
sl@0
   298
			TInt id;
sl@0
   299
			ret=iTopLevelStore->FontStore()->CreateLinkedTypeface(buf(),aSession,id);
sl@0
   300
			}
sl@0
   301
		}
sl@0
   302
		break;
sl@0
   303
	case EFbsMessFetchLinkedTypeface:
sl@0
   304
			{
sl@0
   305
			TBuf<KMaxTypefaceNameLength> name;
sl@0
   306
			ret = aMessage.GetDesLength(0);
sl@0
   307
				
sl@0
   308
			if (ret < 0) 
sl@0
   309
				break;
sl@0
   310
				
sl@0
   311
			if (ret > KMaxTypefaceNameLength)
sl@0
   312
				{
sl@0
   313
				clientPanicRequired = ETrue;
sl@0
   314
				ret = KErrTooBig;
sl@0
   315
				break;
sl@0
   316
				}
sl@0
   317
				
sl@0
   318
			ret = aMessage.Read(0,name);
sl@0
   319
	
sl@0
   320
			TLinkedTypefaceSpecificationArgs spec;
sl@0
   321
				
sl@0
   322
			spec.iName = name;
sl@0
   323
				
sl@0
   324
			if (ret==KErrNone)
sl@0
   325
				{
sl@0
   326
				TRAP(ret, iTopLevelStore->FontStore()->GetLinkedTypefaceL(spec));
sl@0
   327
	
sl@0
   328
				if (ret == KErrNone)
sl@0
   329
					{
sl@0
   330
					TPckgBuf<TLinkedTypefaceSpecificationArgs> specArgs = spec;					
sl@0
   331
					ret = aMessage.Write(2,specArgs);
sl@0
   332
					}
sl@0
   333
				}
sl@0
   334
			}
sl@0
   335
		break;
sl@0
   336
		case EFbsMessUpdateLinkedTypeface:
sl@0
   337
			{
sl@0
   338
			TPckgBuf<TLinkedTypefaceSpecificationArgs> buf;
sl@0
   339
			ret=aMessage.Read(0,buf);
sl@0
   340
			if (ret==KErrNone)
sl@0
   341
				{
sl@0
   342
				TRAP(ret, iTopLevelStore->FontStore()->UpdateLinkedTypefaceL(buf()));
sl@0
   343
				}
sl@0
   344
			}
sl@0
   345
		break;
sl@0
   346
	}
sl@0
   347
sl@0
   348
	if (clientPanicRequired)
sl@0
   349
		{
sl@0
   350
		aMessage.Panic(KFBSERVPanicCategory,ret);
sl@0
   351
		}
sl@0
   352
	else
sl@0
   353
		{
sl@0
   354
		if(!aMessage.IsNull())
sl@0
   355
			{
sl@0
   356
			aMessage.Complete(ret);
sl@0
   357
			}		
sl@0
   358
		}
sl@0
   359
sl@0
   360
#ifdef _DEBUG
sl@0
   361
	aRet=ret;
sl@0
   362
#endif	
sl@0
   363
sl@0
   364
	}
sl@0
   365
sl@0
   366
/**
sl@0
   367
Returns the current sizes of the FBServ default heap, the heap for large bitmaps, 
sl@0
   368
and the heap for small bitmaps.
sl@0
   369
sl@0
   370
Not supported in release builds.
sl@0
   371
sl@0
   372
@internalComponent
sl@0
   373
@test
sl@0
   374
@param aMessage Encapsulates references to integers supplied by the caller, which will on return contain the sizes of the default heap, heap for small bitmaps, and heap for large bitmaps.
sl@0
   375
@leave KErrNotSupported when used in release mode.
sl@0
   376
*/
sl@0
   377
#ifdef _DEBUG
sl@0
   378
void CFontBitmapServer::GetHeapSizesL(const RMessage2& aMessage)
sl@0
   379
	{
sl@0
   380
	TPckgBuf<THeapSizes> data;
sl@0
   381
	TInt defaultHeapSize = 0;
sl@0
   382
	TInt smallBmpHeapSize = 0;		
sl@0
   383
	TInt bigBmpHeapSize = 0;		
sl@0
   384
	
sl@0
   385
	User::Heap().AllocSize(defaultHeapSize);
sl@0
   386
	bigBmpHeapSize = iTopLevelStore->iLargeBitmapChunk.Size();
sl@0
   387
	iTopLevelStore->Heap()->AllocSize(smallBmpHeapSize);
sl@0
   388
	
sl@0
   389
	data().iDefault = defaultHeapSize;
sl@0
   390
	data().iBig = bigBmpHeapSize;
sl@0
   391
	data().iSmall = smallBmpHeapSize;
sl@0
   392
	
sl@0
   393
	aMessage.WriteL(0, data);
sl@0
   394
	}
sl@0
   395
#else
sl@0
   396
void CFontBitmapServer::GetHeapSizesL(const RMessage2&)
sl@0
   397
	{
sl@0
   398
	User::Leave(KErrNotSupported);	
sl@0
   399
	}	
sl@0
   400
#endif
sl@0
   401
sl@0
   402
sl@0
   403
CFontObject::CFontObject(CFontStore* aFontStore, CGlyphAtlas* aGlyphAtlas):
sl@0
   404
	CObject(),
sl@0
   405
	iFontStore(aFontStore),
sl@0
   406
	iGlyphAtlas(aGlyphAtlas)
sl@0
   407
	{
sl@0
   408
	}
sl@0
   409
sl@0
   410
CFontObject::~CFontObject()
sl@0
   411
	{
sl@0
   412
	if (AccessCount()==1)
sl@0
   413
		{
sl@0
   414
		Dec();
sl@0
   415
		}
sl@0
   416
	iFontStore->ReleaseFont(iAddressPointer);
sl@0
   417
	if (iGlyphAtlas)
sl@0
   418
		{
sl@0
   419
		iGlyphAtlas->FontReleased(*iAddressPointer);
sl@0
   420
		}
sl@0
   421
	}
sl@0
   422
sl@0
   423
// CBitmapObject constructor - takes ownership of aBmp
sl@0
   424
CBitmapObject::CBitmapObject(CFbTop& aFbTop, CBitwiseBitmap* aBmp):
sl@0
   425
	CObject(),
sl@0
   426
	iFbTop(&aFbTop),
sl@0
   427
	iAddressPointer(aBmp)
sl@0
   428
	{
sl@0
   429
	__ASSERT_DEBUG(iAddressPointer, User::Invariant());
sl@0
   430
	}
sl@0
   431
sl@0
   432
/** Second-phase constructor of reference counting objects for bitmaps.
sl@0
   433
Adds the CBitmapObject to the bitmap object container and, if it is not a
sl@0
   434
replacement for a dirty bitmap, assigns a server-wide handle to it and adds
sl@0
   435
it to the server's bitmap index. When a replacement bitmap is attached to
sl@0
   436
the corresponding dirty bitmap with a call to SetCleanBitmap(), then it is
sl@0
   437
assigned the same server-wide handle as the bitmap to be replaced.
sl@0
   438
sl@0
   439
@param aReplacement If ETrue the bitmap is being created as a replacement
sl@0
   440
	for a bitmap being made dirty by a resize or compress operation.
sl@0
   441
@internalComponent
sl@0
   442
*/
sl@0
   443
void CBitmapObject::ConstructL(TBool aReplacement)
sl@0
   444
	{
sl@0
   445
	iFbTop->iBitmapCon->AddL(this);
sl@0
   446
	if (!aReplacement)
sl@0
   447
		{
sl@0
   448
		iHandle = reinterpret_cast<TInt>(this);
sl@0
   449
		while (iFbTop->iBitmapObjectIndex.FindInOrder(this, Compare) != KErrNotFound)
sl@0
   450
			{
sl@0
   451
			++iHandle;
sl@0
   452
			}
sl@0
   453
		User::LeaveIfError(iFbTop->iBitmapObjectIndex.InsertInOrder(this, Compare));
sl@0
   454
		}
sl@0
   455
	}
sl@0
   456
sl@0
   457
void CleanupBitmapObject(TAny* aPtr)
sl@0
   458
	{
sl@0
   459
	CBitmapObject* ptr = static_cast<CBitmapObject*>(aPtr);	
sl@0
   460
	ptr->Close();
sl@0
   461
	}
sl@0
   462
sl@0
   463
/** Create a reference counting object for a new bitmap.
sl@0
   464
sl@0
   465
@param aFbTop Reference to the CFbTop singleton.
sl@0
   466
@param aBmp Bitmap to be attached to the new reference counting object.
sl@0
   467
	The bitmap must have been pushed on the clean-up stack and it will be
sl@0
   468
	popped out of the stack by this function. Ownership will be transferred
sl@0
   469
	to the reference counting object.
sl@0
   470
@param aReplacement If ETrue the bitmap is being created as a replacement
sl@0
   471
	for a bitmap being made dirty by a resize or compress operation.
sl@0
   472
@internalComponent
sl@0
   473
*/
sl@0
   474
CBitmapObject* CBitmapObject::NewL(CFbTop& aFbTop, CBitwiseBitmap* aBmp, TBool aReplacement)
sl@0
   475
	{
sl@0
   476
	CBitmapObject* bmpObj = new(ELeave) CBitmapObject(aFbTop, aBmp);
sl@0
   477
	CleanupStack::Pop(aBmp); // aBmp is owned now by bmpObj
sl@0
   478
	TCleanupItem bitmapObjectCleanupItem(CleanupBitmapObject, bmpObj);
sl@0
   479
	CleanupStack::PushL(bitmapObjectCleanupItem);
sl@0
   480
	bmpObj->ConstructL(aReplacement);
sl@0
   481
	CleanupStack::Pop(bmpObj);
sl@0
   482
	return bmpObj;
sl@0
   483
	}
sl@0
   484
sl@0
   485
CBitmapObject::~CBitmapObject()
sl@0
   486
	{
sl@0
   487
	iFbTop->BackgroundCompression()->RemoveFromCompressionQueue(this);
sl@0
   488
	// the associated clean bitmap object cannot possibly be now in the background compression queue
sl@0
   489
	if (iHandle)
sl@0
   490
		{
sl@0
   491
		if (Owner() == NULL)
sl@0
   492
			{
sl@0
   493
			TInt index = iFbTop->iBitmapObjectIndex.FindInOrder(this, Compare);
sl@0
   494
			if (index != KErrNotFound)
sl@0
   495
				{
sl@0
   496
				if (iCleanBitmap)
sl@0
   497
					{
sl@0
   498
					iFbTop->iBitmapObjectIndex[index] = iCleanBitmap;
sl@0
   499
					}
sl@0
   500
				else
sl@0
   501
					{
sl@0
   502
					iFbTop->iBitmapObjectIndex.Remove(index);
sl@0
   503
					}
sl@0
   504
				}
sl@0
   505
			}
sl@0
   506
		if (iCleanBitmap != NULL)
sl@0
   507
			{
sl@0
   508
			iCleanBitmap->SetOwner(NULL);
sl@0
   509
			iCleanBitmap->Close();
sl@0
   510
			}
sl@0
   511
		}
sl@0
   512
	delete iAddressPointer;
sl@0
   513
	}
sl@0
   514
sl@0
   515
void CBitmapObject::SetCleanBitmap(CBitmapObject* aNewBmpObj)
sl@0
   516
	{
sl@0
   517
	__ASSERT_DEBUG(iHandle, User::Invariant());
sl@0
   518
	__ASSERT_DEBUG(iCleanBitmap == NULL, User::Invariant());
sl@0
   519
	__ASSERT_DEBUG(aNewBmpObj->Owner() == NULL, User::Invariant());
sl@0
   520
	__ASSERT_DEBUG(aNewBmpObj->iHandle == 0, User::Invariant());
sl@0
   521
	__ASSERT_DEBUG(aNewBmpObj->iCleanBitmap == NULL, User::Invariant());
sl@0
   522
	iCleanBitmap = aNewBmpObj;
sl@0
   523
	aNewBmpObj->SetOwner(this);
sl@0
   524
	aNewBmpObj->iHandle = iHandle;
sl@0
   525
	iAddressPointer->iSettings.SetDirtyBitmap();
sl@0
   526
	aNewBmpObj->iAddressPointer->Extra()->iSerialNumber = iAddressPointer->Extra()->iSerialNumber;
sl@0
   527
	aNewBmpObj->iAddressPointer->Extra()->iTouchCount = iAddressPointer->Extra()->iTouchCount + 1;
sl@0
   528
	}
sl@0
   529
sl@0
   530
void CBitmapObject::Close()
sl@0
   531
	{
sl@0
   532
	if ((iCleanBitmap != NULL) && (Owner() != NULL) && (AccessCount() == 2))
sl@0
   533
		{
sl@0
   534
		static_cast<CBitmapObject*>(Owner())->iCleanBitmap = iCleanBitmap;
sl@0
   535
		iCleanBitmap->SetOwner(Owner());
sl@0
   536
		iHandle = 0;
sl@0
   537
		Dec();
sl@0
   538
		}
sl@0
   539
	CObject::Close();
sl@0
   540
	}
sl@0
   541
sl@0
   542
TInt CBitmapObject::Compare(const CBitmapObject& aBmpObj1, const CBitmapObject& aBmpObj2)
sl@0
   543
	{
sl@0
   544
	return aBmpObj1.iHandle - aBmpObj2.iHandle;
sl@0
   545
	}
sl@0
   546
sl@0
   547
TInt CBitmapObject::Compare(const TInt* aHandle, const CBitmapObject& aBmpObj)
sl@0
   548
	{
sl@0
   549
	return *aHandle - aBmpObj.iHandle;
sl@0
   550
	}
sl@0
   551
sl@0
   552
// CSharedBitmapObject constructor - takes ownership of aBmp and aKey
sl@0
   553
CSharedBitmapObject::CSharedBitmapObject(CFbTop& aFbTop, CBitwiseBitmap* aBmp, TDesC* aKey):
sl@0
   554
	CBitmapObject(aFbTop, aBmp),
sl@0
   555
	iKey(aKey)
sl@0
   556
	{
sl@0
   557
	__ASSERT_DEBUG(iKey, User::Invariant());	
sl@0
   558
	}
sl@0
   559
sl@0
   560
/** Second-phase constructor of reference counting objects for bitmaps
sl@0
   561
loaded to share from a file. Adds the CSharedBitmapObject to the bitmap
sl@0
   562
object container, assigns a server-wide handle to it and adds it to the
sl@0
   563
server's bitmap index and to the server's shared bitmap hash map.
sl@0
   564
sl@0
   565
@param aHash Hash value of the key associated with the bitmap.
sl@0
   566
@internalComponent
sl@0
   567
*/
sl@0
   568
void CSharedBitmapObject::ConstructL(TUint aHash)
sl@0
   569
	{
sl@0
   570
	CBitmapObject::ConstructL(EFalse);
sl@0
   571
	iFbTop->iSharedBitmapObjectHashMap.Insert(*this, aHash);
sl@0
   572
	}
sl@0
   573
sl@0
   574
/** Create a reference counting object for a bitmap loaded to share from a file.
sl@0
   575
sl@0
   576
@param aFbTop Reference to the CFbTop singleton.
sl@0
   577
@param aBmp Bitmap to be attached to the new reference counting object.
sl@0
   578
	The bitmap must have been pushed on the clean-up stack and it will be
sl@0
   579
	popped out of the stack by this function. Ownership will be transferred
sl@0
   580
	to the reference counting object.
sl@0
   581
@param aKey Key associated with the bitmap. The key must have been pushed on
sl@0
   582
	the clean-up stack and it will be popped out of the stack by this function.
sl@0
   583
	Ownership will be transferred to the reference counting object.
sl@0
   584
@param aHash Hash value of the key associated with the bitmap.
sl@0
   585
@internalComponent
sl@0
   586
*/
sl@0
   587
CSharedBitmapObject* CSharedBitmapObject::NewL(CFbTop& aFbTop, CBitwiseBitmap* aBmp, TDesC* aKey, TUint aHash)
sl@0
   588
	{
sl@0
   589
	CSharedBitmapObject* bmpObj = new(ELeave) CSharedBitmapObject(aFbTop, aBmp, aKey);
sl@0
   590
	CleanupStack::Pop(2, aKey); // aBmp and aKey are owned now by bmpObj
sl@0
   591
	TCleanupItem bitmapObjectCleanupItem(CleanupBitmapObject, bmpObj);
sl@0
   592
	CleanupStack::PushL(bitmapObjectCleanupItem);
sl@0
   593
	bmpObj->ConstructL(aHash);
sl@0
   594
	CleanupStack::Pop(bmpObj);
sl@0
   595
	return bmpObj;
sl@0
   596
	}
sl@0
   597
sl@0
   598
CSharedBitmapObject::~CSharedBitmapObject()
sl@0
   599
	{
sl@0
   600
	iFbTop->iSharedBitmapObjectHashMap.Remove(*this);
sl@0
   601
	delete iKey;
sl@0
   602
	}
sl@0
   603
sl@0
   604
// Constructs a single key object from constituent parts that uniquely identify a bitmap
sl@0
   605
HBufC* CSharedBitmapObject::KeyLC(const TDesC& aFileName, TInt aId, const TTime& aModTime)
sl@0
   606
	{
sl@0
   607
	static const TInt K16BitSizeOfTInt  = sizeof(TInt) /sizeof(TUint16);
sl@0
   608
	static const TInt K16BitSizeOfTTime = sizeof(TTime)/sizeof(TUint16);
sl@0
   609
	
sl@0
   610
	HBufC* key = HBufC::NewLC(K16BitSizeOfTInt + K16BitSizeOfTTime + aFileName.Length());
sl@0
   611
	
sl@0
   612
	TPtr keyPtr = key->Des();
sl@0
   613
	
sl@0
   614
	keyPtr.Append(reinterpret_cast<const TUint16*>(&aId),      K16BitSizeOfTInt);
sl@0
   615
	keyPtr.Append(reinterpret_cast<const TUint16*>(&aModTime), K16BitSizeOfTTime);
sl@0
   616
	keyPtr.Append(aFileName);
sl@0
   617
sl@0
   618
	return key;
sl@0
   619
	}