os/graphics/graphicscomposition/openwfsupport/test/tstreamoperation/tnativestream.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:
sl@0
    14
// Implementation of Test class for OpenWfc Native Stream 
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include <graphics/symbianstream.h>
sl@0
    19
#include <graphics/streammap.h>
sl@0
    20
#include <graphics/compositionsurfaceupdate.h>
sl@0
    21
#include <graphics/extensioncontainer.h>
sl@0
    22
#include <graphics/suerror.h>
sl@0
    23
#include <test/extendtef.h>
sl@0
    24
#include <dispchannel.h>
sl@0
    25
#include <hal.h>
sl@0
    26
#include <test/singletontestexithelper.inl>
sl@0
    27
#include "tnativestream.h"
sl@0
    28
#include "surfaceutility.h"
sl@0
    29
sl@0
    30
#ifdef EGLSYNCHELPER_INCLUDED
sl@0
    31
    #include <EGL/egl.h>
sl@0
    32
    #include "eglsynchelper.h"
sl@0
    33
#endif
sl@0
    34
sl@0
    35
#define BUFFER_READ_HANDLE_BASE  0x100
sl@0
    36
#define BUFFER_WRITE_HANDLE_BASE 0x200
sl@0
    37
#define INDEX_TO_READ_HANDLE(x)  ((SymbianStreamBuffer) ((x)+BUFFER_READ_HANDLE_BASE))
sl@0
    38
#define INDEX_TO_WRITE_HANDLE(x)  ((SymbianStreamBuffer) ((x)+BUFFER_WRITE_HANDLE_BASE))
sl@0
    39
#define BUFFER_READ_HANDLE_TO_INDEX(x)  (TInt) (x > 0 ? (x&0xFF) : (x-BUFFER_READ_HANDLE_BASE))
sl@0
    40
#define BUFFER_WRITE_HANDLE_TO_INDEX(x)  (TInt) (x > 0 ? (x&0xFF) : (x-BUFFER_WRITE_HANDLE_BASE))
sl@0
    41
#define WFC_INVALID_HANDLE NULL
sl@0
    42
#define KGrowCleanupStack   12
sl@0
    43
#define KCompositorVersion 0x01023456
sl@0
    44
#define KCompositorVersionMajor 0x1
sl@0
    45
#define KCompositorVersionMinor 0x2
sl@0
    46
#define KCompositorVersionRevision 0x3456
sl@0
    47
sl@0
    48
void PopHeap(void* aHeapPtr)
sl@0
    49
    {
sl@0
    50
    User::SwitchHeap((RHeap*)aHeapPtr);
sl@0
    51
    }
sl@0
    52
sl@0
    53
void GrowCleanupStackL()
sl@0
    54
    {
sl@0
    55
    TInt n = KGrowCleanupStack;
sl@0
    56
    while(n--)
sl@0
    57
        {
sl@0
    58
        CleanupStack::PushL((CBase*)NULL);
sl@0
    59
        }
sl@0
    60
    CleanupStack::Pop(KGrowCleanupStack);
sl@0
    61
    }
sl@0
    62
sl@0
    63
// Helper functions
sl@0
    64
/* supported external image formats */
sl@0
    65
enum OWF_PIXEL_FORMAT   {
sl@0
    66
    OWF_IMAGE_NOT_SUPPORTED = 0,
sl@0
    67
    OWF_IMAGE_ARGB8888      = 0x8888,
sl@0
    68
    OWF_IMAGE_XRGB8888      = 0xf888,
sl@0
    69
    OWF_IMAGE_RGB888        = 0x888,
sl@0
    70
    OWF_IMAGE_RGB565        = 0x565,
sl@0
    71
    OWF_IMAGE_L32           = 0xA32,
sl@0
    72
    OWF_IMAGE_L16           = 0xA16,
sl@0
    73
    OWF_IMAGE_L8            = 0xA8,
sl@0
    74
    OWF_IMAGE_L1            = 0xA1,
sl@0
    75
    OWF_IMAGE_ARGB_INTERNAL = 0x666 /* OWFpixel rep */
sl@0
    76
} ;
sl@0
    77
sl@0
    78
struct CTestNativeStream::OWF_IMAGE_FORMAT{
sl@0
    79
    OWF_PIXEL_FORMAT        pixelFormat;
sl@0
    80
    bool              linear;
sl@0
    81
    bool              premultiplied;
sl@0
    82
    int                  rowPadding; /* row alignment, in bytes */
sl@0
    83
} ;
sl@0
    84
sl@0
    85
TInt CTestNativeStream::BytesPerPixel(TUidPixelFormat aPixelFormat)
sl@0
    86
    {
sl@0
    87
    switch (aPixelFormat)
sl@0
    88
        {
sl@0
    89
        case EUidPixelFormatXRGB_8888:
sl@0
    90
        case EUidPixelFormatARGB_8888:
sl@0
    91
        case EUidPixelFormatBGRX_8888:
sl@0
    92
        case EUidPixelFormatXBGR_8888:
sl@0
    93
        case EUidPixelFormatBGRA_8888:
sl@0
    94
        case EUidPixelFormatABGR_8888:  
sl@0
    95
        case EUidPixelFormatABGR_8888_PRE:
sl@0
    96
        case EUidPixelFormatARGB_8888_PRE:
sl@0
    97
        case EUidPixelFormatBGRA_8888_PRE:
sl@0
    98
        case EUidPixelFormatARGB_2101010:
sl@0
    99
        case EUidPixelFormatABGR_2101010:
sl@0
   100
            return 4;
sl@0
   101
        case EUidPixelFormatBGR_888:
sl@0
   102
        case EUidPixelFormatRGB_888:
sl@0
   103
            return 3;
sl@0
   104
        case EUidPixelFormatXRGB_4444:
sl@0
   105
        case EUidPixelFormatARGB_4444:
sl@0
   106
        case EUidPixelFormatXBGR_4444:
sl@0
   107
        case EUidPixelFormatRGB_565:
sl@0
   108
        case EUidPixelFormatBGR_565:
sl@0
   109
        case EUidPixelFormatARGB_1555:
sl@0
   110
        case EUidPixelFormatXRGB_1555:
sl@0
   111
        case EUidPixelFormatARGB_8332:
sl@0
   112
        case EUidPixelFormatBGRX_5551:
sl@0
   113
        case EUidPixelFormatBGRA_5551:
sl@0
   114
        case EUidPixelFormatBGRA_4444:
sl@0
   115
        case EUidPixelFormatBGRX_4444:
sl@0
   116
        case EUidPixelFormatAP_88:
sl@0
   117
            return  2;
sl@0
   118
        case EUidPixelFormatRGB_332:
sl@0
   119
        case EUidPixelFormatBGR_332:
sl@0
   120
        case EUidPixelFormatA_8:
sl@0
   121
        case EUidPixelFormatL_8:
sl@0
   122
            return  1;
sl@0
   123
        case EUidPixelFormatP_8:
sl@0
   124
            return -1;
sl@0
   125
        case EUidPixelFormatP_4:
sl@0
   126
        case EUidPixelFormatL_4:
sl@0
   127
            return -2;
sl@0
   128
        case EUidPixelFormatL_2:
sl@0
   129
        case EUidPixelFormatP_2:
sl@0
   130
            return -4;
sl@0
   131
        case EUidPixelFormatL_1 :
sl@0
   132
            return -8;
sl@0
   133
        default:
sl@0
   134
            {
sl@0
   135
            return 0;
sl@0
   136
            }
sl@0
   137
        }
sl@0
   138
    }
sl@0
   139
sl@0
   140
/*****************************************
sl@0
   141
 * Helper Creates Surface from OWF spec 
sl@0
   142
 * 
sl@0
   143
 *
sl@0
   144
 */
sl@0
   145
TSurfaceId CTestNativeStream::helperCreateSurfaceL(khronos_int32_t width,
sl@0
   146
        khronos_int32_t height,
sl@0
   147
        const OWF_IMAGE_FORMAT*   format,
sl@0
   148
        khronos_int32_t nbufs,
sl@0
   149
        TUidPixelFormat overridePixelFormat)
sl@0
   150
	{
sl@0
   151
	RSurfaceManager::TSurfaceCreationAttributesBuf bf;
sl@0
   152
	RSurfaceManager::TSurfaceCreationAttributes& b = bf();
sl@0
   153
	
sl@0
   154
	TBool premultiplied = format->premultiplied;
sl@0
   155
	OWF_PIXEL_FORMAT pixelFormat = format->pixelFormat;
sl@0
   156
	khronos_int32_t bytesPerPixel = 0;
sl@0
   157
	
sl@0
   158
	if (overridePixelFormat != EUidPixelFormatUnknown)
sl@0
   159
	    {
sl@0
   160
        bytesPerPixel = BytesPerPixel(overridePixelFormat);
sl@0
   161
        b.iAlignment = 4;
sl@0
   162
        b.iPixelFormat = overridePixelFormat;
sl@0
   163
	    }
sl@0
   164
	else
sl@0
   165
	    {
sl@0
   166
        switch(pixelFormat)
sl@0
   167
            {
sl@0
   168
            case OWF_IMAGE_RGB565:
sl@0
   169
                b.iPixelFormat = EUidPixelFormatRGB_565;
sl@0
   170
                bytesPerPixel = 2;
sl@0
   171
                b.iAlignment = 4;
sl@0
   172
                break;
sl@0
   173
            case OWF_IMAGE_ARGB8888:
sl@0
   174
                {
sl@0
   175
                if (premultiplied)
sl@0
   176
                    {
sl@0
   177
                    b.iPixelFormat = EUidPixelFormatARGB_8888_PRE;
sl@0
   178
                    }
sl@0
   179
                else
sl@0
   180
                    {
sl@0
   181
                    b.iPixelFormat = EUidPixelFormatARGB_8888;
sl@0
   182
                    }
sl@0
   183
                bytesPerPixel = 4;
sl@0
   184
                b.iAlignment = 4;
sl@0
   185
                break;
sl@0
   186
                }
sl@0
   187
            case OWF_IMAGE_XRGB8888 :
sl@0
   188
                b.iPixelFormat = EUidPixelFormatXRGB_8888;
sl@0
   189
                bytesPerPixel = 4;
sl@0
   190
                b.iAlignment = 4;
sl@0
   191
                break;
sl@0
   192
            case OWF_IMAGE_L8 :
sl@0
   193
                b.iPixelFormat = EUidPixelFormatA_8;
sl@0
   194
                bytesPerPixel = 1;
sl@0
   195
                b.iAlignment = 4;
sl@0
   196
                break;
sl@0
   197
            case OWF_IMAGE_L1 :
sl@0
   198
                b.iPixelFormat = EUidPixelFormatL_1;
sl@0
   199
                bytesPerPixel = -8;
sl@0
   200
                b.iAlignment = 4;
sl@0
   201
                break;
sl@0
   202
            default:
sl@0
   203
                User::Leave(KErrNotSupported);	
sl@0
   204
                break;
sl@0
   205
            }
sl@0
   206
	    }
sl@0
   207
	
sl@0
   208
	b.iSize.iWidth = width;
sl@0
   209
	b.iSize.iHeight = height;
sl@0
   210
	b.iBuffers = nbufs;								// number of buffers in the surface
sl@0
   211
	b.iOffsetToFirstBuffer = 0;						// way of reserving space before the surface pixel data
sl@0
   212
	if (bytesPerPixel >= 0)
sl@0
   213
	    {
sl@0
   214
	    b.iStride = bytesPerPixel * width;	// number of bytes between start of one line and start of next	
sl@0
   215
	    }
sl@0
   216
	else
sl@0
   217
	    {
sl@0
   218
	    b.iStride = (width-(bytesPerPixel+1)) / (-bytesPerPixel);
sl@0
   219
	    }
sl@0
   220
	b.iContiguous = EFalse;
sl@0
   221
	b.iMappable = ETrue;
sl@0
   222
	
sl@0
   223
	TSurfaceId surface = TSurfaceId::CreateNullId();
sl@0
   224
	User::LeaveIfError(iUtility->Manager().CreateSurface(bf, surface));
sl@0
   225
	
sl@0
   226
	return surface;
sl@0
   227
	}
sl@0
   228
sl@0
   229
SymbianStreamType CTestNativeStream::helperCreateImageStream(khronos_int32_t width,
sl@0
   230
                                 khronos_int32_t height,
sl@0
   231
                                 const OWF_IMAGE_FORMAT*  format,
sl@0
   232
                                 khronos_int32_t nbufs,
sl@0
   233
                                 TUidPixelFormat overridePixelFormat)
sl@0
   234
	{
sl@0
   235
	TSurfaceId surface;
sl@0
   236
	
sl@0
   237
	TRAPD(err,surface = helperCreateSurfaceL(width, height, format, nbufs, overridePixelFormat));
sl@0
   238
	if (err)
sl@0
   239
	    {
sl@0
   240
	    return WFC_INVALID_HANDLE;
sl@0
   241
	    }
sl@0
   242
	SymbianStreamType ns;
sl@0
   243
	SymbianStreamAcquire(&surface, &ns);
sl@0
   244
	
sl@0
   245
	iUtility->Manager().CloseSurface(surface);
sl@0
   246
	
sl@0
   247
	return ns;
sl@0
   248
	}
sl@0
   249
sl@0
   250
RSemaphore      gSemaphore;
sl@0
   251
RSemaphore      gSemaphore2;
sl@0
   252
sl@0
   253
TGlobalNativeStreamVar	gVarInstance={0};
sl@0
   254
const TGlobalNativeStreamVar& TGlobalNativeStreamVar::Instance()
sl@0
   255
	{
sl@0
   256
	return gVarInstance;
sl@0
   257
	}
sl@0
   258
sl@0
   259
void TGlobalNativeStreamVar::SetSurfaceID(TSurfaceId aSurfaceID)
sl@0
   260
    {
sl@0
   261
    iSurfaceID = aSurfaceID;
sl@0
   262
    }
sl@0
   263
sl@0
   264
void TGlobalNativeStreamVar::SetTestComplete(TBool aTestComplete)
sl@0
   265
    {
sl@0
   266
    iTestComplete = aTestComplete;
sl@0
   267
    }
sl@0
   268
sl@0
   269
void TGlobalNativeStreamVar::SetBuffers(TInt aBuffers)
sl@0
   270
    {
sl@0
   271
    iBuffers = aBuffers;
sl@0
   272
    }
sl@0
   273
sl@0
   274
TSurfaceId TGlobalNativeStreamVar::SurfaceID() const
sl@0
   275
    {
sl@0
   276
    return iSurfaceID;
sl@0
   277
    }
sl@0
   278
sl@0
   279
TBool TGlobalNativeStreamVar::TestComplete() const
sl@0
   280
    {
sl@0
   281
    return iTestComplete;
sl@0
   282
    }
sl@0
   283
sl@0
   284
TInt TGlobalNativeStreamVar::Buffers() const
sl@0
   285
    {
sl@0
   286
    return iBuffers;
sl@0
   287
    }
sl@0
   288
sl@0
   289
/*
sl@0
   290
 * CTestNativeStream implementation
sl@0
   291
 * 
sl@0
   292
 * 
sl@0
   293
 * 
sl@0
   294
 * 
sl@0
   295
 */
sl@0
   296
sl@0
   297
CTestNativeStream::CTestNativeStream(): iUtility(this)
sl@0
   298
	{
sl@0
   299
	// No implementation required
sl@0
   300
	}
sl@0
   301
sl@0
   302
CTestNativeStream::~CTestNativeStream()
sl@0
   303
	{
sl@0
   304
	DeleteOwfSingletons();
sl@0
   305
	}
sl@0
   306
sl@0
   307
void CTestNativeStream::SetupL()
sl@0
   308
	{
sl@0
   309
	TRAPD(err_FailedToCreateSurfaceUtility, iUtility = CSurfaceUtility::NewL( NULL ));
sl@0
   310
	ASSERT_EQUALS(err_FailedToCreateSurfaceUtility,KErrNone);
sl@0
   311
	DefineOwfSingletonKeys();
sl@0
   312
	}
sl@0
   313
sl@0
   314
/**
sl@0
   315
 * test Suite furniture 
sl@0
   316
 **/
sl@0
   317
void CTestNativeStream::TearDownL()
sl@0
   318
	{
sl@0
   319
	delete iUtility();
sl@0
   320
	}
sl@0
   321
sl@0
   322
/**
sl@0
   323
WFC context callback function invoked by native stream when the stream's content
sl@0
   324
is updated. For testing, we simply call a class member function that checks that the
sl@0
   325
correct native stream handle and events mask were supplied.
sl@0
   326
*/
sl@0
   327
void CTestNativeStream::SourceStreamUpdatedCallback(
sl@0
   328
        SymbianStreamType aNs, khronos_int32_t aEvents, void* aData, void* aParam)
sl@0
   329
    {
sl@0
   330
    (void)aData;
sl@0
   331
    if (aEvents == ESOWF_ObserverReturnDefaultEvent && aParam)
sl@0
   332
        {
sl@0
   333
        SYMOWF_DEFAULT_EVENT_PARAM* parameter = (SYMOWF_DEFAULT_EVENT_PARAM*) aParam;
sl@0
   334
        if ((parameter->length) == sizeof(SYMOWF_DEFAULT_EVENT_PARAM))
sl@0
   335
            {
sl@0
   336
            parameter->event = ESOWF_EventUpdated;
sl@0
   337
            }
sl@0
   338
        return;
sl@0
   339
        }
sl@0
   340
        
sl@0
   341
    ASSERT(CTestNativeStream::iTester);
sl@0
   342
    CTestNativeStream::iTester->CheckSourceStreamUpdated(aNs, aParam);
sl@0
   343
    }
sl@0
   344
sl@0
   345
void CTestNativeStream::CheckSourceStreamUpdated(SymbianStreamType aNs, void* aParam)
sl@0
   346
    {
sl@0
   347
    RHeap *h1 = &(User::Heap());
sl@0
   348
    if (aParam)
sl@0
   349
        {
sl@0
   350
        ASSERT_EQUALS(iNs, aNs);
sl@0
   351
        SYMOWF_CONTENT_UPDATED_PARAM* param = (SYMOWF_CONTENT_UPDATED_PARAM*) aParam;
sl@0
   352
        ASSERT_TRUE(param->id == SYM_CONTENT_UPDATE_BEGIN || 
sl@0
   353
                    param->id == SYM_CONTENT_UPDATE_END ||
sl@0
   354
                    param->id == SYM_CONTENT_UPDATE);
sl@0
   355
sl@0
   356
        iSourceStreamUpdatedCalled++;
sl@0
   357
        iStreamUpdatedParameter = param->id; 
sl@0
   358
        switch(param->id)
sl@0
   359
            {
sl@0
   360
            case SYM_CONTENT_UPDATE_BEGIN:
sl@0
   361
                param->immediateAvailable = iImmediateAvailable;
sl@0
   362
                param->immediateVisibility = iImmediateVisible;
sl@0
   363
                param->serialNumber = iStreamUpdatedSerialNumber;
sl@0
   364
                break;
sl@0
   365
                
sl@0
   366
            case SYM_CONTENT_UPDATE:
sl@0
   367
            case SYM_CONTENT_UPDATE_END:
sl@0
   368
                ASSERT_EQUALS(iExpectedSourceStreamUpdatedEventMask, param->par);        
sl@0
   369
                iContextUpdatedFlags |= param->par & (~ESOWF_EventUpdated);    
sl@0
   370
                break;
sl@0
   371
            default:
sl@0
   372
                break;
sl@0
   373
            }
sl@0
   374
        }
sl@0
   375
    else
sl@0
   376
        {
sl@0
   377
        iSourceStreamUpdatedCalled++;
sl@0
   378
        }
sl@0
   379
        
sl@0
   380
    }
sl@0
   381
sl@0
   382
/**
sl@0
   383
Remove the native stream notifications. The creator of the source is responsible
sl@0
   384
for destroying the native stream. 
sl@0
   385
sl@0
   386
Now with the new SymbianStreamRemoveObserver function we need to pass in an observer
sl@0
   387
*/
sl@0
   388
void CTestNativeStream::RemoveNsNotifications()
sl@0
   389
    {
sl@0
   390
    SymbianStreamRemoveObserver(iNs, &iScreenNo, ESOWF_EventAvailable);
sl@0
   391
    SymbianStreamRemoveObserver(iNs, &iScreenNo, ESOWF_EventDisplayed);
sl@0
   392
    SymbianStreamRemoveObserver(iNs, &iScreenNo, ESOWF_EventDisplayedX);
sl@0
   393
    }
sl@0
   394
sl@0
   395
CTestNativeStream* CTestNativeStream::iTester = NULL;
sl@0
   396
sl@0
   397
// Create a suite of all the tests
sl@0
   398
CTestSuite* CTestNativeStream::CreateSuiteL(const TDesC& aName)
sl@0
   399
	{
sl@0
   400
	SymbianStreamRegisterScreenNotifications(0, 10, KCompositorVersion);
sl@0
   401
	SUB_SUITE_OPT(CTestNativeStream,NULL);
sl@0
   402
sl@0
   403
		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0100L);
sl@0
   404
		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0101L);
sl@0
   405
		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0102L);
sl@0
   406
		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0103L);
sl@0
   407
		
sl@0
   408
		// Test with 1, 2 and 3 buffers
sl@0
   409
		ADD_TEST_STEP_PARAM_RANGE(GRAPHICS_OPENWFC_NATIVESTREAM_0104L,1,4);
sl@0
   410
		ADD_TEST_STEP_PARAM_RANGE(GRAPHICS_OPENWFC_NATIVESTREAM_0105L,1,4);
sl@0
   411
		ADD_TEST_STEP_PARAM_RANGE(GRAPHICS_OPENWFC_NATIVESTREAM_0106L,1,4);
sl@0
   412
		
sl@0
   413
		// Concurrent tests
sl@0
   414
		ADD_TEST_STEP_PARAM_RANGE(CreateSharedNativeStreamL,1,4);
sl@0
   415
		ADD_THIS_TEST_STEP(DestroySharedNativeStreamL);
sl@0
   416
		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0107_1L);
sl@0
   417
		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0107_2L);
sl@0
   418
		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0107_3L);
sl@0
   419
		
sl@0
   420
		// Test SUS with OpenWF pipeline
sl@0
   421
		ADD_TEST_STEP_PARAM_RANGE(GRAPHICS_OPENWFC_NATIVESTREAM_0108L, 1, 4);
sl@0
   422
		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0109L);
sl@0
   423
		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0110L);
sl@0
   424
		
sl@0
   425
		// Test various cases for Native Stream callbacks
sl@0
   426
		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0111L);
sl@0
   427
		// Test multithreaded cases for Native Stream callbacks
sl@0
   428
		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0112_1L);
sl@0
   429
		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0112_2L);
sl@0
   430
		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0112_3L);
sl@0
   431
		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0112_4L);
sl@0
   432
		
sl@0
   433
		// Notification tests
sl@0
   434
		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0113L);
sl@0
   435
		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0114L);
sl@0
   436
		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0115L);
sl@0
   437
		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0116L);
sl@0
   438
		
sl@0
   439
		// Notification cancel
sl@0
   440
		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0117_1L);
sl@0
   441
		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0117_2L);
sl@0
   442
		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0117_3L);
sl@0
   443
		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0117_4L);
sl@0
   444
		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0118_1L);
sl@0
   445
		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0118_2L);
sl@0
   446
		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0118_3L);
sl@0
   447
		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0118_4L);
sl@0
   448
		
sl@0
   449
		// Notification overflow
sl@0
   450
		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0119_1L);
sl@0
   451
		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0119_2L);
sl@0
   452
		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0119_3L);
sl@0
   453
		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0120_1L);
sl@0
   454
		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0120_2L);
sl@0
   455
		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0120_3L);
sl@0
   456
		
sl@0
   457
		// Notifications cancelled due to removal of source observer
sl@0
   458
		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0122L);
sl@0
   459
		
sl@0
   460
		// Sym native stream add/remove observers
sl@0
   461
		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0130L);
sl@0
   462
		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0131L);
sl@0
   463
		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0132L);
sl@0
   464
		
sl@0
   465
		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0133L);
sl@0
   466
sl@0
   467
		// Test with 1, 2 and 3 buffers
sl@0
   468
		ADD_TEST_STEP_PARAM_RANGE(GRAPHICS_OPENWFC_NATIVESTREAM_0140L,1,4);
sl@0
   469
		ADD_TEST_STEP_PARAM_RANGE(GRAPHICS_OPENWFC_NATIVESTREAM_0141L,1,4);
sl@0
   470
		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0142L);
sl@0
   471
        ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0143L);
sl@0
   472
        ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0144L);
sl@0
   473
sl@0
   474
	END_SUITE;	
sl@0
   475
	
sl@0
   476
	}
sl@0
   477
sl@0
   478
// This handles any non-member uses of the extended ASSERT_XXX macros
sl@0
   479
void TefUnitFailLeaveL()
sl@0
   480
	{
sl@0
   481
	User::Leave(KErrTEFUnitFail);
sl@0
   482
	}
sl@0
   483
sl@0
   484
SymbianStreamType CTestNativeStream::NsCheckL(const TSurfaceId aId, TInt aCheck, TBool aFind)
sl@0
   485
	{
sl@0
   486
	// Acquire (create OR find) the stream
sl@0
   487
	SymbianStreamType ns = NULL;
sl@0
   488
	TInt err;
sl@0
   489
	if (aFind)
sl@0
   490
		{
sl@0
   491
		err = (TInt)SymbianStreamFind(&aId, &ns);
sl@0
   492
		}
sl@0
   493
	else
sl@0
   494
		{
sl@0
   495
		err = SymbianStreamAcquire(&aId, &ns);
sl@0
   496
		}
sl@0
   497
	ASSERT_TRUE(err == KErrNone);
sl@0
   498
	// Check the hash map count
sl@0
   499
	ASSERT_EQUALS((COpenWfcStreamMap::InstanceL().Count()), aCheck);
sl@0
   500
    SymbianStreamBuffer bufferHandle;
sl@0
   501
    err = SymbianStreamAcquireReadBuffer(ns,&bufferHandle);
sl@0
   502
    ASSERT_TRUE(err == KErrNone);
sl@0
   503
    long bufferIndex;
sl@0
   504
    const TSurfaceId* checkId = NULL;
sl@0
   505
    err = SymbianStreamGetBufferId(ns,bufferHandle,&bufferIndex,&checkId);
sl@0
   506
    ASSERT_TRUE(err == KErrNone);
sl@0
   507
    SymbianStreamReleaseReadBuffer(ns,bufferHandle);
sl@0
   508
	ASSERT_NOT_NULL(checkId);
sl@0
   509
	ASSERT_EQUALS(*checkId, aId);
sl@0
   510
	return ns;
sl@0
   511
	}
sl@0
   512
sl@0
   513
void CTestNativeStream::CreateSharedNativeStreamL(TInt aBuffers)
sl@0
   514
	{
sl@0
   515
    RHeap* mainHeap = COpenWfcStreamMap::InstanceL().GetMainHeap();
sl@0
   516
    GrowCleanupStackL();
sl@0
   517
    
sl@0
   518
	CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
sl@0
   519
	
sl@0
   520
	gVarInstance.SetTestComplete(EFalse);
sl@0
   521
	gVarInstance.SetBuffers(aBuffers);
sl@0
   522
	
sl@0
   523
	TSize surfaceSize(TSize(100,100));
sl@0
   524
	khronos_int32_t width = surfaceSize.iWidth;
sl@0
   525
	khronos_int32_t height = surfaceSize.iHeight;
sl@0
   526
	
sl@0
   527
	OWF_IMAGE_FORMAT pixelFormat =
sl@0
   528
		{
sl@0
   529
		OWF_IMAGE_ARGB8888,
sl@0
   530
		ETrue,
sl@0
   531
		ETrue,
sl@0
   532
		4
sl@0
   533
		};	
sl@0
   534
	
sl@0
   535
	// Create the first stream
sl@0
   536
	SymbianStreamType ns=helperCreateImageStream(width,
sl@0
   537
													height,
sl@0
   538
													&pixelFormat,
sl@0
   539
													aBuffers);
sl@0
   540
	ASSERT_TRUE(ns);
sl@0
   541
	
sl@0
   542
    SymbianStreamBuffer bufferHandle;
sl@0
   543
    SymbianStreamAcquireReadBuffer(ns,&bufferHandle);
sl@0
   544
    long bufferIndex;
sl@0
   545
    const TSurfaceId* checkId = NULL;
sl@0
   546
    TInt err = SymbianStreamGetBufferId(ns,bufferHandle,&bufferIndex,&checkId);
sl@0
   547
    ASSERT_TRUE(err == KErrNone);
sl@0
   548
    SymbianStreamReleaseReadBuffer(ns,bufferHandle);
sl@0
   549
	gVarInstance.SetSurfaceID(*checkId);
sl@0
   550
    gSemaphore.CreateLocal(1);
sl@0
   551
    gSemaphore.Wait(); 
sl@0
   552
    gSemaphore2.CreateLocal(1);
sl@0
   553
    gSemaphore2.Wait(); 
sl@0
   554
    CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
sl@0
   555
	}
sl@0
   556
sl@0
   557
void CTestNativeStream::DestroySharedNativeStreamL()
sl@0
   558
	{
sl@0
   559
	GrowCleanupStackL();
sl@0
   560
	
sl@0
   561
	CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(COpenWfcStreamMap::InstanceL().GetMainHeap())));
sl@0
   562
	
sl@0
   563
    gSemaphore2.Close();
sl@0
   564
	gSemaphore.Close();
sl@0
   565
	TSurfaceId id = gVarInstance.SurfaceID();
sl@0
   566
	SymbianStreamType ns;
sl@0
   567
	TInt err = SymbianStreamFind(&id,&ns);
sl@0
   568
	ASSERT_TRUE(err == KErrNone);
sl@0
   569
	ASSERT_TRUE(ns);
sl@0
   570
	// Decrease stream's reference count by one. This removes reference added by owfNativeStreamFind()
sl@0
   571
	SymbianStreamRemoveReference(ns);
sl@0
   572
	// Decrease stream's reference count by one to make reference count zero, and destroy the stream
sl@0
   573
	SymbianStreamRemoveReference(ns);
sl@0
   574
	CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
sl@0
   575
	}
sl@0
   576
sl@0
   577
// Test observers
sl@0
   578
void TestUpdateCallback(SymbianStreamType aStream, khronos_int32_t aEvent, void* aData, void* aParam)
sl@0
   579
    {
sl@0
   580
    (void) aStream;
sl@0
   581
    switch (aEvent)
sl@0
   582
        {
sl@0
   583
        case ESOWF_ObserverReturnDefaultEvent:
sl@0
   584
            if (aParam)
sl@0
   585
                {
sl@0
   586
                SYMOWF_DEFAULT_EVENT_PARAM* parameter = (SYMOWF_DEFAULT_EVENT_PARAM*) aParam;
sl@0
   587
                if ((parameter->length) == sizeof(SYMOWF_DEFAULT_EVENT_PARAM))
sl@0
   588
                    {
sl@0
   589
                    parameter->event = ESOWF_EventUpdated;
sl@0
   590
                    }
sl@0
   591
                }
sl@0
   592
            return;
sl@0
   593
            
sl@0
   594
        case ESOWF_EventUpdated:
sl@0
   595
            {
sl@0
   596
            TInt* localNumber = (TInt*)aData;
sl@0
   597
             ++(*localNumber);
sl@0
   598
            }
sl@0
   599
            break;
sl@0
   600
        default:
sl@0
   601
            break;
sl@0
   602
        }
sl@0
   603
    }
sl@0
   604
sl@0
   605
// Test compose target
sl@0
   606
void TestComposedCallback(SymbianStreamType aStream, khronos_int32_t aEvent, void* aData, void* aParam)
sl@0
   607
    {
sl@0
   608
    (void) aStream;
sl@0
   609
    switch (aEvent)
sl@0
   610
        {
sl@0
   611
        case ESOWF_ObserverReturnDefaultEvent:
sl@0
   612
            if (aParam)
sl@0
   613
                {
sl@0
   614
                SYMOWF_DEFAULT_EVENT_PARAM* parameter = (SYMOWF_DEFAULT_EVENT_PARAM*) aParam;
sl@0
   615
                if ((parameter->length) == sizeof(SYMOWF_DEFAULT_EVENT_PARAM))
sl@0
   616
                    {
sl@0
   617
                    parameter->event = ESOWF_EventComposed;
sl@0
   618
                    }
sl@0
   619
                }
sl@0
   620
            return;
sl@0
   621
            
sl@0
   622
        case ESOWF_EventComposed:
sl@0
   623
            {
sl@0
   624
            TInt* localNumber = (TInt*)aData;
sl@0
   625
             ++(*localNumber);
sl@0
   626
            }
sl@0
   627
            break;
sl@0
   628
        default:
sl@0
   629
            break;
sl@0
   630
        }
sl@0
   631
    }
sl@0
   632
sl@0
   633
/**
sl@0
   634
@SYMTestCaseID			GFX_OPENWFC_NATIVESTREAM_0100
sl@0
   635
@SYMTestCaseDesc		Create a native stream using SymbianStreamAcquire()
sl@0
   636
@SYMREQ					
sl@0
   637
@SYMPREQ				PREQ2400
sl@0
   638
@SYMTestType			CT
sl@0
   639
@SYMTestPriority		
sl@0
   640
@SYMTestPurpose			Verify native stream objects can be created and persist unique surface ID values
sl@0
   641
@SYMTestActions	
sl@0
   642
		Create two surfaces,
sl@0
   643
		Create two streams from the surfaces
sl@0
   644
		Read back the surface Ids from the streams
sl@0
   645
@SYMTestExpectedResults
sl@0
   646
		The surface IDs should be non-null and unique
sl@0
   647
		The streams should be non-null and unique
sl@0
   648
		The returned surface Ids should match the constructed IDs
sl@0
   649
 **/		
sl@0
   650
void CTestNativeStream::GRAPHICS_OPENWFC_NATIVESTREAM_0100L()
sl@0
   651
	{
sl@0
   652
	RHeap* mainHeap = COpenWfcStreamMap::InstanceL().GetMainHeap();
sl@0
   653
	TRAPD(err, GrowCleanupStackL());
sl@0
   654
	ASSERT_TRUE(err == KErrNone);
sl@0
   655
	
sl@0
   656
	TInt count = COpenWfcStreamMap::InstanceL().Count();
sl@0
   657
	TSurfaceId surface=iUtility->CreateSurfaceL(TSize(100,100),EUidPixelFormatARGB_8888_PRE,400,2);
sl@0
   658
	ASSERT_FALSE(surface.IsNull());
sl@0
   659
	CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
sl@0
   660
	SymbianStreamType ns;
sl@0
   661
	err = SymbianStreamAcquire(&surface, &ns);
sl@0
   662
	ASSERT_TRUE(err == KErrNone);
sl@0
   663
    SymbianStreamBuffer bufferHandle;
sl@0
   664
    err = SymbianStreamAcquireReadBuffer(ns, &bufferHandle);
sl@0
   665
    ASSERT_TRUE(err == KErrNone);
sl@0
   666
    long bufferIndex;
sl@0
   667
    const TSurfaceId* getId = NULL;
sl@0
   668
    err = SymbianStreamGetBufferId(ns,bufferHandle,&bufferIndex,&getId);
sl@0
   669
    ASSERT_TRUE(err == KErrNone);
sl@0
   670
    TInt ChunkHandle = 100;
sl@0
   671
    err = SymbianStreamGetChunkHandle(ns, &ChunkHandle);
sl@0
   672
    ASSERT_TRUE(err == KErrNone);    
sl@0
   673
    err = SymbianStreamReleaseReadBuffer(ns,bufferHandle);
sl@0
   674
    ASSERT_TRUE(err == KErrNone);    
sl@0
   675
	ASSERT_EQUALS(*getId,surface);
sl@0
   676
	CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
sl@0
   677
	
sl@0
   678
	TSurfaceId surface2=iUtility->CreateSurfaceL(TSize(100,100),EUidPixelFormatARGB_8888_PRE,400,2);
sl@0
   679
	ASSERT_FALSE(surface2.IsNull());
sl@0
   680
	ASSERT_NOT_EQUALS(surface,surface2);
sl@0
   681
	CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
sl@0
   682
	SymbianStreamType ns2;
sl@0
   683
	err = SymbianStreamAcquire(&surface2,&ns2);
sl@0
   684
	ASSERT_TRUE(err == KErrNone);
sl@0
   685
	ASSERT_TRUE(ns2);
sl@0
   686
	ASSERT_FALSE(SymbianStreamSame(ns, ns2));
sl@0
   687
	ASSERT_EQUALS((COpenWfcStreamMap::InstanceL().Count()), count + 2);
sl@0
   688
	err = SymbianStreamAcquireReadBuffer(ns2,&bufferHandle);
sl@0
   689
	ASSERT_TRUE(err == KErrNone);
sl@0
   690
    const TSurfaceId* getId2 = NULL;
sl@0
   691
    err = SymbianStreamGetBufferId(ns2,bufferHandle,&bufferIndex,&getId2);
sl@0
   692
    ASSERT_TRUE(err == KErrNone);
sl@0
   693
    err = SymbianStreamReleaseReadBuffer(ns2,bufferHandle);
sl@0
   694
    ASSERT_TRUE(err == KErrNone);
sl@0
   695
	ASSERT_NOT_NULL(getId2);
sl@0
   696
	ASSERT_EQUALS(*getId2,surface2);
sl@0
   697
	
sl@0
   698
	SymbianStreamRemoveReference(ns);
sl@0
   699
	ASSERT_EQUALS((COpenWfcStreamMap::InstanceL().Count()), count + 1);
sl@0
   700
	CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
sl@0
   701
	iUtility->DestroySurface(surface);
sl@0
   702
	
sl@0
   703
	CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
sl@0
   704
	SymbianStreamRemoveReference(ns2);
sl@0
   705
	ASSERT_EQUALS((COpenWfcStreamMap::InstanceL().Count()), count);
sl@0
   706
	CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
sl@0
   707
	iUtility->DestroySurface(surface2);
sl@0
   708
	}
sl@0
   709
sl@0
   710
/**
sl@0
   711
@SYMTestCaseID			GFX_OPENWFC_NATIVESTREAM_0101
sl@0
   712
@SYMTestCaseDesc		Create a native stream using SymbianStreamCreateImageStream()
sl@0
   713
@SYMREQ					
sl@0
   714
@SYMPREQ				PREQ2400
sl@0
   715
@SYMTestType			CT
sl@0
   716
@SYMTestPriority		
sl@0
   717
@SYMTestPurpose			Verify native stream objects can be created and persist unique surface ID values
sl@0
   718
@SYMTestActions	
sl@0
   719
		Create two streams from the parameters passed in
sl@0
   720
		Read back the surface Ids from the streams
sl@0
   721
@SYMTestExpectedResults
sl@0
   722
		The surface IDs should be non-null and unique
sl@0
   723
		The streams should be non-null and unique
sl@0
   724
 **/
sl@0
   725
void CTestNativeStream::GRAPHICS_OPENWFC_NATIVESTREAM_0101L()
sl@0
   726
	{
sl@0
   727
	RHeap* mainHeap = COpenWfcStreamMap::InstanceL().GetMainHeap();
sl@0
   728
	TRAPD(err, GrowCleanupStackL());
sl@0
   729
	ASSERT_TRUE(err == KErrNone);
sl@0
   730
	
sl@0
   731
	TSize surfaceSize(TSize(100,100));
sl@0
   732
	TInt width = surfaceSize.iWidth;
sl@0
   733
	TInt height = surfaceSize.iHeight;
sl@0
   734
	TInt buffers = 2;
sl@0
   735
sl@0
   736
	OWF_IMAGE_FORMAT pixelFormat =
sl@0
   737
		{
sl@0
   738
		OWF_IMAGE_ARGB8888,
sl@0
   739
	    ETrue,
sl@0
   740
	    ETrue,
sl@0
   741
	    4
sl@0
   742
	    };	
sl@0
   743
	
sl@0
   744
	CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
sl@0
   745
	
sl@0
   746
	// Create the first stream
sl@0
   747
	SymbianStreamType ns=helperCreateImageStream(width,
sl@0
   748
													height,
sl@0
   749
													&pixelFormat,
sl@0
   750
													buffers);
sl@0
   751
	ASSERT_TRUE(ns);
sl@0
   752
    SymbianStreamBuffer bufferHandle;
sl@0
   753
    err = SymbianStreamAcquireReadBuffer(ns,&bufferHandle);
sl@0
   754
    ASSERT_TRUE(err == KErrNone);
sl@0
   755
    long bufferIndex;
sl@0
   756
    const TSurfaceId* getId = NULL;
sl@0
   757
    err = SymbianStreamGetBufferId(ns,bufferHandle,&bufferIndex,&getId);
sl@0
   758
    ASSERT_TRUE(err == KErrNone);
sl@0
   759
    err = SymbianStreamReleaseReadBuffer(ns,bufferHandle);
sl@0
   760
    ASSERT_TRUE(err == KErrNone);
sl@0
   761
	
sl@0
   762
	// Create the second stream
sl@0
   763
	SymbianStreamType ns2=helperCreateImageStream(width,
sl@0
   764
													height,
sl@0
   765
													&pixelFormat,
sl@0
   766
													buffers);
sl@0
   767
	ASSERT_TRUE(ns2);
sl@0
   768
	
sl@0
   769
    err = SymbianStreamAcquireReadBuffer(ns2,&bufferHandle);
sl@0
   770
    ASSERT_TRUE(err == KErrNone);
sl@0
   771
    const TSurfaceId* getId2 = NULL;
sl@0
   772
    err = SymbianStreamGetBufferId(ns2,bufferHandle,&bufferIndex,&getId2);
sl@0
   773
    ASSERT_TRUE(err == KErrNone);
sl@0
   774
    err = SymbianStreamReleaseReadBuffer(ns2,bufferHandle);
sl@0
   775
    ASSERT_TRUE(err == KErrNone);
sl@0
   776
	ASSERT_NOT_NULL(getId2);
sl@0
   777
	
sl@0
   778
	ASSERT_NOT_EQUALS(ns,ns2);
sl@0
   779
	ASSERT_NOT_EQUALS(getId,getId2);
sl@0
   780
	
sl@0
   781
	SymbianStreamRemoveReference(ns);
sl@0
   782
	SymbianStreamRemoveReference(ns2);
sl@0
   783
	
sl@0
   784
	CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
sl@0
   785
	}
sl@0
   786
sl@0
   787
/**
sl@0
   788
@SYMTestCaseID			GFX_OPENWFC_NATIVESTREAM_0102
sl@0
   789
@SYMTestCaseDesc		Create a native stream 2
sl@0
   790
@SYMREQ					
sl@0
   791
@SYMPREQ				PREQ2400
sl@0
   792
@SYMTestType			CT
sl@0
   793
@SYMTestPriority		
sl@0
   794
@SYMTestPurpose			Verify native stream objects can be created and persist unique surface ID values
sl@0
   795
@SYMTestActions	
sl@0
   796
		Create two surfaces,
sl@0
   797
		Create two streams from the surfaces
sl@0
   798
		Read back the surface Ids from the streams
sl@0
   799
		Acquire multiple time the native streams
sl@0
   800
		Find native streams
sl@0
   801
@SYMTestExpectedResults
sl@0
   802
		The surface IDs should be non-null and unique
sl@0
   803
		The streams should be non-null and unique
sl@0
   804
		The returned surface Ids should match the constructed IDs
sl@0
   805
		The hash map counter should be updated accordingly when native streams are created or destroyed
sl@0
   806
 **/		
sl@0
   807
void CTestNativeStream::GRAPHICS_OPENWFC_NATIVESTREAM_0102L()
sl@0
   808
	{
sl@0
   809
	RHeap* mainHeap = COpenWfcStreamMap::InstanceL().GetMainHeap();
sl@0
   810
	TRAPD(err, GrowCleanupStackL());
sl@0
   811
	ASSERT_TRUE(err == KErrNone);
sl@0
   812
	
sl@0
   813
	COpenWfcStreamMap& singleton = COpenWfcStreamMap::InstanceL();
sl@0
   814
	TInt check = COpenWfcStreamMap::InstanceL().Count() + 1;
sl@0
   815
	// Create the first surface
sl@0
   816
	TSurfaceId surfaceId1 = iUtility->CreateSurfaceL(TSize(100, 100), EUidPixelFormatARGB_8888_PRE, 400, 2);
sl@0
   817
	ASSERT_FALSE(surfaceId1.IsNull());
sl@0
   818
	
sl@0
   819
	CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
sl@0
   820
	SymbianStreamType ns1 = NsCheckL(surfaceId1, check, EFalse);
sl@0
   821
	
sl@0
   822
	TSurfaceId surfaceId2;
sl@0
   823
	surfaceId2.CreateNullId();
sl@0
   824
	SymbianStreamType ns2;
sl@0
   825
	err = SymbianStreamFind(&surfaceId2,&ns2);
sl@0
   826
	ASSERT_TRUE(err == KErrNotFound);
sl@0
   827
	ASSERT_FALSE(ns2);
sl@0
   828
	CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
sl@0
   829
	
sl@0
   830
	// Create the second surface
sl@0
   831
	surfaceId2 = iUtility->CreateSurfaceL(TSize(100, 100), EUidPixelFormatARGB_8888_PRE, 400, 2);
sl@0
   832
	ASSERT_FALSE(surfaceId2.IsNull()); 
sl@0
   833
	
sl@0
   834
	CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
sl@0
   835
	err = SymbianStreamFind(&surfaceId2,&ns2);
sl@0
   836
	ASSERT_TRUE(err == KErrNotFound);
sl@0
   837
	ASSERT_FALSE(ns2);
sl@0
   838
	
sl@0
   839
	ns2 = NsCheckL(surfaceId2, ++check, EFalse);
sl@0
   840
	
sl@0
   841
	NsCheckL(surfaceId1, check, EFalse);
sl@0
   842
	
sl@0
   843
	NsCheckL(surfaceId1, check, ETrue);
sl@0
   844
	
sl@0
   845
	NsCheckL(surfaceId2, check, ETrue);
sl@0
   846
	
sl@0
   847
	SymbianStreamRemoveReference(ns1);
sl@0
   848
	ASSERT_EQUALS((singleton.Count()), check);
sl@0
   849
	
sl@0
   850
	SymbianStreamRemoveReference(ns2);
sl@0
   851
	ASSERT_EQUALS((singleton.Count()), check);
sl@0
   852
	
sl@0
   853
	SymbianStreamRemoveReference(ns2);
sl@0
   854
	ASSERT_EQUALS((singleton.Count()), --check);
sl@0
   855
sl@0
   856
	SymbianStreamRemoveReference(ns1);
sl@0
   857
	ASSERT_EQUALS((singleton.Count()), check);
sl@0
   858
	
sl@0
   859
	SymbianStreamRemoveReference(ns1);
sl@0
   860
	ASSERT_EQUALS((singleton.Count()), --check);
sl@0
   861
	CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
sl@0
   862
	
sl@0
   863
	iUtility->DestroySurface(surfaceId1);
sl@0
   864
	iUtility->DestroySurface(surfaceId2);
sl@0
   865
	
sl@0
   866
	CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
sl@0
   867
	err = SymbianStreamFind(&surfaceId2,&ns2);
sl@0
   868
	ASSERT_TRUE(err == KErrNotFound);
sl@0
   869
	ASSERT_FALSE(ns2);
sl@0
   870
	CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
sl@0
   871
	}
sl@0
   872
sl@0
   873
struct SupportedFormats
sl@0
   874
    {
sl@0
   875
    TUidPixelFormat symbianPixelFormat;
sl@0
   876
    } supportedFormats[]=
sl@0
   877
    {
sl@0
   878
        EUidPixelFormatXRGB_8888,
sl@0
   879
        EUidPixelFormatARGB_8888,
sl@0
   880
        EUidPixelFormatBGRX_8888,
sl@0
   881
        EUidPixelFormatXBGR_8888,
sl@0
   882
        EUidPixelFormatBGRA_8888,
sl@0
   883
        EUidPixelFormatABGR_8888, 
sl@0
   884
        EUidPixelFormatABGR_8888_PRE,
sl@0
   885
        EUidPixelFormatARGB_8888_PRE,
sl@0
   886
        EUidPixelFormatBGRA_8888_PRE,
sl@0
   887
        EUidPixelFormatARGB_2101010,
sl@0
   888
        EUidPixelFormatABGR_2101010,
sl@0
   889
        EUidPixelFormatBGR_888,
sl@0
   890
        EUidPixelFormatRGB_888,
sl@0
   891
        EUidPixelFormatXRGB_4444,
sl@0
   892
        EUidPixelFormatARGB_4444,
sl@0
   893
        EUidPixelFormatXBGR_4444,
sl@0
   894
        EUidPixelFormatRGB_565,
sl@0
   895
        EUidPixelFormatBGR_565,
sl@0
   896
        EUidPixelFormatARGB_1555,
sl@0
   897
        EUidPixelFormatXRGB_1555,
sl@0
   898
        EUidPixelFormatARGB_8332,
sl@0
   899
        EUidPixelFormatBGRX_5551,
sl@0
   900
        EUidPixelFormatBGRA_5551,
sl@0
   901
        EUidPixelFormatBGRA_4444,
sl@0
   902
        EUidPixelFormatBGRX_4444,
sl@0
   903
        EUidPixelFormatAP_88,
sl@0
   904
        EUidPixelFormatRGB_332,
sl@0
   905
        EUidPixelFormatBGR_332,
sl@0
   906
        EUidPixelFormatA_8,
sl@0
   907
        EUidPixelFormatL_8,
sl@0
   908
        EUidPixelFormatP_8,
sl@0
   909
        EUidPixelFormatP_4,
sl@0
   910
        EUidPixelFormatL_4,
sl@0
   911
        EUidPixelFormatL_2,
sl@0
   912
        EUidPixelFormatP_2,
sl@0
   913
        EUidPixelFormatL_1
sl@0
   914
    };
sl@0
   915
sl@0
   916
/**
sl@0
   917
@SYMTestCaseID			GFX_OPENWFC_NATIVESTREAM_0103
sl@0
   918
@SYMTestCaseDesc		Retrieve stream attributes using SymbianStreamGetHeader()
sl@0
   919
@SYMREQ					
sl@0
   920
@SYMPREQ				PREQ2400
sl@0
   921
@SYMTestType			CT
sl@0
   922
@SYMTestPriority		
sl@0
   923
@SYMTestPurpose			Verify native stream object attributes can be retrieved.
sl@0
   924
@SYMTestActions	
sl@0
   925
		Create a native stream based on a supported image/pixel format
sl@0
   926
		Retrieve all of the stream attributes
sl@0
   927
		Retreive none of the stream attributes
sl@0
   928
@SYMTestExpectedResults
sl@0
   929
		The retrieved attributes should match the parameters used to create the surface stream
sl@0
   930
		Retrieving no attributes should not cause a crash
sl@0
   931
 **/
sl@0
   932
void CTestNativeStream::GRAPHICS_OPENWFC_NATIVESTREAM_0103L()
sl@0
   933
	{
sl@0
   934
	// Native stream attributes
sl@0
   935
    TSize surfaceSize(TSize(100,50));
sl@0
   936
    khronos_int32_t width = surfaceSize.iWidth;
sl@0
   937
    khronos_int32_t height = surfaceSize.iHeight;
sl@0
   938
    khronos_int32_t numBuffers = 2;
sl@0
   939
    
sl@0
   940
    for (TInt x=0; x<sizeof(supportedFormats)/sizeof(supportedFormats[0]); x++)
sl@0
   941
        {
sl@0
   942
        INFO_PRINTF2(_L("Pixel format %x"),supportedFormats[x]);
sl@0
   943
        khronos_int32_t streamPixelSize = BytesPerPixel(supportedFormats[x].symbianPixelFormat);
sl@0
   944
        
sl@0
   945
        OWF_IMAGE_FORMAT pixelFormat =
sl@0
   946
            {
sl@0
   947
            OWF_IMAGE_NOT_SUPPORTED,
sl@0
   948
            EFalse,
sl@0
   949
            EFalse,
sl@0
   950
            2
sl@0
   951
            };  
sl@0
   952
        
sl@0
   953
        SymbianStreamType ns=helperCreateImageStream(width,
sl@0
   954
                                                     height,
sl@0
   955
                                                     &pixelFormat,
sl@0
   956
                                                     numBuffers,
sl@0
   957
                                                     supportedFormats[x].symbianPixelFormat);      //will ignore pixelFormat
sl@0
   958
        ASSERT_TRUE(ns);
sl@0
   959
        
sl@0
   960
        // Store the retrieved attributes
sl@0
   961
        TInt32 attWidth = 0;
sl@0
   962
        TInt32 attHeight = 0;
sl@0
   963
        TInt32 attStreamStride = 0;
sl@0
   964
        TInt32 attStreamFormat = EUidPixelFormatUnknown;
sl@0
   965
        TInt32 attStreamPixelSize = 0;
sl@0
   966
        
sl@0
   967
        SymbianStreamGetHeader(ns, &attWidth, &attHeight, &attStreamStride, &attStreamFormat, &attStreamPixelSize);		
sl@0
   968
            
sl@0
   969
        ASSERT_EQUALS(attWidth, width);
sl@0
   970
        ASSERT_EQUALS(attHeight, height);
sl@0
   971
        ASSERT_EQUALS((TInt32)attStreamFormat, (TInt32)supportedFormats[x].symbianPixelFormat);
sl@0
   972
        if (BytesPerPixel(supportedFormats[x].symbianPixelFormat) > 0)
sl@0
   973
            {
sl@0
   974
            ASSERT_EQUALS(attStreamStride, (streamPixelSize * width));
sl@0
   975
            }
sl@0
   976
        else
sl@0
   977
            {
sl@0
   978
            ASSERT_EQUALS(attStreamStride, (width-(streamPixelSize+1)) / (-streamPixelSize));
sl@0
   979
            }
sl@0
   980
        ASSERT_EQUALS(attStreamPixelSize, (TInt32)BytesPerPixel(supportedFormats[x].symbianPixelFormat));	
sl@0
   981
            
sl@0
   982
        SymbianStreamGetHeader(ns, NULL, NULL, NULL, NULL, NULL);
sl@0
   983
        
sl@0
   984
        SymbianStreamRemoveReference(ns);
sl@0
   985
        }
sl@0
   986
	}
sl@0
   987
sl@0
   988
/**
sl@0
   989
@SYMTestCaseID			GFX_OPENWFC_NATIVESTREAM_0104
sl@0
   990
@SYMTestCaseDesc		Acquire write/read buffers and retrieve the buffer ptr (single threaded test).
sl@0
   991
@SYMREQ					
sl@0
   992
@SYMPREQ				PREQ2400
sl@0
   993
@SYMTestType			CT
sl@0
   994
@SYMTestPriority		
sl@0
   995
@SYMTestPurpose         Verify owfNativeStreamAcquireWriteBuffer(), owfNativeStreamReleaseWriteBuffer(),
sl@0
   996
                        owfNativeStreamAcquireReadBuffer() and owfNativeStreamReleaseReadBuffer() methods
sl@0
   997
						work as expected.
sl@0
   998
						
sl@0
   999
@SYMTestActions	
sl@0
  1000
		Create a native stream 
sl@0
  1001
		For each buffer:
sl@0
  1002
		- Acquire the write buffer (wB)
sl@0
  1003
		- Get the write buffer ptr (pWB)
sl@0
  1004
		- Release the write buffer
sl@0
  1005
		- Acquire the read buffer (rB)
sl@0
  1006
		- Get the read buffer ptr (pRB)
sl@0
  1007
		- Release the read buffer	
sl@0
  1008
		Repeat for each buffer. Finally:
sl@0
  1009
		Acquire the write buffer
sl@0
  1010
		Release the write buffer	
sl@0
  1011
@SYMTestExpectedResults
sl@0
  1012
		For each buffer of the native stream, check:
sl@0
  1013
		- The read buffer (rB) should be the same as the write buffer (wB)
sl@0
  1014
		- The read buffer address (pRB) should be the same as the write buffer address (pWB)
sl@0
  1015
		If the number of buffers > 1, check:
sl@0
  1016
		- The write buffer number from the previous acquire write buffer call should not be the same 
sl@0
  1017
		as the write buffer number from the next acquire write buffer call
sl@0
  1018
		The final acquire/release write/read calls should check:
sl@0
  1019
		The write buffer number should acquire the first buffer number
sl@0
  1020
 **/
sl@0
  1021
void CTestNativeStream::GRAPHICS_OPENWFC_NATIVESTREAM_0104L(TInt aNumBuffers)
sl@0
  1022
	{
sl@0
  1023
	RHeap* mainHeap = COpenWfcStreamMap::InstanceL().GetMainHeap();
sl@0
  1024
	TRAPD(err, GrowCleanupStackL());
sl@0
  1025
	ASSERT_TRUE(err == KErrNone);
sl@0
  1026
sl@0
  1027
	CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
sl@0
  1028
	
sl@0
  1029
	ASSERT_TRUE(aNumBuffers > 0);
sl@0
  1030
	
sl@0
  1031
	TSize surfaceSize(TSize(100,100));
sl@0
  1032
	khronos_int32_t width = surfaceSize.iWidth;
sl@0
  1033
	khronos_int32_t height = surfaceSize.iHeight;
sl@0
  1034
	
sl@0
  1035
	OWF_IMAGE_FORMAT pixelFormat =
sl@0
  1036
		{
sl@0
  1037
		OWF_IMAGE_ARGB8888,
sl@0
  1038
	    ETrue,
sl@0
  1039
	    ETrue,
sl@0
  1040
	    aNumBuffers
sl@0
  1041
	    };	
sl@0
  1042
	
sl@0
  1043
	SymbianStreamType ns=helperCreateImageStream(width,
sl@0
  1044
													height,
sl@0
  1045
													&pixelFormat,
sl@0
  1046
													aNumBuffers);
sl@0
  1047
	ASSERT_TRUE(ns);
sl@0
  1048
	
sl@0
  1049
	TUint8 *pWriteBuffer = NULL;
sl@0
  1050
	TUint8 *pReadBuffer = NULL;
sl@0
  1051
	TUint8 *pPrevWriteBuffer = pWriteBuffer;
sl@0
  1052
	khronos_int32_t writeBuffer;
sl@0
  1053
	khronos_int32_t readBuffer;
sl@0
  1054
	khronos_int32_t bufferIndexWrite;
sl@0
  1055
	khronos_int32_t bufferIndexRead;
sl@0
  1056
	khronos_int32_t bufferIndexWriteFirst;
sl@0
  1057
	khronos_int32_t bufferIndexWriteFinal;
sl@0
  1058
	khronos_int32_t finalWriteBuffer;
sl@0
  1059
	const TSurfaceId* getId = NULL;
sl@0
  1060
	
sl@0
  1061
	TInt bufferCount = aNumBuffers;
sl@0
  1062
	
sl@0
  1063
	// Loop through the buffers
sl@0
  1064
	for (TInt count=0; count<bufferCount; count++)
sl@0
  1065
		{
sl@0
  1066
		// Acquire the write buffer
sl@0
  1067
		err = SymbianStreamAcquireWriteBuffer(ns,&writeBuffer);
sl@0
  1068
		ASSERT_TRUE(err == KErrNone);
sl@0
  1069
		err = SymbianStreamGetBufferId(ns,writeBuffer,&bufferIndexWrite,&getId);
sl@0
  1070
		ASSERT_TRUE(err == KErrNone);
sl@0
  1071
		
sl@0
  1072
		if (count == 0)
sl@0
  1073
		    {
sl@0
  1074
		    bufferIndexWriteFirst = bufferIndexWrite;
sl@0
  1075
		    }
sl@0
  1076
		
sl@0
  1077
		err = SymbianStreamGetBufferPointer(ns,writeBuffer,reinterpret_cast<void**>(&pWriteBuffer));
sl@0
  1078
		ASSERT_TRUE(err == KErrNone);
sl@0
  1079
		ASSERT_NOT_NULL(pWriteBuffer);
sl@0
  1080
		
sl@0
  1081
		err = SymbianStreamReleaseWriteBuffer(ns,writeBuffer);
sl@0
  1082
		ASSERT_TRUE(err == KErrNone);
sl@0
  1083
		
sl@0
  1084
		// Acquire the read buffer
sl@0
  1085
		err = SymbianStreamAcquireReadBuffer(ns,&readBuffer);
sl@0
  1086
		ASSERT_TRUE(err == KErrNone);
sl@0
  1087
		err = SymbianStreamGetBufferId(ns,writeBuffer,&bufferIndexRead,&getId);
sl@0
  1088
		ASSERT_TRUE(err == KErrNone);
sl@0
  1089
		
sl@0
  1090
		err = SymbianStreamGetBufferPointer(ns,readBuffer,reinterpret_cast<void**>(&pReadBuffer));
sl@0
  1091
		ASSERT_TRUE(err == KErrNone);
sl@0
  1092
		ASSERT_NOT_NULL(pReadBuffer);
sl@0
  1093
		
sl@0
  1094
		err = SymbianStreamReleaseReadBuffer(ns,readBuffer);
sl@0
  1095
		ASSERT_TRUE(err == KErrNone);
sl@0
  1096
		
sl@0
  1097
		// Life-cycle checks
sl@0
  1098
		ASSERT_EQUALS(bufferIndexWrite, bufferIndexRead)
sl@0
  1099
		ASSERT_SAME(pWriteBuffer, pReadBuffer);
sl@0
  1100
		
sl@0
  1101
		if (count > 0)
sl@0
  1102
			{
sl@0
  1103
			ASSERT_NOT_SAME(pWriteBuffer, pPrevWriteBuffer);
sl@0
  1104
			}
sl@0
  1105
		
sl@0
  1106
		pPrevWriteBuffer = pWriteBuffer;
sl@0
  1107
		}	
sl@0
  1108
sl@0
  1109
	// The next acquire write/reads should return the first buffer (0).
sl@0
  1110
sl@0
  1111
	err = SymbianStreamAcquireWriteBuffer(ns,&finalWriteBuffer);
sl@0
  1112
	ASSERT_TRUE(err == KErrNone);
sl@0
  1113
	err = SymbianStreamGetBufferId(ns,finalWriteBuffer,&bufferIndexWriteFinal,&getId);
sl@0
  1114
	ASSERT_TRUE(err == KErrNone);
sl@0
  1115
	err = SymbianStreamReleaseWriteBuffer(ns,finalWriteBuffer);
sl@0
  1116
	ASSERT_TRUE(err == KErrNone);
sl@0
  1117
	
sl@0
  1118
	// Final checks
sl@0
  1119
	ASSERT_EQUALS(bufferIndexWriteFinal, bufferIndexWriteFirst);
sl@0
  1120
	
sl@0
  1121
	SymbianStreamRemoveReference(ns);
sl@0
  1122
	
sl@0
  1123
	CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
sl@0
  1124
	}
sl@0
  1125
sl@0
  1126
/**
sl@0
  1127
@SYMTestCaseID			GFX_OPENWFC_NATIVESTREAM_0105
sl@0
  1128
@SYMTestCaseDesc		Create a native stream and acquire a write buffer which is written to (single threaded test)
sl@0
  1129
@SYMREQ					
sl@0
  1130
@SYMPREQ				PREQ2400
sl@0
  1131
@SYMTestType			CT
sl@0
  1132
@SYMTestPriority		
sl@0
  1133
@SYMTestPurpose			Verify native stream buffers can be written to and read from.
sl@0
  1134
@SYMTestActions	
sl@0
  1135
		Create a surface and fill it Red
sl@0
  1136
		Create a native stream surface with the same surface properties (size, pixel format etc.)
sl@0
  1137
		Acquire the native stream write buffer
sl@0
  1138
		Fill the native stream surface Red
sl@0
  1139
		Release the write buffer
sl@0
  1140
		Acquire the native stream read buffer
sl@0
  1141
		Compare the pixel data of the surface to the native stream surface
sl@0
  1142
		Fill the Blue
sl@0
  1143
		Compare the pixel data of the surface to the native stream surface
sl@0
  1144
@SYMTestExpectedResults
sl@0
  1145
		The surface pixel data is the same as the native stream surface pixel data
sl@0
  1146
		After the surface pixel data is changed to Blue, the native stream surface should not be the same
sl@0
  1147
 **/
sl@0
  1148
void CTestNativeStream::GRAPHICS_OPENWFC_NATIVESTREAM_0105L(TInt aNumBuffers)
sl@0
  1149
	{
sl@0
  1150
	RHeap* mainHeap = COpenWfcStreamMap::InstanceL().GetMainHeap();
sl@0
  1151
	TRAPD(err, GrowCleanupStackL());
sl@0
  1152
	ASSERT_TRUE(err == KErrNone);
sl@0
  1153
	
sl@0
  1154
	// Surface properties
sl@0
  1155
	TSize surfaceSize(TSize(100,100));
sl@0
  1156
	
sl@0
  1157
	// Create the comparison surface and fill it Red
sl@0
  1158
	TSurfaceId surface;
sl@0
  1159
	TRAP(err, surface = iUtility->CreateSurfaceL(TSize(surfaceSize.iWidth,surfaceSize.iHeight), 
sl@0
  1160
			EUidPixelFormatXRGB_8888, surfaceSize.iWidth * 4));
sl@0
  1161
	
sl@0
  1162
	TRAP(err, iUtility->FillSurfaceL(surface, 0, KRgbRed));
sl@0
  1163
	
sl@0
  1164
	// Native stream
sl@0
  1165
	khronos_int32_t width = surfaceSize.iWidth;
sl@0
  1166
	khronos_int32_t height = surfaceSize.iHeight;
sl@0
  1167
	
sl@0
  1168
	OWF_IMAGE_FORMAT pixelFormatXRGB888 =
sl@0
  1169
		{
sl@0
  1170
		OWF_IMAGE_XRGB8888,
sl@0
  1171
	    ETrue,
sl@0
  1172
	    EFalse,
sl@0
  1173
	    4
sl@0
  1174
	    };	
sl@0
  1175
	
sl@0
  1176
	CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
sl@0
  1177
	
sl@0
  1178
	SymbianStreamType ns1=helperCreateImageStream(width,
sl@0
  1179
													height,
sl@0
  1180
													&pixelFormatXRGB888,
sl@0
  1181
													aNumBuffers);
sl@0
  1182
	ASSERT_TRUE(ns1);
sl@0
  1183
	
sl@0
  1184
	
sl@0
  1185
    SymbianStreamBuffer bufferHandle;
sl@0
  1186
    err = SymbianStreamAcquireReadBuffer(ns1,&bufferHandle);
sl@0
  1187
    ASSERT_TRUE(err == KErrNone);
sl@0
  1188
    long bufferIndex;
sl@0
  1189
    const TSurfaceId* nSurface = NULL;
sl@0
  1190
    err = SymbianStreamGetBufferId(ns1,bufferHandle,&bufferIndex,&nSurface);
sl@0
  1191
    ASSERT_TRUE(err == KErrNone);
sl@0
  1192
    err = SymbianStreamReleaseReadBuffer(ns1,bufferHandle);
sl@0
  1193
    ASSERT_TRUE(err == KErrNone);
sl@0
  1194
	ASSERT_NOT_NULL(nSurface);
sl@0
  1195
	
sl@0
  1196
	TSurfaceId* nsSurface = const_cast<TSurfaceId*>(nSurface);
sl@0
  1197
	
sl@0
  1198
	// Acquire write buffer. With 3 buffers we should return buffer 1
sl@0
  1199
	khronos_int32_t writeBuffer1;
sl@0
  1200
	err = SymbianStreamAcquireWriteBuffer(ns1,&writeBuffer1);
sl@0
  1201
	ASSERT_TRUE(err == KErrNone);
sl@0
  1202
	
sl@0
  1203
	TUint8 *pWriteBuffer1 = NULL;
sl@0
  1204
	err = SymbianStreamGetBufferPointer(ns1,writeBuffer1,reinterpret_cast<void**>(&pWriteBuffer1));
sl@0
  1205
	ASSERT_TRUE(err == KErrNone);
sl@0
  1206
	ASSERT_NOT_NULL(pWriteBuffer1);
sl@0
  1207
	
sl@0
  1208
	TRAP(err, iUtility->FillNativeStreamSurfaceL(*nsSurface, pWriteBuffer1, KRgbRed));
sl@0
  1209
	
sl@0
  1210
	err = SymbianStreamReleaseWriteBuffer(ns1, writeBuffer1);
sl@0
  1211
	ASSERT_TRUE(err == KErrNone);
sl@0
  1212
	
sl@0
  1213
	// Now we should compare to see if the pixels are the same
sl@0
  1214
	khronos_int32_t readBuffer1;
sl@0
  1215
	err = SymbianStreamAcquireReadBuffer(ns1,&readBuffer1);
sl@0
  1216
	ASSERT_TRUE(err == KErrNone);
sl@0
  1217
	
sl@0
  1218
	TUint8 *pReadBuffer1 = NULL;
sl@0
  1219
	err = SymbianStreamGetBufferPointer(ns1,readBuffer1,reinterpret_cast<void**>(&pReadBuffer1));
sl@0
  1220
	ASSERT_TRUE(err == KErrNone);
sl@0
  1221
	ASSERT_NOT_NULL(pReadBuffer1);
sl@0
  1222
	CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
sl@0
  1223
	ASSERT_TRUE(iUtility->CompareSurfacesL(surface, 0, *nsSurface, pReadBuffer1));	
sl@0
  1224
	
sl@0
  1225
	// Finally, change the surface to blue. The pixels should now be different
sl@0
  1226
	TRAP(err, iUtility->FillSurfaceL(surface, 0, KRgbBlue));
sl@0
  1227
	ASSERT_FALSE(iUtility->CompareSurfacesL(surface, 0, *nsSurface, pReadBuffer1));	
sl@0
  1228
	
sl@0
  1229
	CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
sl@0
  1230
	err = SymbianStreamReleaseReadBuffer(ns1,readBuffer1);
sl@0
  1231
	ASSERT_TRUE(err == KErrNone);
sl@0
  1232
	SymbianStreamRemoveReference(ns1);
sl@0
  1233
	CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
sl@0
  1234
	}
sl@0
  1235
sl@0
  1236
/**
sl@0
  1237
@SYMTestCaseID			GFX_OPENWFC_NATIVESTREAM_0106
sl@0
  1238
@SYMTestCaseDesc		Negative test - Attempt to acquire a write buffer when the write buffer has not been released (single threaded test)
sl@0
  1239
@SYMREQ					
sl@0
  1240
@SYMPREQ				PREQ2400
sl@0
  1241
@SYMTestType			CT
sl@0
  1242
@SYMTestPriority		
sl@0
  1243
@SYMTestPurpose			Verify an invalid handle is returned to the calling thread if the write buffer has not been released
sl@0
  1244
@SYMTestActions	
sl@0
  1245
		Create a native stream surface with 1 buffer
sl@0
  1246
		Acquire the native stream write buffer
sl@0
  1247
		Acquire the native stream write buffer again
sl@0
  1248
@SYMTestExpectedResults
sl@0
  1249
		The 2nd acquire write buffer call should return OWF_INVALID_HANDLE if not single buffered.
sl@0
  1250
 **/
sl@0
  1251
void CTestNativeStream::GRAPHICS_OPENWFC_NATIVESTREAM_0106L(TInt aNumBuffers)
sl@0
  1252
	{
sl@0
  1253
	RHeap* mainHeap = COpenWfcStreamMap::InstanceL().GetMainHeap();
sl@0
  1254
	TRAPD(err, GrowCleanupStackL());
sl@0
  1255
	ASSERT_TRUE(err == KErrNone);
sl@0
  1256
sl@0
  1257
	CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
sl@0
  1258
	
sl@0
  1259
	// Create the first stream (ARGB_8888_PRE)
sl@0
  1260
	TSize surfaceSize(TSize(100,100));
sl@0
  1261
	khronos_int32_t width = surfaceSize.iWidth;
sl@0
  1262
	khronos_int32_t height = surfaceSize.iHeight;
sl@0
  1263
	
sl@0
  1264
	OWF_IMAGE_FORMAT pixelFormatARGB888Pre =
sl@0
  1265
		{
sl@0
  1266
		OWF_IMAGE_ARGB8888,
sl@0
  1267
	    ETrue,
sl@0
  1268
	    EFalse,
sl@0
  1269
	    4
sl@0
  1270
	    };	
sl@0
  1271
	
sl@0
  1272
	SymbianStreamType ns1=helperCreateImageStream(width,
sl@0
  1273
													height,
sl@0
  1274
													&pixelFormatARGB888Pre,
sl@0
  1275
													aNumBuffers);
sl@0
  1276
	ASSERT_TRUE(ns1);
sl@0
  1277
	
sl@0
  1278
	// Acquire write buffer. With just 1 buffer we should return buffer 0
sl@0
  1279
	khronos_int32_t writeBuffer1;
sl@0
  1280
	err = SymbianStreamAcquireWriteBuffer(ns1,&writeBuffer1);
sl@0
  1281
	ASSERT_TRUE(err != KErrBadHandle);
sl@0
  1282
	
sl@0
  1283
	// Try and acquire the write buffer again before we have released it
sl@0
  1284
	khronos_int32_t writeBuffer2;
sl@0
  1285
	err = SymbianStreamAcquireWriteBuffer(ns1,&writeBuffer2);
sl@0
  1286
	ASSERT_TRUE(err != KErrBadHandle);
sl@0
  1287
	if (aNumBuffers == 1)
sl@0
  1288
	    {
sl@0
  1289
	    ASSERT_EQUALS(writeBuffer2, writeBuffer1); 	    
sl@0
  1290
	    }
sl@0
  1291
	else
sl@0
  1292
	    {
sl@0
  1293
	    ASSERT_EQUALS(writeBuffer2, (khronos_int32_t)0); 	    
sl@0
  1294
	    }
sl@0
  1295
	
sl@0
  1296
	err = SymbianStreamReleaseWriteBuffer(ns1,writeBuffer1);
sl@0
  1297
	ASSERT_TRUE(err != KErrBadHandle);
sl@0
  1298
	
sl@0
  1299
	err = SymbianStreamAcquireWriteBuffer(ns1, &writeBuffer2);
sl@0
  1300
	ASSERT_TRUE(err != KErrBadHandle);
sl@0
  1301
	TUint8 *pWriteBuffer2 = NULL;
sl@0
  1302
	err = SymbianStreamGetBufferPointer(ns1,writeBuffer2,reinterpret_cast<void**>(&pWriteBuffer2));
sl@0
  1303
	ASSERT_TRUE(err != KErrBadHandle);
sl@0
  1304
	ASSERT_NOT_NULL(pWriteBuffer2);
sl@0
  1305
	
sl@0
  1306
	SymbianStreamRemoveReference(ns1);
sl@0
  1307
	
sl@0
  1308
	CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
sl@0
  1309
	}
sl@0
  1310
sl@0
  1311
/**
sl@0
  1312
@SYMTestCaseID			GFX_OPENWFC_NATIVESTREAM_0107
sl@0
  1313
@SYMTestCaseDesc		Attempt to acquire a write buffer when the write buffer has not been released (multi threaded tests)
sl@0
  1314
@SYMREQ					
sl@0
  1315
@SYMPREQ				PREQ2400
sl@0
  1316
@SYMTestType			CT
sl@0
  1317
@SYMTestPriority		
sl@0
  1318
@SYMTestPurpose			Verify an invalid handle is returned to the calling thread if the write buffer has not been released
sl@0
  1319
@SYMTestActions	
sl@0
  1320
		Create a shared native stream surface to be used by multiple threads
sl@0
  1321
		Thread 1 acquires the shared native stream and acquires the write buffer
sl@0
  1322
		Thread 2 acquires the shared native stream and attempts to acquire the write buffer
sl@0
  1323
		Thread 3 acquires the shared native stream and attempts to acquire the write buffer
sl@0
  1324
		Thread 1 releases the write buffer
sl@0
  1325
		Thread 2 acquires the write buffer
sl@0
  1326
		Thread 2 releases the write buffer
sl@0
  1327
@SYMTestExpectedResults
sl@0
  1328
		OWF_INVALID_HANDLE returned when Thread 2 and Thread 3 attempt to acquire the write buffer
sl@0
  1329
		when Thread 1 has already acquired it
sl@0
  1330
 **/
sl@0
  1331
void CTestNativeStream::GRAPHICS_OPENWFC_NATIVESTREAM_0107_1L()
sl@0
  1332
	{
sl@0
  1333
    RHeap* mainHeap = COpenWfcStreamMap::InstanceL().GetMainHeap();
sl@0
  1334
    TRAPD(err, GrowCleanupStackL());
sl@0
  1335
    ASSERT_TRUE(err == KErrNone);
sl@0
  1336
        
sl@0
  1337
    CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
sl@0
  1338
	INFO_PRINTF2(_L("** GRAPHICS_OPENWFC_NATIVESTREAM_0107 - %i buffers **"), gVarInstance.Buffers());
sl@0
  1339
	INFO_PRINTF1(_L("Thread 1 - start"));
sl@0
  1340
	TSurfaceId surface = gVarInstance.SurfaceID();
sl@0
  1341
	SymbianStreamType ns;
sl@0
  1342
	err = SymbianStreamAcquire(&surface,&ns);
sl@0
  1343
	ASSERT_TRUE(err == KErrNone);
sl@0
  1344
	ASSERT_TRUE(ns);
sl@0
  1345
	
sl@0
  1346
	khronos_int32_t writeBuffer1;
sl@0
  1347
	err = SymbianStreamAcquireWriteBuffer(ns,&writeBuffer1);
sl@0
  1348
	ASSERT_TRUE(err != KErrBadHandle);
sl@0
  1349
	
sl@0
  1350
	khronos_int32_t bufferIndex;
sl@0
  1351
	const TSurfaceId* getId = NULL;
sl@0
  1352
	err = SymbianStreamGetBufferId(ns,writeBuffer1,&bufferIndex,&getId);
sl@0
  1353
	ASSERT_TRUE(err == KErrNone);
sl@0
  1354
	ASSERT_EQUALS(*getId, surface);
sl@0
  1355
	ASSERT_EQUALS(bufferIndex, (khronos_int32_t)1);
sl@0
  1356
	INFO_PRINTF2(_L("Thread 1 - Write buffer %i acquired"), bufferIndex);
sl@0
  1357
	
sl@0
  1358
	gSemaphore.Signal(2); // Thread 2 and 3 ready to run
sl@0
  1359
	
sl@0
  1360
	gSemaphore2.Wait();
sl@0
  1361
    gSemaphore2.Wait();     // Wait for both threads to signal
sl@0
  1362
	err = SymbianStreamReleaseWriteBuffer(ns,writeBuffer1);
sl@0
  1363
	ASSERT_TRUE(err == KErrNone);
sl@0
  1364
	SymbianStreamRemoveReference(ns);
sl@0
  1365
	INFO_PRINTF2(_L("Thread 1 - Write buffer %i released"), bufferIndex);
sl@0
  1366
sl@0
  1367
	gSemaphore.Signal();	
sl@0
  1368
    CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one    
sl@0
  1369
	}
sl@0
  1370
sl@0
  1371
void CTestNativeStream::GRAPHICS_OPENWFC_NATIVESTREAM_0107_2L()
sl@0
  1372
	{
sl@0
  1373
    RHeap* mainHeap = COpenWfcStreamMap::InstanceL().GetMainHeap();
sl@0
  1374
    TRAPD(err, GrowCleanupStackL());
sl@0
  1375
    ASSERT_TRUE(err == KErrNone);
sl@0
  1376
        
sl@0
  1377
    CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
sl@0
  1378
	gSemaphore.Wait(); // Semaphore count becomes -1
sl@0
  1379
	INFO_PRINTF1(_L("Thread 2 - Start"));
sl@0
  1380
	TSurfaceId surface = gVarInstance.SurfaceID();
sl@0
  1381
	SymbianStreamType ns;
sl@0
  1382
	err = SymbianStreamAcquire(&surface,&ns);
sl@0
  1383
	ASSERT_TRUE(err == KErrNone);
sl@0
  1384
	ASSERT_TRUE(ns);
sl@0
  1385
sl@0
  1386
	khronos_int32_t writeBuffer1;
sl@0
  1387
	err = SymbianStreamAcquireWriteBuffer(ns,&writeBuffer1);
sl@0
  1388
	ASSERT_TRUE(err != KErrBadHandle);
sl@0
  1389
	INFO_PRINTF1(_L("Thread 2 - Attempt to acquire the write buffer"));
sl@0
  1390
	ASSERT_FALSE(writeBuffer1);
sl@0
  1391
	INFO_PRINTF1(_L("Thread 2 - Write buffer already in use by Thread 1!"));
sl@0
  1392
    
sl@0
  1393
	gSemaphore2.Signal();
sl@0
  1394
	
sl@0
  1395
	gSemaphore.Wait();
sl@0
  1396
	
sl@0
  1397
	khronos_int32_t writeBuffer2;
sl@0
  1398
	err = SymbianStreamAcquireWriteBuffer(ns,&writeBuffer2);
sl@0
  1399
	ASSERT_TRUE(err != KErrBadHandle);
sl@0
  1400
	khronos_int32_t bufferIndex;
sl@0
  1401
	const TSurfaceId* getId = NULL;
sl@0
  1402
	err = SymbianStreamGetBufferId(ns,writeBuffer2,&bufferIndex,&getId);
sl@0
  1403
	ASSERT_TRUE(err == KErrNone);
sl@0
  1404
	ASSERT_FALSE(bufferIndex);
sl@0
  1405
	INFO_PRINTF2(_L("Thread 2 - Write buffer %i acquired"), bufferIndex);
sl@0
  1406
	
sl@0
  1407
	err = SymbianStreamReleaseWriteBuffer(ns,writeBuffer2);
sl@0
  1408
	ASSERT_TRUE(err == KErrNone);
sl@0
  1409
	SymbianStreamRemoveReference(ns);
sl@0
  1410
	INFO_PRINTF2(_L("Thread 2 - Write buffer %i released"), bufferIndex);
sl@0
  1411
    CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one    
sl@0
  1412
	}
sl@0
  1413
sl@0
  1414
void CTestNativeStream::GRAPHICS_OPENWFC_NATIVESTREAM_0107_3L()
sl@0
  1415
	{
sl@0
  1416
    RHeap* mainHeap = COpenWfcStreamMap::InstanceL().GetMainHeap();
sl@0
  1417
    TRAPD(err, GrowCleanupStackL());
sl@0
  1418
    ASSERT_TRUE(err == KErrNone);
sl@0
  1419
        
sl@0
  1420
    CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
sl@0
  1421
	gSemaphore.Wait(); // Semaphore count is -2
sl@0
  1422
	INFO_PRINTF1(_L("Thread 3 - start"));
sl@0
  1423
	TSurfaceId surface = gVarInstance.SurfaceID();
sl@0
  1424
	SymbianStreamType ns;
sl@0
  1425
	err = SymbianStreamAcquire(&surface,&ns);
sl@0
  1426
	ASSERT_TRUE(err == KErrNone);
sl@0
  1427
	ASSERT_TRUE(ns);
sl@0
  1428
sl@0
  1429
 	khronos_int32_t writeBuffer1;
sl@0
  1430
 	err = SymbianStreamAcquireWriteBuffer(ns,&writeBuffer1);
sl@0
  1431
 	ASSERT_TRUE(err != KErrBadHandle);
sl@0
  1432
 	INFO_PRINTF1(_L("Thread 3 - Attempt to acquire the write buffer"));
sl@0
  1433
	ASSERT_FALSE(writeBuffer1);
sl@0
  1434
	INFO_PRINTF1(_L("Thread 3 - Write buffer already in use by Thread 1!"));
sl@0
  1435
sl@0
  1436
    gSemaphore2.Signal();
sl@0
  1437
sl@0
  1438
    SymbianStreamRemoveReference(ns);
sl@0
  1439
    CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one    
sl@0
  1440
	}
sl@0
  1441
sl@0
  1442
sl@0
  1443
/**
sl@0
  1444
@SYMTestCaseID			GFX_OPENWFC_NATIVESTREAM_0108
sl@0
  1445
@SYMTestCaseDesc		Content updates on valid and invalid buffers
sl@0
  1446
@SYMREQ					
sl@0
  1447
@SYMPREQ				PREQ2400
sl@0
  1448
@SYMTestType			CT
sl@0
  1449
@SYMTestPriority		
sl@0
  1450
@SYMTestPurpose			Verify native streams can handle content updates for valid and invalid buffer numbers
sl@0
  1451
@SYMTestActions	
sl@0
  1452
		Create a surface with 4 buffers,
sl@0
  1453
		Create a stream from this surface,
sl@0
  1454
		Add an observer to listen out for content updates to the stream,
sl@0
  1455
		Set valid and invalid buffer numbers to be used in content updates
sl@0
  1456
@SYMTestExpectedResults
sl@0
  1457
		For valid buffers, the read buffers should be set correctly and observer 
sl@0
  1458
		callback method is called.
sl@0
  1459
 **/		
sl@0
  1460
void CTestNativeStream::GRAPHICS_OPENWFC_NATIVESTREAM_0108L(TInt aBuffers)
sl@0
  1461
	{
sl@0
  1462
	aBuffers = 3;
sl@0
  1463
	RHeap* mainHeap = COpenWfcStreamMap::InstanceL().GetMainHeap();
sl@0
  1464
	TRAPD(err, GrowCleanupStackL());
sl@0
  1465
	ASSERT_TRUE(err == KErrNone);
sl@0
  1466
sl@0
  1467
	iScreenNo = 0;
sl@0
  1468
	TInt localNumber = 0;
sl@0
  1469
	
sl@0
  1470
	TSurfaceId surface=iUtility->CreateSurfaceL(TSize(100,100), EUidPixelFormatARGB_8888_PRE, 400, aBuffers);
sl@0
  1471
	ASSERT_FALSE(surface.IsNull());
sl@0
  1472
	
sl@0
  1473
	CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
sl@0
  1474
	SymbianStreamType ns;
sl@0
  1475
	err = SymbianStreamAcquire(&surface,&ns);
sl@0
  1476
    ASSERT_TRUE(err == KErrNone);
sl@0
  1477
	ASSERT_TRUE(ns);
sl@0
  1478
	
sl@0
  1479
	err = SymbianStreamAddObserver(ns, TestUpdateCallback, &localNumber);
sl@0
  1480
	ASSERT_TRUE(err == KErrNone);
sl@0
  1481
	khronos_int32_t bufferIndex = 0; 
sl@0
  1482
	khronos_int32_t buffersIndex = 0;
sl@0
  1483
	khronos_int32_t lastValidBufnum = 0;
sl@0
  1484
	
sl@0
  1485
	const TSurfaceId* getId = NULL;
sl@0
  1486
    CExtensionContainer* updateExtension = NULL;
sl@0
  1487
    err = SymbianStreamHasRegisteredScreenNotifications(iScreenNo,reinterpret_cast<void**>(&updateExtension));
sl@0
  1488
    ASSERT_TRUE(err == KErrNone);
sl@0
  1489
    MCompositionSurfaceUpdate* updateProxy=updateExtension->GetInterface<MCompositionSurfaceUpdate>();
sl@0
  1490
    ASSERT_NOT_NULL(updateProxy);
sl@0
  1491
	// Valid inputs
sl@0
  1492
	for (TInt i = 0; i < aBuffers; ++i)
sl@0
  1493
		{
sl@0
  1494
		buffersIndex = (aBuffers + i) % aBuffers;
sl@0
  1495
sl@0
  1496
 		
sl@0
  1497
        updateProxy->ContentUpdated(surface,                    //aSurface
sl@0
  1498
                                    buffersIndex,               //aBuffer
sl@0
  1499
                                    NULL,                       //aRegion
sl@0
  1500
                                    NULL,                       //aStatusConsumed
sl@0
  1501
                                    NULL,                       //aStatusDisplayed
sl@0
  1502
                                    NULL,                       //aTimeStamp
sl@0
  1503
                                    NULL,                       //aStatusDispXTimes
sl@0
  1504
                                    NULL                        //aDisplayedXTimes
sl@0
  1505
                                    );	
sl@0
  1506
		
sl@0
  1507
		// The test can pass without a delay when running locally, but fails on ONB. Insert a delay here temporarily to see if it makes any difference
sl@0
  1508
        User::After(10000); //10 ms delay
sl@0
  1509
		khronos_int32_t readBuffer;
sl@0
  1510
		err = SymbianStreamAcquireReadBuffer(ns,&readBuffer);
sl@0
  1511
		ASSERT_TRUE(err == KErrNone);
sl@0
  1512
		err = SymbianStreamGetBufferId(ns,readBuffer,&bufferIndex,&getId);
sl@0
  1513
		ASSERT_TRUE(err == KErrNone);
sl@0
  1514
		err = SymbianStreamReleaseReadBuffer(ns, readBuffer);
sl@0
  1515
		ASSERT_TRUE(err == KErrNone);
sl@0
  1516
		ASSERT_TRUE(bufferIndex == buffersIndex);
sl@0
  1517
		
sl@0
  1518
        // The test can pass without a delay when running locally, but fails on ONB. Insert a delay here temporarily to see if it makes any difference
sl@0
  1519
        User::After(10000); //10 ms delay
sl@0
  1520
		ASSERT_EQUALS((i+1),localNumber);
sl@0
  1521
		}
sl@0
  1522
	
sl@0
  1523
	// Reset number for negative tests
sl@0
  1524
	localNumber = 0;
sl@0
  1525
	lastValidBufnum = buffersIndex;
sl@0
  1526
	
sl@0
  1527
	// Invalid inputs
sl@0
  1528
	TInt invalidBuffersIndex[] = {-1, -256, aBuffers+29, 10000, -10000, aBuffers};
sl@0
  1529
	TInt size = sizeof(invalidBuffersIndex) / sizeof(invalidBuffersIndex[0]);
sl@0
  1530
	
sl@0
  1531
	for (TInt i = 0; i < size; ++i)
sl@0
  1532
		{
sl@0
  1533
		updateProxy->ContentUpdated(surface,                    //aSurface
sl@0
  1534
                                    invalidBuffersIndex[i],     //aBuffer
sl@0
  1535
                                    NULL,                       //aRegion
sl@0
  1536
                                    NULL,                       //aStatusConsumed
sl@0
  1537
                                    NULL,                       //aStatusDisplayed
sl@0
  1538
                                    NULL,                       //aTimeStamp
sl@0
  1539
                                    NULL,                       //aStatusDispXTimes
sl@0
  1540
                                    NULL                        //aDisplayedXTimes
sl@0
  1541
                                    );
sl@0
  1542
        
sl@0
  1543
		User::After(10000); //10 ms delay
sl@0
  1544
		khronos_int32_t readBuffer;
sl@0
  1545
		err = SymbianStreamAcquireReadBuffer(ns,&readBuffer);
sl@0
  1546
		ASSERT_TRUE(err == KErrNone);
sl@0
  1547
		err = SymbianStreamGetBufferId(ns,readBuffer,&bufferIndex,&getId);
sl@0
  1548
		ASSERT_TRUE(err == KErrNone);
sl@0
  1549
		err = SymbianStreamReleaseReadBuffer(ns, readBuffer);
sl@0
  1550
		ASSERT_TRUE(err == KErrNone);
sl@0
  1551
		ASSERT_TRUE(bufferIndex == lastValidBufnum);
sl@0
  1552
		ASSERT_EQUALS(0,localNumber);
sl@0
  1553
		}
sl@0
  1554
	SymbianStreamRemoveReference(ns);
sl@0
  1555
	CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
sl@0
  1556
	}
sl@0
  1557
sl@0
  1558
/**
sl@0
  1559
@SYMTestCaseID			GFX_OPENWFC_NATIVESTREAM_0109
sl@0
  1560
@SYMTestCaseDesc		Test multiple acquire/release read/write buffer calls
sl@0
  1561
@SYMREQ					
sl@0
  1562
@SYMPREQ				PREQ2400
sl@0
  1563
@SYMTestType			CT
sl@0
  1564
@SYMTestPriority		
sl@0
  1565
@SYMTestPurpose			Verify the buffer index is correctly set
sl@0
  1566
@SYMTestActions	
sl@0
  1567
		Create a surface with 4 buffers,
sl@0
  1568
		Call acquire/release read/write buffer functions and to Submit an update to the surface
sl@0
  1569
@SYMTestExpectedResults
sl@0
  1570
		Verify that acquire/release read/write buffer functions honour SUS update
sl@0
  1571
		Verify that the update callback function is called when the native stream is updated
sl@0
  1572
 **/		
sl@0
  1573
void CTestNativeStream::GRAPHICS_OPENWFC_NATIVESTREAM_0109L()
sl@0
  1574
	{
sl@0
  1575
	RHeap* mainHeap = COpenWfcStreamMap::InstanceL().GetMainHeap();
sl@0
  1576
	TRAPD(err, GrowCleanupStackL());
sl@0
  1577
	ASSERT_TRUE(err == KErrNone);
sl@0
  1578
	
sl@0
  1579
	iScreenNo = 0;
sl@0
  1580
	TInt localNumber = 0;
sl@0
  1581
	TInt count = 0;
sl@0
  1582
	khronos_int32_t bufferIndexRead;
sl@0
  1583
	khronos_int32_t bufferIndexWrite;
sl@0
  1584
	
sl@0
  1585
	TSurfaceId surface=iUtility->CreateSurfaceL(TSize(100,100), EUidPixelFormatARGB_8888_PRE, 400, 4);
sl@0
  1586
	ASSERT_FALSE(surface.IsNull());
sl@0
  1587
	
sl@0
  1588
	CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
sl@0
  1589
	SymbianStreamType ns;
sl@0
  1590
	err = SymbianStreamAcquire(&surface,&ns);
sl@0
  1591
	ASSERT_TRUE(err == KErrNone);
sl@0
  1592
	ASSERT_TRUE(ns);
sl@0
  1593
	
sl@0
  1594
	err = SymbianStreamAddObserver(ns, TestComposedCallback, &localNumber);
sl@0
  1595
	ASSERT_TRUE(err == KErrNone);
sl@0
  1596
	err = SymbianStreamAddObserver(ns, TestUpdateCallback, &localNumber);
sl@0
  1597
	ASSERT_TRUE(err == KErrNone);
sl@0
  1598
	
sl@0
  1599
	khronos_int32_t readBuffer1;
sl@0
  1600
	err = SymbianStreamAcquireReadBuffer(ns,&readBuffer1);
sl@0
  1601
	ASSERT_TRUE(err == KErrNone);
sl@0
  1602
	const TSurfaceId* getId = NULL;
sl@0
  1603
	err = SymbianStreamGetBufferId(ns,readBuffer1,&bufferIndexRead,&getId);
sl@0
  1604
	ASSERT_TRUE(err == KErrNone);
sl@0
  1605
	err = SymbianStreamReleaseReadBuffer(ns, readBuffer1);
sl@0
  1606
	ASSERT_TRUE(err == KErrNone);
sl@0
  1607
	ASSERT_TRUE(bufferIndexRead == 0);
sl@0
  1608
	
sl@0
  1609
	khronos_int32_t writeBuffer1;
sl@0
  1610
	err = SymbianStreamAcquireWriteBuffer(ns,&writeBuffer1);
sl@0
  1611
	ASSERT_TRUE(err == KErrNone);
sl@0
  1612
	
sl@0
  1613
	khronos_int32_t readBuffer2;
sl@0
  1614
	err = SymbianStreamAcquireReadBuffer(ns,&readBuffer2);
sl@0
  1615
	ASSERT_TRUE(err == KErrNone);
sl@0
  1616
	err = SymbianStreamGetBufferId(ns,readBuffer2,&bufferIndexRead,&getId);
sl@0
  1617
	ASSERT_TRUE(err == KErrNone);
sl@0
  1618
	err = SymbianStreamReleaseReadBuffer(ns, readBuffer2);
sl@0
  1619
	ASSERT_TRUE(err == KErrNone);
sl@0
  1620
	ASSERT_TRUE(bufferIndexRead == 0);
sl@0
  1621
	err = SymbianStreamReleaseWriteBuffer(ns,writeBuffer1);
sl@0
  1622
	ASSERT_TRUE(err == KErrNone);
sl@0
  1623
	
sl@0
  1624
	ASSERT_EQUALS((++count),localNumber);
sl@0
  1625
	
sl@0
  1626
	khronos_int32_t readBuffer3;
sl@0
  1627
	err = SymbianStreamAcquireReadBuffer(ns,&readBuffer3);
sl@0
  1628
	ASSERT_TRUE(err == KErrNone);
sl@0
  1629
	err = SymbianStreamGetBufferId(ns,readBuffer3,&bufferIndexRead,&getId);
sl@0
  1630
	ASSERT_TRUE(err == KErrNone);
sl@0
  1631
	err = SymbianStreamReleaseReadBuffer(ns, readBuffer3);
sl@0
  1632
	ASSERT_TRUE(err == KErrNone);
sl@0
  1633
	ASSERT_TRUE(bufferIndexRead == 1);
sl@0
  1634
	
sl@0
  1635
	khronos_int32_t writeBuffer2;
sl@0
  1636
	err = SymbianStreamAcquireWriteBuffer(ns,&writeBuffer2);
sl@0
  1637
	ASSERT_TRUE(err == KErrNone);
sl@0
  1638
	err = SymbianStreamGetBufferId(ns,writeBuffer2,&bufferIndexWrite,&getId);
sl@0
  1639
	ASSERT_TRUE(err == KErrNone);
sl@0
  1640
	ASSERT_TRUE((bufferIndexRead + 1) == bufferIndexWrite);
sl@0
  1641
	
sl@0
  1642
	khronos_int32_t readBuffer4;
sl@0
  1643
	err = SymbianStreamAcquireReadBuffer(ns,&readBuffer4);
sl@0
  1644
	ASSERT_TRUE(err == KErrNone);
sl@0
  1645
	err = SymbianStreamGetBufferId(ns,readBuffer4,&bufferIndexRead,&getId);
sl@0
  1646
	ASSERT_TRUE(err == KErrNone);
sl@0
  1647
	err = SymbianStreamReleaseReadBuffer(ns, readBuffer4);
sl@0
  1648
	ASSERT_TRUE(err == KErrNone);
sl@0
  1649
	ASSERT_TRUE(bufferIndexRead == (bufferIndexWrite - 1));
sl@0
  1650
sl@0
  1651
    CExtensionContainer* updateExtension = NULL;
sl@0
  1652
    err = SymbianStreamHasRegisteredScreenNotifications(iScreenNo,reinterpret_cast<void**>(&updateExtension));
sl@0
  1653
    ASSERT_TRUE(err == KErrNone);
sl@0
  1654
    MCompositionSurfaceUpdate* updateProxy=updateExtension->GetInterface<MCompositionSurfaceUpdate>();
sl@0
  1655
    ASSERT_NOT_NULL(updateProxy);
sl@0
  1656
    
sl@0
  1657
    updateProxy->ContentUpdated(surface,                    //aSurface
sl@0
  1658
                                0,                          //aBuffer
sl@0
  1659
                                NULL,                       //aRegion
sl@0
  1660
                                NULL,                       //aStatusConsumed
sl@0
  1661
                                NULL,                       //aStatusDisplayed
sl@0
  1662
                                NULL,                       //aTimeStamp
sl@0
  1663
                                NULL,                       //aStatusDispXTimes
sl@0
  1664
                                NULL                        //aDisplayedXTimes
sl@0
  1665
                                );  	
sl@0
  1666
	
sl@0
  1667
	ASSERT_EQUALS((++count),localNumber);
sl@0
  1668
	
sl@0
  1669
	khronos_int32_t readBuffer5;
sl@0
  1670
	err = SymbianStreamAcquireReadBuffer(ns,&readBuffer5);
sl@0
  1671
	ASSERT_TRUE(err == KErrNone);
sl@0
  1672
	err = SymbianStreamGetBufferId(ns,readBuffer5,&bufferIndexRead,&getId);
sl@0
  1673
	ASSERT_TRUE(err == KErrNone);
sl@0
  1674
	err = SymbianStreamReleaseReadBuffer(ns, readBuffer5);
sl@0
  1675
	ASSERT_TRUE(err == KErrNone);
sl@0
  1676
	ASSERT_TRUE(bufferIndexRead == 0);
sl@0
  1677
	err = SymbianStreamReleaseWriteBuffer(ns,writeBuffer2);
sl@0
  1678
	ASSERT_TRUE(err == KErrNone);
sl@0
  1679
	
sl@0
  1680
	ASSERT_EQUALS((++count),localNumber);
sl@0
  1681
	
sl@0
  1682
	khronos_int32_t readBuffer6;
sl@0
  1683
	err = SymbianStreamAcquireReadBuffer(ns,&readBuffer6);
sl@0
  1684
	ASSERT_TRUE(err == KErrNone);
sl@0
  1685
	err = SymbianStreamGetBufferId(ns,readBuffer6,&bufferIndexRead,&getId);
sl@0
  1686
	ASSERT_TRUE(err == KErrNone);
sl@0
  1687
	err = SymbianStreamReleaseReadBuffer(ns, readBuffer6);
sl@0
  1688
	ASSERT_TRUE(err == KErrNone);
sl@0
  1689
	ASSERT_TRUE(bufferIndexRead == 0);
sl@0
  1690
	
sl@0
  1691
	khronos_int32_t writeBuffer3;
sl@0
  1692
	err = SymbianStreamAcquireWriteBuffer(ns,&writeBuffer3);
sl@0
  1693
	ASSERT_TRUE(err == KErrNone);
sl@0
  1694
	err = SymbianStreamGetBufferId(ns,writeBuffer3,&bufferIndexWrite,&getId);
sl@0
  1695
	ASSERT_TRUE(err == KErrNone);
sl@0
  1696
	ASSERT_TRUE(bufferIndexWrite == 1);
sl@0
  1697
	err = SymbianStreamReleaseWriteBuffer(ns,writeBuffer3);
sl@0
  1698
	ASSERT_TRUE(err == KErrNone);
sl@0
  1699
	
sl@0
  1700
	khronos_int32_t readBuffer7;
sl@0
  1701
	err = SymbianStreamAcquireReadBuffer(ns,&readBuffer7);
sl@0
  1702
	ASSERT_TRUE(err == KErrNone);
sl@0
  1703
	err = SymbianStreamGetBufferId(ns,readBuffer7,&bufferIndexRead,&getId);
sl@0
  1704
	ASSERT_TRUE(err == KErrNone);
sl@0
  1705
	err = SymbianStreamReleaseReadBuffer(ns, readBuffer7);
sl@0
  1706
	ASSERT_TRUE(err == KErrNone);
sl@0
  1707
	ASSERT_TRUE(bufferIndexRead == 1);
sl@0
  1708
	
sl@0
  1709
	SymbianStreamRemoveReference(ns);
sl@0
  1710
	CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
sl@0
  1711
	}
sl@0
  1712
sl@0
  1713
/**
sl@0
  1714
@SYMTestCaseID			GFX_OPENWFC_NATIVESTREAM_0110
sl@0
  1715
@SYMTestCaseDesc		Verify that the update observer callback function is called after a
sl@0
  1716
                        acquireWriteBuffer/releaseWriteBuffer call.
sl@0
  1717
@SYMREQ					
sl@0
  1718
@SYMPREQ				PREQ2400
sl@0
  1719
@SYMTestType			CT
sl@0
  1720
@SYMTestPriority		
sl@0
  1721
@SYMTestPurpose			
sl@0
  1722
@SYMTestActions	
sl@0
  1723
		Create a surface with 1 buffer
sl@0
  1724
		Add an observer to listen out for content updates to the stream
sl@0
  1725
		Call acquire/release write buffer functions
sl@0
  1726
@SYMTestExpectedResults
sl@0
  1727
		Verify that the release write buffer function notifies any observers listening and the 
sl@0
  1728
		observer callback function is called.
sl@0
  1729
 **/		
sl@0
  1730
void CTestNativeStream::GRAPHICS_OPENWFC_NATIVESTREAM_0110L()
sl@0
  1731
	{
sl@0
  1732
	RHeap* mainHeap = COpenWfcStreamMap::InstanceL().GetMainHeap();
sl@0
  1733
	TRAPD(err, GrowCleanupStackL());
sl@0
  1734
	ASSERT_TRUE(err == KErrNone);
sl@0
  1735
	
sl@0
  1736
	TInt localNumber = 0;
sl@0
  1737
	
sl@0
  1738
	TSurfaceId surface=iUtility->CreateSurfaceL(TSize(100,100), EUidPixelFormatARGB_8888_PRE, 400, 1);
sl@0
  1739
	ASSERT_FALSE(surface.IsNull());
sl@0
  1740
	
sl@0
  1741
	CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
sl@0
  1742
	SymbianStreamType ns;
sl@0
  1743
	err = SymbianStreamAcquire(&surface,&ns);
sl@0
  1744
	ASSERT_TRUE(err == KErrNone);
sl@0
  1745
	ASSERT_TRUE(ns);
sl@0
  1746
	
sl@0
  1747
	err = SymbianStreamAddObserver(ns, TestComposedCallback, &localNumber);
sl@0
  1748
	ASSERT_TRUE(err == KErrNone);
sl@0
  1749
	
sl@0
  1750
	khronos_int32_t writeBuffer1;
sl@0
  1751
	err = SymbianStreamAcquireWriteBuffer(ns,&writeBuffer1);
sl@0
  1752
	ASSERT_TRUE(err == KErrNone);
sl@0
  1753
	err = SymbianStreamReleaseWriteBuffer(ns,writeBuffer1);
sl@0
  1754
	ASSERT_TRUE(err == KErrNone);
sl@0
  1755
	
sl@0
  1756
	if (localNumber == 0)
sl@0
  1757
		{
sl@0
  1758
		User::After(1000000);
sl@0
  1759
		}
sl@0
  1760
	
sl@0
  1761
	ASSERT_TRUE(localNumber == 1);    
sl@0
  1762
	SymbianStreamRemoveReference(ns);
sl@0
  1763
	CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
sl@0
  1764
	}
sl@0
  1765
sl@0
  1766
/**
sl@0
  1767
@SYMTestCaseID          GFX_OPENWFC_NATIVESTREAM_0111
sl@0
  1768
@SYMTestCaseDesc        Tests various cases including some negative cases for Native Stream callbacks
sl@0
  1769
@SYMREQ                 
sl@0
  1770
@SYMPREQ                PREQ2400
sl@0
  1771
@SYMTestType            CT
sl@0
  1772
@SYMTestPriority        
sl@0
  1773
@SYMTestPurpose         
sl@0
  1774
@SYMTestActions 
sl@0
  1775
        Create a surface with 1 buffer
sl@0
  1776
        Add an observer N times
sl@0
  1777
        Remove the same observer M (M <= N) times
sl@0
  1778
        Register Null observer
sl@0
  1779
        Unregister something that was never registered
sl@0
  1780
@SYMTestExpectedResults
sl@0
  1781
        Verify that the observer is called (N - M) times
sl@0
  1782
        Verify that error case behaviour is correct
sl@0
  1783
 **/        
sl@0
  1784
void CTestNativeStream::GRAPHICS_OPENWFC_NATIVESTREAM_0111L()
sl@0
  1785
    {
sl@0
  1786
    RHeap* mainHeap = COpenWfcStreamMap::InstanceL().GetMainHeap();
sl@0
  1787
    TRAPD(err, GrowCleanupStackL());
sl@0
  1788
    ASSERT_TRUE(err == KErrNone);
sl@0
  1789
    
sl@0
  1790
    iScreenNo = 0;
sl@0
  1791
    
sl@0
  1792
    TSurfaceId surface=iUtility->CreateSurfaceL(TSize(100,100), EUidPixelFormatARGB_8888_PRE, 400, 1);
sl@0
  1793
    ASSERT_FALSE(surface.IsNull());
sl@0
  1794
    
sl@0
  1795
    CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
sl@0
  1796
    SymbianStreamType ns;
sl@0
  1797
    err = SymbianStreamAcquire(&surface,&ns);
sl@0
  1798
    ASSERT_TRUE(err == KErrNone);    
sl@0
  1799
    ASSERT_TRUE(ns);
sl@0
  1800
    
sl@0
  1801
    TInt localNumber = 0;
sl@0
  1802
    err = SymbianStreamAddObserver(ns, NULL, &localNumber);
sl@0
  1803
    ASSERT_TRUE(err == KErrBadHandle);
sl@0
  1804
    err = SymbianStreamRemoveObserver(ns, &localNumber, ESOWF_EventComposed);
sl@0
  1805
    ASSERT_TRUE(err == KErrNotFound);
sl@0
  1806
    err = SymbianStreamRemoveObserver(ns, NULL, ESOWF_EventComposed);
sl@0
  1807
    ASSERT_TRUE(err == KErrNotFound);
sl@0
  1808
    err = SymbianStreamAddObserver(ns, TestUpdateCallback, &localNumber);
sl@0
  1809
    ASSERT_TRUE(err == KErrNone);
sl@0
  1810
    err = SymbianStreamRemoveObserver(ns, &localNumber, ESOWF_EventUpdated);
sl@0
  1811
    ASSERT_TRUE(err == KErrNone);
sl@0
  1812
    err = SymbianStreamRemoveObserver(ns, &localNumber, ESOWF_EventUpdated);
sl@0
  1813
    ASSERT_TRUE(err == KErrNotFound);
sl@0
  1814
    
sl@0
  1815
#define N_TIMES 7
sl@0
  1816
#define M_TIMES 3
sl@0
  1817
    
sl@0
  1818
    localNumber = 0;
sl@0
  1819
    TInt k = N_TIMES;
sl@0
  1820
    while (k--)
sl@0
  1821
        {
sl@0
  1822
        err = SymbianStreamAddObserver(ns, TestUpdateCallback, &localNumber);
sl@0
  1823
        ASSERT_TRUE(err != KErrBadHandle);
sl@0
  1824
        }
sl@0
  1825
    k = M_TIMES;
sl@0
  1826
sl@0
  1827
    CExtensionContainer* updateExtension = NULL;
sl@0
  1828
    err = SymbianStreamHasRegisteredScreenNotifications(iScreenNo,reinterpret_cast<void**>(&updateExtension));
sl@0
  1829
    ASSERT_TRUE(err == KErrNone);
sl@0
  1830
    MCompositionSurfaceUpdate* updateProxy=updateExtension->GetInterface<MCompositionSurfaceUpdate>();
sl@0
  1831
    ASSERT_NOT_NULL(updateProxy);
sl@0
  1832
    
sl@0
  1833
    updateProxy->ContentUpdated(surface,                    //aSurface
sl@0
  1834
                                0,                          //aBuffer
sl@0
  1835
                                NULL,                       //aRegion
sl@0
  1836
                                NULL,                       //aStatusConsumed
sl@0
  1837
                                NULL,                       //aStatusDisplayed
sl@0
  1838
                                NULL,                       //aTimeStamp
sl@0
  1839
                                NULL,                       //aStatusDispXTimes
sl@0
  1840
                                NULL                        //aDisplayedXTimes
sl@0
  1841
                                );  
sl@0
  1842
    
sl@0
  1843
    User::After(10000);
sl@0
  1844
    ASSERT_TRUE(localNumber == 1);
sl@0
  1845
    
sl@0
  1846
    while (k--)
sl@0
  1847
        {
sl@0
  1848
        err = SymbianStreamRemoveObserver(ns, &localNumber, ESOWF_EventUpdated);
sl@0
  1849
        ASSERT_TRUE(err != KErrBadHandle);
sl@0
  1850
        }
sl@0
  1851
    
sl@0
  1852
    updateProxy->ContentUpdated(surface,                    //aSurface
sl@0
  1853
                                0,                          //aBuffer
sl@0
  1854
                                NULL,                       //aRegion
sl@0
  1855
                                NULL,                       //aStatusConsumed
sl@0
  1856
                                NULL,                       //aStatusDisplayed
sl@0
  1857
                                NULL,                       //aTimeStamp
sl@0
  1858
                                NULL,                       //aStatusDispXTimes
sl@0
  1859
                                NULL                        //aDisplayedXTimes
sl@0
  1860
                                );      
sl@0
  1861
    
sl@0
  1862
    ASSERT_TRUE(localNumber == 1);
sl@0
  1863
    
sl@0
  1864
    SymbianStreamRemoveReference(ns);
sl@0
  1865
    CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
sl@0
  1866
    }
sl@0
  1867
sl@0
  1868
/**
sl@0
  1869
@SYMTestCaseID          GFX_OPENWFC_NATIVESTREAM_0112
sl@0
  1870
@SYMTestCaseDesc        Tests multithreaded cases for Native Stream callbacks
sl@0
  1871
@SYMREQ                 
sl@0
  1872
@SYMPREQ                PREQ2400
sl@0
  1873
@SYMTestType            CT
sl@0
  1874
@SYMTestPriority        
sl@0
  1875
@SYMTestPurpose         
sl@0
  1876
@SYMTestActions 
sl@0
  1877
        Create 3 threads and call add, remove, notify observers from
sl@0
  1878
        respective threads multiple times
sl@0
  1879
@SYMTestExpectedResults
sl@0
  1880
        Verify that the observers work correctly in multithreaded environment
sl@0
  1881
 **/
sl@0
  1882
void CTestNativeStream::GRAPHICS_OPENWFC_NATIVESTREAM_0112_1L()
sl@0
  1883
    {
sl@0
  1884
    RHeap* mainHeap = COpenWfcStreamMap::InstanceL().GetMainHeap();
sl@0
  1885
    TRAPD(err, GrowCleanupStackL());
sl@0
  1886
    ASSERT_TRUE(err == KErrNone);
sl@0
  1887
        
sl@0
  1888
    CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
sl@0
  1889
    
sl@0
  1890
    INFO_PRINTF1(_L("GRAPHICS_OPENWFC_NATIVESTREAM_0112_1L: Thread 1 start, Register Observer"));
sl@0
  1891
    TSurfaceId surface = gVarInstance.SurfaceID();
sl@0
  1892
    SymbianStreamType ns;
sl@0
  1893
    err = SymbianStreamAcquire(&surface,&ns);
sl@0
  1894
    ASSERT_TRUE(err == KErrNone);
sl@0
  1895
    ASSERT_TRUE(ns);
sl@0
  1896
    
sl@0
  1897
    gVarInstance.iMultithreadCounter = 0;
sl@0
  1898
sl@0
  1899
    TTimeIntervalMicroSeconds32 delay(32000), zeroDelay(0);
sl@0
  1900
    while (delay >= zeroDelay)
sl@0
  1901
        {
sl@0
  1902
        INFO_PRINTF2(_L("Thread 1 is going to add another observer after %i microsecond"), delay.Int());
sl@0
  1903
        User::AfterHighRes(delay);
sl@0
  1904
        SymbianStreamAddObserver(ns, TestUpdateCallback, &gVarInstance.iMultithreadCounter);
sl@0
  1905
        delay = delay.Int() - 43;
sl@0
  1906
        }
sl@0
  1907
    TInt count = 50;
sl@0
  1908
    while (count--)
sl@0
  1909
        {
sl@0
  1910
        INFO_PRINTF1(_L("Thread 1 is going to add another observer without delay"));
sl@0
  1911
        SymbianStreamAddObserver(ns, TestUpdateCallback, &gVarInstance.iMultithreadCounter);
sl@0
  1912
        }
sl@0
  1913
    INFO_PRINTF1(_L("GRAPHICS_OPENWFC_NATIVESTREAM_0112_1L: Thread 1 exits"));
sl@0
  1914
    
sl@0
  1915
    SymbianStreamRemoveReference(ns);
sl@0
  1916
    CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
sl@0
  1917
    }
sl@0
  1918
sl@0
  1919
void CTestNativeStream::GRAPHICS_OPENWFC_NATIVESTREAM_0112_2L()
sl@0
  1920
    {
sl@0
  1921
    RHeap* mainHeap = COpenWfcStreamMap::InstanceL().GetMainHeap();
sl@0
  1922
    TRAPD(err, GrowCleanupStackL());
sl@0
  1923
    ASSERT_TRUE(err == KErrNone);
sl@0
  1924
sl@0
  1925
    CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
sl@0
  1926
    
sl@0
  1927
    INFO_PRINTF1(_L("GRAPHICS_OPENWFC_NATIVESTREAM_0112_2L: Thread 2 start, Unregister Observer"));
sl@0
  1928
    TSurfaceId surface = gVarInstance.SurfaceID();
sl@0
  1929
    SymbianStreamType ns;
sl@0
  1930
    err = SymbianStreamAcquire(&surface,&ns);
sl@0
  1931
    ASSERT_TRUE(err == KErrNone);
sl@0
  1932
    ASSERT_TRUE(ns);
sl@0
  1933
    
sl@0
  1934
    TTimeIntervalMicroSeconds32 delay(32000), zeroDelay(0);
sl@0
  1935
    while (delay > zeroDelay)
sl@0
  1936
        {
sl@0
  1937
        INFO_PRINTF2(_L("Thread 2 is going to remove one observer after %i microsecond"), delay.Int());
sl@0
  1938
        User::AfterHighRes(delay);
sl@0
  1939
        SymbianStreamRemoveObserver(ns, &gVarInstance.iMultithreadCounter, ESOWF_EventUpdated);
sl@0
  1940
        delay = delay.Int() - 49;
sl@0
  1941
        }
sl@0
  1942
    TInt count = 50;
sl@0
  1943
    while (count--)
sl@0
  1944
        {
sl@0
  1945
        INFO_PRINTF1(_L("Thread 2 is going to remove one observer without delay"));
sl@0
  1946
        SymbianStreamRemoveObserver(ns, &gVarInstance.iMultithreadCounter, ESOWF_EventUpdated);
sl@0
  1947
        }
sl@0
  1948
    INFO_PRINTF1(_L("GRAPHICS_OPENWFC_NATIVESTREAM_0112_2L: Thread 2 exits"));    
sl@0
  1949
    SymbianStreamRemoveReference(ns);
sl@0
  1950
    CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
sl@0
  1951
    }
sl@0
  1952
sl@0
  1953
void CTestNativeStream::GRAPHICS_OPENWFC_NATIVESTREAM_0112_3L()
sl@0
  1954
    {
sl@0
  1955
    RHeap* mainHeap = COpenWfcStreamMap::InstanceL().GetMainHeap();
sl@0
  1956
    TRAPD(err, GrowCleanupStackL());
sl@0
  1957
    ASSERT_TRUE(err == KErrNone);
sl@0
  1958
sl@0
  1959
    CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
sl@0
  1960
    
sl@0
  1961
    INFO_PRINTF1(_L("GRAPHICS_OPENWFC_NATIVESTREAM_0112_2L: Thread 3 start, Notify Observer"));
sl@0
  1962
    TSurfaceId surface = gVarInstance.SurfaceID();
sl@0
  1963
    SymbianStreamType ns;
sl@0
  1964
    err = SymbianStreamAcquire(&surface,&ns);
sl@0
  1965
    ASSERT_TRUE(err == KErrNone);
sl@0
  1966
    ASSERT_TRUE(ns);
sl@0
  1967
    
sl@0
  1968
    khronos_int32_t bufferIndex;
sl@0
  1969
    TTimeIntervalMicroSeconds32 delay(32000), zeroDelay(0);
sl@0
  1970
    while (delay > zeroDelay)
sl@0
  1971
        {
sl@0
  1972
        khronos_int32_t writeBuffer;
sl@0
  1973
        err = SymbianStreamAcquireWriteBuffer(ns,&writeBuffer);
sl@0
  1974
        ASSERT_TRUE(err == KErrNone);
sl@0
  1975
        const TSurfaceId* getId = NULL;
sl@0
  1976
        err = SymbianStreamGetBufferId(ns,writeBuffer,&bufferIndex,&getId);
sl@0
  1977
        ASSERT_TRUE(err == KErrNone);
sl@0
  1978
        INFO_PRINTF2(_L("Thread 3 - Write buffer %i acquired"), bufferIndex);
sl@0
  1979
        
sl@0
  1980
        INFO_PRINTF2(_L("Thread 3 going to send notification after %i second"), delay.Int());
sl@0
  1981
        User::AfterHighRes(delay);
sl@0
  1982
        delay = delay.Int() - 58;
sl@0
  1983
        err = SymbianStreamReleaseWriteBuffer(ns, writeBuffer);
sl@0
  1984
        ASSERT_TRUE(err == KErrNone);
sl@0
  1985
        }
sl@0
  1986
    TInt count = 50;
sl@0
  1987
    while (count--)
sl@0
  1988
        {
sl@0
  1989
        khronos_int32_t writeBuffer;
sl@0
  1990
        err = SymbianStreamAcquireWriteBuffer(ns,&writeBuffer);
sl@0
  1991
        ASSERT_TRUE(err == KErrNone);
sl@0
  1992
        const TSurfaceId* getId = NULL;
sl@0
  1993
        err = SymbianStreamGetBufferId(ns,writeBuffer,&bufferIndex,&getId);
sl@0
  1994
        ASSERT_TRUE(err == KErrNone);
sl@0
  1995
        INFO_PRINTF2(_L("Thread 3 - Write buffer %i acquired"), bufferIndex);
sl@0
  1996
        
sl@0
  1997
        INFO_PRINTF1(_L("Thread 3 going to send notification without delay"));
sl@0
  1998
        err = SymbianStreamReleaseWriteBuffer(ns, writeBuffer);
sl@0
  1999
        ASSERT_TRUE(err == KErrNone);
sl@0
  2000
        }
sl@0
  2001
    INFO_PRINTF1(_L("GRAPHICS_OPENWFC_NATIVESTREAM_0112_2L: Thread 3 exits"));
sl@0
  2002
    
sl@0
  2003
    SymbianStreamRemoveReference(ns);
sl@0
  2004
    CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
sl@0
  2005
    }
sl@0
  2006
sl@0
  2007
/**
sl@0
  2008
Submit updates to the native stream whilst observers are being added and removed. 
sl@0
  2009
Do not run in parallel with 0112_3L 
sl@0
  2010
*/
sl@0
  2011
void CTestNativeStream::GRAPHICS_OPENWFC_NATIVESTREAM_0112_4L()
sl@0
  2012
    {
sl@0
  2013
    RHeap* mainHeap = COpenWfcStreamMap::InstanceL().GetMainHeap();
sl@0
  2014
    TRAPD(err, GrowCleanupStackL());
sl@0
  2015
    ASSERT_TRUE(err == KErrNone);
sl@0
  2016
sl@0
  2017
    CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
sl@0
  2018
    
sl@0
  2019
    INFO_PRINTF1(_L("GRAPHICS_OPENWFC_NATIVESTREAM_0112_2L: Thread 3 start, Notify Observer"));
sl@0
  2020
    
sl@0
  2021
    TTimeIntervalMicroSeconds32 delay(32000), zeroDelay(0);
sl@0
  2022
    
sl@0
  2023
    iScreenNo = 0;
sl@0
  2024
    TRequestStatus displayedStatus, availableStatus, displayedXStatus;
sl@0
  2025
    TUint32 timeStamp = 0;
sl@0
  2026
    TInt bufferNo = 0;
sl@0
  2027
    TInt numBuffers = 2;
sl@0
  2028
    TInt displayedX = 5;
sl@0
  2029
sl@0
  2030
    CExtensionContainer* updateExtension = NULL;
sl@0
  2031
    err = SymbianStreamHasRegisteredScreenNotifications(iScreenNo,reinterpret_cast<void**>(&updateExtension));
sl@0
  2032
    ASSERT_TRUE(err == KErrNone);
sl@0
  2033
    MCompositionSurfaceUpdate* updateProxy=updateExtension->GetInterface<MCompositionSurfaceUpdate>();
sl@0
  2034
    ASSERT_NOT_NULL(updateProxy);
sl@0
  2035
    
sl@0
  2036
    while (delay > zeroDelay)
sl@0
  2037
        {        
sl@0
  2038
        INFO_PRINTF2(_L("Thread 0112_4 submitting update after %i second"), delay.Int());
sl@0
  2039
        User::AfterHighRes(delay);
sl@0
  2040
        delay = delay.Int() - 58;                
sl@0
  2041
        
sl@0
  2042
        updateProxy->ContentUpdated(gVarInstance.SurfaceID(),                    //aSurface
sl@0
  2043
                                    bufferNo,                   //aBuffer
sl@0
  2044
                                    NULL,                       //aRegion
sl@0
  2045
                                    &availableStatus,           //aStatusConsumed
sl@0
  2046
                                    &displayedStatus,           //aStatusDisplayed
sl@0
  2047
                                    &timeStamp,                 //aTimeStamp
sl@0
  2048
                                    &displayedXStatus,          //aStatusDispXTimes
sl@0
  2049
                                    &displayedX                 //aDisplayedXTimes
sl@0
  2050
                                    );                
sl@0
  2051
        
sl@0
  2052
        bufferNo = (bufferNo + 1) % numBuffers;        
sl@0
  2053
        }   
sl@0
  2054
    
sl@0
  2055
    TInt count = 50;
sl@0
  2056
    while (count--)
sl@0
  2057
        {
sl@0
  2058
        INFO_PRINTF1(_L("Thread 0112_4 Set notifications"));
sl@0
  2059
        INFO_PRINTF1(_L("Thread 0112_4 submitting update without delay"));
sl@0
  2060
sl@0
  2061
        updateProxy->ContentUpdated(gVarInstance.SurfaceID(),   //aSurface
sl@0
  2062
                                    bufferNo,                   //aBuffer
sl@0
  2063
                                    NULL,                       //aRegion
sl@0
  2064
                                    &availableStatus,           //aStatusConsumed
sl@0
  2065
                                    &displayedStatus,           //aStatusDisplayed
sl@0
  2066
                                    &timeStamp,                 //aTimeStamp
sl@0
  2067
                                    &displayedXStatus,          //aStatusDispXTimes
sl@0
  2068
                                    &displayedX                 //aDisplayedXTimes
sl@0
  2069
                                    );         
sl@0
  2070
        
sl@0
  2071
        bufferNo = (bufferNo + 1) % numBuffers;
sl@0
  2072
        }    
sl@0
  2073
    INFO_PRINTF1(_L("GRAPHICS_OPENWFC_NATIVESTREAM_0112_4L: Thread exits"));
sl@0
  2074
    CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
sl@0
  2075
    }
sl@0
  2076
sl@0
  2077
/**
sl@0
  2078
@SYMTestCaseID          GFX_OPENWFC_NATIVESTREAM_0113
sl@0
  2079
@SYMTestCaseDesc        Test displayed notification
sl@0
  2080
@SYMREQ                 
sl@0
  2081
@SYMPREQ                PREQ2400
sl@0
  2082
@SYMTestType            CT
sl@0
  2083
@SYMTestPriority        High
sl@0
  2084
@SYMTestPurpose         Tests an end to end displayed notification.
sl@0
  2085
@SYMTestActions
sl@0
  2086
sl@0
  2087
     1.  Create a surface
sl@0
  2088
     2.  Create a native stream for the surface
sl@0
  2089
     3.  Register the test class as an observer for ESOWF_EventUpdated to act as a fake composer
sl@0
  2090
     4.  Register for displayed notifications
sl@0
  2091
     5.  Submit an update to the surface
sl@0
  2092
     6.  The observer function should be invoked and verifies that stream and event parameters.
sl@0
  2093
     7.  The tester simulates the end of a composition by firing owfNativeStreanProcessNotifications
sl@0
  2094
     8.  Wait on the displayed request status. 
sl@0
  2095
     9.  Remove the source stream updated observer
sl@0
  2096
     10. Destroy the native stream.
sl@0
  2097
     
sl@0
  2098
     The test is then repeated but the compositor claims the native stream is not visible.
sl@0
  2099
        
sl@0
  2100
@SYMTestExpectedResults
sl@0
  2101
    No errors, displayed status completed with KErrNone.
sl@0
  2102
        
sl@0
  2103
 **/
sl@0
  2104
sl@0
  2105
void CTestNativeStream::GRAPHICS_OPENWFC_NATIVESTREAM_0113L()
sl@0
  2106
    {
sl@0
  2107
    RHeap* mainHeap = COpenWfcStreamMap::InstanceL().GetMainHeap();
sl@0
  2108
    TRAPD(err, GrowCleanupStackL());
sl@0
  2109
    ASSERT_TRUE(err == KErrNone);
sl@0
  2110
    
sl@0
  2111
    iSourceStreamUpdatedCalled = 0;
sl@0
  2112
    iImmediateAvailable = EFalse;
sl@0
  2113
    iImmediateVisible = SYM_CONTENT_NOT_VISIBLE;
sl@0
  2114
    iContextUpdatedFlags = 0;
sl@0
  2115
    iScreenNo = 0;    
sl@0
  2116
    
sl@0
  2117
    for (TInt i = 0; i < 2; ++i)
sl@0
  2118
        {
sl@0
  2119
        TSurfaceId surface=iUtility->CreateSurfaceL(TSize(100,100), EUidPixelFormatARGB_8888_PRE, 400, 4);
sl@0
  2120
        ASSERT_FALSE(surface.IsNull());
sl@0
  2121
        CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
sl@0
  2122
        
sl@0
  2123
        CTestNativeStream::iTester = this;
sl@0
  2124
        TBool visible = (i == 0);
sl@0
  2125
        
sl@0
  2126
        RHeap* threadHeap3 = &User::Heap();
sl@0
  2127
        err = SymbianStreamAcquire(&surface,&iNs);
sl@0
  2128
        ASSERT_TRUE(err == KErrNone);
sl@0
  2129
        ASSERT_TRUE(iNs);
sl@0
  2130
        
sl@0
  2131
        iExpectedSourceStreamUpdatedEventMask = 0;
sl@0
  2132
        err = SymbianStreamAddObserver(iNs, SourceStreamUpdatedCallback, this);
sl@0
  2133
        ASSERT_TRUE(err == KErrNone);
sl@0
  2134
        
sl@0
  2135
        TRequestStatus statusDisplayed;
sl@0
  2136
        TUint32 displayedTime;    
sl@0
  2137
sl@0
  2138
        CExtensionContainer* updateExtension = NULL;
sl@0
  2139
        err = SymbianStreamHasRegisteredScreenNotifications(iScreenNo,reinterpret_cast<void**>(&updateExtension));
sl@0
  2140
        ASSERT_TRUE(err == KErrNone);
sl@0
  2141
        MCompositionSurfaceUpdate* updateProxy=updateExtension->GetInterface<MCompositionSurfaceUpdate>();
sl@0
  2142
        ASSERT_NOT_NULL(updateProxy);
sl@0
  2143
        
sl@0
  2144
        iSourceStreamUpdatedCalled = 0;
sl@0
  2145
        updateProxy->ContentUpdated(surface,                    //aSurface
sl@0
  2146
                                    0,                          //aBuffer
sl@0
  2147
                                    NULL,                       //aRegion
sl@0
  2148
                                    NULL,                       //aStatusConsumed
sl@0
  2149
                                    &statusDisplayed,           //aStatusDisplayed
sl@0
  2150
                                    &displayedTime,             //aTimeStamp
sl@0
  2151
                                    NULL,                       //aStatusDispXTimes
sl@0
  2152
                                    NULL                        //aDisplayedXTimes
sl@0
  2153
                                    );
sl@0
  2154
        
sl@0
  2155
        ASSERT_TRUE(iSourceStreamUpdatedCalled == 1);
sl@0
  2156
        err = SymbianStreamRemoveObserver(iNs, this, ESOWF_EventUpdated);
sl@0
  2157
        ASSERT_TRUE(err == KErrNone);
sl@0
  2158
    
sl@0
  2159
        iExpectedSourceStreamUpdatedEventMask = ESOWF_EventDisplayed;
sl@0
  2160
        err = SymbianStreamAddExtendedObserver(iNs, SourceStreamUpdatedCallback, this, iScreenNo, ESOWF_EventUpdated);
sl@0
  2161
        ASSERT_TRUE(err == KErrNone);
sl@0
  2162
    
sl@0
  2163
        updateProxy->ContentUpdated(surface,                    //aSurface
sl@0
  2164
                                    0,                          //aBuffer
sl@0
  2165
                                    NULL,                       //aRegion
sl@0
  2166
                                    NULL,                       //aStatusConsumed
sl@0
  2167
                                    &statusDisplayed,           //aStatusDisplayed
sl@0
  2168
                                    &displayedTime,             //aTimeStamp
sl@0
  2169
                                    NULL,                       //aStatusDispXTimes
sl@0
  2170
                                    NULL                        //aDisplayedXTimes
sl@0
  2171
                                    );
sl@0
  2172
        
sl@0
  2173
        ASSERT_TRUE(iSourceStreamUpdatedCalled);
sl@0
  2174
        
sl@0
  2175
        // Pretend that a composition has occured
sl@0
  2176
        ++iStreamUpdatedSerialNumber; 
sl@0
  2177
        if (visible)
sl@0
  2178
            {
sl@0
  2179
            khronos_int32_t newNotificationsMask = 0;
sl@0
  2180
            SymbianStreamProcessNotifications(iNs, 
sl@0
  2181
                                                ESOWF_EventDisplayed,
sl@0
  2182
                                                iScreenNo,
sl@0
  2183
                                                iStreamUpdatedSerialNumber, 
sl@0
  2184
                                                &newNotificationsMask);
sl@0
  2185
    
sl@0
  2186
            // No updates during composition so newNotificationMask should still be zero 
sl@0
  2187
            ASSERT_TRUE(newNotificationsMask == 0);
sl@0
  2188
            }        
sl@0
  2189
        // Simulate multiple sources
sl@0
  2190
        SymbianStreamCheckVisible(iNs, ESOWF_EventDisplayed, iScreenNo, iStreamUpdatedSerialNumber); 
sl@0
  2191
        SymbianStreamCheckVisible(iNs, ESOWF_EventDisplayed, iScreenNo, iStreamUpdatedSerialNumber);
sl@0
  2192
        
sl@0
  2193
        // Make sure displayed event was completed
sl@0
  2194
        User::WaitForRequest(statusDisplayed);
sl@0
  2195
        if (visible)
sl@0
  2196
            {
sl@0
  2197
            ASSERT_EQUALS(statusDisplayed.Int(), KErrNone);
sl@0
  2198
            }
sl@0
  2199
        else
sl@0
  2200
            {
sl@0
  2201
            ASSERT_EQUALS(statusDisplayed.Int(), KErrNotVisible);
sl@0
  2202
            }
sl@0
  2203
        
sl@0
  2204
        err = SymbianStreamRemoveObserver(iNs, this, ESOWF_EventUpdated);
sl@0
  2205
        ASSERT_TRUE(err == KErrNone);
sl@0
  2206
        SymbianStreamRemoveReference(iNs);
sl@0
  2207
        CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one   
sl@0
  2208
        iUtility->DestroySurface(surface);
sl@0
  2209
        }
sl@0
  2210
    }
sl@0
  2211
sl@0
  2212
/**
sl@0
  2213
@SYMTestCaseID          GFX_OPENWFC_NATIVESTREAM_0114
sl@0
  2214
@SYMTestCaseDesc        Test available notification
sl@0
  2215
@SYMREQ                 
sl@0
  2216
@SYMPREQ                PREQ2400
sl@0
  2217
@SYMTestType            CT
sl@0
  2218
@SYMTestPriority        High
sl@0
  2219
@SYMTestPurpose         Tests an end to end available notification.
sl@0
  2220
@SYMTestActions
sl@0
  2221
sl@0
  2222
     1.  Create a surface
sl@0
  2223
     2.  Create a native stream for the surface
sl@0
  2224
     3.  Register the test class as an observer for ESOWF_EventUpdated to act as a fake composer
sl@0
  2225
     4.  Register for displayed notifications
sl@0
  2226
     5.  Submit an update to the surface
sl@0
  2227
     6.  The observer function should be invoked and verifies that stream and event parameters.
sl@0
  2228
     7.  The tester simulates the end of a composition by firing owfNativeStreanProcessNotifications
sl@0
  2229
     8.  Verify that available notification has not been sent.
sl@0
  2230
     9.  Send another display update to change the read buffer to buffer 1
sl@0
  2231
     10. Verify that the source-stream updated callback is invoked.
sl@0
  2232
     11. The tester simulates the end of a composition by firing owfNativeStreanProcessNotifications
sl@0
  2233
     12. Wait for available status to be completed
sl@0
  2234
     13. Remove the source stream updated observer
sl@0
  2235
     14. Destroy the native stream.
sl@0
  2236
     
sl@0
  2237
     The test is then repeated but the compositor claims the native stream is not visible.
sl@0
  2238
        
sl@0
  2239
@SYMTestExpectedResults
sl@0
  2240
    No errors, available status completed with KErrNone.
sl@0
  2241
        
sl@0
  2242
 **/
sl@0
  2243
void CTestNativeStream::GRAPHICS_OPENWFC_NATIVESTREAM_0114L()
sl@0
  2244
    {  
sl@0
  2245
    RHeap* mainHeap = COpenWfcStreamMap::InstanceL().GetMainHeap();
sl@0
  2246
    TRAPD(err, GrowCleanupStackL());
sl@0
  2247
    ASSERT_TRUE(err == KErrNone);
sl@0
  2248
    
sl@0
  2249
    iScreenNo = 0;
sl@0
  2250
    iContextUpdatedFlags = 0;
sl@0
  2251
    iStreamUpdatedSerialNumber = 1;
sl@0
  2252
    iSourceStreamUpdatedCalled = 0;
sl@0
  2253
    // during compositio or first time after a commit
sl@0
  2254
    iImmediateAvailable = EFalse;
sl@0
  2255
    iImmediateVisible = SYM_CONTENT_VISIBLE;
sl@0
  2256
    
sl@0
  2257
    for (TInt i = 0; i < 2; ++i)
sl@0
  2258
        {
sl@0
  2259
        TBool visible = (i == 0);
sl@0
  2260
        TSurfaceId surface=iUtility->CreateSurfaceL(TSize(100,100), EUidPixelFormatARGB_8888_PRE, 400, 4);
sl@0
  2261
        ASSERT_FALSE(surface.IsNull());
sl@0
  2262
        CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
sl@0
  2263
        
sl@0
  2264
        CTestNativeStream::iTester = this;
sl@0
  2265
        
sl@0
  2266
        err = SymbianStreamAcquire(&surface,&iNs);
sl@0
  2267
        ASSERT_TRUE(err == KErrNone);
sl@0
  2268
        ASSERT_TRUE(iNs);
sl@0
  2269
        
sl@0
  2270
        err = SymbianStreamAddExtendedObserver(iNs, SourceStreamUpdatedCallback, this, iScreenNo, ESOWF_EventUpdated);
sl@0
  2271
        ASSERT_TRUE(err == KErrNone);
sl@0
  2272
        
sl@0
  2273
        TRequestStatus statusAvailable;
sl@0
  2274
        iSourceStreamUpdatedCalled = 0;
sl@0
  2275
sl@0
  2276
        CExtensionContainer* updateExtension = NULL;
sl@0
  2277
        err = SymbianStreamHasRegisteredScreenNotifications(iScreenNo,reinterpret_cast<void**>(&updateExtension));
sl@0
  2278
        ASSERT_TRUE(err == KErrNone);
sl@0
  2279
        MCompositionSurfaceUpdate* updateProxy=updateExtension->GetInterface<MCompositionSurfaceUpdate>();
sl@0
  2280
        ASSERT_NOT_NULL(updateProxy);
sl@0
  2281
        
sl@0
  2282
        ASSERT_TRUE(iSourceStreamUpdatedCalled == 0);
sl@0
  2283
        
sl@0
  2284
        iExpectedSourceStreamUpdatedEventMask = 0;
sl@0
  2285
        //we are during a composition
sl@0
  2286
        ++iStreamUpdatedSerialNumber;
sl@0
  2287
        updateProxy->ContentUpdated(surface,                    //aSurface
sl@0
  2288
                                    0,                          //aBuffer
sl@0
  2289
                                    NULL,                       //aRegion
sl@0
  2290
                                    &statusAvailable,           //aStatusConsumed
sl@0
  2291
                                    NULL,                       //aStatusDisplayed
sl@0
  2292
                                    NULL,                       //aTimeStamp
sl@0
  2293
                                    NULL,                       //aStatusDispXTimes
sl@0
  2294
                                    NULL                        //aDisplayedXTimes
sl@0
  2295
                                    );
sl@0
  2296
        
sl@0
  2297
        // Verify that the context's callback is invoked when SubmitUpdate is called.
sl@0
  2298
        ASSERT_TRUE(iSourceStreamUpdatedCalled == 2);
sl@0
  2299
        
sl@0
  2300
        // Available should only be compled when submit update is called with a different buffer no.
sl@0
  2301
        // if the stream is multi-buffered.
sl@0
  2302
        ASSERT_EQUALS(statusAvailable.Int(), KRequestPending);
sl@0
  2303
        
sl@0
  2304
        // Pretend that a composition has occured
sl@0
  2305
        khronos_int32_t newNotificationsMask = 0;
sl@0
  2306
        if (visible)
sl@0
  2307
            {            
sl@0
  2308
            SymbianStreamProcessNotifications(iNs, 
sl@0
  2309
                                              0, 
sl@0
  2310
                                              iScreenNo,
sl@0
  2311
                                              iStreamUpdatedSerialNumber,
sl@0
  2312
                                              &newNotificationsMask);
sl@0
  2313
    
sl@0
  2314
            // No updates during composition so newNotificationMask should still be zero 
sl@0
  2315
            ASSERT_TRUE(newNotificationsMask == 0);
sl@0
  2316
            SymbianStreamProcessNotifications(iNs, 
sl@0
  2317
                                              0, 
sl@0
  2318
                                              iScreenNo,
sl@0
  2319
                                              iStreamUpdatedSerialNumber,
sl@0
  2320
                                              &newNotificationsMask);
sl@0
  2321
    
sl@0
  2322
            // No updates during composition so newNotificationMask should still be zero 
sl@0
  2323
            ASSERT_TRUE(newNotificationsMask == 0);
sl@0
  2324
            }
sl@0
  2325
        SymbianStreamCheckVisible(iNs, ESOWF_EventAvailable, iScreenNo, iStreamUpdatedSerialNumber); 
sl@0
  2326
        SymbianStreamCheckVisible(iNs, ESOWF_EventAvailable, iScreenNo, iStreamUpdatedSerialNumber);        
sl@0
  2327
                
sl@0
  2328
        // Available for buffer zero should not be completed yet
sl@0
  2329
        ASSERT_EQUALS(statusAvailable.Int(), KRequestPending);
sl@0
  2330
        
sl@0
  2331
        // Update and switch to buffer 1
sl@0
  2332
        iExpectedSourceStreamUpdatedEventMask = ESOWF_EventAvailable;
sl@0
  2333
        //we are during a composition
sl@0
  2334
        ++iStreamUpdatedSerialNumber;
sl@0
  2335
        updateProxy->ContentUpdated(surface,                    //aSurface
sl@0
  2336
                                    1,                          //aBuffer
sl@0
  2337
                                    NULL,                       //aRegion
sl@0
  2338
                                    NULL,                       //aStatusConsumed
sl@0
  2339
                                    NULL,                       //aStatusDisplayed
sl@0
  2340
                                    NULL,                       //aTimeStamp
sl@0
  2341
                                    NULL,                       //aStatusDispXTimes
sl@0
  2342
                                    NULL                        //aDisplayedXTimes
sl@0
  2343
                                    );
sl@0
  2344
        
sl@0
  2345
        ASSERT_TRUE(iSourceStreamUpdatedCalled == 4);
sl@0
  2346
        
sl@0
  2347
        // Consume update on buffer 1. This should make buffer 0 available
sl@0
  2348
        if (visible)
sl@0
  2349
            {
sl@0
  2350
            SymbianStreamProcessNotifications(iNs, 
sl@0
  2351
                                                ESOWF_EventAvailable, 
sl@0
  2352
                                                iScreenNo,
sl@0
  2353
                                                iStreamUpdatedSerialNumber,
sl@0
  2354
                                                &newNotificationsMask);
sl@0
  2355
            
sl@0
  2356
            ASSERT_TRUE(newNotificationsMask == 0);
sl@0
  2357
sl@0
  2358
            SymbianStreamProcessNotifications(iNs,