egl/sfopenvg/symbian/riEGLOS.cpp
branchEGL_MERGE
changeset 57 2bf8a359aa2f
child 59 0fb7b31791c3
equal deleted inserted replaced
14:0be82064630b 57:2bf8a359aa2f
       
     1 /*------------------------------------------------------------------------
       
     2  *
       
     3  * EGL 1.3
       
     4  * -------
       
     5  *
       
     6  * Copyright (c) 2007 The Khronos Group Inc.
       
     7  *
       
     8  * Permission is hereby granted, free of charge, to any person obtaining a
       
     9  * copy of this software and /or associated documentation files
       
    10  * (the "Materials "), to deal in the Materials without restriction,
       
    11  * including without limitation the rights to use, copy, modify, merge,
       
    12  * publish, distribute, sublicense, and/or sell copies of the Materials,
       
    13  * and to permit persons to whom the Materials are furnished to do so,
       
    14  * subject to the following conditions: 
       
    15  *
       
    16  * The above copyright notice and this permission notice shall be included 
       
    17  * in all copies or substantial portions of the Materials. 
       
    18  *
       
    19  * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
       
    20  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
       
    21  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
       
    22  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
       
    23  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
       
    24  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR
       
    25  * THE USE OR OTHER DEALINGS IN THE MATERIALS.
       
    26  *
       
    27  *//**
       
    28  * \file
       
    29  * \brief	Generic OS EGL functionality (not thread safe, no window rendering)
       
    30  * \note
       
    31   *//*-------------------------------------------------------------------*/
       
    32 
       
    33 #include "egl.h"
       
    34 #include "riImage.h"
       
    35 #include "riDefs.h"
       
    36 
       
    37 #include <e32std.h>
       
    38 #include <w32std.h>
       
    39 #include <eglosnativewindowtype.h>
       
    40 
       
    41 namespace OpenVGRI
       
    42 {
       
    43 //internal fucntions
       
    44 VGImageFormat MapSymbianDisplayModeToVG(TDisplayMode aMode);
       
    45 void ReadPixelsToCFbsBitmap(CFbsBitmap& aBitmap, TUint aW, TUint aH);
       
    46 
       
    47 
       
    48 /*-------------------------------------------------------------------*//*!
       
    49 * \brief	
       
    50 * \param	
       
    51 * \return	
       
    52 * \note		
       
    53 *//*-------------------------------------------------------------------*/
       
    54 
       
    55 void* OSGetCurrentThreadID(void)
       
    56 {
       
    57 	int g_threadid = RThread().Id();
       
    58 	return (void*)g_threadid;
       
    59 }
       
    60 
       
    61 /*-------------------------------------------------------------------*//*!
       
    62 * \brief	
       
    63 * \param	
       
    64 * \return	
       
    65 * \note		
       
    66 *//*-------------------------------------------------------------------*/
       
    67 
       
    68 void OSDeinitMutex(void)
       
    69 {
       
    70 }
       
    71 
       
    72 void OSAcquireMutex(void)
       
    73 {
       
    74 }
       
    75 
       
    76 void OSReleaseMutex(void)
       
    77 {
       
    78 }
       
    79 
       
    80 /*-------------------------------------------------------------------*//*!
       
    81 * \brief	
       
    82 * \param	
       
    83 * \return	
       
    84 * \note		
       
    85 *//*-------------------------------------------------------------------*/
       
    86 
       
    87 struct OSWindowContext
       
    88 {
       
    89 	//RDrawableWindow*    iDrawWindow; //added by Jose.
       
    90 	TNativeWindowType   iNativeWindowType;
       
    91 	//TNativeWindowType*  iNativeWindowType;   
       
    92 };
       
    93 
       
    94 void* OSCreateWindowContext(EGLNativeWindowType window)
       
    95 {
       
    96     OSWindowContext* ctx = NULL;
       
    97     try
       
    98     {
       
    99         ctx = RI_NEW(OSWindowContext, ());
       
   100     }
       
   101 	catch(std::bad_alloc)
       
   102 	{
       
   103 		return NULL;
       
   104 	}
       
   105     //ctx->iNativeWindowType = (TNativeWindowType*)window;   //added by Jose
       
   106 	
       
   107 	RDrawableWindow* drawbleWindow = (RDrawableWindow*)window; //added by Jose
       
   108 	ctx->iNativeWindowType.iSize.iHeight = drawbleWindow->Size().iHeight;//added by Jose
       
   109 	ctx->iNativeWindowType.iSize.iWidth = drawbleWindow->Size().iWidth;	//added by Jose	
       
   110 		
       
   111     return ctx;
       
   112 }
       
   113 
       
   114 void OSDestroyWindowContext(void* context)
       
   115 {
       
   116     OSWindowContext* ctx = (OSWindowContext*)context;
       
   117     if(ctx)
       
   118     {
       
   119         RI_DELETE(ctx);
       
   120     }
       
   121 }
       
   122 
       
   123 bool OSIsWindow(const void* context)
       
   124 {
       
   125     OSWindowContext* ctx = (OSWindowContext*)context;
       
   126     if(ctx)
       
   127     {
       
   128         return true;
       
   129     }
       
   130     return false;
       
   131 }
       
   132 
       
   133 void OSGetWindowSize(const void* context, int& width, int& height)
       
   134 {
       
   135 	OSWindowContext* ctx = (OSWindowContext*)context;
       
   136 	
       
   137 	
       
   138     if(ctx)
       
   139     {
       
   140     	width=ctx->iNativeWindowType.iSize.iWidth;
       
   141 		height=ctx->iNativeWindowType.iSize.iHeight; 
       
   142 		
       
   143 		RDebug::Printf(" $$$$$$$$$$$$$ In OSGetWindowSize,Thread Id %Lu  $$$$$$$$$$$$$ ",(RThread().Id()));
       
   144 		RDebug::Printf(" $$$$$$$$$$$$$ In OSGetWindowSize,Width is  %d  $$$$$$$$$$$$$ ",width);
       
   145 		RDebug::Printf(" $$$$$$$$$$$$$ In OSGetWindowSize,Height is %d  $$$$$$$$$$$$$ ",height);
       
   146 		
       
   147     }
       
   148     else
       
   149     {
       
   150         width = 0;
       
   151         height = 0;
       
   152     }
       
   153 }
       
   154 
       
   155 
       
   156 EGLDisplay OSGetDisplay(EGLNativeDisplayType display_id)
       
   157 {
       
   158     RI_UNREF(display_id);
       
   159     return (EGLDisplay)1;    //support only a single display
       
   160 }
       
   161 
       
   162 
       
   163 void OSBlitToWindow(void* context, const Drawable* drawable)
       
   164 {
       
   165 	
       
   166     OSWindowContext* ctx = (OSWindowContext*)context;
       
   167     //blit if either of iBitmap or iMaskBitmap exist
       
   168     if(ctx && ctx->iNativeWindowType.iBitmap)
       
   169     {
       
   170         TUint w = drawable->getWidth();
       
   171         TUint h = drawable->getHeight();
       
   172         
       
   173         RDebug::Printf("!!!!!!!!!!!!!!!!!!!!!!!!!! In OSBlitToWindow(),w is = %d\n", w);
       
   174         RDebug::Printf("!!!!!!!!!!!!!!!!!!!!!!!!!!!!In OSBlitToWindow,h is = %d\n", h);
       
   175         
       
   176         //these should be same as bitmap
       
   177         if(ctx->iNativeWindowType.iBitmap)
       
   178         	{
       
   179         	CFbsBitmap* bitmap = ctx->iNativeWindowType.iBitmap;        	
       
   180         	ReadPixelsToCFbsBitmap(*bitmap, w, h);        	
       
   181         	}
       
   182     }
       
   183 }
       
   184 
       
   185 void ReadPixelsToCFbsBitmap(CFbsBitmap& aBitmap, TUint aW, TUint aH)
       
   186 	{
       
   187 	TSize sz = aBitmap.SizeInPixels();
       
   188 	RI_ASSERT(aW==sz.iWidth);
       
   189 	RI_ASSERT(aH==sz.iHeight);
       
   190 	
       
   191 	VGImageFormat f = MapSymbianDisplayModeToVG(aBitmap.DisplayMode());
       
   192 	
       
   193 	TInt bitmapDataStride = aBitmap.DataStride();
       
   194 	
       
   195 	//copy from source OpenVG model to target(CFbsBitmap) buffer			
       
   196 	aBitmap.BeginDataAccess();
       
   197 	//openvg returns pixels in cartesian coordinates (y+) where as CFbsBitmap
       
   198 	//wants screen coordinates (y-) so we read pixels out starting at top left corner 
       
   199 	TUint8* ptarget = (TUint8*)aBitmap.DataAddress()+(aH-1)*bitmapDataStride;
       
   200 	
       
   201 	#ifdef BUILD_WITH_PRIVATE_OPENVG
       
   202 	//	do_vgReadPixels(ptarget, -bitmapDataStride, f, 0, 0, aW, aH);             //added by Jose.Need to remove the comments	
       
   203 	#else
       
   204 		vgReadPixels(ptarget, -bitmapDataStride, f, 0, 0, aW, aH);
       
   205 	#endif
       
   206 	
       
   207 	aBitmap.EndDataAccess(EFalse);
       
   208 	}
       
   209 
       
   210 VGImageFormat MapSymbianDisplayModeToVG(TDisplayMode aMode)
       
   211 	{
       
   212 	VGImageFormat f;
       
   213 	switch(aMode)
       
   214 		{
       
   215 		case EColor16MA:
       
   216 			f = VG_sARGB_8888;
       
   217 			break;
       
   218 		case EColor16MU:
       
   219 			f = VG_sRGBX_8888;
       
   220 			break;
       
   221 		case EColor64K:
       
   222 			f = VG_sRGB_565;
       
   223 			break;
       
   224 		case EGray256:
       
   225 			f = VG_A_8;
       
   226 			break;
       
   227 		case EGray2:
       
   228 			f = VG_BW_1;
       
   229 			break;
       
   230 		default:
       
   231 			RI_ASSERT(0);
       
   232 		}
       
   233 	return f;
       
   234 	}
       
   235 EGLBoolean OSGetNativePixmapInfo(NativePixmapType pixmap, int* width, int* height, int* stride, VGImageFormat* format, int** data)
       
   236 {
       
   237 	TSize size = ((CFbsBitmap*)pixmap)->SizeInPixels();
       
   238     *width  = size.iWidth;
       
   239     *height = size.iHeight;
       
   240     *stride = ((CFbsBitmap*)pixmap)->DataStride();   
       
   241     
       
   242     RDebug::Printf(" ---------------------------- In OSGetNativePixmapInfo  width is %d  ^^^^^^^^^^^^^^^^^ ",size.iWidth);
       
   243     RDebug::Printf(" ---------------------------- In OSGetNativePixmapInfo,height addr is %d  ^^^^^^^^^^^^^^^^",size.iHeight);
       
   244     
       
   245     *data = (int*)(((CFbsBitmap*)pixmap)->DataAddress());
       
   246     TDisplayMode mode = ((CFbsBitmap*)pixmap)->DisplayMode(); 
       
   247 	switch(mode)
       
   248 	{
       
   249 	case EColor16MA:
       
   250 		*format = VG_sRGBA_8888;
       
   251 		break;
       
   252 	case EColor16MU:
       
   253 		*format = VG_sRGBX_8888;
       
   254 		break;
       
   255 	case EColor64K:
       
   256 		*format = VG_sRGB_565;
       
   257 		break;
       
   258 	case EGray256:
       
   259 		*format = VG_A_8;
       
   260 		break;
       
   261 	case EGray2:
       
   262 		*format = VG_BW_1;
       
   263 		break;
       
   264 	default:
       
   265 		RI_ASSERT(0);
       
   266 	}
       
   267     return EGL_TRUE;
       
   268 }
       
   269 }   //namespace OpenVGRI