os/graphics/graphicsresourceservices/graphicsresourceimplementation/src/sgresource.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/graphicsresourceservices/graphicsresourceimplementation/src/sgresource.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,84 @@
     1.4 +// Copyright (c) 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 - kernel resource implementation
    1.18 +//
    1.19 +
    1.20 +#include <kernel/kern_priv.h>
    1.21 +#include "sgextensionimpl.h"
    1.22 +
    1.23 +DSgResourceImpl::DSgResourceImpl(DSgExtensionImpl& aExtensionImpl, TUint64 aId, TUint32 aAttribs,
    1.24 +	                             const TDesC8& aMetaData, DChunk* aDataChunk, TInt aDataSize)
    1.25 +	: iExtensionImpl(aExtensionImpl), iRefCount(1), iId(aId), iAttributes(aAttribs),
    1.26 +	  iMetaDataSize(aMetaData.Size()), iDataChunk(aDataChunk), iDataSize(aDataSize)
    1.27 +	{
    1.28 +	memcpy(this + 1, aMetaData.Ptr(), aMetaData.Size());
    1.29 +	}
    1.30 +
    1.31 +DSgResourceImpl::~DSgResourceImpl()
    1.32 +	{
    1.33 +	if (iDataChunk)
    1.34 +		{
    1.35 +		Kern::ChunkClose(iDataChunk);
    1.36 +		}
    1.37 +	}
    1.38 +
    1.39 +TInt DSgResourceImpl::Open()
    1.40 +	{
    1.41 +	return NKern::SafeInc(iRefCount) > 0 ? KErrNone : KErrNotFound;
    1.42 +	}
    1.43 +
    1.44 +void DSgResourceImpl::Close()
    1.45 +	{
    1.46 +	if (NKern::SafeDec(iRefCount) == 1)
    1.47 +		{
    1.48 +		iExtensionImpl.DeleteResource(this);
    1.49 +		}
    1.50 +	}
    1.51 +
    1.52 +TUint64 DSgResourceImpl::Id() const
    1.53 +	{
    1.54 +	return iId;
    1.55 +	}
    1.56 +
    1.57 +TUint32 DSgResourceImpl::Attributes() const
    1.58 +	{
    1.59 +	return iAttributes;
    1.60 +	}
    1.61 +
    1.62 +TInt DSgResourceImpl::GetMetaData(TDes8& aMetaData) const
    1.63 +	{
    1.64 +	if (aMetaData.MaxSize() < iMetaDataSize)
    1.65 +		{
    1.66 +		return KErrOverflow;
    1.67 +		}
    1.68 +	if (iMetaDataSize == 0)
    1.69 +		{
    1.70 +		aMetaData.Zero();
    1.71 +		}
    1.72 +	else
    1.73 +		{
    1.74 +		aMetaData.Copy(TPtrC8(reinterpret_cast<const TUint8*>(this + 1), iMetaDataSize));
    1.75 +		}
    1.76 +	return KErrNone;
    1.77 +	}
    1.78 +
    1.79 +DChunk* DSgResourceImpl::DataChunk() const
    1.80 +	{
    1.81 +	return iDataChunk;
    1.82 +	}
    1.83 +
    1.84 +TInt DSgResourceImpl::DataSize() const
    1.85 +	{
    1.86 +	return iDataSize;
    1.87 +	}