os/graphics/graphicsresourceservices/graphicsresourceimplementation/src/sgimage.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/graphicsresourceservices/graphicsresourceimplementation/src/sgimage.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,226 @@
1.4 +// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// Graphics Resource - image implementation
1.18 +//
1.19 +
1.20 +#include "sgdriver.h"
1.21 +
1.22 +EXPORT_C TInt RSgImage::Create(const TSgImageInfo& aInfo, const TAny* aDataAddress, TInt aDataStride, const TSgAttributeArrayBase* aAttributes)
1.23 + {
1.24 + if (iImpl)
1.25 + {
1.26 + return KErrInUse;
1.27 + }
1.28 + __ASSERT_ALWAYS(gPls.iDriver, Panic(ESgPanicNoDriver));
1.29 + return gPls.iDriver->CreateImage(aInfo, aDataAddress, aDataStride, aAttributes, iImpl);
1.30 + }
1.31 +
1.32 +EXPORT_C TInt RSgImage::Create(const TSgImageInfo& aInfo, const RSgImage& aImage, const TSgAttributeArrayBase* aAttributes)
1.33 + {
1.34 + if (iImpl)
1.35 + {
1.36 + return KErrInUse;
1.37 + }
1.38 + __ASSERT_ALWAYS(gPls.iDriver, Panic(ESgPanicNoDriver));
1.39 + return gPls.iDriver->CreateImage(aInfo, static_cast<XSgImage*>(aImage.iImpl), aAttributes, iImpl);
1.40 + }
1.41 +
1.42 +EXPORT_C TInt RSgImage::GetInfo(TSgImageInfo& aInfo) const
1.43 + {
1.44 + if (!iImpl)
1.45 + {
1.46 + return KErrBadHandle;
1.47 + }
1.48 + __ASSERT_ALWAYS(gPls.iDriver, Panic(ESgPanicNoDriver));
1.49 + __ASSERT_ALWAYS(gPls.iDriver->CheckImage(iImpl), Panic(ESgPanicBadDrawableHandle));
1.50 + static_cast<XSgImage*>(iImpl)->GetInfo(aInfo);
1.51 + return KErrNone;
1.52 + }
1.53 +
1.54 +EXPORT_C TInt RSgImage::GetAttribute(TUid aUid, TInt& aValue) const
1.55 + {
1.56 + if (!iImpl)
1.57 + {
1.58 + return KErrBadHandle;
1.59 + }
1.60 + __ASSERT_ALWAYS(gPls.iDriver, Panic(ESgPanicNoDriver));
1.61 + __ASSERT_ALWAYS(gPls.iDriver->CheckImage(iImpl), Panic(ESgPanicBadDrawableHandle));
1.62 + return static_cast<XSgImage*>(iImpl)->GetAttribute(aUid, aValue);
1.63 + }
1.64 +
1.65 +EXPORT_C TInt RSgImage::GetPixelFormats(TUint32 aUsage, RArray<TInt>& aPixelFormats, const TSgAttributeArrayBase* aAttributes)
1.66 + {
1.67 + static const TInt KSupportedPixelFormats[] =
1.68 + {
1.69 + ESgPixelFormatA_8,
1.70 + ESgPixelFormatRGB_565,
1.71 + ESgPixelFormatXRGB_8888,
1.72 + ESgPixelFormatARGB_8888,
1.73 + ESgPixelFormatARGB_8888_PRE
1.74 + };
1.75 + static const TInt KNumSupportedPixelFormats = sizeof(KSupportedPixelFormats) / sizeof(TInt);
1.76 + if (aUsage == 0 || aPixelFormats.Count() != 0)
1.77 + {
1.78 + return KErrArgument;
1.79 + }
1.80 + if (aAttributes)
1.81 + {
1.82 + return KErrNotSupported;
1.83 + }
1.84 + if (aUsage & ~KSgUsageAll)
1.85 + {
1.86 + return KErrNone;
1.87 + }
1.88 + _LIT(KLibOpenVg, "libOpenVG.dll");
1.89 + _LIT(KLibOpenGles, "libGLESv1_CM.dll");
1.90 + _LIT(KLibOpenGles2, "libGLESv2.dll");
1.91 + RLibrary lib;
1.92 + if (aUsage & (ESgUsageBitOpenVgImage | ESgUsageBitOpenVgSurface))
1.93 + {
1.94 + if (lib.Load(KLibOpenVg) != KErrNone)
1.95 + {
1.96 + return KErrNone;
1.97 + }
1.98 + lib.Close();
1.99 + }
1.100 + if (aUsage & (ESgUsageBitOpenGlesTexture2D | ESgUsageBitOpenGlesSurface))
1.101 + {
1.102 + if (lib.Load(KLibOpenGles) != KErrNone)
1.103 + {
1.104 + return KErrNone;
1.105 + }
1.106 + lib.Close();
1.107 + }
1.108 + if (aUsage & (ESgUsageBitOpenGles2Texture2D | ESgUsageBitOpenGles2Surface))
1.109 + {
1.110 + if (lib.Load(KLibOpenGles2) != KErrNone)
1.111 + {
1.112 + return KErrNone;
1.113 + }
1.114 + lib.Close();
1.115 + }
1.116 + TInt err = KErrNone;
1.117 + for (TInt i = 0; i < KNumSupportedPixelFormats; ++i)
1.118 + {
1.119 + if (KSupportedPixelFormats[i] == ESgPixelFormatA_8 && (aUsage & KSgUsageAllSurfaceTypes))
1.120 + {
1.121 + continue;
1.122 + }
1.123 + err = aPixelFormats.Append(KSupportedPixelFormats[i]);
1.124 + if (err != KErrNone)
1.125 + {
1.126 + break;
1.127 + }
1.128 + }
1.129 + return err;
1.130 + }
1.131 +
1.132 +XSgImage::XSgImage(TSgDrawableId aId, TUint32 aAttribs, const TSgImageMetaData& aMetaData, TAny* aDataAddress, TInt aDataStride)
1.133 + : iRefCount(1), iId(aId), iInfo(aMetaData.iSizeInPixels, aMetaData.iPixelFormat, aAttribs & KSgUsageBitMask),
1.134 + iDataAddress(aDataAddress), iDataStride(aDataStride)
1.135 + {
1.136 + }
1.137 +
1.138 +XSgImage::~XSgImage()
1.139 + {
1.140 + __ASSERT_DEBUG(iRefCount == 0, Panic(ESgPanicBadRefCount));
1.141 + }
1.142 +
1.143 +TInt XSgImage::Open()
1.144 + {
1.145 + if (User::SafeInc(iRefCount) == 0)
1.146 + {
1.147 + return KErrNotFound;
1.148 + }
1.149 + return KErrNone;
1.150 + }
1.151 +
1.152 +void XSgImage::Close()
1.153 + {
1.154 + if (User::SafeDec(iRefCount) == 1)
1.155 + {
1.156 + gPls.iDriver->DeleteImage(this);
1.157 + }
1.158 + }
1.159 +
1.160 +TInt XSgImage::RefCount() const
1.161 + {
1.162 + return iRefCount;
1.163 + }
1.164 +
1.165 +TSgDrawableId XSgImage::Id() const
1.166 + {
1.167 + return iId;
1.168 + }
1.169 +
1.170 +TUid XSgImage::DrawableType() const
1.171 + {
1.172 + return KSgImageTypeUid;
1.173 + }
1.174 +
1.175 +TInt XSgImage::GetInterface(TUid aInterfaceUid, TAny*& aInterfacePtr)
1.176 + {
1.177 + if (aInterfaceUid == KNullUid)
1.178 + {
1.179 + return KErrArgument;
1.180 + }
1.181 + if (aInterfaceUid.iUid == MSgImage_Sw::EInterfaceUid)
1.182 + {
1.183 + aInterfacePtr = static_cast<MSgImage_Sw*>(this);
1.184 + return KErrNone;
1.185 + }
1.186 + return KErrExtensionNotSupported;
1.187 + }
1.188 +
1.189 +void XSgImage::GetInfo(TSgImageInfo& aInfo) const
1.190 + {
1.191 + aInfo = iInfo;
1.192 + }
1.193 +
1.194 +TInt XSgImage::GetAttribute(TUid aUid, TInt& /*aValue*/) const
1.195 + {
1.196 + if (aUid == KNullUid)
1.197 + {
1.198 + return KErrArgument;
1.199 + }
1.200 + return KErrNotSupported;
1.201 + }
1.202 +
1.203 +TInt XSgImage::Compare(const XSgImage& aImage1, const XSgImage& aImage2)
1.204 + {
1.205 + return Compare(&aImage1.iId, aImage2);
1.206 + }
1.207 +
1.208 +TInt XSgImage::Compare(const TSgDrawableId* aId, const XSgImage& aImage)
1.209 + {
1.210 + if (aId->iId > aImage.iId.iId)
1.211 + {
1.212 + return 1;
1.213 + }
1.214 + if (aId->iId < aImage.iId.iId)
1.215 + {
1.216 + return -1;
1.217 + }
1.218 + return 0;
1.219 + }
1.220 +
1.221 +TAny* XSgImage::DataAddress() const
1.222 + {
1.223 + return iDataAddress;
1.224 + }
1.225 +
1.226 +TInt XSgImage::DataStride() const
1.227 + {
1.228 + return iDataStride;
1.229 + }