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 "directgdiadapter.h"
|
sl@0
|
17 |
#include "swdirectgdidriverimpl.h"
|
sl@0
|
18 |
#include "swdirectgdiimagesourceimpl.h"
|
sl@0
|
19 |
#include "swdirectgdiimagetargetimpl.h"
|
sl@0
|
20 |
#include "pixelutil.h"
|
sl@0
|
21 |
#include <e32cmn.h>
|
sl@0
|
22 |
#include <pixelformats.h>
|
sl@0
|
23 |
#include <graphics/sgimage_sw.h>
|
sl@0
|
24 |
|
sl@0
|
25 |
/**
|
sl@0
|
26 |
@panic DGDIAdapter 6, if the reference count to DirectGDI driver is invalid.
|
sl@0
|
27 |
@panic DGDIAdapter 45, if objects are still in the source or target image array.
|
sl@0
|
28 |
*/
|
sl@0
|
29 |
CSwDirectGdiDriverImpl::~CSwDirectGdiDriverImpl()
|
sl@0
|
30 |
{
|
sl@0
|
31 |
GRAPHICS_ASSERT_DEBUG(iEngines.Count() == 0, EDirectGdiPanicDriverInvalidRefCount);
|
sl@0
|
32 |
GRAPHICS_ASSERT_DEBUG(iTargets.Count() == 0, EDirectGdiPanicItemsLeftInImageArray);
|
sl@0
|
33 |
GRAPHICS_ASSERT_DEBUG(iImageSources.Count() == 0, EDirectGdiPanicItemsLeftInImageArray);
|
sl@0
|
34 |
|
sl@0
|
35 |
// Delete all the engines owned by this driver
|
sl@0
|
36 |
iEngines.ResetAndDestroy();
|
sl@0
|
37 |
iTargets.ResetAndDestroy();
|
sl@0
|
38 |
iImageSources.ResetAndDestroy();
|
sl@0
|
39 |
}
|
sl@0
|
40 |
|
sl@0
|
41 |
/**
|
sl@0
|
42 |
Constructor, which initialises base class.
|
sl@0
|
43 |
*/
|
sl@0
|
44 |
CSwDirectGdiDriverImpl::CSwDirectGdiDriverImpl(RLibrary aLibrary)
|
sl@0
|
45 |
: CDirectGdiDriverInternal(aLibrary)
|
sl@0
|
46 |
{
|
sl@0
|
47 |
}
|
sl@0
|
48 |
|
sl@0
|
49 |
/**
|
sl@0
|
50 |
Empty function as this adaptation is synchronous.
|
sl@0
|
51 |
@see CDirectGdiDriverInternal::Flush()
|
sl@0
|
52 |
*/
|
sl@0
|
53 |
void CSwDirectGdiDriverImpl::Flush()
|
sl@0
|
54 |
{
|
sl@0
|
55 |
}
|
sl@0
|
56 |
|
sl@0
|
57 |
/**
|
sl@0
|
58 |
Empty function as this adaptation is synchronous.
|
sl@0
|
59 |
@see CDirectGdiDriverInternal::Finish()
|
sl@0
|
60 |
*/
|
sl@0
|
61 |
void CSwDirectGdiDriverImpl::Finish()
|
sl@0
|
62 |
{
|
sl@0
|
63 |
}
|
sl@0
|
64 |
|
sl@0
|
65 |
/**
|
sl@0
|
66 |
@see CDirectGdiDriver::GetError()
|
sl@0
|
67 |
*/
|
sl@0
|
68 |
TInt CSwDirectGdiDriverImpl::GetError()
|
sl@0
|
69 |
{
|
sl@0
|
70 |
TInt err = iErrorCode;
|
sl@0
|
71 |
iErrorCode = KErrNone;
|
sl@0
|
72 |
return err;
|
sl@0
|
73 |
}
|
sl@0
|
74 |
|
sl@0
|
75 |
/**
|
sl@0
|
76 |
@see CDirectGdiDriverInternal::CloseDrawableSource()
|
sl@0
|
77 |
@panic DGDIAdapter 57, if aHandleRet is not KNullHandle (debug only).
|
sl@0
|
78 |
*/
|
sl@0
|
79 |
TInt CSwDirectGdiDriverImpl::CreateDrawableSource(TInt& aHandleRet, const RSgDrawable& aSgDrawable)
|
sl@0
|
80 |
{
|
sl@0
|
81 |
TInt err = KErrNotSupported;
|
sl@0
|
82 |
const TUid typeUid = aSgDrawable.DrawableType();
|
sl@0
|
83 |
if(KSgImageTypeUid == typeUid)
|
sl@0
|
84 |
{
|
sl@0
|
85 |
CSwDirectGdiImageSourceImpl* imageSource = NULL;
|
sl@0
|
86 |
RSgImage* image = (RSgImage*) (&aSgDrawable);
|
sl@0
|
87 |
err = CSwDirectGdiImageSourceImpl::New(imageSource, *this, *image);
|
sl@0
|
88 |
|
sl@0
|
89 |
if (err == KErrNone)
|
sl@0
|
90 |
{
|
sl@0
|
91 |
aHandleRet = reinterpret_cast<TInt>(imageSource);
|
sl@0
|
92 |
}
|
sl@0
|
93 |
}
|
sl@0
|
94 |
return err;
|
sl@0
|
95 |
}
|
sl@0
|
96 |
|
sl@0
|
97 |
/**
|
sl@0
|
98 |
@see CDirectGdiDriverInternal::CreateDrawableSource()
|
sl@0
|
99 |
@panic DGDIAdapter 47, if the drawable source belonging to aHandle could not be found in the internal
|
sl@0
|
100 |
list of sources (debug only).
|
sl@0
|
101 |
*/
|
sl@0
|
102 |
void CSwDirectGdiDriverImpl::CloseDrawableSource(TInt& aHandle)
|
sl@0
|
103 |
{
|
sl@0
|
104 |
// Graphics Resource and DirectGDI reference implementation only support pixel based resource
|
sl@0
|
105 |
CSwDirectGdiImageSourceImpl* source = reinterpret_cast<CSwDirectGdiImageSourceImpl*>(aHandle);
|
sl@0
|
106 |
if (source)
|
sl@0
|
107 |
source->Close();
|
sl@0
|
108 |
aHandle = KNullHandle;
|
sl@0
|
109 |
}
|
sl@0
|
110 |
|
sl@0
|
111 |
/**
|
sl@0
|
112 |
@see CDirectGdiDriverInternal::CreateImageTarget()
|
sl@0
|
113 |
@panic DGDIAdapter 58, if aHandleRet is not KNullHandle (debug only).
|
sl@0
|
114 |
@panic DGDIAdapter 1023, if the attempt to get an RSgImage interface MSgImage_Sw failed.
|
sl@0
|
115 |
*/
|
sl@0
|
116 |
TInt CSwDirectGdiDriverImpl::CreateImageTarget(TInt& aHandleRet, const RSgImage& aImage)
|
sl@0
|
117 |
{
|
sl@0
|
118 |
TSgImageInfo info;
|
sl@0
|
119 |
TInt ret = aImage.GetInfo(info);
|
sl@0
|
120 |
if (ret != KErrNone)
|
sl@0
|
121 |
{
|
sl@0
|
122 |
return ret;
|
sl@0
|
123 |
}
|
sl@0
|
124 |
TDisplayMode displayMode = PixelFormatUtil::ConvertToDisplayMode(info.iPixelFormat);
|
sl@0
|
125 |
TSize size = info.iSizeInPixels;
|
sl@0
|
126 |
CFbsDrawDevice* device = NULL;
|
sl@0
|
127 |
const MSgImage_Sw* pImage;
|
sl@0
|
128 |
TInt err = aImage.GetInterface(pImage);
|
sl@0
|
129 |
GRAPHICS_ASSERT_DEBUG((err == KErrNone) && (pImage != NULL), EDirectGdiPanicInvalidInterfaceHandle);
|
sl@0
|
130 |
TRAP(err, device = CFbsDrawDevice::NewBitmapDeviceL(size, displayMode, pImage->DataStride()));
|
sl@0
|
131 |
if (err != KErrNone)
|
sl@0
|
132 |
{
|
sl@0
|
133 |
return err;
|
sl@0
|
134 |
}
|
sl@0
|
135 |
|
sl@0
|
136 |
// Setup the new device with the memory from the image
|
sl@0
|
137 |
device->SetBits(pImage->DataAddress());
|
sl@0
|
138 |
|
sl@0
|
139 |
// Create a new image
|
sl@0
|
140 |
if (err == KErrNone)
|
sl@0
|
141 |
{
|
sl@0
|
142 |
CSwDirectGdiImageTargetImpl* target = NULL;
|
sl@0
|
143 |
err = CSwDirectGdiImageTargetImpl::New(target, *this, device, aImage);
|
sl@0
|
144 |
if (err == KErrNone)
|
sl@0
|
145 |
{
|
sl@0
|
146 |
// Make sure we aren't overwriting an exisiting valid handle.
|
sl@0
|
147 |
GRAPHICS_ASSERT_DEBUG(aHandleRet == KNullHandle, EDirectGdiPanicTargetHandleNotNull);
|
sl@0
|
148 |
aHandleRet = reinterpret_cast<TInt>(target);
|
sl@0
|
149 |
}
|
sl@0
|
150 |
}
|
sl@0
|
151 |
|
sl@0
|
152 |
if (err != KErrNone)
|
sl@0
|
153 |
{
|
sl@0
|
154 |
delete device;
|
sl@0
|
155 |
}
|
sl@0
|
156 |
|
sl@0
|
157 |
return err;
|
sl@0
|
158 |
}
|
sl@0
|
159 |
|
sl@0
|
160 |
/**
|
sl@0
|
161 |
@see CDirectGdiDriverInternal::CloseImageTarget()
|
sl@0
|
162 |
@panic DGDIAdapter 40, if the image target associated with aHandle could not be found in the
|
sl@0
|
163 |
internal list of targets (debug only).
|
sl@0
|
164 |
*/
|
sl@0
|
165 |
void CSwDirectGdiDriverImpl::CloseImageTarget(TInt& aHandle)
|
sl@0
|
166 |
{
|
sl@0
|
167 |
CSwDirectGdiImageTargetImpl* target = reinterpret_cast<CSwDirectGdiImageTargetImpl*>(aHandle);
|
sl@0
|
168 |
if (target)
|
sl@0
|
169 |
target->Close();
|
sl@0
|
170 |
aHandle = KNullHandle;
|
sl@0
|
171 |
}
|
sl@0
|
172 |
|
sl@0
|
173 |
|
sl@0
|
174 |
/**
|
sl@0
|
175 |
@see CDirectGdiDriverInteral::CreateEngine()
|
sl@0
|
176 |
*/
|
sl@0
|
177 |
TInt CSwDirectGdiDriverImpl::CreateEngine(MDirectGdiEngine*& aEngine)
|
sl@0
|
178 |
{
|
sl@0
|
179 |
TInt err = KErrNoMemory;
|
sl@0
|
180 |
CSwDirectGdiEngine* engine = new CSwDirectGdiEngine(this);
|
sl@0
|
181 |
aEngine = engine;
|
sl@0
|
182 |
if(engine != NULL)
|
sl@0
|
183 |
{
|
sl@0
|
184 |
// Put this in an array so we can destroy it on close
|
sl@0
|
185 |
err = iEngines.InsertInAddressOrder(engine);
|
sl@0
|
186 |
if (KErrNone != err)
|
sl@0
|
187 |
{
|
sl@0
|
188 |
delete engine;
|
sl@0
|
189 |
aEngine = NULL;
|
sl@0
|
190 |
}
|
sl@0
|
191 |
}
|
sl@0
|
192 |
return err;
|
sl@0
|
193 |
}
|
sl@0
|
194 |
|
sl@0
|
195 |
/**
|
sl@0
|
196 |
@see CDirectGdiDriverInternal::DestroyEngine()
|
sl@0
|
197 |
@panic DGDIAdapter 60, if aEngine could not be found in the internal list of engines (debug only).
|
sl@0
|
198 |
*/
|
sl@0
|
199 |
void CSwDirectGdiDriverImpl::DestroyEngine(MDirectGdiEngine* aEngine)
|
sl@0
|
200 |
{
|
sl@0
|
201 |
TInt index = iEngines.FindInAddressOrder(aEngine);
|
sl@0
|
202 |
GRAPHICS_ASSERT_DEBUG(index != KErrNotFound, EDirectGdiPanicEngineNotFound);
|
sl@0
|
203 |
iEngines.Remove(index);
|
sl@0
|
204 |
delete (static_cast<CSwDirectGdiEngine*>(aEngine));
|
sl@0
|
205 |
}
|
sl@0
|
206 |
|
sl@0
|
207 |
/**
|
sl@0
|
208 |
@see CDirectGdiDriverInternal::SetError()
|
sl@0
|
209 |
*/
|
sl@0
|
210 |
void CSwDirectGdiDriverImpl::SetError(TInt aErr)
|
sl@0
|
211 |
{
|
sl@0
|
212 |
if (aErr != KErrNone && iErrorCode == KErrNone)
|
sl@0
|
213 |
{
|
sl@0
|
214 |
iErrorCode = aErr;
|
sl@0
|
215 |
}
|
sl@0
|
216 |
}
|
sl@0
|
217 |
|
sl@0
|
218 |
/**
|
sl@0
|
219 |
No extensions interfaces are supported.
|
sl@0
|
220 |
|
sl@0
|
221 |
@see CDirectGdiDriver::GetInterface()
|
sl@0
|
222 |
*/
|
sl@0
|
223 |
TInt CSwDirectGdiDriverImpl::GetInterface(TUid /*aInterfaceId*/, TAny*& aInterface)
|
sl@0
|
224 |
{
|
sl@0
|
225 |
aInterface = NULL;
|
sl@0
|
226 |
return KErrExtensionNotSupported;
|
sl@0
|
227 |
}
|
sl@0
|
228 |
|
sl@0
|
229 |
/**
|
sl@0
|
230 |
Deactivate the target if it was the current target, decrement the reference count of the target as it can be shared
|
sl@0
|
231 |
across many DirectGDI contexts.
|
sl@0
|
232 |
|
sl@0
|
233 |
@param aRenderingTarget The target object which you want to deactivate.
|
sl@0
|
234 |
|
sl@0
|
235 |
@panic DGDIAdapter 55, if aRengeringTarget is NULL.
|
sl@0
|
236 |
*/
|
sl@0
|
237 |
void CSwDirectGdiDriverImpl::Deactivate(CSwDirectGdiImageTargetImpl* aRenderingTarget)
|
sl@0
|
238 |
{
|
sl@0
|
239 |
GRAPHICS_ASSERT_ALWAYS(aRenderingTarget, EDirectGdiPanicNullTargetDeactivate);
|
sl@0
|
240 |
aRenderingTarget->Close();
|
sl@0
|
241 |
}
|
sl@0
|
242 |
|
sl@0
|
243 |
/**
|
sl@0
|
244 |
Checks whether the image source handle is valid.
|
sl@0
|
245 |
|
sl@0
|
246 |
@param aHandle The handle to an Image Source that should be found.
|
sl@0
|
247 |
@return ETrue if aHandle is a valid handle to an image registered with the driver, otherwise EFalse.
|
sl@0
|
248 |
*/
|
sl@0
|
249 |
TBool CSwDirectGdiDriverImpl::ValidImageSource(TInt aHandle) const
|
sl@0
|
250 |
{
|
sl@0
|
251 |
CSwDirectGdiImageSourceImpl* impl = reinterpret_cast<CSwDirectGdiImageSourceImpl*>(aHandle);
|
sl@0
|
252 |
return iImageSources.FindInAddressOrder(impl) != KErrNotFound;
|
sl@0
|
253 |
}
|
sl@0
|
254 |
|
sl@0
|
255 |
/**
|
sl@0
|
256 |
Checks whether the target image handle is valid.
|
sl@0
|
257 |
|
sl@0
|
258 |
@param aHandle The handle to an Image Target that should be found.
|
sl@0
|
259 |
@return ETrue if aHandle is a valid handle to an image registered with the driver, otherwise EFalse.
|
sl@0
|
260 |
*/
|
sl@0
|
261 |
TBool CSwDirectGdiDriverImpl::ValidImageTarget(TInt aHandle) const
|
sl@0
|
262 |
{
|
sl@0
|
263 |
CSwDirectGdiImageTargetImpl* impl = reinterpret_cast<CSwDirectGdiImageTargetImpl*>(aHandle);
|
sl@0
|
264 |
return iTargets.FindInAddressOrder(impl) != KErrNotFound;
|
sl@0
|
265 |
}
|
sl@0
|
266 |
|
sl@0
|
267 |
/**
|
sl@0
|
268 |
Removes the specified image target from the internal list of targets.
|
sl@0
|
269 |
|
sl@0
|
270 |
@param aImageTarget The image to remove.
|
sl@0
|
271 |
@return KErrNotFound if it could not be found in the internal list, otherwise KErrNone.
|
sl@0
|
272 |
*/
|
sl@0
|
273 |
TInt CSwDirectGdiDriverImpl::UnregisterTargetImage(const CSwDirectGdiImageTargetImpl& aImageTarget)
|
sl@0
|
274 |
{
|
sl@0
|
275 |
TInt err = KErrNone;
|
sl@0
|
276 |
TInt index = iTargets.FindInAddressOrder(&aImageTarget);
|
sl@0
|
277 |
if (index == KErrNotFound)
|
sl@0
|
278 |
{
|
sl@0
|
279 |
err = KErrNotFound;
|
sl@0
|
280 |
}
|
sl@0
|
281 |
else
|
sl@0
|
282 |
{
|
sl@0
|
283 |
iTargets.Remove(index);
|
sl@0
|
284 |
iTargets.GranularCompress();
|
sl@0
|
285 |
}
|
sl@0
|
286 |
return err;
|
sl@0
|
287 |
}
|
sl@0
|
288 |
|
sl@0
|
289 |
/**
|
sl@0
|
290 |
Removes the specified image source from the internal list of sources.
|
sl@0
|
291 |
|
sl@0
|
292 |
@param aImageSource The image to remove.
|
sl@0
|
293 |
@return KErrNotFound if it could not be found in the internal list, otherwise KErrNone.
|
sl@0
|
294 |
*/
|
sl@0
|
295 |
TInt CSwDirectGdiDriverImpl::UnregisterSourceImage(const CSwDirectGdiImageSourceImpl& aImageSource)
|
sl@0
|
296 |
{
|
sl@0
|
297 |
TInt err = KErrNone;
|
sl@0
|
298 |
TInt index = iImageSources.FindInAddressOrder(&aImageSource);
|
sl@0
|
299 |
if (index == KErrNotFound)
|
sl@0
|
300 |
{
|
sl@0
|
301 |
err = KErrNotFound;
|
sl@0
|
302 |
}
|
sl@0
|
303 |
else
|
sl@0
|
304 |
{
|
sl@0
|
305 |
iImageSources.Remove(index);
|
sl@0
|
306 |
iImageSources.GranularCompress();
|
sl@0
|
307 |
}
|
sl@0
|
308 |
return err;
|
sl@0
|
309 |
}
|
sl@0
|
310 |
|
sl@0
|
311 |
/**
|
sl@0
|
312 |
Helper function. When an image source is constructed, it registers itself on the driver's internal
|
sl@0
|
313 |
list of image sources.
|
sl@0
|
314 |
@param aImageSource The image to add to the array.
|
sl@0
|
315 |
@return KErrNone if successful, otherwise one of the system-wide error codes.
|
sl@0
|
316 |
*/
|
sl@0
|
317 |
TInt CSwDirectGdiDriverImpl::RegisterSourceImage(const CSwDirectGdiImageSourceImpl& aImageSource)
|
sl@0
|
318 |
{
|
sl@0
|
319 |
return iImageSources.InsertInAddressOrder(&aImageSource);
|
sl@0
|
320 |
}
|
sl@0
|
321 |
|
sl@0
|
322 |
/**
|
sl@0
|
323 |
Helper function. When an image target is constructed, it registers itself on the driver's internal
|
sl@0
|
324 |
list of image targets.
|
sl@0
|
325 |
@param aImageTarget The image to add to the array.
|
sl@0
|
326 |
@return KErrNone if successful, otherwise one of the system-wide error codes.
|
sl@0
|
327 |
*/
|
sl@0
|
328 |
TInt CSwDirectGdiDriverImpl::RegisterTargetImage(const CSwDirectGdiImageTargetImpl& aImageTarget)
|
sl@0
|
329 |
{
|
sl@0
|
330 |
return iTargets.InsertInAddressOrder(&aImageTarget);
|
sl@0
|
331 |
}
|
sl@0
|
332 |
|