graphicsresourceservices/graphicsresourceimplementation/src/sgimage.cpp
branchRCL_3
changeset 19 bbf46f59e123
equal deleted inserted replaced
18:57c618273d5c 19:bbf46f59e123
       
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Graphics Resource - image implementation
       
    15 //
       
    16 
       
    17 #include "sgdriver.h"
       
    18 
       
    19 EXPORT_C TInt RSgImage::Create(const TSgImageInfo& aInfo, const TAny* aDataAddress, TInt aDataStride, const TSgAttributeArrayBase* aAttributes)
       
    20 	{
       
    21 	if (iImpl)
       
    22 		{
       
    23 		return KErrInUse;
       
    24 		}
       
    25 	__ASSERT_ALWAYS(gPls.iDriver, Panic(ESgPanicNoDriver));
       
    26 	return gPls.iDriver->CreateImage(aInfo, aDataAddress, aDataStride, aAttributes, iImpl);
       
    27 	}
       
    28 
       
    29 EXPORT_C TInt RSgImage::Create(const TSgImageInfo& aInfo, const RSgImage& aImage, const TSgAttributeArrayBase* aAttributes)
       
    30 	{
       
    31 	if (iImpl)
       
    32 		{
       
    33 		return KErrInUse;
       
    34 		}
       
    35 	__ASSERT_ALWAYS(gPls.iDriver, Panic(ESgPanicNoDriver));
       
    36 	return gPls.iDriver->CreateImage(aInfo, static_cast<XSgImage*>(aImage.iImpl), aAttributes, iImpl);
       
    37 	}
       
    38 
       
    39 EXPORT_C TInt RSgImage::GetInfo(TSgImageInfo& aInfo) const
       
    40 	{
       
    41 	if (!iImpl)
       
    42 		{
       
    43 		return KErrBadHandle;
       
    44 		}
       
    45 	__ASSERT_ALWAYS(gPls.iDriver, Panic(ESgPanicNoDriver));
       
    46 	__ASSERT_ALWAYS(gPls.iDriver->CheckImage(iImpl), Panic(ESgPanicBadDrawableHandle));
       
    47 	static_cast<XSgImage*>(iImpl)->GetInfo(aInfo);
       
    48 	return KErrNone;
       
    49 	}
       
    50 
       
    51 EXPORT_C TInt RSgImage::GetAttribute(TUid aUid, TInt& aValue) const
       
    52 	{
       
    53 	if (!iImpl)
       
    54 		{
       
    55 		return KErrBadHandle;
       
    56 		}
       
    57 	__ASSERT_ALWAYS(gPls.iDriver, Panic(ESgPanicNoDriver));
       
    58 	__ASSERT_ALWAYS(gPls.iDriver->CheckImage(iImpl), Panic(ESgPanicBadDrawableHandle));
       
    59 	return static_cast<XSgImage*>(iImpl)->GetAttribute(aUid, aValue);
       
    60 	}
       
    61 
       
    62 EXPORT_C TInt RSgImage::GetPixelFormats(TUint32 aUsage, RArray<TInt>& aPixelFormats, const TSgAttributeArrayBase* aAttributes)
       
    63 	{
       
    64 	static const TInt KSupportedPixelFormats[] =
       
    65 		{
       
    66 		ESgPixelFormatA_8,
       
    67 		ESgPixelFormatRGB_565,
       
    68 		ESgPixelFormatXRGB_8888,
       
    69 		ESgPixelFormatARGB_8888,
       
    70 		ESgPixelFormatARGB_8888_PRE
       
    71 		};
       
    72 	static const TInt KNumSupportedPixelFormats = sizeof(KSupportedPixelFormats) / sizeof(TInt);
       
    73 	if (aUsage == 0 || aPixelFormats.Count() != 0)
       
    74 		{
       
    75 		return KErrArgument;
       
    76 		}
       
    77 	if (aAttributes)
       
    78 		{
       
    79 		return KErrNotSupported;
       
    80 		}
       
    81 	if (aUsage & ~KSgUsageAll)
       
    82 		{
       
    83 		return KErrNone;
       
    84 		}
       
    85 	_LIT(KLibOpenVg, "libOpenVG.dll");
       
    86 	_LIT(KLibOpenGles, "libGLESv1_CM.dll");
       
    87 	_LIT(KLibOpenGles2, "libGLESv2.dll");
       
    88 	RLibrary lib;
       
    89 	if (aUsage & (ESgUsageBitOpenVgImage | ESgUsageBitOpenVgSurface))
       
    90 		{
       
    91 		if (lib.Load(KLibOpenVg) != KErrNone)
       
    92 			{
       
    93 			return KErrNone;
       
    94 			}
       
    95 		lib.Close();
       
    96 		}
       
    97 	if (aUsage & (ESgUsageBitOpenGlesTexture2D | ESgUsageBitOpenGlesSurface))
       
    98 		{
       
    99 		if (lib.Load(KLibOpenGles) != KErrNone)
       
   100 			{
       
   101 			return KErrNone;
       
   102 			}
       
   103 		lib.Close();
       
   104 		}
       
   105 	if (aUsage & (ESgUsageBitOpenGles2Texture2D | ESgUsageBitOpenGles2Surface))
       
   106 		{
       
   107 		if (lib.Load(KLibOpenGles2) != KErrNone)
       
   108 			{
       
   109 			return KErrNone;
       
   110 			}
       
   111 		lib.Close();
       
   112 		}
       
   113 	TInt err = KErrNone;
       
   114 	for (TInt i = 0; i < KNumSupportedPixelFormats; ++i)
       
   115 		{
       
   116 		if (KSupportedPixelFormats[i] == ESgPixelFormatA_8 && (aUsage & KSgUsageAllSurfaceTypes))
       
   117 			{
       
   118 			continue;
       
   119 			}
       
   120 		err = aPixelFormats.Append(KSupportedPixelFormats[i]);
       
   121 		if (err != KErrNone)
       
   122 			{
       
   123 			break;
       
   124 			}
       
   125 		}
       
   126 	return err;
       
   127 	}
       
   128 
       
   129 XSgImage::XSgImage(TSgDrawableId aId, TUint32 aAttribs, const TSgImageMetaData& aMetaData, TAny* aDataAddress, TInt aDataStride)
       
   130 	: iRefCount(1), iId(aId), iInfo(aMetaData.iSizeInPixels, aMetaData.iPixelFormat, aAttribs & KSgUsageBitMask),
       
   131 	  iDataAddress(aDataAddress), iDataStride(aDataStride)
       
   132 	{
       
   133 	}
       
   134 
       
   135 XSgImage::~XSgImage()
       
   136 	{
       
   137 	__ASSERT_DEBUG(iRefCount == 0, Panic(ESgPanicBadRefCount));
       
   138 	}
       
   139 
       
   140 TInt XSgImage::Open()
       
   141 	{
       
   142 	if (User::SafeInc(iRefCount) == 0)
       
   143 		{
       
   144 		return KErrNotFound;
       
   145 		}
       
   146 	return KErrNone;
       
   147 	}
       
   148 
       
   149 void XSgImage::Close()
       
   150 	{
       
   151 	if (User::SafeDec(iRefCount) == 1)
       
   152 		{
       
   153 		gPls.iDriver->DeleteImage(this);
       
   154 		}
       
   155 	}
       
   156 
       
   157 TInt XSgImage::RefCount() const
       
   158 	{
       
   159 	return iRefCount;
       
   160 	}
       
   161 
       
   162 TSgDrawableId XSgImage::Id() const
       
   163 	{
       
   164 	return iId;
       
   165 	}
       
   166 
       
   167 TUid XSgImage::DrawableType() const
       
   168 	{
       
   169 	return KSgImageTypeUid;
       
   170 	}
       
   171 
       
   172 TInt XSgImage::GetInterface(TUid aInterfaceUid, TAny*& aInterfacePtr)
       
   173 	{
       
   174 	if (aInterfaceUid == KNullUid)
       
   175 		{
       
   176 		return KErrArgument;
       
   177 		}
       
   178 	if (aInterfaceUid.iUid == MSgImage_Sw::EInterfaceUid)
       
   179 		{
       
   180 		aInterfacePtr = static_cast<MSgImage_Sw*>(this);
       
   181 		return KErrNone;
       
   182 		}
       
   183 	return KErrExtensionNotSupported;
       
   184 	}
       
   185 
       
   186 void XSgImage::GetInfo(TSgImageInfo& aInfo) const
       
   187 	{
       
   188 	aInfo = iInfo;
       
   189 	}
       
   190 
       
   191 TInt XSgImage::GetAttribute(TUid aUid, TInt& /*aValue*/) const
       
   192 	{
       
   193 	if (aUid == KNullUid)
       
   194 		{
       
   195 		return KErrArgument;
       
   196 		}
       
   197 	return KErrNotSupported;
       
   198 	}
       
   199 
       
   200 TInt XSgImage::Compare(const XSgImage& aImage1, const XSgImage& aImage2)
       
   201 	{
       
   202 	return Compare(&aImage1.iId, aImage2);
       
   203 	}
       
   204 
       
   205 TInt XSgImage::Compare(const TSgDrawableId* aId, const XSgImage& aImage)
       
   206 	{
       
   207 	if (aId->iId > aImage.iId.iId)
       
   208 		{
       
   209 		return 1;
       
   210 		}
       
   211 	if (aId->iId < aImage.iId.iId)
       
   212 		{
       
   213 		return -1;
       
   214 		}
       
   215 	return 0;
       
   216 	}
       
   217 
       
   218 TAny* XSgImage::DataAddress() const
       
   219 	{
       
   220 	return iDataAddress;
       
   221 	}
       
   222 
       
   223 TInt XSgImage::DataStride() const
       
   224 	{
       
   225 	return iDataStride;
       
   226 	}