sl@0
|
1 |
// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
#include "sgimagecollectionimpl.h"
|
sl@0
|
17 |
#include "sgimageimpl.h"
|
sl@0
|
18 |
|
sl@0
|
19 |
|
sl@0
|
20 |
TInt XSgImageCollectionImpl::New(XSgImageCollectionImpl*& aPtr, XSgDriverImpl& aDriverImpl,
|
sl@0
|
21 |
const TSgImageInfo& aInfo, TInt aImageCount, TBool aIsCached,
|
sl@0
|
22 |
TInt aStride, TInt aOffsetToFirstBuffer, TInt aOffsetBetweenBuffers,
|
sl@0
|
23 |
TInt aMetaDataIndex, const XSgImageCollectionImpl* aCollection)
|
sl@0
|
24 |
{
|
sl@0
|
25 |
aPtr = static_cast<XSgImageCollectionImpl*>(aDriverImpl.Alloc(sizeof(XSgImageCollectionImpl)));
|
sl@0
|
26 |
if (!aPtr)
|
sl@0
|
27 |
{
|
sl@0
|
28 |
return KErrNoMemory;
|
sl@0
|
29 |
}
|
sl@0
|
30 |
new(aPtr) XSgImageCollectionImpl(aDriverImpl);
|
sl@0
|
31 |
TInt err = aPtr->Construct(aInfo, aImageCount, aIsCached, aStride, aOffsetToFirstBuffer, aOffsetBetweenBuffers, aMetaDataIndex, aCollection);
|
sl@0
|
32 |
if (err != KErrNone)
|
sl@0
|
33 |
{
|
sl@0
|
34 |
aPtr->Delete();
|
sl@0
|
35 |
aPtr = NULL;
|
sl@0
|
36 |
}
|
sl@0
|
37 |
return err;
|
sl@0
|
38 |
}
|
sl@0
|
39 |
|
sl@0
|
40 |
|
sl@0
|
41 |
TInt XSgImageCollectionImpl::Construct(const TSgImageInfo& aInfo, TInt aImageCount, TBool aIsCached,
|
sl@0
|
42 |
TInt aStride, TInt aOffsetToFirstBuffer, TInt aOffsetBetweenBuffers,
|
sl@0
|
43 |
TInt aMetaDataIndex, const XSgImageCollectionImpl* aCollection)
|
sl@0
|
44 |
{
|
sl@0
|
45 |
TInt maxNumberOfHints;
|
sl@0
|
46 |
TInt err;
|
sl@0
|
47 |
err=iDriverImpl.GetSurfaceManagerAttrib(RSurfaceManager::EMaxNumberOfHints,maxNumberOfHints);
|
sl@0
|
48 |
if (err != KErrNone)
|
sl@0
|
49 |
{
|
sl@0
|
50 |
return err;
|
sl@0
|
51 |
}
|
sl@0
|
52 |
|
sl@0
|
53 |
if (aInfo.iUserAttributeCount > maxNumberOfHints)
|
sl@0
|
54 |
{
|
sl@0
|
55 |
return KErrOverflow;
|
sl@0
|
56 |
}
|
sl@0
|
57 |
RSurfaceManager::THintPair* hints = new RSurfaceManager::THintPair[aInfo.iUserAttributeCount];
|
sl@0
|
58 |
if(!hints)
|
sl@0
|
59 |
{
|
sl@0
|
60 |
return KErrNoMemory;
|
sl@0
|
61 |
}
|
sl@0
|
62 |
|
sl@0
|
63 |
RSurfaceManager::TSurfaceCreationAttributesBuf reqs;
|
sl@0
|
64 |
reqs().iSize = aInfo.iSizeInPixels;
|
sl@0
|
65 |
reqs().iBuffers = aImageCount;
|
sl@0
|
66 |
reqs().iPixelFormat = aInfo.iPixelFormat;
|
sl@0
|
67 |
reqs().iStride = aStride;
|
sl@0
|
68 |
reqs().iOffsetToFirstBuffer = aOffsetToFirstBuffer;
|
sl@0
|
69 |
reqs().iAlignment = 4;
|
sl@0
|
70 |
reqs().iContiguous = EFalse;
|
sl@0
|
71 |
reqs().iCacheAttrib = aIsCached ? RSurfaceManager::ECached : RSurfaceManager::ENotCached;
|
sl@0
|
72 |
reqs().iMappable = ETrue;
|
sl@0
|
73 |
reqs().iOffsetBetweenBuffers = aOffsetBetweenBuffers;
|
sl@0
|
74 |
reqs().iSurfaceHints = hints;
|
sl@0
|
75 |
reqs().iHintCount = aInfo.iUserAttributeCount;
|
sl@0
|
76 |
for (TInt i = 0; i < aInfo.iUserAttributeCount; ++i)
|
sl@0
|
77 |
{
|
sl@0
|
78 |
reqs().iSurfaceHints[i].iKey = aInfo.iUserAttributes[i].iUid;
|
sl@0
|
79 |
reqs().iSurfaceHints[i].iValue = aInfo.iUserAttributes[i].iValue;
|
sl@0
|
80 |
reqs().iSurfaceHints[i].iMutable = EFalse;
|
sl@0
|
81 |
}
|
sl@0
|
82 |
TSurfaceId surfaceId;
|
sl@0
|
83 |
if (!aCollection)
|
sl@0
|
84 |
{
|
sl@0
|
85 |
err = iDriverImpl.CreateSurface(reqs, surfaceId);
|
sl@0
|
86 |
}
|
sl@0
|
87 |
else
|
sl@0
|
88 |
{
|
sl@0
|
89 |
err = iDriverImpl.CreateSurface(reqs, surfaceId, aCollection->iDataChunk);
|
sl@0
|
90 |
}
|
sl@0
|
91 |
delete[] hints;
|
sl@0
|
92 |
hints = NULL;
|
sl@0
|
93 |
reqs().iSurfaceHints = NULL;
|
sl@0
|
94 |
if (err != KErrNone)
|
sl@0
|
95 |
{
|
sl@0
|
96 |
return err;
|
sl@0
|
97 |
}
|
sl@0
|
98 |
iSurfaceId = surfaceId;
|
sl@0
|
99 |
iCount = aImageCount;
|
sl@0
|
100 |
RChunk chunk;
|
sl@0
|
101 |
if (!aCollection)
|
sl@0
|
102 |
{
|
sl@0
|
103 |
err = iDriverImpl.MapSurface(surfaceId, chunk);
|
sl@0
|
104 |
}
|
sl@0
|
105 |
else
|
sl@0
|
106 |
{
|
sl@0
|
107 |
chunk = aCollection->iDataChunk;
|
sl@0
|
108 |
err = chunk.Duplicate(RThread()); // Get a process-wide handle
|
sl@0
|
109 |
}
|
sl@0
|
110 |
if (err != KErrNone)
|
sl@0
|
111 |
{
|
sl@0
|
112 |
return err;
|
sl@0
|
113 |
}
|
sl@0
|
114 |
iDataChunk = chunk;
|
sl@0
|
115 |
iMetaDataIndex = aMetaDataIndex;
|
sl@0
|
116 |
new(chunk.Base() + aMetaDataIndex * sizeof(TSgImageMetaData)) TSgImageMetaData(aInfo, iDriverImpl.PixelFormatTable(), aIsCached);
|
sl@0
|
117 |
return KErrNone;
|
sl@0
|
118 |
}
|
sl@0
|
119 |
|
sl@0
|
120 |
|
sl@0
|
121 |
XSgImageCollectionImpl::~XSgImageCollectionImpl()
|
sl@0
|
122 |
{
|
sl@0
|
123 |
if (!iSurfaceId.IsNull())
|
sl@0
|
124 |
{
|
sl@0
|
125 |
iDriverImpl.CloseSurface(iSurfaceId);
|
sl@0
|
126 |
iDataChunk.Close();
|
sl@0
|
127 |
}
|
sl@0
|
128 |
}
|
sl@0
|
129 |
|
sl@0
|
130 |
|
sl@0
|
131 |
void XSgImageCollectionImpl::Close()
|
sl@0
|
132 |
{
|
sl@0
|
133 |
XSgDriverImpl& driverImpl = iDriverImpl;
|
sl@0
|
134 |
driverImpl.Wait();
|
sl@0
|
135 |
if (DecRefCount() == 0)
|
sl@0
|
136 |
{
|
sl@0
|
137 |
driverImpl.DeleteImageCollection(this);
|
sl@0
|
138 |
}
|
sl@0
|
139 |
driverImpl.Signal();
|
sl@0
|
140 |
}
|
sl@0
|
141 |
|
sl@0
|
142 |
|
sl@0
|
143 |
const TSurfaceId& XSgImageCollectionImpl::SurfaceId() const
|
sl@0
|
144 |
{
|
sl@0
|
145 |
return iSurfaceId;
|
sl@0
|
146 |
}
|
sl@0
|
147 |
|
sl@0
|
148 |
|
sl@0
|
149 |
TInt XSgImageCollectionImpl::GetInfo(TSgImageInfo& aInfo) const
|
sl@0
|
150 |
{
|
sl@0
|
151 |
reinterpret_cast<TSgImageMetaData*>(iDataChunk.Base() + iMetaDataIndex * sizeof(TSgImageMetaData))->GetInfo(aInfo);
|
sl@0
|
152 |
for (TInt i = 0; i < aInfo.iUserAttributeCount; ++i)
|
sl@0
|
153 |
{
|
sl@0
|
154 |
RSurfaceManager::THintPair hint;
|
sl@0
|
155 |
hint.iKey = aInfo.iUserAttributes[i].iUid;
|
sl@0
|
156 |
TInt err = iDriverImpl.GetSurfaceHint(iSurfaceId, hint);
|
sl@0
|
157 |
if (err != KErrNone)
|
sl@0
|
158 |
{
|
sl@0
|
159 |
return err;
|
sl@0
|
160 |
}
|
sl@0
|
161 |
aInfo.iUserAttributes[i].iValue = hint.iValue;
|
sl@0
|
162 |
}
|
sl@0
|
163 |
return KErrNone;
|
sl@0
|
164 |
}
|
sl@0
|
165 |
|
sl@0
|
166 |
|
sl@0
|
167 |
TInt XSgImageCollectionImpl::Count() const
|
sl@0
|
168 |
{
|
sl@0
|
169 |
return iCount;
|
sl@0
|
170 |
}
|
sl@0
|
171 |
|
sl@0
|
172 |
|
sl@0
|
173 |
TInt XSgImageCollectionImpl::OpenImage(TInt aIndex, MSgDrawableAdapter*& aResult)
|
sl@0
|
174 |
{
|
sl@0
|
175 |
if (aIndex < 0 || aIndex >= iCount)
|
sl@0
|
176 |
{
|
sl@0
|
177 |
return KErrArgument;
|
sl@0
|
178 |
}
|
sl@0
|
179 |
union
|
sl@0
|
180 |
{
|
sl@0
|
181 |
TSgDrawableId id;
|
sl@0
|
182 |
TSgImageId_SurfaceManager id_SurfaceManager;
|
sl@0
|
183 |
};
|
sl@0
|
184 |
id_SurfaceManager.iSurfaceId = iSurfaceId;
|
sl@0
|
185 |
id_SurfaceManager.iBufferIndex = aIndex;
|
sl@0
|
186 |
id_SurfaceManager.iMetaDataIndex = iMetaDataIndex;
|
sl@0
|
187 |
id_SurfaceManager.iFlags = 0;
|
sl@0
|
188 |
iDriverImpl.Wait();
|
sl@0
|
189 |
TInt err = iDriverImpl.OpenImage(id, KSgDefaultOpenMode, aResult);
|
sl@0
|
190 |
iDriverImpl.Signal();
|
sl@0
|
191 |
return err;
|
sl@0
|
192 |
}
|