os/graphics/fbs/fontandbitmapserver/tfbs/tfbsoogm.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) 2009-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: Test the operation of the Font and Bitmap Server's GOoM plug-in
sl@0
    14
//
sl@0
    15
sl@0
    16
sl@0
    17
#include <gdi.h>
sl@0
    18
#include "tfbsoogm.h"
sl@0
    19
sl@0
    20
sl@0
    21
sl@0
    22
const TInt KTFbsOogmFrameworkPause = 500000; // How long does this need to be in order to be reliable?
sl@0
    23
const TInt KTFbsOogmImageSizeX = 2048;
sl@0
    24
const TInt KTFbsOogmImageSizeY = 2048;
sl@0
    25
sl@0
    26
sl@0
    27
void CTFbsOogm::RunTestCaseL( TInt aCurTestCase )
sl@0
    28
    {
sl@0
    29
    ( (CTFbsOogmStep*)iStep )->SetTestStepID( KUnknownSYMTestCaseIDName );
sl@0
    30
sl@0
    31
    switch( aCurTestCase )
sl@0
    32
        {
sl@0
    33
    case 1:
sl@0
    34
        ( (CTFbsOogmStep*)iStep )->SetTestStepID( _L("GRAPHICS-FBSERV-0675") );
sl@0
    35
sl@0
    36
        CacheClearanceAndLimitAdjustments();
sl@0
    37
        break;
sl@0
    38
sl@0
    39
    default:
sl@0
    40
        ( (CTFbsOogmStep*)iStep )->SetTestStepID( KNotATestSYMTestCaseIDName );
sl@0
    41
        ( (CTFbsOogmStep*)iStep )->CloseTMSGraphicsStep();
sl@0
    42
        TestComplete();
sl@0
    43
sl@0
    44
        break;
sl@0
    45
        }
sl@0
    46
sl@0
    47
    ( (CTFbsOogmStep*)iStep )->RecordTestResultL();
sl@0
    48
sl@0
    49
    }
sl@0
    50
sl@0
    51
sl@0
    52
sl@0
    53
/**
sl@0
    54
 	@SYMTestCaseID
sl@0
    55
	GRAPHICS-FBSERV-0675
sl@0
    56
sl@0
    57
	@SYMTestCaseDesc
sl@0
    58
	Tests the operation of Font and Bitmap server's  Out-Of-Graphics-Memory plugin.
sl@0
    59
	ie Ensure that the hardware glyph cache is cleared in response to a low graphics 
sl@0
    60
	memory notification, and that the cache's maximum size limit is reduced.
sl@0
    61
sl@0
    62
sl@0
    63
	@SYMTestActions
sl@0
    64
	Acquire the glyph cache's usage and other metrics.
sl@0
    65
	
sl@0
    66
	Populate the glyph-cache.
sl@0
    67
sl@0
    68
	Acquire the glyph-cache's usage and other metrics.
sl@0
    69
sl@0
    70
	Precipitate an Out-of-Graphics-Memory condition, triggering the GOOM monitor.
sl@0
    71
sl@0
    72
	Acquire the glyph cache's usage and other metrics.
sl@0
    73
sl@0
    74
	Ensure the glyph-cache has been cleared and its maximum limit reduced.
sl@0
    75
sl@0
    76
	Precipitate a MemoryGood() call from the GOoM framework.
sl@0
    77
sl@0
    78
	Establish that the cache-size limit has been reinstated.
sl@0
    79
sl@0
    80
	@SYMTestExpectedResults
sl@0
    81
    The glyph-cache should be cleared in response to OoGM condition and its upper limit reduced.
sl@0
    82
sl@0
    83
    The Glyph-cache's upper limit should be reinstated in response to a memory-good notification.
sl@0
    84
 */
sl@0
    85
void CTFbsOogm::CacheClearanceAndLimitAdjustments()
sl@0
    86
    {
sl@0
    87
    __UHEAP_MARK;
sl@0
    88
sl@0
    89
    RArray <RSgImage> sgImageArray;
sl@0
    90
    RSgDriver sgDriver;
sl@0
    91
    TInt err = sgDriver.Open();
sl@0
    92
sl@0
    93
    if( KErrNone != err )
sl@0
    94
        {
sl@0
    95
		TEST( KErrNone == err );
sl@0
    96
		INFO_PRINTF2( _L("SgDriver Open() returned error %d"), err );
sl@0
    97
sl@0
    98
        return;
sl@0
    99
        }
sl@0
   100
sl@0
   101
    if( (NULL == RFbsSession::GetSession()) )
sl@0
   102
         {
sl@0
   103
        if( KErrNone != RFbsSession::Connect() )
sl@0
   104
            {
sl@0
   105
 			TEST( -1 );
sl@0
   106
			INFO_PRINTF1(_L("Failed to connect to FbServ"));
sl@0
   107
sl@0
   108
            goto CleanupAndGo;
sl@0
   109
            }
sl@0
   110
         }
sl@0
   111
sl@0
   112
sl@0
   113
	// Establish the initial condition of the glyph-cache.
sl@0
   114
    TGlyphCacheMetrics initialGlyphCacheMetrics;
sl@0
   115
    err = RFbsSession::GetSession()->GetGlyphCacheMetrics( initialGlyphCacheMetrics );
sl@0
   116
    if( KErrNone != err )
sl@0
   117
        {
sl@0
   118
		TEST( KErrNone == err );
sl@0
   119
		INFO_PRINTF2( _L("GetGlyphCacheMetrics() returned error %d"), err );
sl@0
   120
sl@0
   121
        goto CleanupAndGo;
sl@0
   122
        }
sl@0
   123
sl@0
   124
	// Check that initial conditions are as expected.
sl@0
   125
    // There was a test here for a cache-size of zero, but this was felt to be a hazardous assumption.
sl@0
   126
	TEST( initialGlyphCacheMetrics.iGpuCacheSizeLimitIsMax );
sl@0
   127
    INFO_PRINTF4( _L("Initial iMaxCacheSizeInBytes %d iCacheSizeInBytes %d iGpuCacheSizeLimitIsMax %d "),
sl@0
   128
                      initialGlyphCacheMetrics.iMaxCacheSizeInBytes,
sl@0
   129
                      initialGlyphCacheMetrics.iCacheSizeInBytes,
sl@0
   130
                      initialGlyphCacheMetrics.iGpuCacheSizeLimitIsMax );
sl@0
   131
sl@0
   132
sl@0
   133
    TRAP( err, UseGpuL() ); // Populate the glyph cache then acquire its usage metrics.
sl@0
   134
    if( KErrNone != err )
sl@0
   135
        {
sl@0
   136
        TEST( KErrNone == err );
sl@0
   137
        INFO_PRINTF2( _L("UseGpuL() left with %d"), err );
sl@0
   138
sl@0
   139
        goto CleanupAndGo;
sl@0
   140
        }
sl@0
   141
sl@0
   142
sl@0
   143
    TGlyphCacheMetrics usageGlyphCacheMetrics;
sl@0
   144
    err = RFbsSession::GetSession()->GetGlyphCacheMetrics( usageGlyphCacheMetrics );
sl@0
   145
    if( KErrNone != err )
sl@0
   146
        {
sl@0
   147
		TEST( KErrNone == err );
sl@0
   148
		INFO_PRINTF2( _L("GetGlyphCacheMetrics() returned %d"), err );
sl@0
   149
sl@0
   150
        goto CleanupAndGo;
sl@0
   151
        }
sl@0
   152
sl@0
   153
    // Check that the glyph cache has been populated
sl@0
   154
    TEST( usageGlyphCacheMetrics.iCacheSizeInBytes > initialGlyphCacheMetrics.iCacheSizeInBytes);
sl@0
   155
    TEST( usageGlyphCacheMetrics.iGpuCacheSizeLimitIsMax );
sl@0
   156
    INFO_PRINTF4( _L("Usage iMaxCacheSizeInBytes %d iCacheSizeInBytes %d iGpuCacheSizeLimitIsMax %d "),
sl@0
   157
                       usageGlyphCacheMetrics.iMaxCacheSizeInBytes,
sl@0
   158
                       usageGlyphCacheMetrics.iCacheSizeInBytes,
sl@0
   159
                       usageGlyphCacheMetrics.iGpuCacheSizeLimitIsMax );
sl@0
   160
sl@0
   161
sl@0
   162
sl@0
   163
    // Precipitate the GOoM framework's call into the Plug-in's FreeRam() method.
sl@0
   164
    err = FillGraphicsMemoryWithImages( TSize(KTFbsOogmImageSizeX, KTFbsOogmImageSizeY), sgImageArray );
sl@0
   165
    if( KErrNoGraphicsMemory != err )
sl@0
   166
        {
sl@0
   167
		TEST( KErrNoGraphicsMemory == err );
sl@0
   168
		INFO_PRINTF2( _L("FillGraphicsMemoryWithImages() returned %d"), err );
sl@0
   169
sl@0
   170
        goto CleanupAndGo;
sl@0
   171
        }
sl@0
   172
sl@0
   173
	// Await the GOOM framework's call into FbServ's OoGM plugin,
sl@0
   174
    // then establish the cache's usage and other metrics.
sl@0
   175
    User::After( KTFbsOogmFrameworkPause );
sl@0
   176
    TGlyphCacheMetrics postOogmGlyphCacheMetrics;
sl@0
   177
    err = RFbsSession::GetSession()->GetGlyphCacheMetrics( postOogmGlyphCacheMetrics );
sl@0
   178
sl@0
   179
    if( KErrNone != err )
sl@0
   180
        {
sl@0
   181
		TEST( KErrNone == err );
sl@0
   182
		INFO_PRINTF2( _L("GetGlyphCacheMetrics() returned %d"), err );
sl@0
   183
sl@0
   184
        goto CleanupAndGo;
sl@0
   185
        }
sl@0
   186
sl@0
   187
    // The cache should have been cleared and the maximum size limit reduced.
sl@0
   188
    TEST( 0 == postOogmGlyphCacheMetrics.iCacheSizeInBytes );
sl@0
   189
    TEST( !postOogmGlyphCacheMetrics.iGpuCacheSizeLimitIsMax );
sl@0
   190
    INFO_PRINTF4( _L("Post-Oogm iMaxCacheSizeInBytes %d iCacheSizeInBytes %d iGpuCacheSizeLimitIsMax %d "),
sl@0
   191
                        postOogmGlyphCacheMetrics.iMaxCacheSizeInBytes,
sl@0
   192
                        postOogmGlyphCacheMetrics.iCacheSizeInBytes,
sl@0
   193
                        postOogmGlyphCacheMetrics.iGpuCacheSizeLimitIsMax );
sl@0
   194
sl@0
   195
sl@0
   196
sl@0
   197
   // Remove the images. This should provoke a GOoM monitor call into the plug-in's MemoryGood().
sl@0
   198
    for ( TInt i = sgImageArray.Count()-1; i >= 0; --i )
sl@0
   199
        {
sl@0
   200
        sgImageArray[i].Close();
sl@0
   201
        }
sl@0
   202
    sgImageArray.Reset();
sl@0
   203
sl@0
   204
    // Await activity from the GOoM monitor
sl@0
   205
    User::After( KTFbsOogmFrameworkPause );
sl@0
   206
    TGlyphCacheMetrics reinstatedGlyphCacheMetrics;
sl@0
   207
    err = RFbsSession::GetSession()->GetGlyphCacheMetrics( reinstatedGlyphCacheMetrics );
sl@0
   208
    if( KErrNone != err )
sl@0
   209
        {
sl@0
   210
        TEST( KErrNone == err );
sl@0
   211
        INFO_PRINTF2( _L("GetGlyphCacheMetrics() returned error %d"), err );
sl@0
   212
sl@0
   213
        goto CleanupAndGo;
sl@0
   214
        }
sl@0
   215
sl@0
   216
    // Cache size limit should have been increased
sl@0
   217
    TEST( reinstatedGlyphCacheMetrics.iGpuCacheSizeLimitIsMax );
sl@0
   218
    INFO_PRINTF4( _L("After Mem Clear iMaxCacheSizeInBytes %d iCacheSizeInBytes %d iGpuCacheSizeLimitIsMax %d "),
sl@0
   219
                      reinstatedGlyphCacheMetrics.iMaxCacheSizeInBytes,
sl@0
   220
                      reinstatedGlyphCacheMetrics.iCacheSizeInBytes,
sl@0
   221
                      reinstatedGlyphCacheMetrics.iGpuCacheSizeLimitIsMax );
sl@0
   222
sl@0
   223
sl@0
   224
sl@0
   225
  CleanupAndGo:
sl@0
   226
    // Release any images before closing the array.
sl@0
   227
    // If the test was successful this should already be empty.
sl@0
   228
    for (TInt i = sgImageArray.Count()-1; i >= 0; --i)
sl@0
   229
        {
sl@0
   230
        sgImageArray[i].Close();
sl@0
   231
        }
sl@0
   232
sl@0
   233
    // Allow GOoM to make any pending adjustments before proceeding with any further tests.
sl@0
   234
    User::After( KTFbsOogmFrameworkPause );
sl@0
   235
    sgImageArray.Close();
sl@0
   236
    sgDriver.Close();
sl@0
   237
sl@0
   238
    __UHEAP_MARKEND;
sl@0
   239
    }
sl@0
   240
sl@0
   241
sl@0
   242
sl@0
   243
CTFbsOogm::CTFbsOogm( CTestStep* aStep )
sl@0
   244
: CTGraphicsBase(aStep)
sl@0
   245
    {
sl@0
   246
    }
sl@0
   247
sl@0
   248
sl@0
   249
sl@0
   250
const TInt KNumGlyphCodesLatin = 96;
sl@0
   251
/*
sl@0
   252
 Lookup table to convert from ascii code to
sl@0
   253
glyph code for the Deja Vu family of fonts.
sl@0
   254
 */
sl@0
   255
const TUint DejaVuASCIIToGlyphCode[] =
sl@0
   256
    {
sl@0
   257
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
sl@0
   258
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
sl@0
   259
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
sl@0
   260
    0, 0, 3, 4, 5, 6, 7, 8, 9, 10,
sl@0
   261
    11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
sl@0
   262
    21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
sl@0
   263
    31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
sl@0
   264
    41, 42, 43, 44, 45, 46, 47, 48, 49, 50,
sl@0
   265
    51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
sl@0
   266
    61, 62, 63, 64, 65, 66, 67, 68, 69, 70,
sl@0
   267
    71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
sl@0
   268
    81, 82, 83, 84, 85, 86, 87, 88, 89, 90,
sl@0
   269
    91, 92, 93, 94, 95, 96, 97, 98,
sl@0
   270
    };
sl@0
   271
sl@0
   272
sl@0
   273
sl@0
   274
void CTFbsOogm::ConstructL()
sl@0
   275
    {
sl@0
   276
    }
sl@0
   277
sl@0
   278
sl@0
   279
CTFbsOogm::~CTFbsOogm()
sl@0
   280
    {
sl@0
   281
    RFbsSession::Disconnect();
sl@0
   282
    }
sl@0
   283
sl@0
   284
sl@0
   285
sl@0
   286
/**
sl@0
   287
 Utility function to fill the GPU memory.
sl@0
   288
 */
sl@0
   289
TInt CTFbsOogm::FillGraphicsMemoryWithImages( const TSize& aSize, RArray<RSgImage>& aImages )
sl@0
   290
    {
sl@0
   291
    TInt err = KErrNone;
sl@0
   292
sl@0
   293
    // Loop should terminate with KErrNoGraphicsMemory
sl@0
   294
    while( KErrNone == err )
sl@0
   295
        {
sl@0
   296
        RSgImage sgImage;
sl@0
   297
        err = sgImage.Create( TSgImageInfo(aSize, ESgPixelFormatA_8, ESgUsageBitOpenVgImage) );
sl@0
   298
        if( KErrNone == err )
sl@0
   299
            {
sl@0
   300
            err = aImages.Append( sgImage );
sl@0
   301
            }
sl@0
   302
        }
sl@0
   303
sl@0
   304
    INFO_PRINTF2( _L("Images created %d"), aImages.Count() );
sl@0
   305
    return err;
sl@0
   306
    }
sl@0
   307
sl@0
   308
sl@0
   309
sl@0
   310
/**
sl@0
   311
 Utility function to populate the GPU with typeface glyphs.
sl@0
   312
 */
sl@0
   313
void CTFbsOogm::UseGpuL()
sl@0
   314
    {
sl@0
   315
    _LIT( KTKASTypefaceName, "DejaVu Sans Condensed" );
sl@0
   316
sl@0
   317
    // Need to open one of these "in the context" of this process in order
sl@0
   318
    // to manipulate RSgImages. Even though we are only calling 'Open', 'Next' and 'Close' on
sl@0
   319
    // RFbsGlyphDataIterator
sl@0
   320
    RSgDriver sgDriver;
sl@0
   321
    User::LeaveIfError( sgDriver.Open() );
sl@0
   322
sl@0
   323
    // CFbsTypefaceStore seems to need an fbserv session open.
sl@0
   324
    if( (NULL == RFbsSession::GetSession()) )
sl@0
   325
     {
sl@0
   326
     User::LeaveIfError( RFbsSession::Connect() );
sl@0
   327
     }
sl@0
   328
sl@0
   329
    TUint* glyphCodesLatin = new(ELeave) TUint[ KNumGlyphCodesLatin ];
sl@0
   330
sl@0
   331
    for ( TInt ii = 0; ii < KNumGlyphCodesLatin; ++ii )
sl@0
   332
        {
sl@0
   333
        TUint asciiCode = ii+0x20; // ASCII characters from 0020 to 007F
sl@0
   334
        glyphCodesLatin[ii] = DejaVuASCIIToGlyphCode[asciiCode];
sl@0
   335
        }
sl@0
   336
sl@0
   337
    iTs = ( CFbsTypefaceStore* )CFbsTypefaceStore::NewL( NULL );
sl@0
   338
    User::LeaveIfError( iTs->GetNearestFontToDesignHeightInPixels((CFont*&)iFont, TFontSpec(KTKASTypefaceName, 15)) );
sl@0
   339
sl@0
   340
    TInt iterErr = KErrNone;
sl@0
   341
    TInt iterNextErr = KErrNone;
sl@0
   342
sl@0
   343
    for( TInt arraySize = 1; (arraySize < KNumGlyphCodesLatin) && (iterErr == KErrNone); ++arraySize )
sl@0
   344
        {
sl@0
   345
        RFbsGlyphDataIterator iter;
sl@0
   346
        iterErr = iter.Open( *iFont, glyphCodesLatin, arraySize );
sl@0
   347
sl@0
   348
        if( KErrNone != iterErr )
sl@0
   349
            {
sl@0
   350
            continue;
sl@0
   351
            }
sl@0
   352
sl@0
   353
          for ( TInt index = 0; KErrNone == iterNextErr; iterNextErr = iter.Next(), ++index )
sl@0
   354
              {
sl@0
   355
              // Iterating through the glyphs should introduce them into the cache
sl@0
   356
             if(iter.GlyphCode() != glyphCodesLatin[index])
sl@0
   357
                {
sl@0
   358
                 INFO_PRINTF4( _L("Wanted glyphcode %d, got %d"), arraySize, glyphCodesLatin[index], iter.GlyphCode() );
sl@0
   359
                }
sl@0
   360
              }
sl@0
   361
sl@0
   362
        iterNextErr = KErrNone;
sl@0
   363
        iter.Close();
sl@0
   364
        }
sl@0
   365
sl@0
   366
    sgDriver.Close();
sl@0
   367
    }
sl@0
   368
sl@0
   369
sl@0
   370
__CONSTRUCT_STEP__( FbsOogm )