egl/sfopenvg/symbian/riEGLOS.cpp
branchEGL_MERGE
changeset 180 f767bd5f4cfc
parent 119 5f371025658c
child 181 c1509651cd2b
equal deleted inserted replaced
119:5f371025658c 180:f767bd5f4cfc
     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;
       
    90 	TNativeWindowType   iNativeWindowType;
       
    91 	   
       
    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;
       
   106 	
       
   107 	RDrawableWindow* drawbleWindow = (RDrawableWindow*)window;
       
   108 	ctx->iNativeWindowType.iSize.iHeight = drawbleWindow->Size().iHeight;
       
   109 	ctx->iNativeWindowType.iSize.iWidth = drawbleWindow->Size().iWidth;
       
   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     else
       
   144     {
       
   145         width = 0;
       
   146         height = 0;
       
   147     }
       
   148 }
       
   149 
       
   150 
       
   151 EGLDisplay OSGetDisplay(EGLNativeDisplayType display_id)
       
   152 {
       
   153     RI_UNREF(display_id);
       
   154     return (EGLDisplay)1;    //support only a single display
       
   155 }
       
   156 
       
   157 
       
   158 void OSBlitToWindow(void* context, const Drawable* drawable)
       
   159 {
       
   160 	TUint w = drawable->getWidth();
       
   161 	TUint h = drawable->getHeight();
       
   162     
       
   163 	OSWindowContext* ctx = (OSWindowContext*)context;
       
   164     //blit if either of iBitmap or iMaskBitmap exist
       
   165     if(ctx && ctx->iNativeWindowType.iBitmap)
       
   166     {
       
   167       
       
   168         //these should be same as bitmap
       
   169         if(ctx->iNativeWindowType.iBitmap)
       
   170         	{
       
   171         	CFbsBitmap* bitmap = ctx->iNativeWindowType.iBitmap;        	
       
   172         	ReadPixelsToCFbsBitmap(*bitmap, w, h);        	
       
   173         	}
       
   174     }
       
   175 }
       
   176 
       
   177 void ReadPixelsToCFbsBitmap(CFbsBitmap& aBitmap, TUint aW, TUint aH)
       
   178 	{
       
   179 	TSize sz = aBitmap.SizeInPixels();
       
   180 	RI_ASSERT(aW==sz.iWidth);
       
   181 	RI_ASSERT(aH==sz.iHeight);
       
   182 	
       
   183 	VGImageFormat f = MapSymbianDisplayModeToVG(aBitmap.DisplayMode());
       
   184 	
       
   185 	TInt bitmapDataStride = aBitmap.DataStride();
       
   186 	
       
   187 	//copy from source OpenVG model to target(CFbsBitmap) buffer			
       
   188 	aBitmap.BeginDataAccess();
       
   189 	//openvg returns pixels in cartesian coordinates (y+) where as CFbsBitmap
       
   190 	//wants screen coordinates (y-) so we read pixels out starting at top left corner 
       
   191 	TUint8* ptarget = (TUint8*)aBitmap.DataAddress()+(aH-1)*bitmapDataStride;
       
   192 	
       
   193 	#ifdef BUILD_WITH_PRIVATE_OPENVG
       
   194 	//	do_vgReadPixels(ptarget, -bitmapDataStride, f, 0, 0, aW, aH);             //added by Jose.Need to remove the comments	
       
   195 	#else
       
   196 		vgReadPixels(ptarget, -bitmapDataStride, f, 0, 0, aW, aH);
       
   197 	#endif
       
   198 	
       
   199 	aBitmap.EndDataAccess(EFalse);
       
   200 	}
       
   201 
       
   202 VGImageFormat MapSymbianDisplayModeToVG(TDisplayMode aMode)
       
   203 	{
       
   204 	VGImageFormat f;
       
   205 	switch(aMode)
       
   206 		{
       
   207 		case EColor16MA:
       
   208 			f = VG_sARGB_8888;
       
   209 			break;
       
   210 		case EColor16MU:
       
   211 			f = VG_sRGBX_8888;
       
   212 			break;
       
   213 		case EColor64K:
       
   214 			f = VG_sRGB_565;
       
   215 			break;
       
   216 		case EGray256:
       
   217 			f = VG_A_8;
       
   218 			break;
       
   219 		case EGray2:
       
   220 			f = VG_BW_1;
       
   221 			break;
       
   222 		default:
       
   223 			RI_ASSERT(0);
       
   224 		}
       
   225 	return f;
       
   226 	}
       
   227 EGLBoolean OSGetNativePixmapInfo(NativePixmapType pixmap, int* width, int* height, int* stride, VGImageFormat* format, int** data)
       
   228 {
       
   229 	TSize size = ((CFbsBitmap*)pixmap)->SizeInPixels();
       
   230     *width  = size.iWidth;
       
   231     *height = size.iHeight;
       
   232     *stride = ((CFbsBitmap*)pixmap)->DataStride();   
       
   233    
       
   234     *data = (int*)(((CFbsBitmap*)pixmap)->DataAddress());
       
   235     TDisplayMode mode = ((CFbsBitmap*)pixmap)->DisplayMode(); 
       
   236 	switch(mode)
       
   237 	{
       
   238 	case EColor16MA:
       
   239 		*format = VG_sRGBA_8888;
       
   240 		break;
       
   241 	case EColor16MU:
       
   242 		*format = VG_sRGBX_8888;
       
   243 		break;
       
   244 	case EColor64K:
       
   245 		*format = VG_sRGB_565;
       
   246 		break;
       
   247 	case EGray256:
       
   248 		*format = VG_A_8;
       
   249 		break;
       
   250 	case EGray2:
       
   251 		*format = VG_BW_1;
       
   252 		break;
       
   253 	default:
       
   254 		RI_ASSERT(0);
       
   255 	}
       
   256     return EGL_TRUE;
       
   257 }
       
   258 }   //namespace OpenVGRI