os/graphics/graphicsresourceservices/graphicsresourceimplementation/src/sgimage.cpp
Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // Graphics Resource - image implementation
19 EXPORT_C TInt RSgImage::Create(const TSgImageInfo& aInfo, const TAny* aDataAddress, TInt aDataStride, const TSgAttributeArrayBase* aAttributes)
25 __ASSERT_ALWAYS(gPls.iDriver, Panic(ESgPanicNoDriver));
26 return gPls.iDriver->CreateImage(aInfo, aDataAddress, aDataStride, aAttributes, iImpl);
29 EXPORT_C TInt RSgImage::Create(const TSgImageInfo& aInfo, const RSgImage& aImage, const TSgAttributeArrayBase* aAttributes)
35 __ASSERT_ALWAYS(gPls.iDriver, Panic(ESgPanicNoDriver));
36 return gPls.iDriver->CreateImage(aInfo, static_cast<XSgImage*>(aImage.iImpl), aAttributes, iImpl);
39 EXPORT_C TInt RSgImage::GetInfo(TSgImageInfo& aInfo) const
45 __ASSERT_ALWAYS(gPls.iDriver, Panic(ESgPanicNoDriver));
46 __ASSERT_ALWAYS(gPls.iDriver->CheckImage(iImpl), Panic(ESgPanicBadDrawableHandle));
47 static_cast<XSgImage*>(iImpl)->GetInfo(aInfo);
51 EXPORT_C TInt RSgImage::GetAttribute(TUid aUid, TInt& aValue) const
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);
62 EXPORT_C TInt RSgImage::GetPixelFormats(TUint32 aUsage, RArray<TInt>& aPixelFormats, const TSgAttributeArrayBase* aAttributes)
64 static const TInt KSupportedPixelFormats[] =
67 ESgPixelFormatRGB_565,
68 ESgPixelFormatXRGB_8888,
69 ESgPixelFormatARGB_8888,
70 ESgPixelFormatARGB_8888_PRE
72 static const TInt KNumSupportedPixelFormats = sizeof(KSupportedPixelFormats) / sizeof(TInt);
73 if (aUsage == 0 || aPixelFormats.Count() != 0)
79 return KErrNotSupported;
81 if (aUsage & ~KSgUsageAll)
85 _LIT(KLibOpenVg, "libOpenVG.dll");
86 _LIT(KLibOpenGles, "libGLESv1_CM.dll");
87 _LIT(KLibOpenGles2, "libGLESv2.dll");
89 if (aUsage & (ESgUsageBitOpenVgImage | ESgUsageBitOpenVgSurface))
91 if (lib.Load(KLibOpenVg) != KErrNone)
97 if (aUsage & (ESgUsageBitOpenGlesTexture2D | ESgUsageBitOpenGlesSurface))
99 if (lib.Load(KLibOpenGles) != KErrNone)
105 if (aUsage & (ESgUsageBitOpenGles2Texture2D | ESgUsageBitOpenGles2Surface))
107 if (lib.Load(KLibOpenGles2) != KErrNone)
114 for (TInt i = 0; i < KNumSupportedPixelFormats; ++i)
116 if (KSupportedPixelFormats[i] == ESgPixelFormatA_8 && (aUsage & KSgUsageAllSurfaceTypes))
120 err = aPixelFormats.Append(KSupportedPixelFormats[i]);
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)
135 XSgImage::~XSgImage()
137 __ASSERT_DEBUG(iRefCount == 0, Panic(ESgPanicBadRefCount));
140 TInt XSgImage::Open()
142 if (User::SafeInc(iRefCount) == 0)
149 void XSgImage::Close()
151 if (User::SafeDec(iRefCount) == 1)
153 gPls.iDriver->DeleteImage(this);
157 TInt XSgImage::RefCount() const
162 TSgDrawableId XSgImage::Id() const
167 TUid XSgImage::DrawableType() const
169 return KSgImageTypeUid;
172 TInt XSgImage::GetInterface(TUid aInterfaceUid, TAny*& aInterfacePtr)
174 if (aInterfaceUid == KNullUid)
178 if (aInterfaceUid.iUid == MSgImage_Sw::EInterfaceUid)
180 aInterfacePtr = static_cast<MSgImage_Sw*>(this);
183 return KErrExtensionNotSupported;
186 void XSgImage::GetInfo(TSgImageInfo& aInfo) const
191 TInt XSgImage::GetAttribute(TUid aUid, TInt& /*aValue*/) const
193 if (aUid == KNullUid)
197 return KErrNotSupported;
200 TInt XSgImage::Compare(const XSgImage& aImage1, const XSgImage& aImage2)
202 return Compare(&aImage1.iId, aImage2);
205 TInt XSgImage::Compare(const TSgDrawableId* aId, const XSgImage& aImage)
207 if (aId->iId > aImage.iId.iId)
211 if (aId->iId < aImage.iId.iId)
218 TAny* XSgImage::DataAddress() const
223 TInt XSgImage::DataStride() const