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 |
// Graphics Resource - image implementation
|
sl@0
|
15 |
//
|
sl@0
|
16 |
|
sl@0
|
17 |
#include "sgdriver.h"
|
sl@0
|
18 |
|
sl@0
|
19 |
EXPORT_C TInt RSgImage::Create(const TSgImageInfo& aInfo, const TAny* aDataAddress, TInt aDataStride, const TSgAttributeArrayBase* aAttributes)
|
sl@0
|
20 |
{
|
sl@0
|
21 |
if (iImpl)
|
sl@0
|
22 |
{
|
sl@0
|
23 |
return KErrInUse;
|
sl@0
|
24 |
}
|
sl@0
|
25 |
__ASSERT_ALWAYS(gPls.iDriver, Panic(ESgPanicNoDriver));
|
sl@0
|
26 |
return gPls.iDriver->CreateImage(aInfo, aDataAddress, aDataStride, aAttributes, iImpl);
|
sl@0
|
27 |
}
|
sl@0
|
28 |
|
sl@0
|
29 |
EXPORT_C TInt RSgImage::Create(const TSgImageInfo& aInfo, const RSgImage& aImage, const TSgAttributeArrayBase* aAttributes)
|
sl@0
|
30 |
{
|
sl@0
|
31 |
if (iImpl)
|
sl@0
|
32 |
{
|
sl@0
|
33 |
return KErrInUse;
|
sl@0
|
34 |
}
|
sl@0
|
35 |
__ASSERT_ALWAYS(gPls.iDriver, Panic(ESgPanicNoDriver));
|
sl@0
|
36 |
return gPls.iDriver->CreateImage(aInfo, static_cast<XSgImage*>(aImage.iImpl), aAttributes, iImpl);
|
sl@0
|
37 |
}
|
sl@0
|
38 |
|
sl@0
|
39 |
EXPORT_C TInt RSgImage::GetInfo(TSgImageInfo& aInfo) const
|
sl@0
|
40 |
{
|
sl@0
|
41 |
if (!iImpl)
|
sl@0
|
42 |
{
|
sl@0
|
43 |
return KErrBadHandle;
|
sl@0
|
44 |
}
|
sl@0
|
45 |
__ASSERT_ALWAYS(gPls.iDriver, Panic(ESgPanicNoDriver));
|
sl@0
|
46 |
__ASSERT_ALWAYS(gPls.iDriver->CheckImage(iImpl), Panic(ESgPanicBadDrawableHandle));
|
sl@0
|
47 |
static_cast<XSgImage*>(iImpl)->GetInfo(aInfo);
|
sl@0
|
48 |
return KErrNone;
|
sl@0
|
49 |
}
|
sl@0
|
50 |
|
sl@0
|
51 |
EXPORT_C TInt RSgImage::GetAttribute(TUid aUid, TInt& aValue) const
|
sl@0
|
52 |
{
|
sl@0
|
53 |
if (!iImpl)
|
sl@0
|
54 |
{
|
sl@0
|
55 |
return KErrBadHandle;
|
sl@0
|
56 |
}
|
sl@0
|
57 |
__ASSERT_ALWAYS(gPls.iDriver, Panic(ESgPanicNoDriver));
|
sl@0
|
58 |
__ASSERT_ALWAYS(gPls.iDriver->CheckImage(iImpl), Panic(ESgPanicBadDrawableHandle));
|
sl@0
|
59 |
return static_cast<XSgImage*>(iImpl)->GetAttribute(aUid, aValue);
|
sl@0
|
60 |
}
|
sl@0
|
61 |
|
sl@0
|
62 |
EXPORT_C TInt RSgImage::GetPixelFormats(TUint32 aUsage, RArray<TInt>& aPixelFormats, const TSgAttributeArrayBase* aAttributes)
|
sl@0
|
63 |
{
|
sl@0
|
64 |
static const TInt KSupportedPixelFormats[] =
|
sl@0
|
65 |
{
|
sl@0
|
66 |
ESgPixelFormatA_8,
|
sl@0
|
67 |
ESgPixelFormatRGB_565,
|
sl@0
|
68 |
ESgPixelFormatXRGB_8888,
|
sl@0
|
69 |
ESgPixelFormatARGB_8888,
|
sl@0
|
70 |
ESgPixelFormatARGB_8888_PRE
|
sl@0
|
71 |
};
|
sl@0
|
72 |
static const TInt KNumSupportedPixelFormats = sizeof(KSupportedPixelFormats) / sizeof(TInt);
|
sl@0
|
73 |
if (aUsage == 0 || aPixelFormats.Count() != 0)
|
sl@0
|
74 |
{
|
sl@0
|
75 |
return KErrArgument;
|
sl@0
|
76 |
}
|
sl@0
|
77 |
if (aAttributes)
|
sl@0
|
78 |
{
|
sl@0
|
79 |
return KErrNotSupported;
|
sl@0
|
80 |
}
|
sl@0
|
81 |
if (aUsage & ~KSgUsageAll)
|
sl@0
|
82 |
{
|
sl@0
|
83 |
return KErrNone;
|
sl@0
|
84 |
}
|
sl@0
|
85 |
_LIT(KLibOpenVg, "libOpenVG.dll");
|
sl@0
|
86 |
_LIT(KLibOpenGles, "libGLESv1_CM.dll");
|
sl@0
|
87 |
_LIT(KLibOpenGles2, "libGLESv2.dll");
|
sl@0
|
88 |
RLibrary lib;
|
sl@0
|
89 |
if (aUsage & (ESgUsageBitOpenVgImage | ESgUsageBitOpenVgSurface))
|
sl@0
|
90 |
{
|
sl@0
|
91 |
if (lib.Load(KLibOpenVg) != KErrNone)
|
sl@0
|
92 |
{
|
sl@0
|
93 |
return KErrNone;
|
sl@0
|
94 |
}
|
sl@0
|
95 |
lib.Close();
|
sl@0
|
96 |
}
|
sl@0
|
97 |
if (aUsage & (ESgUsageBitOpenGlesTexture2D | ESgUsageBitOpenGlesSurface))
|
sl@0
|
98 |
{
|
sl@0
|
99 |
if (lib.Load(KLibOpenGles) != KErrNone)
|
sl@0
|
100 |
{
|
sl@0
|
101 |
return KErrNone;
|
sl@0
|
102 |
}
|
sl@0
|
103 |
lib.Close();
|
sl@0
|
104 |
}
|
sl@0
|
105 |
if (aUsage & (ESgUsageBitOpenGles2Texture2D | ESgUsageBitOpenGles2Surface))
|
sl@0
|
106 |
{
|
sl@0
|
107 |
if (lib.Load(KLibOpenGles2) != KErrNone)
|
sl@0
|
108 |
{
|
sl@0
|
109 |
return KErrNone;
|
sl@0
|
110 |
}
|
sl@0
|
111 |
lib.Close();
|
sl@0
|
112 |
}
|
sl@0
|
113 |
TInt err = KErrNone;
|
sl@0
|
114 |
for (TInt i = 0; i < KNumSupportedPixelFormats; ++i)
|
sl@0
|
115 |
{
|
sl@0
|
116 |
if (KSupportedPixelFormats[i] == ESgPixelFormatA_8 && (aUsage & KSgUsageAllSurfaceTypes))
|
sl@0
|
117 |
{
|
sl@0
|
118 |
continue;
|
sl@0
|
119 |
}
|
sl@0
|
120 |
err = aPixelFormats.Append(KSupportedPixelFormats[i]);
|
sl@0
|
121 |
if (err != KErrNone)
|
sl@0
|
122 |
{
|
sl@0
|
123 |
break;
|
sl@0
|
124 |
}
|
sl@0
|
125 |
}
|
sl@0
|
126 |
return err;
|
sl@0
|
127 |
}
|
sl@0
|
128 |
|
sl@0
|
129 |
XSgImage::XSgImage(TSgDrawableId aId, TUint32 aAttribs, const TSgImageMetaData& aMetaData, TAny* aDataAddress, TInt aDataStride)
|
sl@0
|
130 |
: iRefCount(1), iId(aId), iInfo(aMetaData.iSizeInPixels, aMetaData.iPixelFormat, aAttribs & KSgUsageBitMask),
|
sl@0
|
131 |
iDataAddress(aDataAddress), iDataStride(aDataStride)
|
sl@0
|
132 |
{
|
sl@0
|
133 |
}
|
sl@0
|
134 |
|
sl@0
|
135 |
XSgImage::~XSgImage()
|
sl@0
|
136 |
{
|
sl@0
|
137 |
__ASSERT_DEBUG(iRefCount == 0, Panic(ESgPanicBadRefCount));
|
sl@0
|
138 |
}
|
sl@0
|
139 |
|
sl@0
|
140 |
TInt XSgImage::Open()
|
sl@0
|
141 |
{
|
sl@0
|
142 |
if (User::SafeInc(iRefCount) == 0)
|
sl@0
|
143 |
{
|
sl@0
|
144 |
return KErrNotFound;
|
sl@0
|
145 |
}
|
sl@0
|
146 |
return KErrNone;
|
sl@0
|
147 |
}
|
sl@0
|
148 |
|
sl@0
|
149 |
void XSgImage::Close()
|
sl@0
|
150 |
{
|
sl@0
|
151 |
if (User::SafeDec(iRefCount) == 1)
|
sl@0
|
152 |
{
|
sl@0
|
153 |
gPls.iDriver->DeleteImage(this);
|
sl@0
|
154 |
}
|
sl@0
|
155 |
}
|
sl@0
|
156 |
|
sl@0
|
157 |
TInt XSgImage::RefCount() const
|
sl@0
|
158 |
{
|
sl@0
|
159 |
return iRefCount;
|
sl@0
|
160 |
}
|
sl@0
|
161 |
|
sl@0
|
162 |
TSgDrawableId XSgImage::Id() const
|
sl@0
|
163 |
{
|
sl@0
|
164 |
return iId;
|
sl@0
|
165 |
}
|
sl@0
|
166 |
|
sl@0
|
167 |
TUid XSgImage::DrawableType() const
|
sl@0
|
168 |
{
|
sl@0
|
169 |
return KSgImageTypeUid;
|
sl@0
|
170 |
}
|
sl@0
|
171 |
|
sl@0
|
172 |
TInt XSgImage::GetInterface(TUid aInterfaceUid, TAny*& aInterfacePtr)
|
sl@0
|
173 |
{
|
sl@0
|
174 |
if (aInterfaceUid == KNullUid)
|
sl@0
|
175 |
{
|
sl@0
|
176 |
return KErrArgument;
|
sl@0
|
177 |
}
|
sl@0
|
178 |
if (aInterfaceUid.iUid == MSgImage_Sw::EInterfaceUid)
|
sl@0
|
179 |
{
|
sl@0
|
180 |
aInterfacePtr = static_cast<MSgImage_Sw*>(this);
|
sl@0
|
181 |
return KErrNone;
|
sl@0
|
182 |
}
|
sl@0
|
183 |
return KErrExtensionNotSupported;
|
sl@0
|
184 |
}
|
sl@0
|
185 |
|
sl@0
|
186 |
void XSgImage::GetInfo(TSgImageInfo& aInfo) const
|
sl@0
|
187 |
{
|
sl@0
|
188 |
aInfo = iInfo;
|
sl@0
|
189 |
}
|
sl@0
|
190 |
|
sl@0
|
191 |
TInt XSgImage::GetAttribute(TUid aUid, TInt& /*aValue*/) const
|
sl@0
|
192 |
{
|
sl@0
|
193 |
if (aUid == KNullUid)
|
sl@0
|
194 |
{
|
sl@0
|
195 |
return KErrArgument;
|
sl@0
|
196 |
}
|
sl@0
|
197 |
return KErrNotSupported;
|
sl@0
|
198 |
}
|
sl@0
|
199 |
|
sl@0
|
200 |
TInt XSgImage::Compare(const XSgImage& aImage1, const XSgImage& aImage2)
|
sl@0
|
201 |
{
|
sl@0
|
202 |
return Compare(&aImage1.iId, aImage2);
|
sl@0
|
203 |
}
|
sl@0
|
204 |
|
sl@0
|
205 |
TInt XSgImage::Compare(const TSgDrawableId* aId, const XSgImage& aImage)
|
sl@0
|
206 |
{
|
sl@0
|
207 |
if (aId->iId > aImage.iId.iId)
|
sl@0
|
208 |
{
|
sl@0
|
209 |
return 1;
|
sl@0
|
210 |
}
|
sl@0
|
211 |
if (aId->iId < aImage.iId.iId)
|
sl@0
|
212 |
{
|
sl@0
|
213 |
return -1;
|
sl@0
|
214 |
}
|
sl@0
|
215 |
return 0;
|
sl@0
|
216 |
}
|
sl@0
|
217 |
|
sl@0
|
218 |
TAny* XSgImage::DataAddress() const
|
sl@0
|
219 |
{
|
sl@0
|
220 |
return iDataAddress;
|
sl@0
|
221 |
}
|
sl@0
|
222 |
|
sl@0
|
223 |
TInt XSgImage::DataStride() const
|
sl@0
|
224 |
{
|
sl@0
|
225 |
return iDataStride;
|
sl@0
|
226 |
}
|