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