os/graphics/egl/egltest/src/egltest_stress_process_sgimage.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) 2010 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
/**
sl@0
    17
 @file
sl@0
    18
 @test
sl@0
    19
*/
sl@0
    20
sl@0
    21
#include "egltest_stress_process_sgimage.h"
sl@0
    22
sl@0
    23
GLDEF_C TInt E32Main()
sl@0
    24
	{
sl@0
    25
	RDebug::Print(_L("Stress test client process::E32Main - entry"));
sl@0
    26
	CTrapCleanup* TheTrapCleanup = CTrapCleanup::New();
sl@0
    27
sl@0
    28
	TRAPD(err, LaunchClientProcessL());
sl@0
    29
	if (err)
sl@0
    30
		{
sl@0
    31
		User::Panic(KStressTestChildAppPanic, err);
sl@0
    32
		}
sl@0
    33
sl@0
    34
    delete TheTrapCleanup;
sl@0
    35
sl@0
    36
	RDebug::Print(_L("Stress test client process::E32Main - exit"));
sl@0
    37
	return KErrNone;
sl@0
    38
	}
sl@0
    39
sl@0
    40
LOCAL_C void LaunchClientProcessL()
sl@0
    41
	{
sl@0
    42
	__UHEAP_MARK;
sl@0
    43
	RProcess::Rendezvous(KErrNone);
sl@0
    44
sl@0
    45
    RSemaphore sem;
sl@0
    46
    User::LeaveIfError(sem.OpenGlobal(KEglStressTest));
sl@0
    47
    CleanupClosePushL(sem);
sl@0
    48
sl@0
    49
    //Access data passed from the main process
sl@0
    50
    TStressProcessInfo info;
sl@0
    51
    TPckg<TStressProcessInfo> pckgInfo(info);
sl@0
    52
    User::LeaveIfError(User::GetDesParameter(KMultiProcessSlot, pckgInfo));
sl@0
    53
sl@0
    54
    //Create RSgDriver and open the image
sl@0
    55
    RSgDriver driver;
sl@0
    56
    User::LeaveIfError(driver.Open());
sl@0
    57
    CleanupClosePushL(driver);
sl@0
    58
sl@0
    59
    RSgImage image;
sl@0
    60
    User::LeaveIfError(image.Open(info.iSgId));
sl@0
    61
    CleanupClosePushL(image);
sl@0
    62
sl@0
    63
    EGLDisplay display;
sl@0
    64
    EGL_LEAVE_NULL(display, eglGetDisplay(EGL_DEFAULT_DISPLAY));
sl@0
    65
    EGL_LEAVE_ERROR(eglInitialize(display, NULL, NULL));
sl@0
    66
    EGL_LEAVE_ERROR(eglBindAPI(EGL_OPENVG_API));
sl@0
    67
sl@0
    68
    //Initialise to remove arm compiler warnings
sl@0
    69
    EGLConfig config = 0;
sl@0
    70
    EGLContext context = EGL_NO_CONTEXT;
sl@0
    71
    EGLSurface surface = EGL_NO_SURFACE;
sl@0
    72
sl@0
    73
    if(info.iTestType == EStressRead)
sl@0
    74
        {
sl@0
    75
        TSgImageInfo sginfo;
sl@0
    76
        User::LeaveIfError(image.GetInfo(sginfo));
sl@0
    77
sl@0
    78
        //Create an independant pixmap surface on which to copy the vgimage 
sl@0
    79
        RSgImage image2;
sl@0
    80
        User::LeaveIfError(image2.Create(sginfo, NULL, NULL));
sl@0
    81
        CleanupClosePushL(image2);
sl@0
    82
        ChooseConfigAndCreateContextL(display, context, config, image2, KStressTestChildAppPanic, info.iAlphaPre);
sl@0
    83
        EGL_LEAVE_NULL(surface, CreatePixmapSurfaceL(display, config, image2, info.iAlphaPre)); 
sl@0
    84
        CleanupStack::PopAndDestroy(&image2);
sl@0
    85
        }
sl@0
    86
    else
sl@0
    87
        {
sl@0
    88
        ChooseConfigAndCreateContextL(display, context, config, image, KStressTestChildAppPanic, info.iAlphaPre);
sl@0
    89
        EGL_LEAVE_NULL(surface, CreatePixmapSurfaceL(display, config, image, info.iAlphaPre));       
sl@0
    90
        }
sl@0
    91
sl@0
    92
    EGL_LEAVE_ERROR(eglMakeCurrent(display, surface, surface, context));
sl@0
    93
sl@0
    94
    VGImage vgImage;
sl@0
    95
    GenerateVgImageL(display, &image, vgImage);
sl@0
    96
sl@0
    97
    /* Create and install the active scheduler */
sl@0
    98
    CActiveScheduler* sched = new(ELeave) CActiveScheduler;
sl@0
    99
    CActiveScheduler::Install(sched);
sl@0
   100
    CleanupStack::PushL(sched);
sl@0
   101
sl@0
   102
    TInt width = vgGetParameteri(vgImage, VG_IMAGE_WIDTH);
sl@0
   103
    VgLeaveIfErrorL();
sl@0
   104
sl@0
   105
    TInt height = vgGetParameteri(vgImage, VG_IMAGE_HEIGHT);
sl@0
   106
    VgLeaveIfErrorL();
sl@0
   107
sl@0
   108
    VGImageFormat format = static_cast<VGImageFormat>(vgGetParameteri(vgImage, VG_IMAGE_FORMAT));
sl@0
   109
    VgLeaveIfErrorL();
sl@0
   110
sl@0
   111
    TBool testPass = ETrue;
sl@0
   112
sl@0
   113
    CTReadWriteChild* painter = CTReadWriteChild::NewL(vgImage, width, height, info.iByteSize, format, info.iTestType, testPass);
sl@0
   114
    CleanupStack::PushL(painter);
sl@0
   115
    painter->After(TTimeIntervalMicroSeconds32(0));
sl@0
   116
sl@0
   117
    //Data access is synchronised from the main process
sl@0
   118
    sem.Wait();
sl@0
   119
    sched->Start();
sl@0
   120
sl@0
   121
    if(testPass == EFalse)
sl@0
   122
        {
sl@0
   123
		// Leave with a 'known' test error so that we can catch this particular failure 
sl@0
   124
        User::Leave(KTestStressUnexpectedPixelError);
sl@0
   125
        }
sl@0
   126
    
sl@0
   127
    CleanupStack::PopAndDestroy(5, &sem); //painter, sched, image, driver, sem
sl@0
   128
      
sl@0
   129
    __UHEAP_MARKEND;
sl@0
   130
    }
sl@0
   131
sl@0
   132
/**
sl@0
   133
 *    class CTReadWriteChild
sl@0
   134
 *    A Child of CTReadWrite which contains member data not included in the base class and 
sl@0
   135
 *    implementations of pure virtual functions.
sl@0
   136
 *    a) One for each particular test case
sl@0
   137
 *    b) Support functions MakeCurrentL() and IsFinished()
sl@0
   138
 *    
sl@0
   139
 *    The base class is an active object and the implemented virtual functions are invoked
sl@0
   140
 *    indirectly from the RunL() function
sl@0
   141
 */
sl@0
   142
CTReadWriteChild::CTReadWriteChild(VGImage aImage, TInt aWidth, TInt aHeight, TInt aByteSize, VGImageFormat aFormat, const TTestType& aTestType, TBool& aTestPass)
sl@0
   143
: CTReadWrite(aWidth, aHeight, aByteSize, aFormat, aTestType, aTestPass),
sl@0
   144
    iImage(aImage)
sl@0
   145
    {
sl@0
   146
    }
sl@0
   147
sl@0
   148
CTReadWriteChild* CTReadWriteChild::NewL(VGImage aImage, TInt aWidth, TInt aHeight, TInt aByteSize, VGImageFormat aFormat, const TTestType& aTestType, TBool& aTestPass)
sl@0
   149
    {
sl@0
   150
    CTReadWriteChild* self = new (ELeave) CTReadWriteChild(aImage, aWidth, aHeight, aByteSize, aFormat, aTestType, aTestPass);
sl@0
   151
    CleanupStack::PushL(self);
sl@0
   152
    self->ConstructL();
sl@0
   153
    CleanupStack::Pop(self);
sl@0
   154
    return self;
sl@0
   155
    }
sl@0
   156
sl@0
   157
void CTReadWriteChild::MakeCurrentL() const
sl@0
   158
    {
sl@0
   159
    }
sl@0
   160
sl@0
   161
void CTReadWriteChild::ReadImageFuncL()
sl@0
   162
    {
sl@0
   163
    vgGetImageSubData(iImage, iData, iWidth*iByteSize, iFormat, 0, 0, iWidth, iHeight);
sl@0
   164
    VgLeaveIfErrorL();
sl@0
   165
    }
sl@0
   166
sl@0
   167
void CTReadWriteChild::ReadFuncL()
sl@0
   168
    {
sl@0
   169
    vgDrawImage(iImage);
sl@0
   170
    vgReadPixels(iData, iWidth*iByteSize, iFormat, 0, 0, iWidth, iHeight);
sl@0
   171
    VgLeaveIfErrorL();
sl@0
   172
sl@0
   173
    //Small delay to aid pixel access sharing between processes
sl@0
   174
    User::After(TTimeIntervalMicroSeconds32(1000));
sl@0
   175
    }
sl@0
   176
sl@0
   177
void CTReadWriteChild::WriteImageFuncL()
sl@0
   178
    {
sl@0
   179
    vgImageSubData(iImage, iData, iWidth*iByteSize, iFormat, 0, 0, iWidth, iHeight);
sl@0
   180
    VgLeaveIfErrorL();
sl@0
   181
    }
sl@0
   182
sl@0
   183
TBool CTReadWriteChild::IsFinished()
sl@0
   184
    {
sl@0
   185
    return ETrue;
sl@0
   186
    }
sl@0
   187
sl@0
   188
void CTReadWriteChild::VgImageFuncL()
sl@0
   189
    {
sl@0
   190
    vgDrawImage(iImage);
sl@0
   191
    VgLeaveIfErrorL();
sl@0
   192
    }
sl@0
   193
sl@0
   194
void CTReadWriteChild::PixmapSurfaceFuncL()
sl@0
   195
    {
sl@0
   196
    vgDrawImage(iImage);
sl@0
   197
    VgLeaveIfErrorL();
sl@0
   198
    }