openvg/openvgrefimplementation/sfopenvg/sfopenvg/symbian/riEGLOS.cpp
branchNewGraphicsArchitecture
changeset 6 250ac10a3d98
child 118 6aeef2faff80
equal deleted inserted replaced
5:8448d8896a16 6:250ac10a3d98
       
     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 	TNativeWindowType*  iNativeWindowType;   
       
    90 };
       
    91 
       
    92 void* OSCreateWindowContext(EGLNativeWindowType window)
       
    93 {
       
    94     OSWindowContext* ctx = NULL;
       
    95     try
       
    96     {
       
    97         ctx = RI_NEW(OSWindowContext, ());
       
    98     }
       
    99 	catch(std::bad_alloc)
       
   100 	{
       
   101 		return NULL;
       
   102 	}
       
   103     ctx->iNativeWindowType = (TNativeWindowType*)window;
       
   104     return ctx;
       
   105 }
       
   106 
       
   107 void OSDestroyWindowContext(void* context)
       
   108 {
       
   109     OSWindowContext* ctx = (OSWindowContext*)context;
       
   110     if(ctx)
       
   111     {
       
   112         RI_DELETE(ctx);
       
   113     }
       
   114 }
       
   115 
       
   116 bool OSIsWindow(const void* context)
       
   117 {
       
   118     OSWindowContext* ctx = (OSWindowContext*)context;
       
   119     if(ctx)
       
   120     {
       
   121         return true;
       
   122     }
       
   123     return false;
       
   124 }
       
   125 
       
   126 void OSGetWindowSize(const void* context, int& width, int& height)
       
   127 {
       
   128     OSWindowContext* ctx = (OSWindowContext*)context;
       
   129     if(ctx)
       
   130     {
       
   131     	width=ctx->iNativeWindowType->iSize.iWidth;
       
   132 		height=ctx->iNativeWindowType->iSize.iHeight; 
       
   133     }
       
   134     else
       
   135     {
       
   136         width = 0;
       
   137         height = 0;
       
   138     }
       
   139 }
       
   140 
       
   141 
       
   142 EGLDisplay OSGetDisplay(EGLNativeDisplayType display_id)
       
   143 {
       
   144     RI_UNREF(display_id);
       
   145     return (EGLDisplay)1;    //support only a single display
       
   146 }
       
   147 
       
   148 
       
   149 void OSBlitToWindow(void* context, const Drawable* drawable)
       
   150 {
       
   151     OSWindowContext* ctx = (OSWindowContext*)context;
       
   152     //blit if either of iBitmap or iMaskBitmap exist
       
   153     if(ctx && ctx->iNativeWindowType->iBitmap)
       
   154     {
       
   155         TUint w = drawable->getWidth();
       
   156         TUint h = drawable->getHeight();
       
   157         
       
   158         //these should be same as bitmap
       
   159         if(ctx->iNativeWindowType->iBitmap)
       
   160         	{
       
   161         	CFbsBitmap* bitmap = ctx->iNativeWindowType->iBitmap;        	
       
   162         	ReadPixelsToCFbsBitmap(*bitmap, w, h);        	
       
   163         	}
       
   164     }
       
   165 }
       
   166 
       
   167 void ReadPixelsToCFbsBitmap(CFbsBitmap& aBitmap, TUint aW, TUint aH)
       
   168 	{
       
   169 	TSize sz = aBitmap.SizeInPixels();
       
   170 	RI_ASSERT(aW==sz.iWidth);
       
   171 	RI_ASSERT(aH==sz.iHeight);
       
   172 	
       
   173 	VGImageFormat f = MapSymbianDisplayModeToVG(aBitmap.DisplayMode());
       
   174 	
       
   175 	TInt bitmapDataStride = aBitmap.DataStride();
       
   176 	
       
   177 	//copy from source OpenVG model to target(CFbsBitmap) buffer			
       
   178 	aBitmap.BeginDataAccess();
       
   179 	//openvg returns pixels in cartesian coordinates (y+) where as CFbsBitmap
       
   180 	//wants screen coordinates (y-) so we read pixels out starting at top left corner 
       
   181 	TUint8* ptarget = (TUint8*)aBitmap.DataAddress()+(aH-1)*bitmapDataStride;
       
   182 	vgReadPixels(ptarget, -bitmapDataStride, f, 0, 0, aW, aH);
       
   183 	aBitmap.EndDataAccess(EFalse);
       
   184 	}
       
   185 
       
   186 VGImageFormat MapSymbianDisplayModeToVG(TDisplayMode aMode)
       
   187 	{
       
   188 	VGImageFormat f;
       
   189 	switch(aMode)
       
   190 		{
       
   191 		case EColor16MA:
       
   192 			f = VG_sARGB_8888;
       
   193 			break;
       
   194 		case EColor16MU:
       
   195 			f = VG_sRGBX_8888;
       
   196 			break;
       
   197 		case EColor64K:
       
   198 			f = VG_sRGB_565;
       
   199 			break;
       
   200 		case EGray256:
       
   201 			f = VG_A_8;
       
   202 			break;
       
   203 		case EGray2:
       
   204 			f = VG_BW_1;
       
   205 			break;
       
   206 		default:
       
   207 			RI_ASSERT(0);
       
   208 		}
       
   209 	return f;
       
   210 	}
       
   211 EGLBoolean OSGetNativePixmapInfo(NativePixmapType pixmap, int* width, int* height, int* stride, VGImageFormat* format, int** data)
       
   212 {
       
   213 	TSize size = ((CFbsBitmap*)pixmap)->SizeInPixels();
       
   214     *width  = size.iWidth;
       
   215     *height = size.iHeight;
       
   216     *stride = ((CFbsBitmap*)pixmap)->DataStride();    
       
   217     
       
   218     *data = (int*)(((CFbsBitmap*)pixmap)->DataAddress());
       
   219     TDisplayMode mode = ((CFbsBitmap*)pixmap)->DisplayMode(); 
       
   220 	switch(mode)
       
   221 	{
       
   222 	case EColor16MA:
       
   223 		*format = VG_sRGBA_8888;
       
   224 		break;
       
   225 	case EColor16MU:
       
   226 		*format = VG_sRGBX_8888;
       
   227 		break;
       
   228 	case EColor64K:
       
   229 		*format = VG_sRGB_565;
       
   230 		break;
       
   231 	case EGray256:
       
   232 		*format = VG_A_8;
       
   233 		break;
       
   234 	case EGray2:
       
   235 		*format = VG_BW_1;
       
   236 		break;
       
   237 	default:
       
   238 		RI_ASSERT(0);
       
   239 	}
       
   240     return EGL_TRUE;
       
   241 }
       
   242 }   //namespace OpenVGRI