egl/egltest/endpointtestsuite/automated/tsrc/egltest_surface.cpp
changeset 136 62bb7c97884c
parent 98 bf7481649c98
equal deleted inserted replaced
121:d72fc2aace31 136:62bb7c97884c
    21 
    21 
    22 
    22 
    23 #include "egltest_surface.h"
    23 #include "egltest_surface.h"
    24 #include "egltest_endpoint_images.h"
    24 #include "egltest_endpoint_images.h"
    25 #include <graphics/surfaceconfiguration.h>
    25 #include <graphics/surfaceconfiguration.h>
       
    26 #include <e32std.h>
       
    27 #include <e32math.h>
       
    28 #include <VG/vgu.h>
       
    29 
    26 
    30 
    27 #define SURF_ASSERT(x) { if (!(x)) { RDebug::Printf("ASSERT(%s) failed at %s:%d", #x, __FILE__, __LINE__); User::Panic(_L("ASSERT SURF"), __LINE__); }}
    31 #define SURF_ASSERT(x) { if (!(x)) { RDebug::Printf("ASSERT(%s) failed at %s:%d", #x, __FILE__, __LINE__); User::Panic(_L("ASSERT SURF"), __LINE__); }}
    28 
    32 
    29 // Macros for indicating what is what.
    33 // Macros for indicating what is what.
    30 #define SIZE(x, y) x, y
    34 #define SIZE(x, y) x, y
    35 #define DefaultStride 0
    39 #define DefaultStride 0
    36 // Note: Offset to first buffer.
    40 // Note: Offset to first buffer.
    37 #define Offset(x) x
    41 #define Offset(x) x
    38 #define WindowPos(x, y)  x, y
    42 #define WindowPos(x, y)  x, y
    39 #define WindowMode(m) m
    43 #define WindowMode(m) m
       
    44 
       
    45 #define LARGEST_POSSIBLE_FLAG 0x80000000
    40 
    46 
    41 static const TSurfaceParamsCommon KSurfaceParams[] =
    47 static const TSurfaceParamsCommon KSurfaceParams[] =
    42 {
    48 {
    43     {
    49     {
    44         EStandardSurface,
    50         EStandardSurface,
   129         EFalse,
   135         EFalse,
   130         { 0 },
   136         { 0 },
   131         WindowPos(0, 0),
   137         WindowPos(0, 0),
   132         WindowMode(EColor16MAP)
   138         WindowMode(EColor16MAP)
   133     },
   139     },
       
   140     {
       
   141         ELargestPossibleSurface,
       
   142         SIZE(LARGEST_POSSIBLE_FLAG, LARGEST_POSSIBLE_FLAG),
       
   143         Buffers(2),
       
   144         DefaultAlignment,
       
   145         DefaultStride,
       
   146         Offset(0),
       
   147         EUidPixelFormatARGB_8888_PRE,
       
   148         EFalse,
       
   149         { 0 },
       
   150         WindowPos(0, 0),
       
   151         WindowMode(EColor16MAP)
       
   152     },    
       
   153     {
       
   154         ESmallSurface,
       
   155         SIZE(16, 16),
       
   156         Buffers(1),
       
   157         DefaultAlignment,
       
   158         DefaultStride,
       
   159         Offset(0),
       
   160         EUidPixelFormatARGB_8888_PRE,
       
   161         EFalse,
       
   162         { 0 },
       
   163         WindowPos(0, 0),
       
   164         WindowMode(EColor16MAP)
       
   165     },
       
   166     {
       
   167         ETinySurface,
       
   168         SIZE(8, 8),
       
   169         Buffers(1),
       
   170         DefaultAlignment,
       
   171         DefaultStride,
       
   172         Offset(0),
       
   173         EUidPixelFormatARGB_8888_PRE,
       
   174         EFalse,
       
   175         { 0 },
       
   176         WindowPos(0, 0),
       
   177         WindowMode(EColor16MAP)
       
   178     },
   134 };
   179 };
   135 
   180 
   136 
   181 const TInt KSurfaceMaxIndex = sizeof(KSurfaceParams) / sizeof(KSurfaceParams[0]);
   137 TInt KSurfaceMaxIndex = sizeof(KSurfaceParams) / sizeof(KSurfaceParams[0]);
   182 
       
   183 struct TSurfaceSize
       
   184     {
       
   185     TInt iWidth;
       
   186     TInt iHeight;
       
   187     };
       
   188 
       
   189 static const TSurfaceSize KSurfaceSizes[] =
       
   190     {
       
   191         {  320,  240 },
       
   192         {  640,  480 },
       
   193         {  720,  480 },
       
   194         {  854,  480 },
       
   195         {  720,  576 },
       
   196         {  854,  576 },
       
   197         { 1280,  720 },
       
   198         { 1024,  768 },
       
   199         { 1280, 1024 },
       
   200         { 1920, 1080 },
       
   201         { 1600, 1200 },
       
   202 #if 0
       
   203         { 2048, 1536 },
       
   204         { 2560, 1920 },
       
   205         { 3648, 2736 },
       
   206         { 4216, 2638 },
       
   207         { 4000, 3000 },
       
   208         { 4616, 2600 },
       
   209 #endif
       
   210     };
       
   211 
       
   212 const TInt KMaxSurfaceSizes =  sizeof(KSurfaceSizes) / sizeof(KSurfaceSizes[0]);
       
   213 
       
   214 LOCAL_C TUint RandomNumberInRange(TUint aLow, TUint aHigh)
       
   215     {
       
   216     TReal32 rand = Math::Random();
       
   217     rand /= KMaxTUint;
       
   218     rand *= aHigh - aLow;
       
   219     rand += aLow;
       
   220     return TUint(rand);
       
   221     }
       
   222 
       
   223 
       
   224 void CSurface::CreateL(TInt aIndex)
       
   225     {
       
   226     CreateL(aIndex, TPoint(0, 0));
       
   227     }
       
   228 
       
   229 
       
   230 TSize CSurface::Size()
       
   231     {
       
   232     return iActualSize;
       
   233     }
       
   234 
       
   235 
       
   236 TInt CSurface::SizeInBytes() const
       
   237     {
       
   238     RSurfaceManager::TInfoBuf infoBuf;
       
   239     RSurfaceManager surfMgr;
       
   240     TInt err = surfMgr.Open();
       
   241     if (err != KErrNone)
       
   242         {
       
   243         RDebug::Printf("Error opening surface manager... Err=%d", err);
       
   244         return 0;
       
   245         }
       
   246     err = surfMgr.SurfaceInfo(SurfaceId(), infoBuf);
       
   247     if (err != KErrNone)
       
   248         {
       
   249         RDebug::Printf("Could not get surface info - err = %d", err);
       
   250         return 0;
       
   251         }
       
   252     TInt size = infoBuf().iBuffers * infoBuf().iSize.iHeight * infoBuf().iStride;
       
   253     surfMgr.Close();
       
   254     return size;
       
   255     }
       
   256 
   138 
   257 
   139 CRawSurface* CRawSurface::NewL()
   258 CRawSurface* CRawSurface::NewL()
   140     {
   259     {
   141     CRawSurface* obj = new (ELeave) CRawSurface();
   260     CRawSurface* obj = new (ELeave) CRawSurface();
   142     CleanupStack::PushL(obj);
   261     CleanupStack::PushL(obj);
   144     CleanupStack::Pop(obj);
   263     CleanupStack::Pop(obj);
   145     return obj;
   264     return obj;
   146     }
   265     }
   147 
   266 
   148 
   267 
       
   268 
   149 CRawSurface::CRawSurface() : iDrawBuffer(0), iBuffers(0)
   269 CRawSurface::CRawSurface() : iDrawBuffer(0), iBuffers(0)
   150     {
   270     {
   151     }
   271     }
   152 
   272 
   153 
   273 
   154 void CRawSurface::ConstructL()
   274 void CRawSurface::ConstructL()
   155     {
   275     {
   156     iSurfaceId = TSurfaceId::CreateNullId();
   276     iSurfaceId = TSurfaceId::CreateNullId();
   157     User::LeaveIfError(iSurfaceManager.Open());
   277     User::LeaveIfError(iSurfaceManager.Open());
   158     User::LeaveIfError(iSurfaceUpdate.Connect(5));
   278     User::LeaveIfError(iSurfaceUpdate.Connect());
   159     }
   279     }
   160 
   280 
   161 
   281 
   162 CRawSurface::~CRawSurface()
   282 CRawSurface::~CRawSurface()
   163     {
   283     {
   190         }
   310         }
   191     return 0; // Make sure no compiler moans about "not all paths return a value".
   311     return 0; // Make sure no compiler moans about "not all paths return a value".
   192     }
   312     }
   193 
   313 
   194 
   314 
   195 void CRawSurface::GetSurfAttribs(RSurfaceManager::TSurfaceCreationAttributesBuf &aSurfaceAttribs, TInt aIndex)
   315 void CRawSurface::GetSurfAttribs(RSurfaceManager::TSurfaceCreationAttributesBuf &aSurfaceAttribs, 
       
   316         TInt aIndex, TInt aSizeIndex)
   196     {
   317     {
   197     SURF_ASSERT(aIndex < KSurfaceMaxIndex);
   318     SURF_ASSERT(aIndex < KSurfaceMaxIndex);
   198     SURF_ASSERT(aIndex == KSurfaceParams[aIndex].iIndex);
   319     SURF_ASSERT(aIndex == KSurfaceParams[aIndex].iIndex);
   199     iParamIndex = aIndex;
   320     iParamIndex = aIndex;
   200     aSurfaceAttribs().iSize = TSize(KSurfaceParams[aIndex].iXSize, KSurfaceParams[aIndex].iYSize);
   321     if (KSurfaceParams[aIndex].iXSize & LARGEST_POSSIBLE_FLAG)
       
   322         {
       
   323         
       
   324         aSurfaceAttribs().iSize = 
       
   325                 TSize(KSurfaceSizes[aSizeIndex].iWidth, KSurfaceSizes[aSizeIndex].iHeight);
       
   326         }
       
   327     else
       
   328         {
       
   329         aSurfaceAttribs().iSize = 
       
   330                 TSize(KSurfaceParams[aIndex].iXSize, KSurfaceParams[aIndex].iYSize);
       
   331         }
   201     iBuffers = KSurfaceParams[aIndex].iBuffers;
   332     iBuffers = KSurfaceParams[aIndex].iBuffers;
   202     aSurfaceAttribs().iBuffers = iBuffers;
   333     aSurfaceAttribs().iBuffers = iBuffers;
   203     aSurfaceAttribs().iPixelFormat = KSurfaceParams[aIndex].iPixelFormat;
   334     aSurfaceAttribs().iPixelFormat = KSurfaceParams[aIndex].iPixelFormat;
   204     TInt stride = KSurfaceParams[aIndex].iStrideInBytes;
   335     TInt stride = KSurfaceParams[aIndex].iStrideInBytes;
   205     if (stride == 0)
   336     if (stride == 0)
   206         {
   337         {
   207         stride = KSurfaceParams[aIndex].iXSize * PixelSize(KSurfaceParams[aIndex].iPixelFormat);
   338         stride = aSurfaceAttribs().iSize.iWidth * PixelSize(KSurfaceParams[aIndex].iPixelFormat);
   208         }
   339         }
   209     aSurfaceAttribs().iStride = stride;
   340     aSurfaceAttribs().iStride = stride;
   210     aSurfaceAttribs().iOffsetToFirstBuffer = KSurfaceParams[aIndex].iOffsetToFirstBuffer;
   341     aSurfaceAttribs().iOffsetToFirstBuffer = KSurfaceParams[aIndex].iOffsetToFirstBuffer;
   211     aSurfaceAttribs().iAlignment = KSurfaceParams[aIndex].iAlignment;
   342     aSurfaceAttribs().iAlignment = KSurfaceParams[aIndex].iAlignment;
   212     aSurfaceAttribs().iContiguous = EFalse;
   343     aSurfaceAttribs().iContiguous = EFalse;
   216     aSurfaceAttribs().iHintCount = 0;
   347     aSurfaceAttribs().iHintCount = 0;
   217     aSurfaceAttribs().iMappable = ETrue;
   348     aSurfaceAttribs().iMappable = ETrue;
   218     }
   349     }
   219 
   350 
   220 
   351 
   221 //From CSurface.
   352 void CRawSurface::CreateL(TInt aIndex, const TPoint &/* aPoint */)
   222 void CRawSurface::CreateL(TInt aIndex)
       
   223     {
   353     {
   224     RSurfaceManager::TSurfaceCreationAttributesBuf surfaceAttribs;
   354     RSurfaceManager::TSurfaceCreationAttributesBuf surfaceAttribs;
   225 
   355     SURF_ASSERT(aIndex < KSurfaceMaxIndex);
   226     GetSurfAttribs(surfaceAttribs, aIndex);
   356     TInt sizeIndex = 0;
   227     TInt err = iSurfaceManager.CreateSurface(surfaceAttribs, iSurfaceId);
   357     if (KSurfaceParams[aIndex].iXSize & LARGEST_POSSIBLE_FLAG)
       
   358         {
       
   359         sizeIndex = KMaxSurfaceSizes-1;
       
   360         
       
   361         }
       
   362     TInt err = KErrNone;
       
   363     do
       
   364         {
       
   365         GetSurfAttribs(surfaceAttribs, aIndex, sizeIndex);
       
   366         err = iSurfaceManager.CreateSurface(surfaceAttribs, iSurfaceId);
       
   367         iActualSize = surfaceAttribs().iSize;
       
   368         sizeIndex--;
       
   369         }
       
   370     while(err != KErrNone && sizeIndex >= 0);
   228     User::LeaveIfError(err);
   371     User::LeaveIfError(err);
   229     }
   372     }
   230 
   373 
   231 
   374 
   232 TUint8* CRawSurface::MapSurfaceAndGetInfoLC(RSurfaceManager::TSurfaceInfoV01& aInfo)
   375 TUint8* CRawSurface::MapSurfaceAndGetInfoLC(RSurfaceManager::TSurfaceInfoV01& aInfo)
   237     RSurfaceManager::TInfoBuf infoBuf;
   380     RSurfaceManager::TInfoBuf infoBuf;
   238     User::LeaveIfError(iSurfaceManager.SurfaceInfo(iSurfaceId, infoBuf));
   381     User::LeaveIfError(iSurfaceManager.SurfaceInfo(iSurfaceId, infoBuf));
   239     aInfo = infoBuf();
   382     aInfo = infoBuf();
   240     TInt offset = -1000;  // So we hopefully detect when it goes horribly wrong.
   383     TInt offset = -1000;  // So we hopefully detect when it goes horribly wrong.
   241     User::LeaveIfError(iSurfaceManager.GetBufferOffset(iSurfaceId, iDrawBuffer, offset));
   384     User::LeaveIfError(iSurfaceManager.GetBufferOffset(iSurfaceId, iDrawBuffer, offset));
       
   385     SURF_ASSERT(offset >= 0);
   242     return iSurfaceChunk.Base() + offset;
   386     return iSurfaceChunk.Base() + offset;
   243     }
   387     }
   244 
   388 
   245 
   389 
   246 void CRawSurface::DrawContentL(TInt aImageIndex)
   390 void CRawSurface::DrawContentL(TInt aImageIndex)
   263         bitmap->GetScanLine(buf, TPoint(0, y), pixelStride, displaymode);
   407         bitmap->GetScanLine(buf, TPoint(0, y), pixelStride, displaymode);
   264         }
   408         }
   265 
   409 
   266     CleanupStack::PopAndDestroy(2, image);
   410     CleanupStack::PopAndDestroy(2, image);
   267     }
   411     }
   268 
       
   269 
   412 
   270 void CRawSurface::DrawContentL(const TRgb& aColour)
   413 void CRawSurface::DrawContentL(const TRgb& aColour)
   271     {
   414     {
   272     //Map the surface and get its info.
   415     //Map the surface and get its info.
   273     RSurfaceManager::TSurfaceInfoV01 surfaceInfo;
   416     RSurfaceManager::TSurfaceInfoV01 surfaceInfo;
   296 
   439 
   297     CleanupStack::PopAndDestroy();
   440     CleanupStack::PopAndDestroy();
   298     }
   441     }
   299 
   442 
   300 
   443 
   301 void CRawSurface::SubmitContentL(TBool aShouldWaitForDisplay, TInt /* aRectsIndex */)
   444 void CRawSurface::DrawComplexL(const TRgb& aColour)
       
   445     {
       
   446     DrawContentL(aColour);
       
   447     }
       
   448 
       
   449 
       
   450 TInt CRawSurface::SubmitContent(TBool aShouldWaitForDisplay, TInt /* aRectsIndex */)
   302     {
   451     {
   303     TRequestStatus displayNotify = KRequestPending;
   452     TRequestStatus displayNotify = KRequestPending;
   304     TTimeStamp timeStamp;
   453     TTimeStamp timeStamp;
   305 
   454 
   306     if(aShouldWaitForDisplay)
   455     if(aShouldWaitForDisplay)
   307         {
   456         {
   308         Notify(ENotifyWhenDisplayed, displayNotify, 0);
   457         Notify(ENotifyWhenDisplayed, displayNotify, 0);
   309         }
   458         }
   310 
   459 
   311     TInt err = iSurfaceUpdate.SubmitUpdate(KAllScreens, iSurfaceId, iDrawBuffer, NULL);
   460     TInt err = iSurfaceUpdate.SubmitUpdate(KAllScreens, iSurfaceId, iDrawBuffer, NULL);
   312     User::LeaveIfError(err);
   461     if (err != KErrNone)
       
   462         {
       
   463         if (err != KErrNone)
       
   464             {
       
   465             RDebug::Printf("%s:%d: SubmitUpdate gave unexpected error %d", __FILE__, __LINE__, err);
       
   466             }
       
   467         return err;
       
   468         }
   313     iDrawBuffer = (iDrawBuffer + 1) % iBuffers;
   469     iDrawBuffer = (iDrawBuffer + 1) % iBuffers;
   314 
   470 
   315     if(aShouldWaitForDisplay)
   471     if(aShouldWaitForDisplay)
   316         {
   472         {
   317         TUint32 dummy;
   473         TUint32 dummy;
   318         TInt err = WaitFor(ENotifyWhenDisplayed, displayNotify, 100 * 1000, dummy);
   474         err = WaitFor(ENotifyWhenDisplayed, displayNotify, 100 * 1000, dummy);
   319         if (err != KErrNone && err != KErrNotVisible && err != KErrOverflow)
   475         if (err != KErrNone && err != KErrNotVisible && err != KErrOverflow)
   320             {
   476             {
   321             RDebug::Printf("%s:%d: NotifyWhenDisplayed gave unexpected error %d", __FILE__, __LINE__, err);
   477 //            RDebug::Printf("%s:%d: NotifyWhenDisplayed gave unexpected error %d", __FILE__, __LINE__, err);
   322             User::Leave(err);
   478             return err;
   323             }
   479             }
   324         }
   480         }
       
   481     return KErrNone;
   325     }
   482     }
   326 
   483 
   327 
   484 
   328 TSurfaceId CRawSurface::SurfaceId() const
   485 TSurfaceId CRawSurface::SurfaceId() const
   329     {
   486     {
   370     {
   527     {
   371     RTimer timer;
   528     RTimer timer;
   372     TInt err = timer.CreateLocal();
   529     TInt err = timer.CreateLocal();
   373     if (err != KErrNone)
   530     if (err != KErrNone)
   374         {
   531         {
       
   532         RDebug::Printf("%s:%d: Could not create timer... err= %d", __FILE__, __LINE__, err);
   375         return err;
   533         return err;
   376         }
   534         }
   377     TRequestStatus timerStatus = KRequestPending;
   535     TRequestStatus timerStatus = KRequestPending;
   378 #if __WINS__
   536 #if __WINS__
   379     // Windows timer isn't very precise - add some "fuzz" to the timeout to ensure we do not wait "too little".
   537     // Windows timer isn't very precise - add some "fuzz" to the timeout to ensure we do not wait "too little".
   401     TInt result = aStatus.Int();
   559     TInt result = aStatus.Int();
   402     aStatus = KRequestPending;
   560     aStatus = KRequestPending;
   403     return result;
   561     return result;
   404     }
   562     }
   405 
   563 
   406 
       
   407 
       
   408 const TText *CRawSingleBufferSurface::GetSurfaceTypeStr() const
   564 const TText *CRawSingleBufferSurface::GetSurfaceTypeStr() const
   409     {
   565     {
   410     return _S("CRawSingleBufferedSurface");
   566     return _S("CRawSingleBufferedSurface");
   411     }
   567     }
   412 
   568 
   418     CleanupStack::Pop(obj);
   574     CleanupStack::Pop(obj);
   419     return obj;
   575     return obj;
   420     }
   576     }
   421 
   577 
   422 
   578 
   423 void CRawSingleBufferSurface::CreateL(TInt aIndex)
   579 void CRawSingleBufferSurface::CreateL(TInt aIndex, const TPoint & /*aPoint */)
   424     {
   580     {
   425     RSurfaceManager::TSurfaceCreationAttributesBuf surfaceAttribs;
   581     RSurfaceManager::TSurfaceCreationAttributesBuf surfaceAttribs;
   426 
   582 
   427     GetSurfAttribs(surfaceAttribs, aIndex);
   583     TInt sizeIndex = 0;
   428 
   584     if (KSurfaceParams[aIndex].iXSize & LARGEST_POSSIBLE_FLAG)
   429     iBuffers = 1;
   585         {
   430     surfaceAttribs().iBuffers = 1;
   586         sizeIndex = KMaxSurfaceSizes-1;
   431 
   587         }
   432     TInt err = iSurfaceManager.CreateSurface(surfaceAttribs, iSurfaceId);
   588     TInt err = KErrNone;
   433     User::LeaveIfError(err);
   589     do
       
   590         {
       
   591         GetSurfAttribs(surfaceAttribs, aIndex, sizeIndex);
       
   592         iBuffers = 1;
       
   593         surfaceAttribs().iBuffers = 1;
       
   594         err = iSurfaceManager.CreateSurface(surfaceAttribs, iSurfaceId);
       
   595         iActualSize = surfaceAttribs().iSize;
       
   596         sizeIndex--;
       
   597         }
       
   598     while(err != KErrNone && sizeIndex >= 0);
   434     }
   599     }
   435 
   600 
   436 CRawSingleBufferSurface::~CRawSingleBufferSurface()
   601 CRawSingleBufferSurface::~CRawSingleBufferSurface()
   437     {
   602     {
   438     }
   603     }
   439 
   604 
   440 class CWindow: public CBase
   605 
   441     {
   606 TInt CEglSurfaceBase::Activate()
   442 public:
       
   443     static CWindow *NewL(TInt aIndex);
       
   444     RWindow& Window();
       
   445     ~CWindow();
       
   446 private:
       
   447     void ConstructL(TInt aIndex);
       
   448     CWindow();
       
   449 
       
   450 private:
       
   451     RWindow iWindow;
       
   452     RWindowGroup iWindowGroup;
       
   453     RWsSession iWsSession;
       
   454     };
       
   455 
       
   456 
       
   457 CWindow* CWindow::NewL(TInt aIndex)
       
   458     {
       
   459     CWindow *self = new (ELeave) CWindow;
       
   460     CleanupStack::PushL(self);
       
   461     self->ConstructL(aIndex);
       
   462     CleanupStack::Pop(self);
       
   463     return self;
       
   464     }
       
   465 
       
   466 
       
   467 void CWindow::ConstructL(TInt aIndex)
       
   468     {
       
   469     RFbsSession::Connect();
       
   470     if (aIndex >= KSurfaceMaxIndex)
       
   471         {
       
   472         User::Leave(KErrOverflow);
       
   473         }
       
   474     User::LeaveIfError(iWsSession.Connect());
       
   475     iWindowGroup = RWindowGroup(iWsSession);
       
   476     User::LeaveIfError(iWindowGroup.Construct((TUint32)this));
       
   477     iWindow = RWindow(iWsSession);
       
   478     User::LeaveIfError(iWindow.Construct(iWindowGroup, -1U));
       
   479     const TSurfaceParamsCommon& winAttrib = KSurfaceParams[aIndex];
       
   480     iWindow.SetExtent(TPoint(winAttrib.iXPos, winAttrib.iYPos), TSize(winAttrib.iXSize, winAttrib.iYSize));
       
   481     iWindow.SetRequiredDisplayMode(winAttrib.iDisplayMode);
       
   482     iWindow.Activate();
       
   483     }
       
   484 
       
   485 
       
   486 CWindow::~CWindow()
       
   487     {
       
   488     iWindow.Close();
       
   489     iWindowGroup.Close();
       
   490     iWsSession.Close();
       
   491     RFbsSession::Disconnect();
       
   492     }
       
   493 
       
   494 
       
   495 CWindow::CWindow()
       
   496     {
       
   497     }
       
   498 
       
   499 
       
   500 RWindow& CWindow::Window()
       
   501     {
       
   502     return iWindow;
       
   503     }
       
   504 
       
   505 
       
   506 CEglWindowSurface* CEglWindowSurface::NewL()
       
   507     {
       
   508     CEglWindowSurface* self = new (ELeave) CEglWindowSurface;
       
   509     CleanupStack::PushL(self);
       
   510     self->ConstructL();
       
   511     CleanupStack::Pop(self);
       
   512     return self;
       
   513     }
       
   514 
       
   515 
       
   516 void CEglWindowSurface::ConstructL()
       
   517     {
       
   518     }
       
   519 
       
   520 
       
   521 CEglWindowSurface::CEglWindowSurface()
       
   522     {
       
   523     }
       
   524 
       
   525 
       
   526 void CEglWindowSurface::CreateL(TInt aIndex)
       
   527     {
       
   528     SURF_ASSERT(aIndex < KSurfaceMaxIndex);
       
   529     SURF_ASSERT(aIndex == KSurfaceParams[aIndex].iIndex);
       
   530     iParamIndex = aIndex;
       
   531     iWindow = CWindow::NewL(aIndex);
       
   532     iDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
       
   533     EGLint err;
       
   534     if (iDisplay == EGL_NO_DISPLAY)
       
   535         {
       
   536         err = eglGetError();
       
   537         RDebug::Printf("%s:%d: err = %d", __FILE__, __LINE__, err);
       
   538         User::Leave(KErrNotSupported);
       
   539         }
       
   540 
       
   541     EGLConfig config;
       
   542     EGLint nConfigs = 0;
       
   543 
       
   544     // TODO: Need to use differnet config attribs based on aIndex.
       
   545     static const EGLint KConfigAttribs[] =
       
   546     {
       
   547         EGL_BUFFER_SIZE,    32,
       
   548         EGL_RED_SIZE,       8,
       
   549         EGL_GREEN_SIZE,     8,
       
   550         EGL_BLUE_SIZE,      8,
       
   551         EGL_ALPHA_SIZE,     8,
       
   552         EGL_SURFACE_TYPE,   EGL_WINDOW_BIT,
       
   553         EGL_RENDERABLE_TYPE,EGL_OPENVG_BIT,
       
   554         EGL_NONE
       
   555     };
       
   556 
       
   557     // Need some way to configure the attribs ...
       
   558     eglChooseConfig(iDisplay, KConfigAttribs, &config, 1, &nConfigs);
       
   559     if (!nConfigs)
       
   560         {
       
   561         err = eglGetError();
       
   562         RDebug::Printf("%s:%d: err = %d", __FILE__, __LINE__, err);
       
   563         User::Leave(KErrNotSupported);
       
   564         }
       
   565 
       
   566     if (!eglBindAPI(EGL_OPENVG_API))
       
   567         {
       
   568         err = eglGetError();
       
   569         RDebug::Printf("%s:%d: err = %d", __FILE__, __LINE__, err);
       
   570         User::Leave(KErrNotSupported);
       
   571         }
       
   572     iContext = eglCreateContext(iDisplay, config, 0, NULL);
       
   573     if (iContext == EGL_NO_CONTEXT)
       
   574         {
       
   575         err = eglGetError();
       
   576         RDebug::Printf("%s:%d: err = %d", __FILE__, __LINE__, err);
       
   577         User::Leave(KErrNotSupported);
       
   578         }
       
   579 
       
   580     iSurface = eglCreateWindowSurface(iDisplay, config, &iWindow->Window(), NULL);
       
   581     if (iSurface == EGL_NO_SURFACE)
       
   582         {
       
   583         err = eglGetError();
       
   584         RDebug::Printf("%s:%d: err = %d", __FILE__, __LINE__, err);
       
   585         User::Leave(KErrNotSupported);
       
   586         }
       
   587     }
       
   588 
       
   589 void CEglWindowSurface::SubmitContentL(TBool aShouldWaitForDisplay, TInt /* aRectsIndex */)
       
   590     {
       
   591     ActivateL();
       
   592     if (!eglSwapBuffers(iDisplay, iSurface))
       
   593         {
       
   594         User::Leave(KErrBadHandle);
       
   595         }
       
   596     if (aShouldWaitForDisplay)
       
   597         {
       
   598         // We are cheating: We just wait for a bit to ensure that the swapbuffer is actually finished.
       
   599         // There is no way to determine how long this takes, so we just grab a number that should be
       
   600         // large enough...
       
   601         User::After(100 * 1000);  // Wait 100ms.
       
   602         }
       
   603     }
       
   604 
       
   605 void CEglWindowSurface::ActivateL()
       
   606     {
   607     {
   607     if (!eglMakeCurrent(iDisplay, iSurface, iSurface, iContext))
   608     if (!eglMakeCurrent(iDisplay, iSurface, iSurface, iContext))
   608         {
   609         {
   609         User::Leave(KErrBadHandle);
   610         EGLint err = eglGetError();
   610         }
   611         RDebug::Printf("%s:%d: eglMakeCurrent gave error 0x%x", __FILE__, __LINE__, err);
   611     }
   612         return KErrBadHandle;
   612 
   613         }
   613 CEglWindowSurface::~CEglWindowSurface()
   614     return KErrNone;
   614     {
   615     }
   615     eglMakeCurrent(iDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
   616 
   616     if (iSurface != EGL_NO_SURFACE)
   617 void CEglSurfaceBase::ActivateL()
   617         {
   618     {
   618         eglDestroySurface(iDisplay, iSurface);
   619     User::LeaveIfError(Activate());
   619         iSurface = EGL_NO_SURFACE;
   620     }
   620         }
   621 
   621 
   622 void CEglSurfaceBase::DrawComplexL(const TRgb& aColour)
   622     if (iDisplay != EGL_NO_DISPLAY)
       
   623         {
       
   624         eglDestroyContext(iDisplay, iContext);
       
   625         }
       
   626 
       
   627     delete iWindow;
       
   628     }
       
   629 
       
   630 TSurfaceId CEglWindowSurface::SurfaceId() const
       
   631     {
       
   632     // Default constructor for id sets it to a NULL-value, so if no window is created, we get
       
   633     // a defined surface id value that is invalid.
       
   634     TSurfaceId id;
       
   635     if (iWindow)
       
   636         {
       
   637         TSurfaceConfiguration surfConfig;
       
   638         iWindow->Window().GetBackgroundSurface(surfConfig);
       
   639         surfConfig.GetSurfaceId(id);
       
   640         }
       
   641     return id;
       
   642     }
       
   643 
       
   644 
       
   645 void CEglWindowSurface::DrawContentL(const TRgb& aColour)
       
   646     {
   623     {
   647     ActivateL();
   624     ActivateL();
   648 
   625 
   649     TSize size;
   626     TSize size;
   650     eglQuerySurface(iDisplay, iSurface, EGL_WIDTH, &size.iWidth);
   627     eglQuerySurface(iDisplay, iSurface, EGL_WIDTH, &size.iWidth);
   651     eglQuerySurface(iDisplay, iSurface, EGL_HEIGHT, &size.iHeight);
   628     eglQuerySurface(iDisplay, iSurface, EGL_HEIGHT, &size.iHeight);
   652 
   629     
       
   630     //Paint lots of random circles to keep the GPU busy.
       
   631     for(TInt i=0; i < 300; i++)
       
   632         {
       
   633         VGPaint paint = vgCreatePaint();
       
   634         VGPath path = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, 1.0f, 0.0f, 0, 0, VG_PATH_CAPABILITY_APPEND_TO);
       
   635         
       
   636         TInt minDim = Min(size.iWidth, size.iHeight);
       
   637         VGfloat cx = RandomNumberInRange(0, size.iWidth);
       
   638         VGfloat cy = RandomNumberInRange(0, size.iHeight);
       
   639         VGfloat diameter = RandomNumberInRange(minDim / 20, minDim / 3);
       
   640         TRgb fillColour(RandomNumberInRange(0, 255), RandomNumberInRange(0, 255), RandomNumberInRange(0, 255), RandomNumberInRange(0, 255));
       
   641         
       
   642         vguEllipse(path, cx, cy, diameter, diameter);
       
   643         vgSetPaint(paint, VG_FILL_PATH);
       
   644         vgSetColor(paint, fillColour.Value());
       
   645         vgDrawPath(path, VG_FILL_PATH);
       
   646         
       
   647         vgDestroyPath(path);
       
   648         vgDestroyPaint(paint);
       
   649         }
       
   650     
       
   651     //Paint the top corner with aColour so we can identify the drawing.
   653     VGfloat fillColour[4];
   652     VGfloat fillColour[4];
   654     fillColour[0] = (VGfloat)aColour.Red() / 255.0f;
   653     fillColour[0] = (VGfloat)aColour.Red() / 255.0f;
   655     fillColour[1] = (VGfloat)aColour.Green() / 255.0f;
   654     fillColour[1] = (VGfloat)aColour.Green() / 255.0f;
   656     fillColour[2] = (VGfloat)aColour.Blue() / 255.0f;
   655     fillColour[2] = (VGfloat)aColour.Blue() / 255.0f;
   657     fillColour[3] = (VGfloat)aColour.Alpha() / 255.0f;
   656     fillColour[3] = (VGfloat)aColour.Alpha() / 255.0f;
       
   657     
       
   658     vgSetfv(VG_CLEAR_COLOR, 4, fillColour);
       
   659     vgClear(0, 0, 20, size.iHeight);
       
   660     }
       
   661 
       
   662 void CEglSurfaceBase::DrawContentL(const TRgb& aColour)
       
   663     {
       
   664     ActivateL();
       
   665 
       
   666     TSize size;
       
   667     eglQuerySurface(iDisplay, iSurface, EGL_WIDTH, &size.iWidth);
       
   668     eglQuerySurface(iDisplay, iSurface, EGL_HEIGHT, &size.iHeight);
       
   669 
       
   670     VGfloat fillColour[4];
       
   671     fillColour[0] = (VGfloat)aColour.Red() / 255.0f;
       
   672     fillColour[1] = (VGfloat)aColour.Green() / 255.0f;
       
   673     fillColour[2] = (VGfloat)aColour.Blue() / 255.0f;
       
   674     fillColour[3] = (VGfloat)aColour.Alpha() / 255.0f;
   658 
   675 
   659     vgSetfv(VG_CLEAR_COLOR, 4, fillColour);
   676     vgSetfv(VG_CLEAR_COLOR, 4, fillColour);
   660     vgClear(0, 0, size.iWidth, size.iHeight);
   677     vgClear(0, 0, size.iWidth, size.iHeight);
   661     }
   678     }
   662 
   679 
   663 
   680 void CEglSurfaceBase::CreateL(TInt aIndex, const TPoint &aOffset)
   664 void CEglWindowSurface::DrawContentL(TInt aIndex)
   681     {
       
   682     SURF_ASSERT(aIndex < KSurfaceMaxIndex);
       
   683     SURF_ASSERT(aIndex == KSurfaceParams[aIndex].iIndex);
       
   684 
       
   685     TInt sizeIndex = 0;
       
   686     if (KSurfaceParams[aIndex].iXSize & LARGEST_POSSIBLE_FLAG)
       
   687         {
       
   688         sizeIndex = KMaxSurfaceSizes-1;
       
   689         }
       
   690     TInt err = KErrNone;
       
   691     do
       
   692         {
       
   693         TRAP(err, DoCreateL(aIndex, aOffset, sizeIndex));
       
   694         sizeIndex--;
       
   695         }
       
   696     while(err != KErrNone && sizeIndex >= 0);
       
   697     if (err != KErrNone)
       
   698         {
       
   699 //        RDebug::Printf("%s:%d: err=%d (%d x %d)", __FILE__, __LINE__, err, iActualSize.iWidth, iActualSize.iHeight);
       
   700         User::Leave(err);
       
   701         }
       
   702     }
       
   703 
       
   704 TInt CEglSurfaceBase::SubmitContent(TBool aShouldWaitForDisplay, TInt /* aRectsIndex */)
       
   705     {
       
   706     TInt err = Activate();
       
   707     if (err != KErrNone)
       
   708         {
       
   709         return err;
       
   710         }
       
   711     if (!eglSwapBuffers(iDisplay, iSurface))
       
   712         {
       
   713         EGLint err = eglGetError();
       
   714         RDebug::Printf("%s:%d: eglSwapBuffers gave error 0x%x", __FILE__, __LINE__, err);
       
   715         return KErrBadHandle;
       
   716         }
       
   717     if (aShouldWaitForDisplay)
       
   718         {
       
   719         // We are cheating: We just wait for a bit to ensure that the swapbuffer is actually finished.
       
   720         // There is no way to determine how long this takes, so we just grab a number that should be
       
   721         // large enough...
       
   722         User::After(100 * 1000);  // Wait 100ms.
       
   723         }
       
   724     return KErrNone;
       
   725     }
       
   726 
       
   727 void CEglSurfaceBase::DrawContentL(TInt aIndex)
   665     {
   728     {
   666     ActivateL();
   729     ActivateL();
   667     CTestVgImage *vgImage = CTestVgImage::NewL(aIndex);
   730     CTestVgImage *vgImage = CTestVgImage::NewL(aIndex);
   668     CleanupStack::PushL(vgImage);
   731     CleanupStack::PushL(vgImage);
   669     vgDrawImage(vgImage->VGImage());
   732     vgDrawImage(vgImage->VGImage());
   670     CleanupStack::PopAndDestroy(vgImage);
   733     CleanupStack::PopAndDestroy(vgImage);
   671     }
   734     }
   672 
   735 
   673 void CEglWindowSurface::GetSurfaceParamsL(TSurfaceParamsRemote &aParams)
   736 void CEglSurfaceBase::GetSurfaceParamsL(TSurfaceParamsRemote &aParams)
   674     {
   737     {
   675     RSurfaceManager surfaceManager;
   738     RSurfaceManager surfaceManager;
   676     User::LeaveIfError(surfaceManager.Open());
   739     User::LeaveIfError(surfaceManager.Open());
   677     RSurfaceManager::TInfoBuf infoBuf;
   740     RSurfaceManager::TInfoBuf infoBuf;
   678     TInt err = surfaceManager.SurfaceInfo(SurfaceId(), infoBuf);
   741     TInt err = surfaceManager.SurfaceInfo(SurfaceId(), infoBuf);
   692         {
   755         {
   693         aParams.iCommonParams.iAttribs[i] = KSurfaceParams[iParamIndex].iAttribs[i];
   756         aParams.iCommonParams.iAttribs[i] = KSurfaceParams[iParamIndex].iAttribs[i];
   694         }
   757         }
   695     }
   758     }
   696 
   759 
       
   760 
       
   761 TInt CEglSurfaceBase::Notify(TNotification /*aWhen*/, TRequestStatus& /*aStatus*/, TUint32 /*aXTImes*/)
       
   762     {
       
   763     return KErrNotSupported;
       
   764     }
       
   765 
       
   766 TInt CEglSurfaceBase::WaitFor(TNotification /*aWhen*/, TRequestStatus& /*aStatus*/,
       
   767         TInt /*aTimeoutinMicroseconds*/, TUint32 & /*aTimeStamp*/)
       
   768     {
       
   769     return KErrNotSupported;
       
   770     }
       
   771 
       
   772 void CEglSurfaceBase::BaseCreateL(TInt aIndex, EGLint aSurfaceType)
       
   773     {
       
   774     iParamIndex = aIndex;
       
   775     iDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
       
   776     
       
   777     EGLint err;
       
   778     if (iDisplay == EGL_NO_DISPLAY)
       
   779         {
       
   780         err = eglGetError();
       
   781         RDebug::Printf("%s:%d: err = 0x%x", __FILE__, __LINE__, err);
       
   782         User::Leave(KErrNotSupported);
       
   783         }
       
   784     
       
   785     EGLint nConfigs = 0;
       
   786     
       
   787     // TODO: Need to use differnet config attribs based on aIndex.
       
   788     EGLint configAttribs[] =
       
   789     {
       
   790         EGL_BUFFER_SIZE,    32,
       
   791         EGL_RED_SIZE,       8,
       
   792         EGL_GREEN_SIZE,     8,
       
   793         EGL_BLUE_SIZE,      8,
       
   794         EGL_ALPHA_SIZE,     8,
       
   795         EGL_SURFACE_TYPE,   EGL_WINDOW_BIT,
       
   796         EGL_RENDERABLE_TYPE,EGL_OPENVG_BIT,
       
   797         EGL_NONE
       
   798     };
       
   799     
       
   800     // Update surfacetype type to match 
       
   801     for(TInt i = 0; configAttribs[i] != EGL_NONE; i += 2)
       
   802         {
       
   803         if (configAttribs[i] == EGL_SURFACE_TYPE)
       
   804             {
       
   805             configAttribs[i+1] = aSurfaceType;
       
   806             }
       
   807         }
       
   808     // Need some way to configure the attribs ...
       
   809     eglChooseConfig(iDisplay, configAttribs, &iConfig, 1, &nConfigs);
       
   810     if (!nConfigs)
       
   811         {
       
   812         err = eglGetError();
       
   813         RDebug::Printf("%s:%d: err = %d", __FILE__, __LINE__, err);
       
   814         User::Leave(KErrNotSupported);
       
   815         }
       
   816     
       
   817     if (!eglBindAPI(EGL_OPENVG_API))
       
   818         {
       
   819         err = eglGetError();
       
   820         RDebug::Printf("%s:%d: err = %d", __FILE__, __LINE__, err);
       
   821         User::Leave(KErrNotSupported);
       
   822         }
       
   823     iContext = eglCreateContext(iDisplay, iConfig, 0, NULL);
       
   824     if (iContext == EGL_NO_CONTEXT)
       
   825         {
       
   826         err = eglGetError();
       
   827         //RDebug::Printf("%s:%d: err = %d", __FILE__, __LINE__, err);
       
   828         User::Leave(KErrNotSupported);
       
   829         }
       
   830     }
       
   831 
       
   832 void CEglSurfaceBase::Destroy()
       
   833     {
       
   834     eglMakeCurrent(iDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
       
   835     if (iSurface != EGL_NO_SURFACE)
       
   836         {
       
   837         eglDestroySurface(iDisplay, iSurface);
       
   838         iSurface = EGL_NO_SURFACE;
       
   839         }
       
   840 
       
   841     if (iDisplay != EGL_NO_DISPLAY)
       
   842         {
       
   843         eglDestroyContext(iDisplay, iContext);
       
   844         }
       
   845     }
       
   846 
       
   847 
       
   848 class CWindow: public CBase
       
   849     {
       
   850 public:
       
   851     static CWindow *NewL(TInt aIndex, const TPoint &aOffset, TInt aSizeIndex);
       
   852     RWindow& Window();
       
   853     ~CWindow();
       
   854 private:
       
   855     void ConstructL(TInt aIndex, const TPoint &aOffset, TInt aSizeIndex);
       
   856     CWindow();
       
   857 
       
   858 private:
       
   859     RWindow iWindow;
       
   860     RWindowGroup iWindowGroup;
       
   861     RWsSession iWsSession;
       
   862     };
       
   863 
       
   864 
       
   865 CWindow* CWindow::NewL(TInt aIndex, const TPoint &aOffset, TInt aSizeIndex)
       
   866     {
       
   867     CWindow *self = new (ELeave) CWindow;
       
   868     CleanupStack::PushL(self);
       
   869     self->ConstructL(aIndex, aOffset, aSizeIndex);
       
   870     CleanupStack::Pop(self);
       
   871     return self;
       
   872     }
       
   873 
       
   874 
       
   875 void CWindow::ConstructL(TInt aIndex, const TPoint &aOffset, TInt aSizeIndex)
       
   876     {
       
   877     RFbsSession::Connect();
       
   878     if (aIndex >= KSurfaceMaxIndex)
       
   879         {
       
   880         User::Leave(KErrOverflow);
       
   881         }
       
   882     User::LeaveIfError(iWsSession.Connect());
       
   883     iWindowGroup = RWindowGroup(iWsSession);
       
   884     User::LeaveIfError(iWindowGroup.Construct((TUint32)this));
       
   885     iWindow = RWindow(iWsSession);
       
   886     User::LeaveIfError(iWindow.Construct(iWindowGroup, -1U));
       
   887     TSurfaceParamsCommon winAttrib = KSurfaceParams[aIndex];
       
   888     TSize winSize;
       
   889     if (winAttrib.iXSize & LARGEST_POSSIBLE_FLAG)
       
   890         {
       
   891         winSize = TSize(KSurfaceSizes[aSizeIndex].iWidth, KSurfaceSizes[aSizeIndex].iHeight);
       
   892         }
       
   893     else
       
   894         {
       
   895         winSize = TSize(winAttrib.iXSize, winAttrib.iYSize);
       
   896         }
       
   897     iWindow.SetExtent(TPoint(winAttrib.iXPos + aOffset.iX, winAttrib.iYPos + aOffset.iY), winSize);
       
   898     iWindow.SetRequiredDisplayMode(winAttrib.iDisplayMode);
       
   899     iWindow.Activate();
       
   900     }
       
   901 
       
   902 
       
   903 CWindow::~CWindow()
       
   904     {
       
   905     iWindow.Close();
       
   906     iWindowGroup.Close();
       
   907     iWsSession.Close();
       
   908     RFbsSession::Disconnect();
       
   909     }
       
   910 
       
   911 
       
   912 CWindow::CWindow()
       
   913     {
       
   914     }
       
   915 
       
   916 
       
   917 RWindow& CWindow::Window()
       
   918     {
       
   919     return iWindow;
       
   920     }
       
   921 
       
   922 
       
   923 CEglWindowSurface* CEglWindowSurface::NewL()
       
   924     {
       
   925     CEglWindowSurface* self = new (ELeave) CEglWindowSurface;
       
   926     CleanupStack::PushL(self);
       
   927     self->ConstructL();
       
   928     CleanupStack::Pop(self);
       
   929     return self;
       
   930     }
       
   931 
       
   932 
       
   933 void CEglWindowSurface::ConstructL()
       
   934     {
       
   935     }
       
   936 
       
   937 
       
   938 CEglWindowSurface::CEglWindowSurface()
       
   939     {
       
   940     }
       
   941 
       
   942 
       
   943 void CEglWindowSurface::DoCreateL(TInt aIndex, const TPoint &aOffset, TInt aSizeIndex)
       
   944     {
       
   945     iParamIndex = aIndex;
       
   946     iWindow = CWindow::NewL(aIndex, aOffset, aSizeIndex);
       
   947     iActualSize = iWindow->Window().Size();
       
   948     
       
   949     CEglSurfaceBase::BaseCreateL(aIndex, EGL_WINDOW_BIT);
       
   950     
       
   951     iSurface = eglCreateWindowSurface(iDisplay, iConfig, &iWindow->Window(), NULL);
       
   952     if (iSurface == EGL_NO_SURFACE)
       
   953         {
       
   954         EGLint err = eglGetError();
       
   955         RDebug::Printf("%s:%d: err = %x (%d x %d)", __FILE__, __LINE__, err, iActualSize.iWidth, iActualSize.iHeight);
       
   956         User::Leave(KErrNotSupported);
       
   957         }
       
   958     }
       
   959 
       
   960 
       
   961 CEglWindowSurface::~CEglWindowSurface()
       
   962     {
       
   963     Destroy();
       
   964 	eglReleaseThread();
       
   965     delete iWindow;
       
   966     }
       
   967 
       
   968 
       
   969 TSurfaceId CEglWindowSurface::SurfaceId() const
       
   970     {
       
   971     // Default constructor for id sets it to a NULL-value, so if no window is created, we get
       
   972     // a defined surface id value that is invalid.
       
   973     TSurfaceId id;
       
   974     if (iWindow)
       
   975         {
       
   976         TSurfaceConfiguration surfConfig;
       
   977         iWindow->Window().GetBackgroundSurface(surfConfig);
       
   978         surfConfig.GetSurfaceId(id);
       
   979         }
       
   980     return id;
       
   981     }
       
   982 
       
   983 
   697 const TText *CEglWindowSurface::GetSurfaceTypeStr() const
   984 const TText *CEglWindowSurface::GetSurfaceTypeStr() const
   698     {
   985     {
   699     return _S("CEglWindowSurface");
   986     return _S("CEglWindowSurface");
   700     }
   987     }
   701 
   988 
   702 TInt CEglWindowSurface::Notify(TNotification /*aWhen*/, TRequestStatus& /*aStatus*/, TUint32 /*aXTImes*/)
   989 
   703     {
   990 CEglPBufferSurface::CEglPBufferSurface()
   704     return KErrNotSupported;
   991     {
   705     }
   992     }
   706 
   993 
   707 TInt CEglWindowSurface::WaitFor(TNotification /*aWhen*/, TRequestStatus& /*aStatus*/,
   994 
   708         TInt /*aTimeoutinMicroseconds*/, TUint32 & /*aTimeStamp*/)
   995 CEglPBufferSurface::~CEglPBufferSurface()
   709     {
   996     {
   710     return KErrNotSupported;
   997     Destroy();
       
   998 	eglReleaseThread();
       
   999     }
       
  1000     
       
  1001 
       
  1002 CEglPBufferSurface* CEglPBufferSurface::NewL()
       
  1003     {
       
  1004     CEglPBufferSurface* self = new (ELeave) CEglPBufferSurface;
       
  1005     CleanupStack::PushL(self);
       
  1006     self->ConstructL();
       
  1007     CleanupStack::Pop(self);
       
  1008     return self;
       
  1009     }
       
  1010 
       
  1011 
       
  1012 void CEglPBufferSurface::ConstructL()
       
  1013     {
       
  1014     }
       
  1015     
       
  1016 
       
  1017 const TText *CEglPBufferSurface::GetSurfaceTypeStr() const
       
  1018     {
       
  1019     return _S("CEglPBufferSurface");
       
  1020     }
       
  1021 
       
  1022 
       
  1023 void CEglPBufferSurface::DoCreateL(TInt aIndex, const TPoint &/*aOffset*/, TInt aSizeIndex)
       
  1024     {
       
  1025     CEglSurfaceBase::BaseCreateL(aIndex, EGL_PBUFFER_BIT);
       
  1026 
       
  1027     EGLint attribs[] = 
       
  1028             {
       
  1029                 EGL_WIDTH, 0,
       
  1030                 EGL_HEIGHT, 0,
       
  1031                 EGL_NONE,
       
  1032             };
       
  1033     if (KSurfaceParams[aIndex].iXSize & ELargestPossibleSurface)
       
  1034         {
       
  1035         iActualSize.iWidth = KSurfaceSizes[aSizeIndex].iWidth;
       
  1036         iActualSize.iHeight = KSurfaceSizes[aSizeIndex].iHeight;
       
  1037         }
       
  1038     else
       
  1039         {
       
  1040         iActualSize.iWidth = KSurfaceParams[aIndex].iXSize;
       
  1041         iActualSize.iHeight = KSurfaceParams[aIndex].iYSize;
       
  1042         }
       
  1043     for(TInt i = 0; attribs[i] != EGL_NONE; i += 2)
       
  1044         {
       
  1045         switch(attribs[i])
       
  1046             {
       
  1047             case EGL_HEIGHT:
       
  1048                 attribs[i+1] = iActualSize.iHeight;
       
  1049                 break;
       
  1050             case EGL_WIDTH:
       
  1051                 attribs[i+1] = iActualSize.iWidth;
       
  1052                 break;
       
  1053             }
       
  1054         }
       
  1055     
       
  1056     iSurface = eglCreatePbufferSurface(iDisplay, iConfig, attribs);
       
  1057     if (iSurface == EGL_NO_SURFACE)
       
  1058         {
       
  1059         EGLint err = eglGetError();
       
  1060         User::Leave(KErrNotSupported);
       
  1061         }
       
  1062     }
       
  1063 
       
  1064 
       
  1065 TSurfaceId CEglPBufferSurface::SurfaceId() const
       
  1066     {
       
  1067     SURF_ASSERT(0);  // We shouldn't call this!
       
  1068     return TSurfaceId::CreateNullId();
       
  1069     }
       
  1070 
       
  1071 TInt CEglPBufferSurface::SizeInBytes() const
       
  1072     {
       
  1073     // size of a pixel in bits. 
       
  1074     EGLint size;
       
  1075     if (!eglGetConfigAttrib(iDisplay, iConfig, EGL_BUFFER_SIZE, &size))
       
  1076         {
       
  1077         RDebug::Printf("Unable to get EGL_BUFFER_SIZE from config %d, err = %04x", iConfig, eglGetError());
       
  1078         return 0;
       
  1079         }
       
  1080     
       
  1081     return (KSurfaceParams[iParamIndex].iXSize * KSurfaceParams[iParamIndex].iYSize * size) / 8;
   711     }
  1082     }
   712 
  1083 
   713 
  1084 
   714 // Factory function.
  1085 // Factory function.
   715 CSurface *CSurface::SurfaceFactoryL(TSurfaceType aSurfaceType)
  1086 CSurface *CSurface::SurfaceFactoryL(TSurfaceType aSurfaceType)
   716     {
  1087     {
   717     switch(aSurfaceType)
  1088     switch(aSurfaceType)
   718         {
  1089         {
   719         case ESurfTypeRaw:
  1090         case ESurfTypeRaw:
   720             return CRawSurface::NewL();
  1091             return CRawSurface::NewL();
       
  1092             
   721         case ESurfTypeEglWindow:
  1093         case ESurfTypeEglWindow:
   722             return CEglWindowSurface::NewL();
  1094             return CEglWindowSurface::NewL();
       
  1095             
   723         case ESurfTypeRawSingleBuffered:
  1096         case ESurfTypeRawSingleBuffered:
   724             return CRawSingleBufferSurface::NewL();
  1097             return CRawSingleBufferSurface::NewL();
       
  1098             
       
  1099         case ESurfTypePBuffer:
       
  1100             return CEglPBufferSurface::NewL();
       
  1101             
   725         default:
  1102         default:
   726             SURF_ASSERT(0);
  1103             SURF_ASSERT(0);
   727             return NULL;
  1104             return NULL;
   728         }
  1105         }
   729     }
  1106     }
   730