os/graphics/graphicsresourceservices/graphicsresourceimplementation/src/sgextension.cpp
Update contrib.
1 // Copyright (c) 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 - kernel extension implementation
17 #include <kernel/kern_priv.h>
18 #include "sgextensionimpl.h"
20 DSgExtensionImpl* TheSgExtensionImpl = NULL;
22 DECLARE_STANDARD_EXTENSION()
24 __KTRACE_OPT(KBOOT, Kern::Printf("Starting Graphics Extension"));
26 TheSgExtensionImpl = new DSgExtensionImpl;
27 if (TheSgExtensionImpl)
29 err = TheSgExtensionImpl->Construct();
32 delete TheSgExtensionImpl;
33 TheSgExtensionImpl = NULL;
42 __KTRACE_OPT(KBOOT, Kern::Printf("Error: Graphics Extension failed to start"));
47 EXPORT_C TVersion SgExtension::Version()
49 return TVersion(1, 1, 1);
52 EXPORT_C TInt SgExtension::CreateResource(TUint32 aAttribs, const TDesC8& aMetaData, TInt aDataSize, DSgResource*& aResource)
54 if (!TheSgExtensionImpl)
56 __KTRACE_OPT(KPANIC, Kern::Printf("Error: Graphics Extension not ready"));
59 return TheSgExtensionImpl->CreateResource(aAttribs, aMetaData, aDataSize, aResource);
62 EXPORT_C TInt SgExtension::FindAndOpenResource(TUint64 aId, DSgResource*& aResource)
64 if (!TheSgExtensionImpl)
66 __KTRACE_OPT(KPANIC, Kern::Printf("Error: Graphics Extension not ready"));
69 return TheSgExtensionImpl->FindAndOpenResource(aId, aResource);
72 EXPORT_C TInt SgExtension::GlobalResourceCount()
74 if (!TheSgExtensionImpl)
76 __KTRACE_OPT(KPANIC, Kern::Printf("Error: Graphics Extension not ready"));
79 return TheSgExtensionImpl->GlobalResourceCount();
82 EXPORT_C TInt SgExtension::GlobalGraphicsMemoryUsed()
84 if (!TheSgExtensionImpl)
86 __KTRACE_OPT(KPANIC, Kern::Printf("Error: Graphics Extension not ready"));
89 return TheSgExtensionImpl->GlobalGraphicsMemoryUsed();
92 TInt DSgExtensionImpl::Construct()
94 return Kern::MutexCreate(iMutex, KNullDesC8, KMutexOrdGeneral0);
97 TInt DSgExtensionImpl::CreateResource(TUint32 aAttribs, const TDesC8& aMetaData, TInt aDataSize, DSgResource*& aResource)
103 DSgResourceImpl* resource = static_cast<DSgResourceImpl*>(Kern::Alloc(sizeof(DSgResourceImpl) + aMetaData.Size()));
108 TChunkCreateInfo info;
109 info.iType = TChunkCreateInfo::ESharedKernelMultiple;
110 info.iMaxSize = aDataSize;
111 info.iOwnsMemory = ETrue;
113 info.iMapAttr = aAttribs, 0; // suppress compiler warning: cache attribute does not apply to WINS
115 info.iMapAttr = aAttribs & ESgResourceAttrCpuCached ? EMapAttrCachedMax : EMapAttrL1Uncached;
120 TInt err = Kern::ChunkCreate(info, chunk, kernAddr, mapAttr);
123 Kern::Free(resource);
126 err = Kern::ChunkCommit(chunk, 0, aDataSize);
129 Kern::ChunkClose(chunk);
130 Kern::Free(resource);
133 Kern::MutexWait(*iMutex);
134 new(resource) DSgResourceImpl(*this, ++iLastResourceId, aAttribs, aMetaData, chunk, aDataSize);
135 err = iResources.InsertInOrder(resource, DSgResource::Compare);
136 Kern::MutexSignal(*iMutex);
141 aResource = (err == KErrNone ? resource : NULL);
145 TInt DSgExtensionImpl::FindAndOpenResource(TUint64 aId, DSgResource*& aResource)
151 Kern::MutexWait(*iMutex);
152 TInt i = iResources.FindInOrder(aId, DSgResource::Compare);
155 Kern::MutexSignal(*iMutex);
158 DSgResource* resource = iResources[i];
159 TInt err = resource->Open();
160 Kern::MutexSignal(*iMutex);
161 aResource = (err == KErrNone ? resource : NULL);
165 void DSgExtensionImpl::DeleteResource(DSgResource* aResource)
167 Kern::MutexWait(*iMutex);
168 TInt i = iResources.FindInOrder(aResource, DSgResource::Compare);
171 iResources.Remove(i);
175 __KTRACE_OPT(KPANIC, Kern::Printf("Error: internal state of Graphics Extension is inconsistent"));
177 Kern::MutexSignal(*iMutex);
181 TInt DSgExtensionImpl::GlobalResourceCount() const
183 return iResources.Count();
186 TInt DSgExtensionImpl::GlobalGraphicsMemoryUsed() const
189 Kern::MutexWait(*iMutex);
190 TInt n = iResources.Count();
191 for (TInt i = 0; i < n; ++i)
193 ret += iResources[i]->DataChunk()->Size();
195 Kern::MutexSignal(*iMutex);