sl@0: // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include "sgdriver.h" sl@0: #include "sgimagecollectionadapter.h" sl@0: sl@0: sl@0: /** sl@0: @internalComponent sl@0: */ sl@0: const TSurfaceId KNullSurfaceId = {0, 0, 0, 0}; sl@0: sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @prototype sl@0: @deprecated sl@0: sl@0: Default constructor. sl@0: sl@0: @pre None. sl@0: @post This RSgImageCollection handle is null. sl@0: */ sl@0: EXPORT_C RSgImageCollection::RSgImageCollection() sl@0: : iImpl(NULL) sl@0: {} sl@0: sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @prototype sl@0: @deprecated sl@0: sl@0: Creates an image collection with the specified attributes. The number of images in sl@0: the collection cannot be changed after creation. The images in the collection have sl@0: identical attributes. The initial contents of all the images are undefined. sl@0: sl@0: @param aInfo The image attributes of the collection to be created. sl@0: @param aImageCount The number of images in the collection to be created. sl@0: @pre The Graphics Resource driver is initialised for use in the context of the sl@0: calling process. sl@0: @pre This RSgImageCollection handle is null. sl@0: @pre aInfo is supported and specifies mutable images. sl@0: @pre aImageCount is greater than zero. sl@0: @post This RSgImageCollection handle references a newly created image collection with sl@0: the specified attributes. The initial reference count for the image collection sl@0: is one. sl@0: @return KErrNone if successful. sl@0: @return KErrInUse if this RSgImageCollection handle was not null. sl@0: @return KErrArgument if aInfo is invalid or if aImageCount is negative or zero. sl@0: @return KErrTooBig if the size specified in aInfo is too large. sl@0: @return KErrNotSupported if aInfo is not supported or does not specify mutable images. sl@0: @return KErrNoMemory if there is not enough system memory. sl@0: @return KErrNoSpecializedMemory if there is not enough specialised graphics memory. sl@0: @panic SGRES 5 in debug builds if the Graphics Resource driver is not initialised sl@0: for use in the context of the calling process. sl@0: */ sl@0: EXPORT_C TInt RSgImageCollection::Create(const TSgImageInfo& aInfo, TInt aImageCount) sl@0: { sl@0: #ifdef _DEBUG sl@0: gPls.iMutex.Wait(); sl@0: __ASSERT_DEBUG(gPls.iDriver, Panic(ESgPanicNoDriver)); sl@0: #endif sl@0: TInt err = gPls.iDriver->CreateImageCollection(aInfo, aImageCount, iImpl); sl@0: #ifdef _DEBUG sl@0: gPls.iMutex.Signal(); sl@0: #endif sl@0: return err; sl@0: } sl@0: sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @prototype sl@0: @deprecated sl@0: sl@0: Creates a set of image collections that share a single memory chunk. The number of sl@0: images in each collection is the same and cannot be changed after creation. The images sl@0: in each collection have identical attributes. The initial contents of all the images sl@0: are undefined. sl@0: sl@0: Care must be taken when using image collections created in this way. In particular, sl@0: writing to the Nth image of one collection may invalidate the contents of the Nth image sl@0: of all other collections, but will not affect any other images. sl@0: sl@0: @param aInfos An array of aCollectionCount elements with the image attributes of each sl@0: of the collections to be created. sl@0: @param aImageCount The number of images in each of the collections to be created. sl@0: @param aCollections On return, an array of RSgImageCollection handles that reference sl@0: newly created image collections with the specified attributes. sl@0: @param aCollectionCount The number of image collections to be created. sl@0: @pre The Graphics Resource driver is initialised for use in the context of the sl@0: calling process. sl@0: @pre All the elements of aInfos are supported and specify mutable images. sl@0: @pre aImageCount is greater than zero. sl@0: @pre All the RSgImageCollection handles in aCollections are null. sl@0: @pre aCollectionCount is greater than zero. sl@0: @post The initial reference count for each of the newly created image collections is one. sl@0: @return KErrNone if successful. sl@0: @return KErrInUse if any of the RSgImageCollection handles in aCollections was not null. sl@0: @return KErrArgument if any element of aInfos is invalid, if aImageCount is negative sl@0: or zero, or if aCollectionCount is negative or zero. sl@0: @return KErrTooBig if any of the sizes specified in aInfos is too large. sl@0: @return KErrNotSupported if any element of aInfos is not supported or does not specify sl@0: mutable images. sl@0: @return KErrNoMemory if there is not enough system memory. sl@0: @return KErrNoSpecializedMemory if there is not enough specialised graphics memory. sl@0: @panic SGRES 5 in debug builds if the Graphics Resource driver is not initialised sl@0: for use in the context of the calling process. sl@0: */ sl@0: EXPORT_C TInt RSgImageCollection::Create(const TSgImageInfo aInfos[], TInt aImageCount, sl@0: RSgImageCollection aCollections[], TInt aCollectionCount) sl@0: { sl@0: #ifdef _DEBUG sl@0: gPls.iMutex.Wait(); sl@0: __ASSERT_DEBUG(gPls.iDriver, Panic(ESgPanicNoDriver)); sl@0: #endif sl@0: TInt err = gPls.iDriver->CreateImageCollections(aInfos, aImageCount, sl@0: reinterpret_cast(aCollections), aCollectionCount); sl@0: #ifdef _DEBUG sl@0: gPls.iMutex.Signal(); sl@0: #endif sl@0: return err; sl@0: } sl@0: sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @prototype sl@0: @deprecated sl@0: sl@0: Closes a handle to an image collection. If there are no remaining handles to sl@0: the image collection, then it can be destroyed by the Graphics Resource driver. sl@0: Calling Close() on a null handle is allowed but has no effect. sl@0: sl@0: @pre If this RSgImageCollection handle is not null then the Graphics Resource sl@0: driver is initialised for use in the context of the calling process. sl@0: @pre This RSgImageCollection handle is valid. sl@0: @post This RSgImageCollection handle is null. The reference count for the sl@0: previously referenced image collection, if any, is decremented by one. sl@0: @panic SGRES 4 in debug builds if this RSgImageCollection handle is invalid. sl@0: @panic SGRES 5 in debug builds if this RSgImageCollection handle is not null sl@0: and the Graphics Resource driver is not initialised for use in the sl@0: context of the calling process. sl@0: */ sl@0: EXPORT_C void RSgImageCollection::Close() sl@0: { sl@0: if (iImpl) sl@0: { sl@0: #ifdef _DEBUG sl@0: gPls.iMutex.Wait(); sl@0: __ASSERT_DEBUG(gPls.iDriver, Panic(ESgPanicNoDriver)); sl@0: __ASSERT_DEBUG(gPls.iDriver->CheckImageCollection(*iImpl), Panic(ESgPanicBadImageCollectionHandle)); sl@0: #endif sl@0: iImpl->Close(); sl@0: iImpl = NULL; sl@0: #ifdef _DEBUG sl@0: gPls.iMutex.Signal(); sl@0: #endif sl@0: } sl@0: } sl@0: sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @prototype sl@0: @deprecated sl@0: sl@0: Retrieves the surface identifier of an image collection. sl@0: sl@0: @pre The Graphics Resource driver is initialised for use in the context of the sl@0: calling process. sl@0: @pre This RSgImageCollection handle is valid. sl@0: @post None. sl@0: @return The surface identifier of the image collection or the null surface identifier sl@0: if this RSgImageCollection handle is null. sl@0: @panic SGRES 4 in debug builds if this RSgImageCollection handle is invalid. sl@0: @panic SGRES 5 in debug builds if the Graphics Resource driver is not initialised sl@0: for use in the context of the calling process. sl@0: */ sl@0: EXPORT_C const TSurfaceId& RSgImageCollection::SurfaceId() const sl@0: { sl@0: if (!iImpl) sl@0: { sl@0: return KNullSurfaceId; sl@0: } sl@0: #ifdef _DEBUG sl@0: gPls.iMutex.Wait(); sl@0: __ASSERT_DEBUG(gPls.iDriver, Panic(ESgPanicNoDriver)); sl@0: __ASSERT_DEBUG(gPls.iDriver->CheckImageCollection(*iImpl), Panic(ESgPanicBadImageCollectionHandle)); sl@0: #endif sl@0: const TSurfaceId& id = iImpl->SurfaceId(); sl@0: #ifdef _DEBUG sl@0: gPls.iMutex.Signal(); sl@0: #endif sl@0: return id; sl@0: } sl@0: sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @prototype sl@0: @deprecated sl@0: sl@0: Tests whether this RSgImageCollection handle is null. sl@0: sl@0: @pre None. sl@0: @post None. sl@0: @return ETrue, if this RSgImageCollection handle is null, EFalse otherwise. sl@0: */ sl@0: EXPORT_C TBool RSgImageCollection::IsNull() const sl@0: { sl@0: return iImpl == NULL; sl@0: } sl@0: sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @prototype sl@0: @deprecated sl@0: sl@0: Retrieves the values of the attributes of the images in an image collection. This sl@0: function can also retrieve the values of selected user-defined attributes attached sl@0: to an image collection by passing in the globally unique identifiers of the sl@0: user-defined attributes to be retrieved. sl@0: sl@0: @param aInfo On input, the globally unique identifiers of the user-defined attributes sl@0: to be retrieved from the image collection, if any. On return, the values of sl@0: the attributes of the images in the collection and the values of the selected sl@0: user-defined attributes. sl@0: @pre The Graphics Resource driver is initialised for use in the context of the sl@0: calling process. sl@0: @pre This RSgImageCollection handle is valid and not null. sl@0: @pre If aInfo.iUserAttributes is not null then it points to an array of sl@0: aInfo.iUserAttributeCount elements with globally unique identifiers sl@0: corresponding to user-defined attributes attached to the image collection. sl@0: @post None. sl@0: @return KErrNone if successful. sl@0: @return KErrBadHandle if this RSgImageCollection handle is null. sl@0: @return KErrNotFound if any of the user-defined attributes to be retrieved from the sl@0: image collection cannot be found. sl@0: @panic SGRES 4 in debug builds if this RSgImageCollection handle is invalid. sl@0: @panic SGRES 5 in debug builds if the Graphics Resource driver is not initialised sl@0: for use in the context of the calling process. sl@0: */ sl@0: EXPORT_C TInt RSgImageCollection::GetInfo(TSgImageInfo& aInfo) const sl@0: { sl@0: if (!iImpl) sl@0: { sl@0: return KErrBadHandle; sl@0: } sl@0: #ifdef _DEBUG sl@0: gPls.iMutex.Wait(); sl@0: __ASSERT_DEBUG(gPls.iDriver, Panic(ESgPanicNoDriver)); sl@0: __ASSERT_DEBUG(gPls.iDriver->CheckImageCollection(*iImpl), Panic(ESgPanicBadImageCollectionHandle)); sl@0: #endif sl@0: TInt err = iImpl->GetInfo(aInfo); sl@0: #ifdef _DEBUG sl@0: gPls.iMutex.Signal(); sl@0: #endif sl@0: return err; sl@0: } sl@0: sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @prototype sl@0: @deprecated sl@0: sl@0: Retrieves the number of images in an image collection. sl@0: sl@0: @pre The Graphics Resource driver is initialised for use in the context of the sl@0: calling process. sl@0: @pre This RSgImageCollection handle is valid. sl@0: @post None. sl@0: @return The number of images in the image collection or zero if this RSgImageCollection sl@0: handle is null. sl@0: @panic SGRES 4 in debug builds if this RSgImageCollection handle is invalid. sl@0: @panic SGRES 5 in debug builds if the Graphics Resource driver is not initialised sl@0: for use in the context of the calling process. sl@0: */ sl@0: EXPORT_C TInt RSgImageCollection::Count() const sl@0: { sl@0: if (!iImpl) sl@0: { sl@0: return 0; sl@0: } sl@0: #ifdef _DEBUG sl@0: gPls.iMutex.Wait(); sl@0: __ASSERT_DEBUG(gPls.iDriver, Panic(ESgPanicNoDriver)); sl@0: __ASSERT_DEBUG(gPls.iDriver->CheckImageCollection(*iImpl), Panic(ESgPanicBadImageCollectionHandle)); sl@0: #endif sl@0: TInt count = iImpl->Count(); sl@0: #ifdef _DEBUG sl@0: gPls.iMutex.Signal(); sl@0: #endif sl@0: return count; sl@0: } sl@0: sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @prototype sl@0: @deprecated sl@0: sl@0: Opens a new handle to one of the images in an image collection. sl@0: sl@0: @param aIndex The index of the image within the image collection. sl@0: @param aResult On return, an RSgImage handle that references the specified image in sl@0: the collection. sl@0: @pre The Graphics Resource driver is initialised for use in the context of the sl@0: calling process. sl@0: @pre This RSgImageCollection handle is valid and not null. sl@0: @pre aIndex is greater than or equal to zero and less than the number of images in sl@0: the collection. sl@0: @pre aResult is a null handle. sl@0: @post The reference count for the image collection is incremented by one. sl@0: @return KErrNone if successful. sl@0: @return KErrBadHandle if this RSgImageCollection handle is null. sl@0: @return KErrInUse if aResult was not a null handle. sl@0: @return KErrArgument if aIndex is invalid. sl@0: @return KErrNoMemory if there is not enough system memory. sl@0: @panic SGRES 4 in debug builds if this RSgImageCollection handle is invalid. sl@0: @panic SGRES 5 in debug builds if the Graphics Resource driver is not initialised sl@0: for use in the context of the calling process. sl@0: */ sl@0: EXPORT_C TInt RSgImageCollection::OpenImage(TInt aIndex, RSgImage& aResult) sl@0: { sl@0: if (!iImpl) sl@0: { sl@0: return KErrBadHandle; sl@0: } sl@0: #ifdef _DEBUG sl@0: gPls.iMutex.Wait(); sl@0: __ASSERT_DEBUG(gPls.iDriver, Panic(ESgPanicNoDriver)); sl@0: __ASSERT_DEBUG(gPls.iDriver->CheckImageCollection(*iImpl), Panic(ESgPanicBadImageCollectionHandle)); sl@0: #endif sl@0: TInt err = iImpl->OpenImage(aIndex, aResult.iImpl); sl@0: #ifdef _DEBUG sl@0: gPls.iMutex.Signal(); sl@0: #endif sl@0: return err; sl@0: }