os/graphics/graphicsresourceservices/graphicsresourceadaptation/src/sgimagecollectionimpl.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/graphicsresourceservices/graphicsresourceadaptation/src/sgimagecollectionimpl.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,192 @@
     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 +//
    1.18 +
    1.19 +#include "sgimagecollectionimpl.h"
    1.20 +#include "sgimageimpl.h"
    1.21 +
    1.22 +
    1.23 +TInt XSgImageCollectionImpl::New(XSgImageCollectionImpl*& aPtr, XSgDriverImpl& aDriverImpl,
    1.24 +                                 const TSgImageInfo& aInfo, TInt aImageCount, TBool aIsCached,
    1.25 +                                 TInt aStride, TInt aOffsetToFirstBuffer, TInt aOffsetBetweenBuffers,
    1.26 +                                 TInt aMetaDataIndex, const XSgImageCollectionImpl* aCollection)
    1.27 +	{
    1.28 +	aPtr = static_cast<XSgImageCollectionImpl*>(aDriverImpl.Alloc(sizeof(XSgImageCollectionImpl)));
    1.29 +	if (!aPtr)
    1.30 +		{
    1.31 +		return KErrNoMemory;
    1.32 +		}
    1.33 +	new(aPtr) XSgImageCollectionImpl(aDriverImpl);
    1.34 +	TInt err = aPtr->Construct(aInfo, aImageCount, aIsCached, aStride, aOffsetToFirstBuffer, aOffsetBetweenBuffers, aMetaDataIndex, aCollection);
    1.35 +	if (err != KErrNone)
    1.36 +		{
    1.37 +		aPtr->Delete();
    1.38 +		aPtr = NULL;
    1.39 +		}
    1.40 +	return err;
    1.41 +	}
    1.42 +
    1.43 +
    1.44 +TInt XSgImageCollectionImpl::Construct(const TSgImageInfo& aInfo, TInt aImageCount, TBool aIsCached,
    1.45 +                                       TInt aStride, TInt aOffsetToFirstBuffer, TInt aOffsetBetweenBuffers,
    1.46 +                                       TInt aMetaDataIndex, const XSgImageCollectionImpl* aCollection)
    1.47 +	{
    1.48 +	TInt maxNumberOfHints;
    1.49 +	TInt err;
    1.50 +	err=iDriverImpl.GetSurfaceManagerAttrib(RSurfaceManager::EMaxNumberOfHints,maxNumberOfHints);
    1.51 +	if (err != KErrNone)
    1.52 +	    {
    1.53 +	    return err;
    1.54 +	    } 
    1.55 +			
    1.56 +	if (aInfo.iUserAttributeCount > maxNumberOfHints)
    1.57 +		{
    1.58 +		return KErrOverflow;
    1.59 +		}
    1.60 +	RSurfaceManager::THintPair* hints = new RSurfaceManager::THintPair[aInfo.iUserAttributeCount];
    1.61 +	if(!hints)
    1.62 +		{
    1.63 +		return KErrNoMemory;
    1.64 +		}
    1.65 +
    1.66 +	RSurfaceManager::TSurfaceCreationAttributesBuf reqs;
    1.67 +	reqs().iSize = aInfo.iSizeInPixels;
    1.68 +	reqs().iBuffers = aImageCount;
    1.69 +	reqs().iPixelFormat = aInfo.iPixelFormat;
    1.70 +	reqs().iStride = aStride;
    1.71 +	reqs().iOffsetToFirstBuffer = aOffsetToFirstBuffer;
    1.72 +	reqs().iAlignment = 4;
    1.73 +	reqs().iContiguous = EFalse;
    1.74 +	reqs().iCacheAttrib = aIsCached ? RSurfaceManager::ECached : RSurfaceManager::ENotCached;
    1.75 +	reqs().iMappable = ETrue;
    1.76 +	reqs().iOffsetBetweenBuffers = aOffsetBetweenBuffers;
    1.77 +	reqs().iSurfaceHints = hints;
    1.78 +	reqs().iHintCount = aInfo.iUserAttributeCount;
    1.79 +	for (TInt i = 0; i < aInfo.iUserAttributeCount; ++i)
    1.80 +		{
    1.81 +		reqs().iSurfaceHints[i].iKey = aInfo.iUserAttributes[i].iUid;
    1.82 +		reqs().iSurfaceHints[i].iValue = aInfo.iUserAttributes[i].iValue;
    1.83 +		reqs().iSurfaceHints[i].iMutable = EFalse;
    1.84 +		}	
    1.85 +	TSurfaceId surfaceId;
    1.86 +	if (!aCollection)
    1.87 +		{
    1.88 +		err = iDriverImpl.CreateSurface(reqs, surfaceId);
    1.89 +		}
    1.90 +	else
    1.91 +		{
    1.92 +		err = iDriverImpl.CreateSurface(reqs, surfaceId, aCollection->iDataChunk);
    1.93 +		}
    1.94 +	delete[] hints;
    1.95 +	hints = NULL;
    1.96 +	reqs().iSurfaceHints = NULL;
    1.97 +	if (err != KErrNone)
    1.98 +		{
    1.99 +		return err;
   1.100 +		}
   1.101 +	iSurfaceId = surfaceId;
   1.102 +	iCount = aImageCount;
   1.103 +	RChunk chunk;
   1.104 +	if (!aCollection)
   1.105 +		{
   1.106 +		err = iDriverImpl.MapSurface(surfaceId, chunk);
   1.107 +		}
   1.108 +	else
   1.109 +		{
   1.110 +		chunk = aCollection->iDataChunk;
   1.111 +		err = chunk.Duplicate(RThread()); // Get a process-wide handle
   1.112 +		}
   1.113 +	if (err != KErrNone)
   1.114 +		{
   1.115 +		return err;
   1.116 +		}
   1.117 +	iDataChunk = chunk;
   1.118 +	iMetaDataIndex = aMetaDataIndex;
   1.119 +	new(chunk.Base() + aMetaDataIndex * sizeof(TSgImageMetaData)) TSgImageMetaData(aInfo, iDriverImpl.PixelFormatTable(), aIsCached);
   1.120 +	return KErrNone;
   1.121 +	}
   1.122 +
   1.123 +
   1.124 +XSgImageCollectionImpl::~XSgImageCollectionImpl()
   1.125 +	{
   1.126 +	if (!iSurfaceId.IsNull())
   1.127 +		{
   1.128 +		iDriverImpl.CloseSurface(iSurfaceId);
   1.129 +		iDataChunk.Close();
   1.130 +		}
   1.131 +	}
   1.132 +
   1.133 +
   1.134 +void XSgImageCollectionImpl::Close()
   1.135 +	{
   1.136 +	XSgDriverImpl& driverImpl = iDriverImpl;
   1.137 +	driverImpl.Wait();
   1.138 +	if (DecRefCount() == 0)
   1.139 +		{
   1.140 +		driverImpl.DeleteImageCollection(this);
   1.141 +		}
   1.142 +	driverImpl.Signal();
   1.143 +	}
   1.144 +
   1.145 +
   1.146 +const TSurfaceId& XSgImageCollectionImpl::SurfaceId() const
   1.147 +	{
   1.148 +	return iSurfaceId;
   1.149 +	}
   1.150 +
   1.151 +
   1.152 +TInt XSgImageCollectionImpl::GetInfo(TSgImageInfo& aInfo) const
   1.153 +	{
   1.154 +	reinterpret_cast<TSgImageMetaData*>(iDataChunk.Base() + iMetaDataIndex * sizeof(TSgImageMetaData))->GetInfo(aInfo);
   1.155 +	for (TInt i = 0; i < aInfo.iUserAttributeCount; ++i)
   1.156 +		{
   1.157 +		RSurfaceManager::THintPair hint;
   1.158 +		hint.iKey = aInfo.iUserAttributes[i].iUid;
   1.159 +		TInt err = iDriverImpl.GetSurfaceHint(iSurfaceId, hint);
   1.160 +		if (err != KErrNone)
   1.161 +			{
   1.162 +			return err;
   1.163 +			}
   1.164 +		aInfo.iUserAttributes[i].iValue = hint.iValue;
   1.165 +		}
   1.166 +	return KErrNone;
   1.167 +	}
   1.168 +
   1.169 +
   1.170 +TInt XSgImageCollectionImpl::Count() const
   1.171 +	{
   1.172 +	return iCount;
   1.173 +	}
   1.174 +
   1.175 +
   1.176 +TInt XSgImageCollectionImpl::OpenImage(TInt aIndex, MSgDrawableAdapter*& aResult)
   1.177 +	{
   1.178 +	if (aIndex < 0 || aIndex >= iCount)
   1.179 +		{
   1.180 +		return KErrArgument;
   1.181 +		}
   1.182 +	union
   1.183 +		{
   1.184 +		TSgDrawableId id;
   1.185 +		TSgImageId_SurfaceManager id_SurfaceManager;
   1.186 +		};
   1.187 +	id_SurfaceManager.iSurfaceId = iSurfaceId;
   1.188 +	id_SurfaceManager.iBufferIndex = aIndex;
   1.189 +	id_SurfaceManager.iMetaDataIndex = iMetaDataIndex;
   1.190 +	id_SurfaceManager.iFlags = 0;
   1.191 +	iDriverImpl.Wait();
   1.192 +	TInt err = iDriverImpl.OpenImage(id, KSgDefaultOpenMode, aResult);
   1.193 +	iDriverImpl.Signal();
   1.194 +	return err;
   1.195 +	}