egl/sfopenvg/riMiniEGL.h
branchEGL_MERGE
changeset 72 360f71440b77
parent 57 2bf8a359aa2f
equal deleted inserted replaced
60:013f1c757b1e 72:360f71440b77
    36 			- no power management events
    36 			- no power management events
    37 			- no support for swap interval
    37 			- no support for swap interval
    38  * \todo	what happens in egl functions when eglTerminate has been called but the context and surface are still in use?
    38  * \todo	what happens in egl functions when eglTerminate has been called but the context and surface are still in use?
    39  * \todo	OSDeinitMutex should be called in case getEGL fails.
    39  * \todo	OSDeinitMutex should be called in case getEGL fails.
    40  *//*-------------------------------------------------------------------*/
    40  *//*-------------------------------------------------------------------*/
    41 #include <e32std.h>
       
    42 #include "egl.h"
    41 #include "egl.h"
    43 #include "openvg.h"
       
    44 #include "riArray.h"
       
    45 #include "riMath.h"
       
    46 #include "riContext.h"
    42 #include "riContext.h"
    47 #include "riImage.h"
       
    48 
    43 
    49 #ifdef BUILD_WITH_PRIVATE_EGL 
    44 #ifdef BUILD_WITH_PRIVATE_EGL 
    50 #include "eglinternal.h"
    45 #include "eglinternal.h"
    51 #endif
    46 #endif
    52 
    47 
    56 
    51 
    57 //==============================================================================================
    52 //==============================================================================================
    58 
    53 
    59 namespace OpenVGRI
    54 namespace OpenVGRI
    60 {
    55 {
    61 void* OSGetCurrentThreadID(void);
    56 class RIEGLSurface;
    62 void OSAcquireMutex(void);
    57 class RIEGLContext;
    63 void OSReleaseMutex(void);
    58 class RIEGLThread;
    64 void OSDeinitMutex(void);
       
    65 
       
    66 EGLDisplay OSGetDisplay(EGLNativeDisplayType display_id);
       
    67 void* OSCreateWindowContext(EGLNativeWindowType window);
       
    68 void OSDestroyWindowContext(void* context);
       
    69 bool OSIsWindow(const void* context);
       
    70 void OSGetWindowSize(const void* context, int& width, int& height);
       
    71 void OSBlitToWindow(void* context, const Drawable* drawable);
       
    72 EGLBoolean OSGetNativePixmapInfo(NativePixmapType pixmap, int* width, int* height, int* stride, VGImageFormat* format, int** data);
       
    73 
       
    74 
    59 
    75 /*-------------------------------------------------------------------*//*!
    60 /*-------------------------------------------------------------------*//*!
    76 * \brief	
    61 * \brief	
    77 * \param	
    62 * \param	
    78 * \return	
    63 * \return	
   151 	//EGL TRANSPARENT RED VALUE integer transparent red value (undefined)
   136 	//EGL TRANSPARENT RED VALUE integer transparent red value (undefined)
   152 	//EGL TRANSPARENT GREEN VALUE integer transparent green value (undefined)
   137 	//EGL TRANSPARENT GREEN VALUE integer transparent green value (undefined)
   153 	//EGL TRANSPARENT BLUE VALUE integer transparent blue value (undefined)
   138 	//EGL TRANSPARENT BLUE VALUE integer transparent blue value (undefined)
   154 };
   139 };
   155 
   140 
       
   141 
   156 /*-------------------------------------------------------------------*//*!
   142 /*-------------------------------------------------------------------*//*!
   157 * \brief	
   143 * \brief	
   158 * \param	
   144 * \param	
   159 * \return	
   145 * \return	
   160 * \note		
   146 * \note		
   161 *//*-------------------------------------------------------------------*/
   147 *//*-------------------------------------------------------------------*/
   162 
   148 
   163 class RIEGLContext
   149 #define EGL_NUMCONFIGS		60
       
   150 
       
   151 class RIEGLDisplay
   164 {
   152 {
   165 public:
   153 public:
   166 	RIEGLContext(OpenVGRI::VGContext* vgctx, const EGLConfig config);
   154 	RIEGLDisplay(EGLDisplay id);
   167 	~RIEGLContext();
   155 	~RIEGLDisplay();
   168 	void	addReference()				{ m_referenceCount++; }
   156 
   169 	int		removeReference()			{ m_referenceCount--; RI_ASSERT(m_referenceCount >= 0); return m_referenceCount; }
   157 	int                getNumConfigs() const              { return EGL_NUMCONFIGS; }
   170 
   158     const RIEGLConfig& getConfigByIdx(int i) const             { RI_ASSERT(i >= 0 && i < EGL_NUMCONFIGS); return m_configs[i]; }
   171     VGContext*      getVGContext() const      { return m_vgContext; }
   159     const RIEGLConfig& getConfig(const EGLConfig config) const        { for(int i=0;i<EGL_NUMCONFIGS;i++) { if(m_configs[i].m_config == config) return m_configs[i]; } RI_ASSERT(0); return m_configs[0]; }
   172     EGLConfig getConfig() const         { return m_config; }
   160 
       
   161     EGLDisplay        getID() const                       { return m_id; }
       
   162 
       
   163     void              addContext(RIEGLContext* ctx)       { RI_ASSERT(ctx); m_contexts.push_back(ctx); }  //throws bad_alloc
       
   164     void              removeContext(RIEGLContext* ctx)    { RI_ASSERT(ctx); bool res = m_contexts.remove(ctx); RI_ASSERT(res); RI_UNREF(res); }
       
   165 
       
   166     void              addSurface(RIEGLSurface* srf)       { RI_ASSERT(srf); m_surfaces.push_back(srf); }  //throws bad_alloc
       
   167     void              removeSurface(RIEGLSurface* srf)    { RI_ASSERT(srf); bool res = m_surfaces.remove(srf); RI_ASSERT(res); RI_UNREF(res); }
       
   168 
       
   169     EGLBoolean        contextExists(const EGLContext ctx) const;
       
   170     EGLBoolean        surfaceExists(const EGLSurface srf) const;
       
   171     EGLBoolean        configExists(const EGLConfig cfg) const;
       
   172 
   173 private:
   173 private:
   174 	RIEGLContext(const RIEGLContext&);
   174 	RIEGLDisplay(const RIEGLDisplay& t);
   175 	RIEGLContext& operator=(const RIEGLContext&);
   175 	RIEGLDisplay& operator=(const RIEGLDisplay&t);
   176 	VGContext*		m_vgContext;
   176 
   177 	const EGLConfig	m_config;
   177 	EGLDisplay              m_id;
   178 	int				m_referenceCount;
   178 
       
   179 	Array<RIEGLContext*>	m_contexts;
       
   180 	Array<RIEGLSurface*>	m_surfaces;
       
   181 
       
   182 	RIEGLConfig             m_configs[EGL_NUMCONFIGS];
   179 };
   183 };
   180 
       
   181 RIEGLContext* CastToRIEGLContext(EGLContext aCtxId);
       
   182 EGLContext CastFromRIEGLContext(RIEGLContext* aCtx);
       
   183 
   184 
   184 /*-------------------------------------------------------------------*//*!
   185 /*-------------------------------------------------------------------*//*!
   185 * \brief	
   186 * \brief	
   186 * \param	
   187 * \param	
   187 * \return	
   188 * \return	
   188 * \note		
   189 * \note		
   189 *//*-------------------------------------------------------------------*/
   190 *//*-------------------------------------------------------------------*/
   190 
   191 
   191 class RIEGLSurface
       
   192 {
       
   193 public:
       
   194     RIEGLSurface(void* OSWindowContext, const EGLConfig config, Drawable* drawable, bool largestPbuffer, int renderBuffer);
       
   195 	~RIEGLSurface();
       
   196 	void	addReference()				{ m_referenceCount++; }
       
   197 	int		removeReference()			{ m_referenceCount--; RI_ASSERT(m_referenceCount >= 0); return m_referenceCount; }
       
   198 
       
   199     void*           getOSWindowContext() const { return m_OSWindowContext; }
       
   200     EGLConfig       getConfig() const          { return m_config; }
       
   201     Drawable*       getDrawable() const        { return m_drawable; }
       
   202     bool            isLargestPbuffer() const   { return m_largestPbuffer; }
       
   203     int             getRenderBuffer() const    { return m_renderBuffer; }
       
   204 
       
   205 private:
       
   206 	RIEGLSurface(const RIEGLSurface&);
       
   207 	RIEGLSurface& operator=(const RIEGLSurface&);
       
   208     void*            m_OSWindowContext;
       
   209 	const EGLConfig	 m_config;
       
   210 	Drawable*        m_drawable;
       
   211 	bool			 m_largestPbuffer;
       
   212 	int				 m_renderBuffer;		//EGL_BACK_BUFFER or EGL_SINGLE_BUFFER
       
   213 	int				 m_referenceCount;
       
   214 };
       
   215 
       
   216 RIEGLSurface* CastToRIEGLSurface(EGLSurface aSurfaceId);
       
   217 EGLSurface CastFromRIEGLSurface(RIEGLSurface* aSurface);
       
   218 
       
   219 /*-------------------------------------------------------------------*//*!
       
   220 * \brief	
       
   221 * \param	
       
   222 * \return	
       
   223 * \note		
       
   224 *//*-------------------------------------------------------------------*/
       
   225 
       
   226 #define EGL_NUMCONFIGS		60
       
   227 
       
   228 class RIEGLDisplay
       
   229 {
       
   230 public:
       
   231 	RIEGLDisplay(EGLDisplay id);
       
   232 	~RIEGLDisplay();
       
   233 
       
   234 	int                getNumConfigs() const              { return EGL_NUMCONFIGS; }
       
   235     const RIEGLConfig& getConfigByIdx(int i) const             { RI_ASSERT(i >= 0 && i < EGL_NUMCONFIGS); return m_configs[i]; }
       
   236     const RIEGLConfig& getConfig(const EGLConfig config) const        { for(int i=0;i<EGL_NUMCONFIGS;i++) { if(m_configs[i].m_config == config) return m_configs[i]; } RI_ASSERT(0); return m_configs[0]; }
       
   237 
       
   238     EGLDisplay        getID() const                       { return m_id; }
       
   239 
       
   240     void              addContext(RIEGLContext* ctx)       { RI_ASSERT(ctx); m_contexts.push_back(ctx); }  //throws bad_alloc
       
   241     void              removeContext(RIEGLContext* ctx)    { RI_ASSERT(ctx); bool res = m_contexts.remove(ctx); RI_ASSERT(res); RI_UNREF(res); }
       
   242 
       
   243     void              addSurface(RIEGLSurface* srf)       { RI_ASSERT(srf); m_surfaces.push_back(srf); }  //throws bad_alloc
       
   244     void              removeSurface(RIEGLSurface* srf)    { RI_ASSERT(srf); bool res = m_surfaces.remove(srf); RI_ASSERT(res); RI_UNREF(res); }
       
   245 
       
   246     EGLBoolean        contextExists(const EGLContext ctx) const;
       
   247     EGLBoolean        surfaceExists(const EGLSurface srf) const;
       
   248     EGLBoolean        configExists(const EGLConfig cfg) const;
       
   249 
       
   250 private:
       
   251 	RIEGLDisplay(const RIEGLDisplay& t);
       
   252 	RIEGLDisplay& operator=(const RIEGLDisplay&t);
       
   253 
       
   254 	EGLDisplay              m_id;
       
   255 
       
   256 	Array<RIEGLContext*>	m_contexts;
       
   257 	Array<RIEGLSurface*>	m_surfaces;
       
   258 
       
   259 	RIEGLConfig             m_configs[EGL_NUMCONFIGS];
       
   260 };
       
   261 
       
   262 
       
   263 /*-------------------------------------------------------------------*//*!
       
   264 * \brief	
       
   265 * \param	
       
   266 * \return	
       
   267 * \note		
       
   268 *//*-------------------------------------------------------------------*/
       
   269 
       
   270 class RIEGLThread
       
   271 {
       
   272 public:
       
   273 	RIEGLThread(void* currentThreadID);
       
   274 	~RIEGLThread();
       
   275 
       
   276     void*           getThreadID() const       { return m_threadID; }
       
   277 
       
   278     void            makeCurrent(RIEGLContext* c, RIEGLSurface* s)       { m_context = c; m_surface = s; }
       
   279 	RIEGLContext*	getCurrentContext() const   { return m_context; }
       
   280 	RIEGLSurface*	getCurrentSurface() const   { return m_surface; }
       
   281 
       
   282     void            setError(EGLint error)      { m_error = error; }
       
   283     EGLint          getError() const            { return m_error; }
       
   284 
       
   285     void            bindAPI(EGLint api)         { m_boundAPI = api; }
       
   286     EGLint          getBoundAPI() const         { return m_boundAPI; }
       
   287 
       
   288 private:
       
   289 	RIEGLThread(const RIEGLThread&);
       
   290 	RIEGLThread operator=(const RIEGLThread&);
       
   291 
       
   292 	RIEGLContext*		m_context;
       
   293 	RIEGLSurface*		m_surface;
       
   294 	EGLint              m_error;
       
   295 	void*               m_threadID;
       
   296 	EGLint              m_boundAPI;
       
   297 };
       
   298 
       
   299 
       
   300 Image* CastToImage(EGLClientBuffer aBufferId);
       
   301 EGLClientBuffer CastFromImage(Image* aBUffer);
       
   302 
       
   303 /*-------------------------------------------------------------------*//*!
       
   304 * \brief	
       
   305 * \param	
       
   306 * \return	
       
   307 * \note		
       
   308 *//*-------------------------------------------------------------------*/
       
   309 
       
   310 class EGL
   192 class EGL
   311 {
   193 {
   312 public:
   194 public:
   313 	EGL();
   195 	EGL();
   314 	~EGL();
   196 	~EGL();
   339 	Array<RIEGLDisplay*>	m_displays;
   221 	Array<RIEGLDisplay*>	m_displays;
   340 
   222 
   341 	int                     m_referenceCount;
   223 	int                     m_referenceCount;
   342 };
   224 };
   343 
   225 
   344 
       
   345 void* eglvgGetCurrentVGContext(void);
   226 void* eglvgGetCurrentVGContext(void);
   346 bool  eglvgIsInUse(void* image);
   227 bool  eglvgIsInUse(void* image);
   347 
   228 
   348 } //end of namespace
   229 } //end of namespace
   349 
   230 
   350 
       
   351 /*-------------------------------------------------------------------*//*!
       
   352 * \brief	
       
   353 * \param	
       
   354 * \return	
       
   355 * \note		
       
   356 *//*-------------------------------------------------------------------*/
       
   357 
       
   358 #define EGL_GET_DISPLAY(DISPLAY, RETVAL) \
       
   359 	OSAcquireMutex(); \
       
   360 	EGL* egl = getEGL(); \
       
   361     if(!egl) \
       
   362     { \
       
   363 		OSReleaseMutex(); \
       
   364 		return RETVAL; \
       
   365     } \
       
   366 	RIEGLDisplay* display = egl->getDisplay(DISPLAY); \
       
   367 
       
   368 #define EGL_GET_EGL(RETVAL) \
       
   369 	OSAcquireMutex(); \
       
   370 	EGL* egl = getEGL(); \
       
   371     if(!egl) \
       
   372     { \
       
   373 		OSReleaseMutex(); \
       
   374 		return RETVAL; \
       
   375     } \
       
   376 
       
   377 #define EGL_IF_ERROR(COND, ERRORCODE, RETVAL) \
       
   378 	if(COND) { eglSetError(egl, ERRORCODE); OSReleaseMutex(); return RETVAL; } \
       
   379 
       
   380 #define EGL_RETURN(ERRORCODE, RETVAL) \
       
   381 	{ \
       
   382 		eglSetError(egl, ERRORCODE); \
       
   383 		OSReleaseMutex(); \
       
   384 		return RETVAL; \
       
   385 	}
       
   386 
       
   387 //#undef EGL_NUMCONFIGS
       
   388 
       
   389 #endif /* __RIMINIEGL_H */
   231 #endif /* __RIMINIEGL_H */
   390 
   232 
   391 
   233