egl/sfegltest/src/eglrendering.cpp
branchbug235_bringup_0
changeset 211 3804ba25b23f
parent 210 da03feddbab7
child 215 097e92a68d68
equal deleted inserted replaced
210:da03feddbab7 211:3804ba25b23f
    56         RDebug::Printf("[EBT] CEglRendering::VGCheckError error %d", error);
    56         RDebug::Printf("[EBT] CEglRendering::VGCheckError error %d", error);
    57         User::Panic(_L("EBT-VG"), error);
    57         User::Panic(_L("EBT-VG"), error);
    58         }
    58         }
    59     }
    59     }
    60 
    60 
    61 CEGLRendering* CEGLRendering::NewL(RWindow& aWindow)
       
    62 	{
       
    63 	CEGLRendering* self = new (ELeave) CEGLRendering(aWindow);
       
    64 	CleanupStack::PushL(self);
       
    65 	self->ConstructL();
       
    66     CleanupStack::Pop(self);
       
    67 	return self;
       
    68 	}
       
    69 
       
    70 CEGLRendering::CEGLRendering(RWindow& aWindow)
    61 CEGLRendering::CEGLRendering(RWindow& aWindow)
    71 	:  iWindow(aWindow)
    62 	:  iWindow(aWindow)
    72 	,  iCount(0)
       
    73 	{
    63 	{
    74 	}
    64 	}
    75 
    65 
    76 /*
    66 /*
    77  * Construct EGL objects, and OpenVG binding.
    67  * Construct EGL objects, and OpenVG binding.
    86  * ESHELL command prompt).
    76  * ESHELL command prompt).
    87  */
    77  */
    88 void CEGLRendering::ConstructL()
    78 void CEGLRendering::ConstructL()
    89     {
    79     {
    90 	RDebug::Printf("[EBT] CEGLRendering::ConstructL");
    80 	RDebug::Printf("[EBT] CEGLRendering::ConstructL");
    91 	iTimer = CPeriodic::NewL(CActive::EPriorityIdle);
    81 	iRedrawTimer = CPeriodic::NewL(CActive::EPriorityIdle);
    92 	EglSetupL();
    82 	EglSetupL();
    93 	VgSetup();
    83 	KhrSetup();
    94 	VgPaint();
    84 	KhrPaint();
       
    85 	EglSwapBuffers();
    95 	}
    86 	}
    96 
    87 
    97 void CEGLRendering::EglSetupL()
    88 void CEGLRendering::EglSetupL()
    98     {
    89     {
    99     RDebug::Printf("[EBT] CEGLRendering::EglSetupL eglGetDisplay");
    90     RDebug::Printf("[EBT] CEGLRendering::EglSetupL eglGetDisplay");
   130         User::Leave(KErrNotSupported);
   121         User::Leave(KErrNotSupported);
   131         }
   122         }
   132 
   123 
   133     RDebug::Printf("[EBT] CEGLRendering::EglSetupL eglBindApi");
   124     RDebug::Printf("[EBT] CEGLRendering::EglSetupL eglBindApi");
   134     EGLCheckReturnError(eglBindAPI(EGL_OPENVG_API));
   125     EGLCheckReturnError(eglBindAPI(EGL_OPENVG_API));
   135     
   126 
   136     RDebug::Printf("[EBT] CEGLRendering::EglSetupL eglCreateWindowSurface");
   127     RDebug::Printf("[EBT] CEGLRendering::EglSetupL eglCreateWindowSurface");
   137     iSurface = eglCreateWindowSurface(iDisplay, chosenConfig, &iWindow, NULL);
   128     iSurface = eglCreateWindowSurface(iDisplay, chosenConfig, &iWindow, NULL);
   138     EGLCheckError();
   129     EGLCheckError();
   139 
   130 
   140     RDebug::Printf("[EBT] CEGLRendering::EglSetupL eglGetConfigAttrib");
   131     RDebug::Printf("[EBT] CEGLRendering::EglSetupL eglGetConfigAttrib");
   152 
   143 
   153     RDebug::Printf("[EBT] CEGLRendering::EglSetupL eglMakeCurrent");
   144     RDebug::Printf("[EBT] CEGLRendering::EglSetupL eglMakeCurrent");
   154     CEGLRendering::EGLCheckReturnError(eglMakeCurrent(iDisplay, iSurface, iSurface, iContext));
   145     CEGLRendering::EGLCheckReturnError(eglMakeCurrent(iDisplay, iSurface, iSurface, iContext));
   155     }
   146     }
   156 
   147 
   157 void CEGLRendering::VgSetup()
   148 void CEGLRendering::EglSwapBuffers()
   158     {
   149     {
   159     static VGubyte const Segments[] =
   150     RDebug::Printf("[EBT] CEGLRendering::EglSwapBuffers");
   160         {
       
   161         VG_MOVE_TO_ABS,
       
   162         VG_LINE_TO_REL,
       
   163         VG_CLOSE_PATH
       
   164         };
       
   165 
       
   166     static VGfloat const Coords[] =
       
   167         {
       
   168         110, 35,
       
   169         50, 160,
       
   170         };
       
   171 
       
   172     VGfloat strokeColor[4]  = {1.f, 0.f, 0.f, 1.f};
       
   173 
       
   174     RDebug::Printf("[EBT] CEGLRendering::VgSetup vgCreatePaint");
       
   175     iVGPaint = vgCreatePaint();
       
   176     VGCheckError();
       
   177 
       
   178     RDebug::Printf("[EBT] CEGLRendering::VgSetup vgSetParameterX");
       
   179     vgSetParameteri(iVGPaint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
       
   180     VGCheckError();
       
   181     vgSetParameterfv(iVGPaint, VG_PAINT_COLOR, 4, strokeColor);
       
   182     VGCheckError();
       
   183     
       
   184     RDebug::Printf("[EBT] CEGLRendering::VgSetup vgCreatePath");
       
   185     iVGPath = vgCreatePath(VG_PATH_FORMAT_STANDARD,
       
   186                             VG_PATH_DATATYPE_F,
       
   187                             1.0f, // scale
       
   188                             0.0f, // bias
       
   189                             3,    // segmentCapacityHint
       
   190                             4,    // coordCapacityHint
       
   191                             VG_PATH_CAPABILITY_ALL);
       
   192     VGCheckError();
       
   193     
       
   194     RDebug::Printf("[EBT] CEGLRendering::VgSetup vgAppendPathData");
       
   195     vgAppendPathData(iVGPath, sizeof(Segments), Segments, Coords);
       
   196     VGCheckError();
       
   197     }
       
   198 
       
   199 void CEGLRendering::VgPaint()
       
   200     {
       
   201     RDebug::Printf("[EBT] CEGLRendering::VgPaint vgSetPaint");
       
   202     vgSetPaint(iVGPaint, VG_STROKE_PATH);
       
   203     VGCheckError();
       
   204     
       
   205     RDebug::Printf("[EBT] CEGLRendering::VgPaint vgDrawPath");
       
   206     vgDrawPath(iVGPath, VG_STROKE_PATH);
       
   207     VGCheckError();
       
   208 
       
   209     RDebug::Printf("[EBT] CEGLRendering::VgPaint eglSwapBuffers");
       
   210     eglSwapBuffers(iDisplay, iSurface);
   151     eglSwapBuffers(iDisplay, iSurface);
   211     EGLCheckError();
   152     EGLCheckError();
   212     }
   153     }
   213 
   154 
   214 CEGLRendering::~CEGLRendering()
   155 CEGLRendering::~CEGLRendering()
   215     {
   156     {
   216     RDebug::Printf("[EBT] CEGLRendering::~CEGLRendering");
   157     RDebug::Printf("[EBT] CEGLRendering::~CEGLRendering");
   217     
   158 
   218     Stop();
   159     StopRedrawTimer();
   219 
   160     delete iRedrawTimer;
   220     delete iTimer;
       
   221 
   161 
   222     if (EGL_NO_CONTEXT != iContext)
   162     if (EGL_NO_CONTEXT != iContext)
   223         {
   163         {
   224         EGLCheckReturnError(eglDestroyContext(iDisplay, iContext));
   164         EGLCheckReturnError(eglDestroyContext(iDisplay, iContext));
   225         }
   165         }
   231 
   171 
   232     // Call eglMakeCurrent() to ensure the surfaces and contexts are truly destroyed.
   172     // Call eglMakeCurrent() to ensure the surfaces and contexts are truly destroyed.
   233     EGLCheckReturnError(eglMakeCurrent(iDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
   173     EGLCheckReturnError(eglMakeCurrent(iDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
   234     EGLCheckReturnError(eglTerminate(iDisplay));
   174     EGLCheckReturnError(eglTerminate(iDisplay));
   235     EGLCheckReturnError(eglReleaseThread());
   175     EGLCheckReturnError(eglReleaseThread());
   236 
   176     }
   237     delete iBitmap;
   177 
   238     }
   178 void CEGLRendering::StartRedrawTimer()
   239 
       
   240 void CEGLRendering::Start()
       
   241     {
   179     {
   242     // Start drawing the screen periodically
   180     // Start drawing the screen periodically
   243     iTimer->Start(0, KTimerDelay, TCallBack(TimerCallBack, this));
   181     iRedrawTimer->Start(0, KTimerDelay, TCallBack(TimerCallBack, this));
   244     }
   182     }
   245 
   183 
   246 void CEGLRendering::Stop()
   184 void CEGLRendering::StopRedrawTimer()
   247     {
   185     {
   248     if(iTimer)
   186     if(iRedrawTimer)
   249         {
   187         {
   250         iTimer->Cancel();
   188         iRedrawTimer->Cancel();
   251         }
   189         }
   252     }
   190     }
   253 
   191 
   254 /** Update the display */
       
   255 void CEGLRendering::UpdateDisplay()
       
   256 	{
       
   257 	// Flush colour buffer to the window surface
       
   258 	//CEGLRendering::EGLCheckReturnError(eglSwapBuffers(iDisplay, iSurface));
       
   259 	}
       
   260 
       
   261 /** Callback called by refresh timer */
       
   262 TInt CEGLRendering::TimerCallBack(TAny* aDemo)
   192 TInt CEGLRendering::TimerCallBack(TAny* aDemo)
   263 	{
   193 	{
   264 	static_cast<CEGLRendering*>(aDemo)->UpdateDisplay();
   194 	static_cast<CEGLRendering*>(aDemo)->Redraw();
   265 	return KErrNone;
   195 	return KErrNone;
   266 	}
   196 	}
   267 
   197 
       
   198 void CEGLRendering::Redraw()
       
   199     {
       
   200     RDebug::Printf("[EBT] CEGLRendering::Redraw");
       
   201     KhrPaint();
       
   202     EglSwapBuffers();
       
   203     }
       
   204