439 input.iFlags = 0; |
439 input.iFlags = 0; |
440 input.iSessionHandle = 0; |
440 input.iSessionHandle = 0; |
441 input.iReserved1 = 0; |
441 input.iReserved1 = 0; |
442 TInt addedBytes = 0; |
442 TInt addedBytes = 0; |
443 TShapeHeader* chached_header3 = 0; |
443 TShapeHeader* chached_header3 = 0; |
444 |
444 openFont->FreeShaperCacheMemory(KMaxShaperSesssionCacheMemory); |
|
445 openFont->File()->GetFontStore()->SetShaperCacheMemUsage(0); |
|
446 RArray<TInt> cacheMemUsage; |
445 /* Keep inserting pseudo-new shaped entries into the cache to fill it up */ |
447 /* Keep inserting pseudo-new shaped entries into the cache to fill it up */ |
446 while(openFont->File()->GetFontStore()->GetShaperCacheMemUsage() < KMaxShaperSesssionCacheMemory) |
448 while(openFont->File()->GetFontStore()->GetShaperCacheMemUsage() < KMaxShaperSesssionCacheMemory) |
447 { |
449 { |
448 memoryUsed = openFont->File()->GetFontStore()->GetShaperCacheMemUsage(); |
450 memoryUsed = openFont->File()->GetFontStore()->GetShaperCacheMemUsage(); |
449 // Change the cached entries slightly to distinguish between each entry |
451 // Change the cached entries slightly to distinguish between each entry |
451 input.iEnd++; |
453 input.iEnd++; |
452 chached_header3 = glyphCache->Insert(0,iHeap, input, shape, addedBytes); |
454 chached_header3 = glyphCache->Insert(0,iHeap, input, shape, addedBytes); |
453 if (chached_header3 != NULL) |
455 if (chached_header3 != NULL) |
454 openFont->File()->GetFontStore()->SetShaperCacheMemUsage(memoryUsed + addedBytes); |
456 openFont->File()->GetFontStore()->SetShaperCacheMemUsage(memoryUsed + addedBytes); |
455 ((CBitmapFont*)font)->DeleteShape(0, chached_header3); |
457 ((CBitmapFont*)font)->DeleteShape(0, chached_header3); |
|
458 cacheMemUsage.AppendL(openFont->File()->GetFontStore()->GetShaperCacheMemUsage() - memoryUsed); |
456 chached_header3 = NULL; |
459 chached_header3 = NULL; |
457 } |
460 } |
458 |
461 |
459 /* Now try to add a new entry, and check that the entry replaced was the last entry in the cache */ |
462 /* Now try to add a new entry, and check that the entry replaced was the last entry in the cache */ |
460 TInt last_entry_glyph_count = glyphCache->iShaperCacheSentinel->iPrevious->iShapeHeader->iGlyphCount; |
463 TInt last_entry_glyph_count = glyphCache->iShaperCacheSentinel->iPrevious->iShapeHeader->iGlyphCount; |
461 shape->iGlyphCount++; |
464 shape->iGlyphCount++; |
462 params->iEnd = input.iEnd + 1; |
465 input.iEnd++; |
|
466 params->iEnd = input.iEnd; |
463 |
467 |
464 /* Calculate the memory needed for the new entry */ |
468 /* Calculate the memory needed for the new entry */ |
465 TInt bufferSize = (sizeof(TUint32) + sizeof(TInt16) + sizeof(TInt16) * 2) |
469 |
466 * shape->iGlyphCount + sizeof(TInt16) * 2; |
470 |
467 TInt bytes_needed = bufferSize + sizeof(COpenFontShaperCacheEntry) + |
471 TInt heapSizeBefAloc = 0; |
468 sizeof(TShapeHeader) + sizeof(TUint16)*params->iText->Length(); |
472 iHeap->AllocSize(heapSizeBefAloc); |
469 |
473 COpenFontShaperCacheEntry *tempEntry = COpenFontShaperCacheEntry::New(iHeap, input, shape); |
470 TInt bytesToDelete = 0; |
474 TInt heapSizeAftAloc = 0; |
|
475 iHeap->AllocSize(heapSizeAftAloc); |
|
476 TInt bytes_needed = heapSizeAftAloc - heapSizeBefAloc; |
|
477 COpenFontShaperCacheEntry::Delete(iHeap, tempEntry); |
|
478 |
|
479 TInt bytesToDelete = 0; |
|
480 |
471 COpenFontShaperCacheEntry* previous = glyphCache->iShaperCacheSentinel->iPrevious; |
481 COpenFontShaperCacheEntry* previous = glyphCache->iShaperCacheSentinel->iPrevious; |
472 /* Calculate the memory that will be freed to accommodate the new entry, |
482 /* Calculate the memory that will be freed to accommodate the new entry, |
473 and the position of the last entry in the cache once deletion is done */ |
483 and the position of the last entry in the cache once deletion is done */ |
|
484 TInt index = 0; |
474 while (bytesToDelete <= bytes_needed) |
485 while (bytesToDelete <= bytes_needed) |
475 { |
486 { |
476 bytesToDelete += (((sizeof(TUint32) + sizeof(TInt16) + sizeof(TInt16) * 2) * previous->iShapeHeader->iGlyphCount + sizeof(TInt16) * 2) + |
487 |
477 (sizeof(COpenFontShaperCacheEntry) + sizeof(TShapeHeader) + sizeof(TUint16)*params->iText->Length())); |
488 bytesToDelete += cacheMemUsage[index++]; |
478 previous = previous->iPrevious; |
489 previous = previous->iPrevious; |
479 } |
490 } |
480 |
491 cacheMemUsage.Close(); |
481 /* Find the glyphcount of the expected new last entry in the cache */ |
492 /* Find the glyphcount of the expected new last entry in the cache */ |
482 expectedGlyphCount = previous->iShapeHeader->iGlyphCount; |
493 expectedGlyphCount = previous->iShapeHeader->iGlyphCount; |
483 |
494 |
484 /* Finally, do the insertion, and test */ |
495 /* Finally, do the insertion, and test */ |
485 TShapeHeader* cached_header4 = openFont->InsertShapedDataIntoCache(0, params, shape); |
496 TShapeHeader* cached_header4 = openFont->InsertShapedDataIntoCache(0, params, shape); |
497 |
508 |
498 /* Calculate the memory of occupied by the last entry in the cache. This is the memory that will |
509 /* Calculate the memory of occupied by the last entry in the cache. This is the memory that will |
499 be released when the last entry is deleted |
510 be released when the last entry is deleted |
500 */ |
511 */ |
501 last_entry_glyph_count = glyphCache->iShaperCacheSentinel->iPrevious->iShapeHeader->iGlyphCount; |
512 last_entry_glyph_count = glyphCache->iShaperCacheSentinel->iPrevious->iShapeHeader->iGlyphCount; |
502 bufferSize = (sizeof(TUint32) + sizeof(TInt16) + sizeof(TInt16) * 2) |
513 TInt bufferSize = (sizeof(TUint32) + sizeof(TInt16) + sizeof(TInt16) * 2) |
503 * last_entry_glyph_count + sizeof(TInt16) * 2; |
514 * last_entry_glyph_count + sizeof(TInt16) * 2; |
504 |
515 |
505 bytes_needed = bufferSize + sizeof(COpenFontShaperCacheEntry) + |
516 bytes_needed = bufferSize + sizeof(COpenFontShaperCacheEntry) + |
506 sizeof(TShapeHeader) + sizeof(TUint16)*input.iText->Length(); |
517 sizeof(TShapeHeader) + sizeof(TUint16)*input.iText->Length(); |
507 |
518 |