egl/sfegltest/src/eglrendering.cpp
branchbug235_bringup_0
changeset 210 da03feddbab7
parent 205 c7cc034fd51d
child 211 3804ba25b23f
--- a/egl/sfegltest/src/eglrendering.cpp	Fri Oct 22 11:59:21 2010 +0100
+++ b/egl/sfegltest/src/eglrendering.cpp	Fri Oct 22 22:19:05 2010 +0100
@@ -12,256 +12,244 @@
 //
 // Description:
 
+#include "eglrendering.h"
 #include <string.h>
-#include "eglrendering.h"
-#include "openvgengine.h"
-#include <hal.h>
 
 const TInt KTimerDelay = 0;
 
-
 /** Attributes to be passed into eglChooseConfig */
-const EGLint	KColorRGBA8888AttribList[] =
+const EGLint KAttribList[] =
 		{
 		EGL_RED_SIZE,			8,
 		EGL_GREEN_SIZE,			8,
 		EGL_BLUE_SIZE,			8,
         EGL_ALPHA_SIZE,         8,
 		EGL_SURFACE_TYPE,		EGL_WINDOW_BIT,
-		EGL_RENDERABLE_TYPE, 	EGL_OPENVG_BIT,
+		EGL_RENDERABLE_TYPE,	EGL_OPENVG_BIT,
 		EGL_NONE
 		};
 
+void CEGLRendering::EGLCheckError()
+    {
+    EGLint error = eglGetError();
+    if(EGL_SUCCESS != error)
+        {
+        RDebug::Printf("[EBT] CEglRendering::EGLCheckError error %d", error);
+        User::Panic(_L("EBT-EGL"), error);
+        }
+    }
 
-CEGLRendering* CEGLRendering::NewL(RWindow& aWindow, TBool aQhd)
+void CEGLRendering::EGLCheckReturnError(EGLBoolean aBool)
+    {
+    if(!aBool)
+        {
+        RDebug::Printf("[EBT] CEglRendering::EGLCheckReturnError false");
+        User::Panic(_L("EGL-EGL-RTN"), eglGetError());
+        }
+    }
+
+void CEGLRendering::VGCheckError()
+    {
+    VGint error = vgGetError();
+    if(VG_NO_ERROR != error)
+        {
+        RDebug::Printf("[EBT] CEglRendering::VGCheckError error %d", error);
+        User::Panic(_L("EBT-VG"), error);
+        }
+    }
+
+CEGLRendering* CEGLRendering::NewL(RWindow& aWindow)
 	{
-	CEGLRendering* self = CEGLRendering::NewLC(aWindow, aQhd);
-	CleanupStack::Pop(self);
-	return self;
-	}
-
-
-CEGLRendering* CEGLRendering::NewLC(RWindow& aWindow, TBool aQhd)
-	{
-	CEGLRendering* self = new(ELeave) CEGLRendering(aWindow);
+	CEGLRendering* self = new (ELeave) CEGLRendering(aWindow);
 	CleanupStack::PushL(self);
-	self->ConstructL(aQhd);
+	self->ConstructL();
+    CleanupStack::Pop(self);
 	return self;
 	}
 
-CEGLRendering::~CEGLRendering()
-	{
-	Stop();
-	
-	delete iTimer;
-
-	if (iContextVG!=EGL_NO_CONTEXT)
-		{
-		EGLCheckReturnError(eglDestroyContext(iDisplay,iContextVG));
-		}
-	
-	if (iSurface!=EGL_NO_SURFACE)
-		{
-		EGLCheckReturnError(eglDestroySurface(iDisplay,iSurface));
-		}
-	
-	// Call eglMakeCurrent() to ensure the surfaces and contexts are truly destroyed. 
-	EGLCheckReturnError(eglMakeCurrent(iDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
-
-	EGLCheckReturnError(eglTerminate(iDisplay));
-	EGLCheckReturnError(eglReleaseThread());
-
-	delete iBitmap;
-	}
-
-void CEGLRendering::Start()
-	{
-	// Start drawing the screen periodically
-	iTimer->Start(0, KTimerDelay, TCallBack(TimerCallBack,this));
-	}
-
-void CEGLRendering::Stop()
-	{
-	if(iTimer)
-		{
-		iTimer->Cancel();
-		}	
-	}
-
-void CEGLRendering::EGLCheckError()
-	{
-	EGLint error = eglGetError();
-	if(error != EGL_SUCCESS)
-		{
-		User::Panic(_L("EGL error"), error);
-		}
-	}
-
-void CEGLRendering::VGCheckError()
-	{
-	VGint error = vgGetError();
-	if(error != VG_NO_ERROR)
-		{
-		User::Panic(_L("OpenVG error"), error);
-		}
-	}
-
-void CEGLRendering::EGLCheckReturnError(EGLBoolean aBool)
-	{
-	if (!aBool)
-		{
-		User::Panic(_L("EGL return error"),eglGetError());
- 		}
-	}
-
-
 CEGLRendering::CEGLRendering(RWindow& aWindow)
-	: iWindow(aWindow),iCount(0)
+	:  iWindow(aWindow)
+	,  iCount(0)
 	{
 	}
 
 /*
  * Construct EGL objects, and OpenVG binding.
- * 
+ *
  * Here we collaborate with EGL to associate a session, pick and configuration, assign
  * it to the window we have, and then bind the OpenVG rendering API to our newly created
  * context.
- * 
+ *
  * In bring up terms, here is where the first EGL code entry points are called from.  Its
  * the natural point where an EGL bringup starts debugging from, assuming the core EGL
  * works in terms of supporting EGL sync objects (needed for boot before we get to the
  * ESHELL command prompt).
  */
-void CEGLRendering::ConstructL(TBool aQhd)
+void CEGLRendering::ConstructL()
     {
-	RDebug::Printf("CEGLRendering::ConstructL");
-	
-	// Refresh timer	
+	RDebug::Printf("[EBT] CEGLRendering::ConstructL");
 	iTimer = CPeriodic::NewL(CActive::EPriorityIdle);
-	
-	const TDisplayMode dispMode = iWindow.DisplayMode();
-	const TSize windowSize(iWindow.Size());
+	EglSetupL();
+	VgSetup();
+	VgPaint();
+	}
 
-	// Create display object
-	iDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
-	RDebug::Printf("CEGLRendering::ConstructL 1");
-	EGLCheckError();
+void CEGLRendering::EglSetupL()
+    {
+    RDebug::Printf("[EBT] CEGLRendering::EglSetupL eglGetDisplay");
+    iDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
+    EGLCheckError();
 
-	// Initialize display object
-	EGLCheckReturnError(eglInitialize(iDisplay, NULL, NULL));
-	RDebug::Printf("CEGLRendering::ConstructL 2");
-	
-	RDebug::Printf("Vendor string %s", eglQueryString(iDisplay, EGL_VENDOR));
-	RDebug::Printf("Version string %s", eglQueryString(iDisplay, EGL_VERSION));
-	RDebug::Printf("Version string %s", eglQueryString(iDisplay, EGL_EXTENSIONS));
+    RDebug::Printf("[EBT] CEGLRendering::EglSetupL eglInitialize");
+    EGLCheckReturnError(eglInitialize(iDisplay, NULL, NULL));
+
+    RDebug::Printf("[EBT] CEGLRendering::EglSetupL vendor %s", eglQueryString(iDisplay, EGL_VENDOR));
+    RDebug::Printf("[EBT] CEGLRendering::EglSetupL version %s", eglQueryString(iDisplay, EGL_VERSION));
+    RDebug::Printf("[EBT] CEGLRendering::EglSetupL extensions %s", eglQueryString(iDisplay, EGL_EXTENSIONS));
 
-		
-	// Check that EGL provides the capabilities for this app.
-	TInt error = KErrNone;
-	if ( NULL == strstr(eglQueryString(iDisplay, EGL_CLIENT_APIS), "OpenVG") ) 
-		{
-		RDebug::Printf("OpenVG not listed in supported client APIs %s", eglQueryString(iDisplay, EGL_CLIENT_APIS));
-		error = KErrNotSupported;
-		}
-		
+    // Check that EGL provides the capabilities for this app.
+    if(NULL == strstr(eglQueryString(iDisplay, EGL_CLIENT_APIS), "OpenVG"))
+        {
+        RDebug::Printf("[EBT] CEGLRendering::EglSetupL OpenVG not listed in supported client APIs %s", eglQueryString(iDisplay, EGL_CLIENT_APIS));
+        User::Leave(KErrNotSupported);
+        }
+
+    if(NULL == strstr(eglQueryString(iDisplay, EGL_EXTENSIONS), "EGL_SYMBIAN_COMPOSITION") )
+        {
+        RDebug::Printf("[EBT] CEGLRendering::EglSetupL EGL_SYMBIAN_COMPOSITION not listed in extension string %s", eglQueryString(iDisplay, EGL_EXTENSIONS));
+        User::Leave(KErrNotSupported);
+        }
 
-	if ( NULL == strstr(eglQueryString(iDisplay, EGL_EXTENSIONS), "EGL_SYMBIAN_COMPOSITION") ) 
-		{
-		RDebug::Printf("EGL_SYMBIAN_COMPOSITION not listed in extension string %s", eglQueryString(iDisplay, EGL_EXTENSIONS));
-		error = KErrNotSupported;
-		}
-	if (error != KErrNone)
-		{
-		User::Leave(error);
-		}
+    RDebug::Printf("[EBT] CEGLRendering::EglSetupL eglChooseConfig");
+    EGLint numConfigs = 0;
+    EGLConfig chosenConfig = 0;
+    EGLCheckReturnError(eglChooseConfig(iDisplay, KAttribList, &chosenConfig, 1, &numConfigs));
+    if (0 == numConfigs)
+        {
+        RDebug::Printf("[EBT] No matching configs found", eglQueryString(iDisplay, EGL_EXTENSIONS));
+        User::Leave(KErrNotSupported);
+        }
 
-	EGLint numConfigs;
-	EGLConfig chosenConfig = 0;
+    RDebug::Printf("[EBT] CEGLRendering::EglSetupL eglBindApi");
+    EGLCheckReturnError(eglBindAPI(EGL_OPENVG_API));
+    
+    RDebug::Printf("[EBT] CEGLRendering::EglSetupL eglCreateWindowSurface");
+    iSurface = eglCreateWindowSurface(iDisplay, chosenConfig, &iWindow, NULL);
+    EGLCheckError();
 
-	// Choose the config to use
-	EGLCheckReturnError(eglChooseConfig(iDisplay, KColorRGBA8888AttribList, &chosenConfig, 1, &numConfigs));
-	RDebug::Printf("CEGLRendering::ConstructL 3");
-	if (numConfigs == 0)
-		{
-		RDebug::Printf("No matching configs found", eglQueryString(iDisplay, EGL_EXTENSIONS));
-		User::Leave(KErrNotSupported);
-		}
-	
-	// Create window surface to draw direct to.
-	EGLCheckReturnError(eglBindAPI(EGL_OPENVG_API));
-	RDebug::Printf("CEGLRendering::ConstructL 4");
-	iSurface = eglCreateWindowSurface(iDisplay, chosenConfig, &iWindow, NULL);
-	RDebug::Printf("CEGLRendering::ConstructL 5");
-	EGLCheckError();
-
-	TInt redSize, greenSize, blueSize, alphaSize;
+    RDebug::Printf("[EBT] CEGLRendering::EglSetupL eglGetConfigAttrib");
+    TInt redSize, greenSize, blueSize, alphaSize;
+    EGLCheckReturnError(eglGetConfigAttrib(iDisplay, chosenConfig, EGL_ALPHA_SIZE, &alphaSize));
+    EGLCheckReturnError(eglGetConfigAttrib(iDisplay, chosenConfig, EGL_RED_SIZE, &redSize));
+    EGLCheckReturnError(eglGetConfigAttrib(iDisplay, chosenConfig, EGL_GREEN_SIZE, &greenSize));
+    EGLCheckReturnError(eglGetConfigAttrib(iDisplay, chosenConfig, EGL_BLUE_SIZE, &blueSize));
+    RDebug::Printf("[EBT] CEGLRendering::EglSetupL id:%d alpha:%d red:%d green:%d blue:%d",
+                   chosenConfig, alphaSize, redSize, greenSize, blueSize);
 
-	EGLCheckReturnError(eglGetConfigAttrib(iDisplay, chosenConfig, EGL_ALPHA_SIZE, &alphaSize));
-	EGLCheckReturnError(eglGetConfigAttrib(iDisplay, chosenConfig, EGL_RED_SIZE, &redSize));
-	EGLCheckReturnError(eglGetConfigAttrib(iDisplay, chosenConfig, EGL_GREEN_SIZE, &greenSize));
-	EGLCheckReturnError(eglGetConfigAttrib(iDisplay, chosenConfig, EGL_BLUE_SIZE, &blueSize));
-	RDebug::Print(_L("EGLConfig id:%d alpha:%d red:%d green:%d blue:%d"), chosenConfig,
-			alphaSize, redSize, greenSize, blueSize);
-	RDebug::Printf("CEGLRendering::ConstructL 6");
+    RDebug::Printf("[EBT] CEGLRendering::EglSetupL eglCreateContext");
+    iContext = eglCreateContext(iDisplay, chosenConfig, EGL_NO_CONTEXT, NULL);
+    EGLCheckError();
 
-	// Create context to store surface settings
-	iContextVG = eglCreateContext(iDisplay, chosenConfig, EGL_NO_CONTEXT, NULL);
-	RDebug::Printf("CEGLRendering::ConstructL 7");
-	EGLCheckError();
-	
-	CEGLRendering::EGLCheckReturnError(eglMakeCurrent(iDisplay, iSurface, iSurface, iContextVG));
-	RDebug::Printf("CEGLRendering::ConstructL 8");
+    RDebug::Printf("[EBT] CEGLRendering::EglSetupL eglMakeCurrent");
+    CEGLRendering::EGLCheckReturnError(eglMakeCurrent(iDisplay, iSurface, iSurface, iContext));
+    }
 
-    // Now try and draw a line (blue)
-    static VGubyte const starSegments[] = 
+void CEGLRendering::VgSetup()
+    {
+    static VGubyte const Segments[] =
         {
         VG_MOVE_TO_ABS,
         VG_LINE_TO_REL,
         VG_CLOSE_PATH
         };
-    
-    static VGfloat const starCoords[] = 
+
+    static VGfloat const Coords[] =
         {
         110, 35,
         50, 160,
         };
-        
-        
+
     VGfloat strokeColor[4]  = {1.f, 0.f, 0.f, 1.f};
+
+    RDebug::Printf("[EBT] CEGLRendering::VgSetup vgCreatePaint");
+    iVGPaint = vgCreatePaint();
+    VGCheckError();
+
+    RDebug::Printf("[EBT] CEGLRendering::VgSetup vgSetParameterX");
+    vgSetParameteri(iVGPaint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
+    VGCheckError();
+    vgSetParameterfv(iVGPaint, VG_PAINT_COLOR, 4, strokeColor);
+    VGCheckError();
     
-    VGPaint strokePaint = vgCreatePaint();
-
-    vgSetParameteri(strokePaint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
-    vgSetParameterfv(strokePaint, VG_PAINT_COLOR, 4, strokeColor);
-    
-    VGPath path = vgCreatePath(VG_PATH_FORMAT_STANDARD,
+    RDebug::Printf("[EBT] CEGLRendering::VgSetup vgCreatePath");
+    iVGPath = vgCreatePath(VG_PATH_FORMAT_STANDARD,
                             VG_PATH_DATATYPE_F,
                             1.0f, // scale
                             0.0f, // bias
                             3,    // segmentCapacityHint
-                            4,   // coordCapacityHint
+                            4,    // coordCapacityHint
                             VG_PATH_CAPABILITY_ALL);
-                            
-    ASSERT(vgGetError() == VG_NO_ERROR);
-    RDebug::Printf("vgCreatePath");
+    VGCheckError();
+    
+    RDebug::Printf("[EBT] CEGLRendering::VgSetup vgAppendPathData");
+    vgAppendPathData(iVGPath, sizeof(Segments), Segments, Coords);
+    VGCheckError();
+    }
+
+void CEGLRendering::VgPaint()
+    {
+    RDebug::Printf("[EBT] CEGLRendering::VgPaint vgSetPaint");
+    vgSetPaint(iVGPaint, VG_STROKE_PATH);
+    VGCheckError();
     
-                            
-    vgAppendPathData(path, sizeof(starSegments), starSegments, starCoords);
-    ASSERT(vgGetError() == VG_NO_ERROR);
-    RDebug::Printf("vgAppendPathData");
+    RDebug::Printf("[EBT] CEGLRendering::VgPaint vgDrawPath");
+    vgDrawPath(iVGPath, VG_STROKE_PATH);
+    VGCheckError();
+
+    RDebug::Printf("[EBT] CEGLRendering::VgPaint eglSwapBuffers");
+    eglSwapBuffers(iDisplay, iSurface);
+    EGLCheckError();
+    }
+
+CEGLRendering::~CEGLRendering()
+    {
+    RDebug::Printf("[EBT] CEGLRendering::~CEGLRendering");
     
-    vgSetPaint(strokePaint, VG_STROKE_PATH);
-    
-    // Draw the star directly using the OpenVG API.
-    vgDrawPath(path, VG_FILL_PATH | VG_STROKE_PATH);
-    ASSERT(vgGetError() == VG_NO_ERROR);
-    RDebug::Printf("vgDrawPath");
-    
-    eglSwapBuffers(iDisplay, iSurface);
-    RDebug::Printf("eglSwapBuffers");
-    EGLCheckError();
-	}
+    Stop();
+
+    delete iTimer;
+
+    if (EGL_NO_CONTEXT != iContext)
+        {
+        EGLCheckReturnError(eglDestroyContext(iDisplay, iContext));
+        }
+
+    if (EGL_NO_SURFACE != iSurface)
+        {
+        EGLCheckReturnError(eglDestroySurface(iDisplay,iSurface));
+        }
 
+    // Call eglMakeCurrent() to ensure the surfaces and contexts are truly destroyed.
+    EGLCheckReturnError(eglMakeCurrent(iDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
+    EGLCheckReturnError(eglTerminate(iDisplay));
+    EGLCheckReturnError(eglReleaseThread());
+
+    delete iBitmap;
+    }
+
+void CEGLRendering::Start()
+    {
+    // Start drawing the screen periodically
+    iTimer->Start(0, KTimerDelay, TCallBack(TimerCallBack, this));
+    }
+
+void CEGLRendering::Stop()
+    {
+    if(iTimer)
+        {
+        iTimer->Cancel();
+        }
+    }
 
 /** Update the display */
 void CEGLRendering::UpdateDisplay()
@@ -273,7 +261,7 @@
 /** Callback called by refresh timer */
 TInt CEGLRendering::TimerCallBack(TAny* aDemo)
 	{
-	
 	static_cast<CEGLRendering*>(aDemo)->UpdateDisplay();
 	return KErrNone;
 	}
+