Refactored eglbringuptest to separate EGL and VG code
This allows for a more complex demo (e.g. one which includes
animated rendering) to be implemented simply by writing a new
class derived from CEglRendering, and modifying CWsApp::ConstructL
to create an instance of this new class.
--- a/egl/sfegltest/group/eglbringuptest.mmp Fri Oct 22 22:19:05 2010 +0100
+++ b/egl/sfegltest/group/eglbringuptest.mmp Fri Oct 22 22:42:40 2010 +0100
@@ -43,6 +43,7 @@
sourcepath ../src
source main.cpp
source eglrendering.cpp
+source vgline.cpp
library euser.lib
library libc.lib
--- a/egl/sfegltest/inc/eglrendering.h Fri Oct 22 22:19:05 2010 +0100
+++ b/egl/sfegltest/inc/eglrendering.h Fri Oct 22 22:42:40 2010 +0100
@@ -23,37 +23,34 @@
class CEGLRendering : public CBase
{
public:
- static CEGLRendering* NewL(RWindow& aWindow);
~CEGLRendering();
- void Start();
- void Stop();
+ static TInt TimerCallBack(TAny* aDemo);
+ void Redraw();
- void UpdateDisplay();
- static TInt TimerCallBack(TAny* aDemo);
+protected:
+ CEGLRendering(RWindow& aWindow);
+ void ConstructL();
-private:
- CEGLRendering(RWindow& aWindow);
- void ConstructL();
+ void StartRedrawTimer();
+ void StopRedrawTimer();
static void EGLCheckError();
static void EGLCheckReturnError(EGLBoolean aBool);
static void VGCheckError();
-
+
+private:
void EglSetupL();
- void VgSetup();
- void VgPaint();
-
+ virtual void KhrSetup() = 0;
+ virtual void KhrPaint() = 0;
+ void EglSwapBuffers();
+
private:
RWindow& iWindow;
- CPeriodic* iTimer;
- CFbsBitmap* iBitmap;
- TInt iCount;
+ CPeriodic* iRedrawTimer;
EGLDisplay iDisplay;
EGLSurface iSurface;
EGLContext iContext;
- VGPaint iVGPaint;
- VGPath iVGPath;
};
#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/egl/sfegltest/inc/vgline.h Fri Oct 22 22:42:40 2010 +0100
@@ -0,0 +1,36 @@
+// Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+// All rights reserved.
+// This component and the accompanying materials are made available
+// under the terms of "Eclipse Public License v1.0"
+// which accompanies this distribution, and is available
+// at the URL "http://www.eclipse.org/legal/epl-v10.html".
+//
+// Initial Contributors:
+// Nokia Corporation - initial contribution.
+//
+// Contributors:
+//
+// Description:
+
+#ifndef __VGLINE_H__
+#define __VGLINE_H__
+
+#include "eglrendering.h"
+
+class CVGLine : public CEGLRendering
+ {
+public:
+ static CVGLine* NewL(RWindow& aWindow);
+
+private:
+ CVGLine(RWindow& aWindow);
+ void KhrSetup();
+ void KhrPaint();
+
+private:
+ VGPaint iVGPaint;
+ VGPath iVGPath;
+ };
+
+#endif
+
--- a/egl/sfegltest/src/eglrendering.cpp Fri Oct 22 22:19:05 2010 +0100
+++ b/egl/sfegltest/src/eglrendering.cpp Fri Oct 22 22:42:40 2010 +0100
@@ -58,18 +58,8 @@
}
}
-CEGLRendering* CEGLRendering::NewL(RWindow& aWindow)
- {
- CEGLRendering* self = new (ELeave) CEGLRendering(aWindow);
- CleanupStack::PushL(self);
- self->ConstructL();
- CleanupStack::Pop(self);
- return self;
- }
-
CEGLRendering::CEGLRendering(RWindow& aWindow)
: iWindow(aWindow)
- , iCount(0)
{
}
@@ -88,10 +78,11 @@
void CEGLRendering::ConstructL()
{
RDebug::Printf("[EBT] CEGLRendering::ConstructL");
- iTimer = CPeriodic::NewL(CActive::EPriorityIdle);
+ iRedrawTimer = CPeriodic::NewL(CActive::EPriorityIdle);
EglSetupL();
- VgSetup();
- VgPaint();
+ KhrSetup();
+ KhrPaint();
+ EglSwapBuffers();
}
void CEGLRendering::EglSetupL()
@@ -132,7 +123,7 @@
RDebug::Printf("[EBT] CEGLRendering::EglSetupL eglBindApi");
EGLCheckReturnError(eglBindAPI(EGL_OPENVG_API));
-
+
RDebug::Printf("[EBT] CEGLRendering::EglSetupL eglCreateWindowSurface");
iSurface = eglCreateWindowSurface(iDisplay, chosenConfig, &iWindow, NULL);
EGLCheckError();
@@ -154,59 +145,9 @@
CEGLRendering::EGLCheckReturnError(eglMakeCurrent(iDisplay, iSurface, iSurface, iContext));
}
-void CEGLRendering::VgSetup()
+void CEGLRendering::EglSwapBuffers()
{
- static VGubyte const Segments[] =
- {
- VG_MOVE_TO_ABS,
- VG_LINE_TO_REL,
- VG_CLOSE_PATH
- };
-
- 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();
-
- 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
- VG_PATH_CAPABILITY_ALL);
- 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();
-
- RDebug::Printf("[EBT] CEGLRendering::VgPaint vgDrawPath");
- vgDrawPath(iVGPath, VG_STROKE_PATH);
- VGCheckError();
-
- RDebug::Printf("[EBT] CEGLRendering::VgPaint eglSwapBuffers");
+ RDebug::Printf("[EBT] CEGLRendering::EglSwapBuffers");
eglSwapBuffers(iDisplay, iSurface);
EGLCheckError();
}
@@ -214,10 +155,9 @@
CEGLRendering::~CEGLRendering()
{
RDebug::Printf("[EBT] CEGLRendering::~CEGLRendering");
-
- Stop();
- delete iTimer;
+ StopRedrawTimer();
+ delete iRedrawTimer;
if (EGL_NO_CONTEXT != iContext)
{
@@ -233,35 +173,32 @@
EGLCheckReturnError(eglMakeCurrent(iDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
EGLCheckReturnError(eglTerminate(iDisplay));
EGLCheckReturnError(eglReleaseThread());
-
- delete iBitmap;
}
-void CEGLRendering::Start()
+void CEGLRendering::StartRedrawTimer()
{
// Start drawing the screen periodically
- iTimer->Start(0, KTimerDelay, TCallBack(TimerCallBack, this));
+ iRedrawTimer->Start(0, KTimerDelay, TCallBack(TimerCallBack, this));
}
-void CEGLRendering::Stop()
+void CEGLRendering::StopRedrawTimer()
{
- if(iTimer)
+ if(iRedrawTimer)
{
- iTimer->Cancel();
+ iRedrawTimer->Cancel();
}
}
-/** Update the display */
-void CEGLRendering::UpdateDisplay()
- {
- // Flush colour buffer to the window surface
- //CEGLRendering::EGLCheckReturnError(eglSwapBuffers(iDisplay, iSurface));
- }
-
-/** Callback called by refresh timer */
TInt CEGLRendering::TimerCallBack(TAny* aDemo)
{
- static_cast<CEGLRendering*>(aDemo)->UpdateDisplay();
+ static_cast<CEGLRendering*>(aDemo)->Redraw();
return KErrNone;
}
+void CEGLRendering::Redraw()
+ {
+ RDebug::Printf("[EBT] CEGLRendering::Redraw");
+ KhrPaint();
+ EglSwapBuffers();
+ }
+
--- a/egl/sfegltest/src/main.cpp Fri Oct 22 22:19:05 2010 +0100
+++ b/egl/sfegltest/src/main.cpp Fri Oct 22 22:42:40 2010 +0100
@@ -16,7 +16,7 @@
#include <w32std.h>
#include <e32math.h>
#include <e32keys.h>
-#include "eglrendering.h"
+#include "vgline.h"
#define KDefaultScreenNo 0
@@ -179,12 +179,10 @@
RDebug::Printf("[EBT] CWsApp::ConstructL 1");
iAppView = CWsCanvas::NewL(iScrId, iPos);
RDebug::Printf("[EBT] CWsApp::ConstructL 2");
- iDemo = CEGLRendering::NewL(iAppView->Window());
+ iDemo = CVGLine::NewL(iAppView->Window());
RDebug::Printf("[EBT] CWsApp::ConstructL 3");
- iDemo->Start();
+ iSz = iAppView->ScreenSize();
RDebug::Printf("[EBT] CWsApp::ConstructL 4");
- iSz = iAppView->ScreenSize();
- RDebug::Printf("[EBT] CWsApp::ConstructL 5");
}
TInt CWsApp::TimerCallBack(TAny* aApp)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/egl/sfegltest/src/vgline.cpp Fri Oct 22 22:42:40 2010 +0100
@@ -0,0 +1,83 @@
+// Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+// All rights reserved.
+// This component and the accompanying materials are made available
+// under the terms of "Eclipse Public License v1.0"
+// which accompanies this distribution, and is available
+// at the URL "http://www.eclipse.org/legal/epl-v10.html".
+//
+// Initial Contributors:
+// Nokia Corporation - initial contribution.
+//
+// Contributors:
+//
+// Description:
+
+#include "vgline.h"
+
+CVGLine* CVGLine::NewL(RWindow& aWindow)
+ {
+ CVGLine* self = new (ELeave) CVGLine(aWindow);
+ CleanupStack::PushL(self);
+ self->ConstructL();
+ CleanupStack::Pop(self);
+ return self;
+ }
+
+CVGLine::CVGLine(RWindow& aWindow)
+ : CEGLRendering(aWindow)
+ {
+ }
+
+void CVGLine::KhrSetup()
+ {
+ static VGubyte const Segments[] =
+ {
+ VG_MOVE_TO_ABS,
+ VG_LINE_TO_REL,
+ VG_CLOSE_PATH
+ };
+
+ static VGfloat const Coords[] =
+ {
+ 110, 35,
+ 50, 160,
+ };
+
+ VGfloat strokeColor[4] = {1.f, 0.f, 0.f, 1.f};
+
+ RDebug::Printf("[EBT] CVGLine::KhrSetup vgCreatePaint");
+ iVGPaint = vgCreatePaint();
+ VGCheckError();
+
+ RDebug::Printf("[EBT] CVGLine::KhrSetup vgSetParameterX");
+ vgSetParameteri(iVGPaint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
+ VGCheckError();
+ vgSetParameterfv(iVGPaint, VG_PAINT_COLOR, 4, strokeColor);
+ VGCheckError();
+
+ RDebug::Printf("[EBT] CVGLine::KhrSetup vgCreatePath");
+ iVGPath = vgCreatePath(VG_PATH_FORMAT_STANDARD,
+ VG_PATH_DATATYPE_F,
+ 1.0f, // scale
+ 0.0f, // bias
+ 3, // segmentCapacityHint
+ 4, // coordCapacityHint
+ VG_PATH_CAPABILITY_ALL);
+ VGCheckError();
+
+ RDebug::Printf("[EBT] CVGLine::KhrSetup vgAppendPathData");
+ vgAppendPathData(iVGPath, sizeof(Segments), Segments, Coords);
+ VGCheckError();
+ }
+
+void CVGLine::KhrPaint()
+ {
+ RDebug::Printf("[EBT] CVGLine::KhrPaint vgSetPaint");
+ vgSetPaint(iVGPaint, VG_STROKE_PATH);
+ VGCheckError();
+
+ RDebug::Printf("[EBT] CVGLine::KhrPaint vgDrawPath");
+ vgDrawPath(iVGPath, VG_STROKE_PATH);
+ VGCheckError();
+ }
+