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 "directgdidriverimpl.h"
|
sl@0
|
17 |
#include "directgdiimagetargetimpl.h"
|
sl@0
|
18 |
#include "directgdiimagesourceimpl.h"
|
sl@0
|
19 |
#include "directgdiadapter.h"
|
sl@0
|
20 |
#include "directgdiimageref.h"
|
sl@0
|
21 |
#include "vgengine.h"
|
sl@0
|
22 |
#include "confighelper.h"
|
sl@0
|
23 |
#include <graphics/directgdiimagetarget.h>
|
sl@0
|
24 |
#include <graphics/sgresource.h>
|
sl@0
|
25 |
#include <fbs.h>
|
sl@0
|
26 |
#include <bitdev.h>
|
sl@0
|
27 |
|
sl@0
|
28 |
#ifndef __WINS__
|
sl@0
|
29 |
// Static member variable
|
sl@0
|
30 |
XDirectGdiDriverProcessState CDirectGdiDriverImpl::gProcessState;
|
sl@0
|
31 |
#endif
|
sl@0
|
32 |
|
sl@0
|
33 |
/**
|
sl@0
|
34 |
Handles an EGL failure. It may either set the passed-in TInt to a Symbian OS-mapped error code,
|
sl@0
|
35 |
or panic the specified panic code, depending on the egl failure. Done as a macro so the line number is reported.
|
sl@0
|
36 |
*/
|
sl@0
|
37 |
#define HANDLE_EGL_ERROR(err, panic) \
|
sl@0
|
38 |
{ \
|
sl@0
|
39 |
const EGLint eglError = eglGetError(); \
|
sl@0
|
40 |
if (eglError == EGL_BAD_ALLOC) \
|
sl@0
|
41 |
err = KErrNoMemory; \
|
sl@0
|
42 |
else if (eglError == EGL_CONTEXT_LOST) \
|
sl@0
|
43 |
err = KErrDied; \
|
sl@0
|
44 |
else if (eglError != EGL_SUCCESS) \
|
sl@0
|
45 |
{ \
|
sl@0
|
46 |
TBuf16<256> _message; \
|
sl@0
|
47 |
_message.Format(_L16("EGL Error: %x\n"), eglError); \
|
sl@0
|
48 |
GRAPHICS_LOGD_DEBUG(_message); \
|
sl@0
|
49 |
GRAPHICS_ASSERT_DEBUG(eglError == EGL_SUCCESS, panic); \
|
sl@0
|
50 |
} \
|
sl@0
|
51 |
}
|
sl@0
|
52 |
|
sl@0
|
53 |
/**
|
sl@0
|
54 |
Populates the config hash map with matching EGL configs, based on the supported pixel types.
|
sl@0
|
55 |
|
sl@0
|
56 |
@param aDisplay A valid EGL display to retrieve EGL configs for.
|
sl@0
|
57 |
|
sl@0
|
58 |
@panic DGDIAdapter 24, if no suitable EGL configs are present (debug-only).
|
sl@0
|
59 |
@panic DGDIAdapter 25, if no exact matching EGL config can be found.
|
sl@0
|
60 |
@panic DGDIAdapter 29, if RSgImage::GetPixelFormats returns pixel count <= 0.
|
sl@0
|
61 |
|
sl@0
|
62 |
@pre EGL has been initialised by eglInitialize().
|
sl@0
|
63 |
@post The supported EGL configs are stored in the hash map.
|
sl@0
|
64 |
|
sl@0
|
65 |
@return KErrNoError if successful, KErrNotReady if EGL was not initialised, otherwise one of the
|
sl@0
|
66 |
system-wide error codes.
|
sl@0
|
67 |
*/
|
sl@0
|
68 |
TInt CDirectGdiDriverImpl::InitializeEglConfigs(EGLDisplay aDisplay)
|
sl@0
|
69 |
{
|
sl@0
|
70 |
#ifdef _DEBUG_DIRECTGDI
|
sl@0
|
71 |
GRAPHICS_LOG_DEBUG("InitializeEglConfigs");
|
sl@0
|
72 |
#endif
|
sl@0
|
73 |
TInt err = KErrNone;
|
sl@0
|
74 |
|
sl@0
|
75 |
// Get EGL configs upfront and store them in a hash map
|
sl@0
|
76 |
EGLint configSize = 0;
|
sl@0
|
77 |
EGLConfig *configs = NULL;
|
sl@0
|
78 |
|
sl@0
|
79 |
// Query RsgImage for the number of supported target pixel formats. Then we know how much memory should be
|
sl@0
|
80 |
// allocated to the pixelformats array.
|
sl@0
|
81 |
TInt count = 0;
|
sl@0
|
82 |
TSgImageInfo imageInfo;
|
sl@0
|
83 |
imageInfo.iUsage = ESgUsageDirectGdiTarget;
|
sl@0
|
84 |
imageInfo.iSizeInPixels = TSize(1,1);
|
sl@0
|
85 |
TUidPixelFormat* pixelFormats = NULL;
|
sl@0
|
86 |
err = RSgImage::GetPixelFormats(imageInfo, NULL, count);
|
sl@0
|
87 |
GRAPHICS_ASSERT_DEBUG(count > 0, EDirectGdiPanicNoValidPixelFormats);
|
sl@0
|
88 |
|
sl@0
|
89 |
if (err == KErrNone)
|
sl@0
|
90 |
{
|
sl@0
|
91 |
pixelFormats = new TUidPixelFormat[count];
|
sl@0
|
92 |
if (pixelFormats == NULL)
|
sl@0
|
93 |
{
|
sl@0
|
94 |
err = KErrNoMemory;
|
sl@0
|
95 |
}
|
sl@0
|
96 |
}
|
sl@0
|
97 |
|
sl@0
|
98 |
if (err == KErrNone)
|
sl@0
|
99 |
{
|
sl@0
|
100 |
err = RSgImage::GetPixelFormats(imageInfo, pixelFormats, count);
|
sl@0
|
101 |
if (!eglGetConfigs(aDisplay, configs, 0, &configSize) && configSize)
|
sl@0
|
102 |
{
|
sl@0
|
103 |
HANDLE_EGL_ERROR(err, EDirectGdiPanicNoAvailableConfigs);
|
sl@0
|
104 |
}
|
sl@0
|
105 |
}
|
sl@0
|
106 |
|
sl@0
|
107 |
if (err == KErrNone)
|
sl@0
|
108 |
{
|
sl@0
|
109 |
configs = new EGLConfig[configSize];
|
sl@0
|
110 |
if (configs == NULL)
|
sl@0
|
111 |
{
|
sl@0
|
112 |
err = KErrNoMemory;
|
sl@0
|
113 |
}
|
sl@0
|
114 |
}
|
sl@0
|
115 |
|
sl@0
|
116 |
for (TInt i = 0; (i < count) && (err == KErrNone); ++i)
|
sl@0
|
117 |
{
|
sl@0
|
118 |
// Finds a suitable config to map to this bitmap.
|
sl@0
|
119 |
TInt selPixmapAttribs = TConfigHelper::MatchPixelType(pixelFormats[i]);
|
sl@0
|
120 |
EGLint numConfigs = 0;
|
sl@0
|
121 |
if (!eglChooseConfig(aDisplay, TConfigHelper::KSurfaceAttribs[selPixmapAttribs], configs, configSize, &numConfigs))
|
sl@0
|
122 |
{
|
sl@0
|
123 |
HANDLE_EGL_ERROR(err, EDirectGdiPanicNoMatchingConfig);
|
sl@0
|
124 |
break;
|
sl@0
|
125 |
}
|
sl@0
|
126 |
GRAPHICS_ASSERT_ALWAYS(numConfigs >= 1, EDirectGdiPanicNoAvailableConfigs);
|
sl@0
|
127 |
// Find an exact matching config from the available configs.
|
sl@0
|
128 |
TInt match = TConfigHelper::GetSuitablePixmapConfigIndex(aDisplay, configs, numConfigs, selPixmapAttribs);
|
sl@0
|
129 |
GRAPHICS_ASSERT_ALWAYS(match >= 0, EDirectGdiPanicNoMatchingConfig);
|
sl@0
|
130 |
EGLConfig currentConfig = configs[match];
|
sl@0
|
131 |
|
sl@0
|
132 |
// Store this matching config and the pixel type in the hash map.
|
sl@0
|
133 |
err = iPixelConfigMap.Insert(selPixmapAttribs, currentConfig);
|
sl@0
|
134 |
}
|
sl@0
|
135 |
|
sl@0
|
136 |
delete [] configs;
|
sl@0
|
137 |
delete [] pixelFormats;
|
sl@0
|
138 |
|
sl@0
|
139 |
return err;
|
sl@0
|
140 |
}
|
sl@0
|
141 |
|
sl@0
|
142 |
/**
|
sl@0
|
143 |
Constructor to allocate memory to CDirectGdiDriverImpl object.
|
sl@0
|
144 |
|
sl@0
|
145 |
@param aInternal On success, will store a pointer to the newly created CDirectGdiDriverImpl.
|
sl@0
|
146 |
@param aLibrary
|
sl@0
|
147 |
@return KErrNone if successful, otherwise one of the system-wide error codes.
|
sl@0
|
148 |
*/
|
sl@0
|
149 |
TInt CDirectGdiDriverImpl::New(CDirectGdiDriverInternal*& aInternal, RLibrary aLibrary)
|
sl@0
|
150 |
{
|
sl@0
|
151 |
CDirectGdiDriverImpl* self = new CDirectGdiDriverImpl(aLibrary);
|
sl@0
|
152 |
if(!self)
|
sl@0
|
153 |
return KErrNoMemory;
|
sl@0
|
154 |
TInt err = self->Construct();
|
sl@0
|
155 |
if(err != KErrNone)
|
sl@0
|
156 |
{
|
sl@0
|
157 |
aInternal = NULL;
|
sl@0
|
158 |
delete self;
|
sl@0
|
159 |
return err;
|
sl@0
|
160 |
}
|
sl@0
|
161 |
aInternal = self;
|
sl@0
|
162 |
return err;
|
sl@0
|
163 |
}
|
sl@0
|
164 |
|
sl@0
|
165 |
/**
|
sl@0
|
166 |
Destructor - frees the memory for the hashmaps and the source and target arrays.
|
sl@0
|
167 |
|
sl@0
|
168 |
@panic DGDIAdapter 45, if images are still in the source or target image array (debug-only).
|
sl@0
|
169 |
*/
|
sl@0
|
170 |
CDirectGdiDriverImpl::~CDirectGdiDriverImpl()
|
sl@0
|
171 |
{
|
sl@0
|
172 |
// Check that there are no drawbles left in the drawable array
|
sl@0
|
173 |
GRAPHICS_ASSERT_DEBUG(iSourceArray.Count() == 0, EDirectGdiPanicItemsLeftInImageArray);
|
sl@0
|
174 |
GRAPHICS_ASSERT_DEBUG(iTargetArray.Count() == 0, EDirectGdiPanicItemsLeftInImageArray);
|
sl@0
|
175 |
|
sl@0
|
176 |
iSourceArray.Close();
|
sl@0
|
177 |
iTargetArray.Close();
|
sl@0
|
178 |
|
sl@0
|
179 |
delete iVgImageCache;
|
sl@0
|
180 |
|
sl@0
|
181 |
THashMapIter<TInt, EGLContext> contextIter(iPixelContextMap);
|
sl@0
|
182 |
const EGLContext* context = contextIter.NextValue();
|
sl@0
|
183 |
while (context)
|
sl@0
|
184 |
{
|
sl@0
|
185 |
eglDestroyContext(iDisplay, *context);
|
sl@0
|
186 |
context = contextIter.NextValue();
|
sl@0
|
187 |
}
|
sl@0
|
188 |
iPixelContextMap.Close();
|
sl@0
|
189 |
iPixelConfigMap.Close();
|
sl@0
|
190 |
delete iGlyphImageStorage;
|
sl@0
|
191 |
|
sl@0
|
192 |
eglMakeCurrent(iDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
sl@0
|
193 |
// This will terminate the display if it is the last driver.
|
sl@0
|
194 |
ProcessState().CloseDriver(iDisplay);
|
sl@0
|
195 |
eglReleaseThread();
|
sl@0
|
196 |
|
sl@0
|
197 |
SgDriver::Close();
|
sl@0
|
198 |
}
|
sl@0
|
199 |
|
sl@0
|
200 |
/**
|
sl@0
|
201 |
@see CDirectGdiDriver::Flush()
|
sl@0
|
202 |
*/
|
sl@0
|
203 |
void CDirectGdiDriverImpl::Flush()
|
sl@0
|
204 |
{
|
sl@0
|
205 |
vgFlush();
|
sl@0
|
206 |
}
|
sl@0
|
207 |
|
sl@0
|
208 |
/**
|
sl@0
|
209 |
@see CDirectGdiDriver::Finish()
|
sl@0
|
210 |
*/
|
sl@0
|
211 |
void CDirectGdiDriverImpl::Finish()
|
sl@0
|
212 |
{
|
sl@0
|
213 |
// Call eglWaitClient() instead of vgFinish() because MBX EGL implementation currently
|
sl@0
|
214 |
// does nothing with a vgFinish().
|
sl@0
|
215 |
if (eglWaitClient() == EGL_FALSE)
|
sl@0
|
216 |
{
|
sl@0
|
217 |
TInt err = KErrNone;
|
sl@0
|
218 |
HANDLE_EGL_ERROR(err, EDirectGdiPanicFinish);
|
sl@0
|
219 |
SetError(err);
|
sl@0
|
220 |
}
|
sl@0
|
221 |
|
sl@0
|
222 |
}
|
sl@0
|
223 |
|
sl@0
|
224 |
/**
|
sl@0
|
225 |
@see CDirectGdiDriver::GetError()
|
sl@0
|
226 |
|
sl@0
|
227 |
If no error has been reported explicitly, or SetError() has not been called, it will instead return
|
sl@0
|
228 |
the first (if any) OpenVG error to occur since GetError() was last called.
|
sl@0
|
229 |
*/
|
sl@0
|
230 |
TInt CDirectGdiDriverImpl::GetError()
|
sl@0
|
231 |
{
|
sl@0
|
232 |
// Call vgGetError() even when iErrorCode is already set, so that any OpenVG error state is
|
sl@0
|
233 |
// cleared and not reported in future.
|
sl@0
|
234 |
const TInt vgErrorCode = GetVgError();
|
sl@0
|
235 |
|
sl@0
|
236 |
if (iErrorCode == KErrNone)
|
sl@0
|
237 |
{
|
sl@0
|
238 |
iErrorCode = vgErrorCode;
|
sl@0
|
239 |
}
|
sl@0
|
240 |
TInt error = iErrorCode;
|
sl@0
|
241 |
iErrorCode = KErrNone;
|
sl@0
|
242 |
return error;
|
sl@0
|
243 |
}
|
sl@0
|
244 |
|
sl@0
|
245 |
/**
|
sl@0
|
246 |
@see CDirectGdiDriver::CreateDrawableSource()
|
sl@0
|
247 |
|
sl@0
|
248 |
For image resource creates a DirectGDI adaptation-specific resource from the given RSgDrawable resource so
|
sl@0
|
249 |
it can be drawn using the DirectGDI rendering API. Creates an EGLImage, then a VGImage from the
|
sl@0
|
250 |
passed RSgImage and associates the new source with these images. Sources that are successfully created
|
sl@0
|
251 |
are added to an array of sources so that they can be closed and deleted correctly at a later stage.
|
sl@0
|
252 |
Note that an image source cannot be created before an image target has been created and activated.
|
sl@0
|
253 |
This is a limitation of OpenVG as a VG context must exist before an image source can be created.
|
sl@0
|
254 |
|
sl@0
|
255 |
@param aHandleRet Handle of newly created drawable source, must be KNullHandle (is checked by generic driver).
|
sl@0
|
256 |
@param aSgDrawable The RSgDrawable object to use when creating the drawable source. An attempt is made to
|
sl@0
|
257 |
match the pixel format of the new EGL surface with the pixel format of this RSgImage.
|
sl@0
|
258 |
|
sl@0
|
259 |
@pre CDirectGdiDriver object has been initialised from the calling thread and a target has been activated.
|
sl@0
|
260 |
aHandleRet is KNullHandle.
|
sl@0
|
261 |
@post The DirectGDI adaptation-specific resource that is bound to the given
|
sl@0
|
262 |
drawable resource is created and this handle is now associated with it. The reference
|
sl@0
|
263 |
counter on the drawable resource is incremented. The CDirectGdiDriver for this thread
|
sl@0
|
264 |
is now aware of and owns the adaptation-specific resource.
|
sl@0
|
265 |
|
sl@0
|
266 |
@return KErrNone if successful, KErrArgument if the drawable resource is not valid,
|
sl@0
|
267 |
KErrNotSupported if the drawable resource is not created with the type (KSgImageTypeUid),
|
sl@0
|
268 |
otherwise one of the system-wide error codes.
|
sl@0
|
269 |
*/
|
sl@0
|
270 |
TInt CDirectGdiDriverImpl::CreateDrawableSource(TInt& aHandleRet, const RSgDrawable& aSgDrawable)
|
sl@0
|
271 |
{
|
sl@0
|
272 |
TUid typeUid = aSgDrawable.DrawableType();
|
sl@0
|
273 |
if(typeUid != KSgImageTypeUid)
|
sl@0
|
274 |
{
|
sl@0
|
275 |
return KErrNotSupported;
|
sl@0
|
276 |
}
|
sl@0
|
277 |
const RSgImage* image = reinterpret_cast<const RSgImage*>(&aSgDrawable);
|
sl@0
|
278 |
CDirectGdiImageSourceImpl* imageSource = NULL;
|
sl@0
|
279 |
TInt err = CDirectGdiImageSourceImpl::New(imageSource, *this, *image);
|
sl@0
|
280 |
|
sl@0
|
281 |
if (err == KErrNone)
|
sl@0
|
282 |
{
|
sl@0
|
283 |
aHandleRet = reinterpret_cast<TInt>(imageSource);
|
sl@0
|
284 |
}
|
sl@0
|
285 |
|
sl@0
|
286 |
return err;
|
sl@0
|
287 |
}
|
sl@0
|
288 |
|
sl@0
|
289 |
/**
|
sl@0
|
290 |
@see CDirectGdiDriver::CreateDrawableSource()
|
sl@0
|
291 |
|
sl@0
|
292 |
Destroys the DirectGDI adaptation-specific resource associated with this handle.
|
sl@0
|
293 |
Calling this method on a handle that is not associated with any DirectGDI specific
|
sl@0
|
294 |
resource will do nothing. Once Close() is called, this handle can be reused. The handle
|
sl@0
|
295 |
is set to KNullHandle.
|
sl@0
|
296 |
|
sl@0
|
297 |
@param aHandle A reference to a valid handle to a RDirectGdiDrawableSource object which is
|
sl@0
|
298 |
to be closed.
|
sl@0
|
299 |
|
sl@0
|
300 |
@pre CDirectGdiDriver object has been initialised from the calling thread.
|
sl@0
|
301 |
@post The DirectGDI adaptation-specific resource associated with this handle will
|
sl@0
|
302 |
be destroyed (at any time preferred by the adaptation). This handle is no longer
|
sl@0
|
303 |
associated with a DirectGDI adaptation-specific resource. The reference counter of
|
sl@0
|
304 |
the underlying drawable resource is decremented. aHandle is set to KNullHandle.
|
sl@0
|
305 |
|
sl@0
|
306 |
@panic DGDIAdapter 37, if an image source cannot be created from the passed handle.
|
sl@0
|
307 |
*/
|
sl@0
|
308 |
void CDirectGdiDriverImpl::CloseDrawableSource(TInt& aHandle)
|
sl@0
|
309 |
{
|
sl@0
|
310 |
CDirectGdiImageSourceImpl* imageSource = GetImageSourceFromHandle(aHandle);
|
sl@0
|
311 |
GRAPHICS_ASSERT_ALWAYS(imageSource, EDirectGdiPanicCloseDrawableHandleFailure);
|
sl@0
|
312 |
|
sl@0
|
313 |
// Decrement the reference count on this image source. If it reaches zero, it will
|
sl@0
|
314 |
// remove itself from the source array and delete itself.
|
sl@0
|
315 |
imageSource->Close();
|
sl@0
|
316 |
aHandle = KNullHandle;
|
sl@0
|
317 |
}
|
sl@0
|
318 |
|
sl@0
|
319 |
|
sl@0
|
320 |
/**
|
sl@0
|
321 |
@see CDirectGdiDriver::CreateImageTarget()
|
sl@0
|
322 |
|
sl@0
|
323 |
Allocates and constructs a CDirectGdiImageTargetImpl object, and associates it with aHandleRet.
|
sl@0
|
324 |
|
sl@0
|
325 |
@param aHandleRet Handle of newly created Image Target, must be KNullHandle (is checked by generic driver).
|
sl@0
|
326 |
@param aSgImage The RSgImage to associate with the created image target. An attempt is made to match
|
sl@0
|
327 |
the pixel format of the new EGL surface with the pixel format of this RSgImage.
|
sl@0
|
328 |
|
sl@0
|
329 |
@pre CDirectGdiDriver object has been initialised from the calling thread.
|
sl@0
|
330 |
The image resource has been fully constructed and created with the correct usage
|
sl@0
|
331 |
that allows it to be used as a DirectGDI target. aHandleRet is KNullHandle.
|
sl@0
|
332 |
|
sl@0
|
333 |
@post The DirectGDI adaptation-specific resource that is bound to the given image
|
sl@0
|
334 |
resource is created and this handle is now associated with it. The reference counter
|
sl@0
|
335 |
on the image resource is incremented.
|
sl@0
|
336 |
|
sl@0
|
337 |
@return KErrNone if successful, KErrArgument if the image resource is not valid,
|
sl@0
|
338 |
KErrNotSupported if the image resource is not created with the correct
|
sl@0
|
339 |
usage, otherwise one of the system-wide error codes.
|
sl@0
|
340 |
*/
|
sl@0
|
341 |
TInt CDirectGdiDriverImpl::CreateImageTarget(TInt& aHandleRet, const RSgImage& aSgImage)
|
sl@0
|
342 |
{
|
sl@0
|
343 |
CDirectGdiImageTargetImpl* imageTarget = NULL;
|
sl@0
|
344 |
TInt err = CDirectGdiImageTargetImpl::New(imageTarget, *this, aSgImage, iPixelContextMap, iPixelConfigMap, iSharedContext);
|
sl@0
|
345 |
|
sl@0
|
346 |
if (err == KErrNone)
|
sl@0
|
347 |
{
|
sl@0
|
348 |
// Return the handle to the newly created image target.
|
sl@0
|
349 |
aHandleRet = reinterpret_cast<TInt>(imageTarget);
|
sl@0
|
350 |
}
|
sl@0
|
351 |
|
sl@0
|
352 |
return err;
|
sl@0
|
353 |
}
|
sl@0
|
354 |
|
sl@0
|
355 |
/**
|
sl@0
|
356 |
Destroys the DirectGDI adaptation-specific resource associated with this handle.
|
sl@0
|
357 |
Calling this method on a handle that is not associated with any DirectGDI adaptation-
|
sl@0
|
358 |
specific resource will do nothing. Once Close() is called, this handle can be reused.
|
sl@0
|
359 |
|
sl@0
|
360 |
@param aHandle A handle to a RDirectGdiImageTarget object to be closed.
|
sl@0
|
361 |
|
sl@0
|
362 |
@pre CDirectGdiDriver object has been initialised from the calling thread.
|
sl@0
|
363 |
|
sl@0
|
364 |
@post The DirectGDI specific resource associated with this handle will be destroyed
|
sl@0
|
365 |
if the reference count falls to zero. This handle is no longer associated with
|
sl@0
|
366 |
a DirectGDI specific resource. The reference counter of the underlying image
|
sl@0
|
367 |
resource is decremented. aHandle is set to KNullHandle.
|
sl@0
|
368 |
|
sl@0
|
369 |
@panic DGDIAdapter 37, if the image source associated with aHandle is NULL.
|
sl@0
|
370 |
*/
|
sl@0
|
371 |
void CDirectGdiDriverImpl::CloseImageTarget(TInt& aHandle)
|
sl@0
|
372 |
{
|
sl@0
|
373 |
CDirectGdiImageTargetImpl* imageTarget = GetImageTargetFromHandle(aHandle);
|
sl@0
|
374 |
GRAPHICS_ASSERT_ALWAYS(imageTarget, EDirectGdiPanicCloseDrawableHandleFailure);
|
sl@0
|
375 |
|
sl@0
|
376 |
// Decrement the reference count on this image target. If the reference count reaches zero,
|
sl@0
|
377 |
// it is deleted and removed from the targets array.
|
sl@0
|
378 |
imageTarget->Close();
|
sl@0
|
379 |
aHandle = KNullHandle;
|
sl@0
|
380 |
}
|
sl@0
|
381 |
|
sl@0
|
382 |
/**
|
sl@0
|
383 |
Instantiates an adaptation-specific rendering engine.
|
sl@0
|
384 |
|
sl@0
|
385 |
@param aDirectGdiEngine Reference to instantiated engine.
|
sl@0
|
386 |
|
sl@0
|
387 |
@pre CDirectGdiDriver object has been initialised from the calling thread.
|
sl@0
|
388 |
|
sl@0
|
389 |
@return KErrNone if the engine is constructed, else KErrNoMemory.
|
sl@0
|
390 |
*/
|
sl@0
|
391 |
TInt CDirectGdiDriverImpl::CreateEngine(MDirectGdiEngine*& aDirectGdiEngine)
|
sl@0
|
392 |
{
|
sl@0
|
393 |
TInt result = KErrNone;
|
sl@0
|
394 |
aDirectGdiEngine = new CVgEngine(*this);
|
sl@0
|
395 |
if (aDirectGdiEngine == NULL)
|
sl@0
|
396 |
{
|
sl@0
|
397 |
result = KErrNoMemory;
|
sl@0
|
398 |
}
|
sl@0
|
399 |
return result;
|
sl@0
|
400 |
}
|
sl@0
|
401 |
|
sl@0
|
402 |
/**
|
sl@0
|
403 |
Unbinds target from rendering engine and marks it for deletion.
|
sl@0
|
404 |
NOTE: Currently this means just deleting the engine.
|
sl@0
|
405 |
|
sl@0
|
406 |
@param aDirectGdiEngine Engine to operate on.
|
sl@0
|
407 |
|
sl@0
|
408 |
@pre CDirectGdiDriver object has been initialised from the calling thread.
|
sl@0
|
409 |
|
sl@0
|
410 |
@panic DGDIAdapter 38, if the engine is NULL.
|
sl@0
|
411 |
*/
|
sl@0
|
412 |
void CDirectGdiDriverImpl::DestroyEngine(MDirectGdiEngine* aDirectGdiEngine)
|
sl@0
|
413 |
{
|
sl@0
|
414 |
GRAPHICS_ASSERT_ALWAYS(aDirectGdiEngine, EDirectGdiPanicDestroyNullEngine);
|
sl@0
|
415 |
CVgEngine* actualEngine = static_cast<CVgEngine*>(aDirectGdiEngine);
|
sl@0
|
416 |
delete actualEngine;
|
sl@0
|
417 |
}
|
sl@0
|
418 |
|
sl@0
|
419 |
/**
|
sl@0
|
420 |
The only extension interface supported by this implementation is MDirectGdiDriverCacheSize.
|
sl@0
|
421 |
|
sl@0
|
422 |
@see CDirectGdiDriver::GetInterface()
|
sl@0
|
423 |
*/
|
sl@0
|
424 |
TInt CDirectGdiDriverImpl::GetInterface(TUid aInterfaceId, TAny*& aInterface)
|
sl@0
|
425 |
{
|
sl@0
|
426 |
aInterface = NULL;
|
sl@0
|
427 |
TInt err = KErrNone;
|
sl@0
|
428 |
switch (aInterfaceId.iUid)
|
sl@0
|
429 |
{
|
sl@0
|
430 |
case KDirectGdiDriverCacheSizeUid:
|
sl@0
|
431 |
{
|
sl@0
|
432 |
aInterface = static_cast<MDirectGdiDriverCacheSize*>(this);
|
sl@0
|
433 |
break;
|
sl@0
|
434 |
}
|
sl@0
|
435 |
default:
|
sl@0
|
436 |
err = KErrExtensionNotSupported;
|
sl@0
|
437 |
break;
|
sl@0
|
438 |
}
|
sl@0
|
439 |
return err;
|
sl@0
|
440 |
}
|
sl@0
|
441 |
|
sl@0
|
442 |
CDirectGdiDriverImpl::CDirectGdiDriverImpl(RLibrary aLibrary)
|
sl@0
|
443 |
: CDirectGdiDriverInternal(aLibrary),
|
sl@0
|
444 |
iDisplay(EGL_NO_DISPLAY)
|
sl@0
|
445 |
{
|
sl@0
|
446 |
}
|
sl@0
|
447 |
/**
|
sl@0
|
448 |
Performs the second phase of construction.
|
sl@0
|
449 |
|
sl@0
|
450 |
@pre CDirectGdiDriver object has been initialised from the calling thread.
|
sl@0
|
451 |
@post EGL has been initialised. SgDriver has been opened.
|
sl@0
|
452 |
|
sl@0
|
453 |
@panic DGDIAdapter 36, if eglGetDisplay() fails.
|
sl@0
|
454 |
@panic DGDIAdapter 35, if eglInitialize() fails.
|
sl@0
|
455 |
@panic DGDIAdapter 23, if eglBindAPI() fails.
|
sl@0
|
456 |
@return KErrNone if successful, KErrNotFound if no implementation of the Graphics Resource API is found,
|
sl@0
|
457 |
KErrNotSupported if the version of EGL is less than required (1.2), otherwise one of the
|
sl@0
|
458 |
system-wide error codes.
|
sl@0
|
459 |
*/
|
sl@0
|
460 |
TInt CDirectGdiDriverImpl::Construct()
|
sl@0
|
461 |
{
|
sl@0
|
462 |
TInt err = KErrNone;
|
sl@0
|
463 |
iSharedContext = EGL_NO_CONTEXT;
|
sl@0
|
464 |
|
sl@0
|
465 |
// First thing is to check whether the mutex for the Process State was successfully created.
|
sl@0
|
466 |
// If not, it's a fatal error. If it is, we must increment the reference count on the mutex as
|
sl@0
|
467 |
// early as possible to make the creation/destruction of the display thread-safe.
|
sl@0
|
468 |
err = ProcessState().MutexCreationStatus();
|
sl@0
|
469 |
if (err == KErrNone)
|
sl@0
|
470 |
{
|
sl@0
|
471 |
ProcessState().OpenDriver();
|
sl@0
|
472 |
}
|
sl@0
|
473 |
|
sl@0
|
474 |
if (err == KErrNone)
|
sl@0
|
475 |
{
|
sl@0
|
476 |
err = SgDriver::Open();
|
sl@0
|
477 |
}
|
sl@0
|
478 |
|
sl@0
|
479 |
if (err == KErrNone)
|
sl@0
|
480 |
{
|
sl@0
|
481 |
// Create display object
|
sl@0
|
482 |
iDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
|
sl@0
|
483 |
GRAPHICS_ASSERT_ALWAYS(iDisplay != EGL_NO_DISPLAY, EDirectGdiPanicNoDisplay);
|
sl@0
|
484 |
|
sl@0
|
485 |
// Initialise the display. If it is already initialised, EGL will return quickly.
|
sl@0
|
486 |
EGLint major, minor;
|
sl@0
|
487 |
if (!eglInitialize(iDisplay, &major, &minor))
|
sl@0
|
488 |
{
|
sl@0
|
489 |
iDisplay = EGL_NO_DISPLAY;
|
sl@0
|
490 |
HANDLE_EGL_ERROR(err, EDirectGdiPanicInitializeDisplay);
|
sl@0
|
491 |
}
|
sl@0
|
492 |
else if (major < 1 || (major == 1 && minor < 2))
|
sl@0
|
493 |
{
|
sl@0
|
494 |
// Atleast EGL 1.2 needs to be available.
|
sl@0
|
495 |
err = KErrNotSupported;
|
sl@0
|
496 |
}
|
sl@0
|
497 |
}
|
sl@0
|
498 |
|
sl@0
|
499 |
if (err == KErrNone)
|
sl@0
|
500 |
{
|
sl@0
|
501 |
// Let EGL know we will use it for OpenVG
|
sl@0
|
502 |
if(!eglBindAPI(EGL_OPENVG_API))
|
sl@0
|
503 |
{
|
sl@0
|
504 |
HANDLE_EGL_ERROR(err, EDirectGdiPanicBindApi);
|
sl@0
|
505 |
}
|
sl@0
|
506 |
}
|
sl@0
|
507 |
|
sl@0
|
508 |
if (err == KErrNone)
|
sl@0
|
509 |
{
|
sl@0
|
510 |
iGlyphImageStorage = new CFontGlyphImageStorage(KDirectGdiAdapterDefaultMaxGlyphImageCacheSize);
|
sl@0
|
511 |
if(!iGlyphImageStorage)
|
sl@0
|
512 |
{
|
sl@0
|
513 |
err = KErrNoMemory;
|
sl@0
|
514 |
}
|
sl@0
|
515 |
}
|
sl@0
|
516 |
|
sl@0
|
517 |
if (err == KErrNone)
|
sl@0
|
518 |
{
|
sl@0
|
519 |
iVgImageCache = new CVgImageCache(KDirectGdiAdapterDefaultMaxImageCacheSize);
|
sl@0
|
520 |
if(!iVgImageCache)
|
sl@0
|
521 |
{
|
sl@0
|
522 |
err = KErrNoMemory;
|
sl@0
|
523 |
}
|
sl@0
|
524 |
}
|
sl@0
|
525 |
|
sl@0
|
526 |
if (err == KErrNone)
|
sl@0
|
527 |
{
|
sl@0
|
528 |
err = ProcessState().Initialize(iDisplay);
|
sl@0
|
529 |
}
|
sl@0
|
530 |
|
sl@0
|
531 |
if (err == KErrNone)
|
sl@0
|
532 |
{
|
sl@0
|
533 |
err = InitializeEglConfigs(iDisplay);
|
sl@0
|
534 |
}
|
sl@0
|
535 |
|
sl@0
|
536 |
return err;
|
sl@0
|
537 |
}
|
sl@0
|
538 |
|
sl@0
|
539 |
/**
|
sl@0
|
540 |
@see CDirectGdiDriver::SetError()
|
sl@0
|
541 |
|
sl@0
|
542 |
In the event that OpenVG's error state has been set, it will be used as the driver's error state,
|
sl@0
|
543 |
overriding aErr.
|
sl@0
|
544 |
|
sl@0
|
545 |
@param aErr The error code to be set.
|
sl@0
|
546 |
@pre CDirectGdiDriver object has been initialised from the calling thread.
|
sl@0
|
547 |
@post The error state is set to the current OpenVG error state, otherwise aErr, if the current error state
|
sl@0
|
548 |
is empty.
|
sl@0
|
549 |
*/
|
sl@0
|
550 |
void CDirectGdiDriverImpl::SetError(TInt aErr)
|
sl@0
|
551 |
{
|
sl@0
|
552 |
if( iErrorCode == KErrNone )
|
sl@0
|
553 |
{
|
sl@0
|
554 |
iErrorCode = GetVgError();
|
sl@0
|
555 |
if (iErrorCode == KErrNone)
|
sl@0
|
556 |
{
|
sl@0
|
557 |
iErrorCode = aErr;
|
sl@0
|
558 |
}
|
sl@0
|
559 |
}
|
sl@0
|
560 |
}
|
sl@0
|
561 |
|
sl@0
|
562 |
/**
|
sl@0
|
563 |
Static function. Converts the current OpenVG error state (if any) to a standard Symbian error code.
|
sl@0
|
564 |
|
sl@0
|
565 |
@panic DGDIAdapter 64, if the error code received from OpenVG is due to misuse of OpenVG rather
|
sl@0
|
566 |
than a runtime error.
|
sl@0
|
567 |
@return KErrGeneral if the OpenVG error code not recognised, otherwise a system-wide error
|
sl@0
|
568 |
code converted from the OpenVG error code.
|
sl@0
|
569 |
*/
|
sl@0
|
570 |
TInt CDirectGdiDriverImpl::GetVgError()
|
sl@0
|
571 |
{
|
sl@0
|
572 |
TInt error = KErrGeneral;
|
sl@0
|
573 |
switch(vgGetError())
|
sl@0
|
574 |
{
|
sl@0
|
575 |
case VG_NO_ERROR:
|
sl@0
|
576 |
error = KErrNone;
|
sl@0
|
577 |
break;
|
sl@0
|
578 |
case VG_BAD_HANDLE_ERROR:
|
sl@0
|
579 |
error = KErrBadHandle;
|
sl@0
|
580 |
break;
|
sl@0
|
581 |
case VG_ILLEGAL_ARGUMENT_ERROR:
|
sl@0
|
582 |
error = KErrArgument;
|
sl@0
|
583 |
break;
|
sl@0
|
584 |
case VG_OUT_OF_MEMORY_ERROR:
|
sl@0
|
585 |
error = KErrNoMemory;
|
sl@0
|
586 |
break;
|
sl@0
|
587 |
default:
|
sl@0
|
588 |
// Any other error is due to DirectGDI using OpenVG incorrectly somewhere.
|
sl@0
|
589 |
GRAPHICS_PANIC_DEBUG(EDirectGdiPanicVgError);
|
sl@0
|
590 |
}
|
sl@0
|
591 |
return error;
|
sl@0
|
592 |
}
|
sl@0
|
593 |
|
sl@0
|
594 |
/**
|
sl@0
|
595 |
Sets the current engine as the most recent engine which has been activated.
|
sl@0
|
596 |
|
sl@0
|
597 |
@param aCurrentEngine The pointer to the most recent engine.
|
sl@0
|
598 |
*/
|
sl@0
|
599 |
void CDirectGdiDriverImpl::SetCurrentEngine(CVgEngine* aCurrentEngine)
|
sl@0
|
600 |
{
|
sl@0
|
601 |
iCurrentEngine = aCurrentEngine;
|
sl@0
|
602 |
}
|
sl@0
|
603 |
|
sl@0
|
604 |
/**
|
sl@0
|
605 |
Checks whether the given engine is current or not, so that the OpenVG state can be reset.
|
sl@0
|
606 |
|
sl@0
|
607 |
@param aCurrentEngine The pointer to an engine.
|
sl@0
|
608 |
@return ETrue if it is the current engine, else EFalse.
|
sl@0
|
609 |
*/
|
sl@0
|
610 |
TBool CDirectGdiDriverImpl::IsCurrentEngine(const CVgEngine* aCurrentEngine) const
|
sl@0
|
611 |
{
|
sl@0
|
612 |
return (iCurrentEngine == aCurrentEngine);
|
sl@0
|
613 |
}
|
sl@0
|
614 |
|
sl@0
|
615 |
/**
|
sl@0
|
616 |
Checks whether this target is current or not, so that the EGL state can be reset.
|
sl@0
|
617 |
|
sl@0
|
618 |
@param aCurrentTarget The pointer to a target.
|
sl@0
|
619 |
@return ETrue if it is the current target, else EFalse.
|
sl@0
|
620 |
*/
|
sl@0
|
621 |
TBool CDirectGdiDriverImpl::IsCurrentTarget(const CDirectGdiImageTargetImpl* aCurrentTarget) const
|
sl@0
|
622 |
{
|
sl@0
|
623 |
return (iCurrentTarget == aCurrentTarget);
|
sl@0
|
624 |
}
|
sl@0
|
625 |
|
sl@0
|
626 |
/**
|
sl@0
|
627 |
Sets the current target as the most recent target which has been activated.
|
sl@0
|
628 |
|
sl@0
|
629 |
@param aCurrentTarget The pointer to the most recent target.
|
sl@0
|
630 |
*/
|
sl@0
|
631 |
void CDirectGdiDriverImpl::SetCurrentTarget(CDirectGdiImageTargetImpl* aCurrentTarget)
|
sl@0
|
632 |
{
|
sl@0
|
633 |
iCurrentTarget = aCurrentTarget;
|
sl@0
|
634 |
}
|
sl@0
|
635 |
|
sl@0
|
636 |
/**
|
sl@0
|
637 |
Activates the specified target and increments its reference count as it can be shared across many
|
sl@0
|
638 |
DirectGDI contexts.
|
sl@0
|
639 |
|
sl@0
|
640 |
@param aRenderingTarget The target object which is to be activated.
|
sl@0
|
641 |
*/
|
sl@0
|
642 |
void CDirectGdiDriverImpl::Activate(CDirectGdiImageTargetImpl* aRenderingTarget)
|
sl@0
|
643 |
{
|
sl@0
|
644 |
// Reactivate() does the same activation
|
sl@0
|
645 |
Reactivate(aRenderingTarget);
|
sl@0
|
646 |
aRenderingTarget->Open();
|
sl@0
|
647 |
}
|
sl@0
|
648 |
|
sl@0
|
649 |
/**
|
sl@0
|
650 |
Reactivates the specified target, without affecting its reference count.
|
sl@0
|
651 |
|
sl@0
|
652 |
@param aRenderingTarget The target to be reactivated.
|
sl@0
|
653 |
|
sl@0
|
654 |
@panic DGDIAdapter 2, if eglGetError() returns an error we can't handle.
|
sl@0
|
655 |
*/
|
sl@0
|
656 |
void CDirectGdiDriverImpl::Reactivate(CDirectGdiImageTargetImpl* aRenderingTarget)
|
sl@0
|
657 |
{
|
sl@0
|
658 |
if(!aRenderingTarget->Activate())
|
sl@0
|
659 |
{
|
sl@0
|
660 |
TInt error = KErrNone;
|
sl@0
|
661 |
HANDLE_EGL_ERROR(error, EDirectGdiPanicUnexpectedError);
|
sl@0
|
662 |
if(error == KErrNoMemory)
|
sl@0
|
663 |
{
|
sl@0
|
664 |
SetError(error);
|
sl@0
|
665 |
}
|
sl@0
|
666 |
// Can check here whether error == KErrDied, which signifies an EGL_CONTEXT_LOST error.
|
sl@0
|
667 |
// due to a power management event. Then need to destroy and recreate all EGLContexts used.
|
sl@0
|
668 |
// This is not implemented as the EGL used with this reference adaptation does not produce this error.
|
sl@0
|
669 |
// Following pseudocode will achieve this:
|
sl@0
|
670 |
// 1. For each context stored in iPixelMapContext:
|
sl@0
|
671 |
// 1a. Destroy context.
|
sl@0
|
672 |
// 1b. Create replacement context with same parameters.
|
sl@0
|
673 |
// 1c. Search through all rendering targets replacing the context stored (if it matches with the one just destroyed) with the new one.
|
sl@0
|
674 |
// 2. Try activating the rendering target again.
|
sl@0
|
675 |
}
|
sl@0
|
676 |
}
|
sl@0
|
677 |
|
sl@0
|
678 |
/**
|
sl@0
|
679 |
Deactivates the target if it was the current target, and decrements its reference count as it can
|
sl@0
|
680 |
be shared across many DirectGDI contexts.
|
sl@0
|
681 |
|
sl@0
|
682 |
@param aRenderingTarget The target object which you want to deactivate.
|
sl@0
|
683 |
*/
|
sl@0
|
684 |
void CDirectGdiDriverImpl::Deactivate(CDirectGdiImageTargetImpl* aRenderingTarget)
|
sl@0
|
685 |
{
|
sl@0
|
686 |
aRenderingTarget->Close();
|
sl@0
|
687 |
}
|
sl@0
|
688 |
|
sl@0
|
689 |
/**
|
sl@0
|
690 |
Helper function for removing a pointer to a CDirectGdiImageRef object from the source image array.
|
sl@0
|
691 |
@param aImage A pointer to a CDirectGdiImageRef source object.
|
sl@0
|
692 |
@return KErrNone if successful, KErrNotFound if no suitable object pointer can be found,
|
sl@0
|
693 |
otherwise one of the other system wide error codes.
|
sl@0
|
694 |
*/
|
sl@0
|
695 |
TInt CDirectGdiDriverImpl::UnregisterSourceImage(const CDirectGdiImageSourceImpl& aImage)
|
sl@0
|
696 |
{
|
sl@0
|
697 |
TInt index = -1;
|
sl@0
|
698 |
TInt err = iSourceArray.FindInAddressOrder(&aImage, index);
|
sl@0
|
699 |
if (err == KErrNone)
|
sl@0
|
700 |
{
|
sl@0
|
701 |
iSourceArray.Remove(index);
|
sl@0
|
702 |
iSourceArray.GranularCompress();
|
sl@0
|
703 |
}
|
sl@0
|
704 |
|
sl@0
|
705 |
return err;
|
sl@0
|
706 |
}
|
sl@0
|
707 |
|
sl@0
|
708 |
/**
|
sl@0
|
709 |
Helper function for removing a pointer to a CDirectGdiImageRef object from the target image array.
|
sl@0
|
710 |
@param aImage A pointer to a CDirectGdiImageRef source object.
|
sl@0
|
711 |
@return KErrNone if successful, KErrNotFound if no suitable object pointer can be found,
|
sl@0
|
712 |
otherwise one of the other system wide error codes.
|
sl@0
|
713 |
*/
|
sl@0
|
714 |
TInt CDirectGdiDriverImpl::UnregisterTargetImage(const CDirectGdiImageTargetImpl& aImage)
|
sl@0
|
715 |
{
|
sl@0
|
716 |
TInt index = -1;
|
sl@0
|
717 |
TInt err = iTargetArray.FindInAddressOrder(&aImage, index);
|
sl@0
|
718 |
if (err == KErrNone)
|
sl@0
|
719 |
{
|
sl@0
|
720 |
iTargetArray.Remove(index);
|
sl@0
|
721 |
iTargetArray.GranularCompress();
|
sl@0
|
722 |
}
|
sl@0
|
723 |
|
sl@0
|
724 |
return err;
|
sl@0
|
725 |
}
|
sl@0
|
726 |
|
sl@0
|
727 |
/**
|
sl@0
|
728 |
Helper function to convert a handle for a RDirectGdiDrawableSource object to a CDirectGdiImageSourceImpl
|
sl@0
|
729 |
object. In debug builds, it also checks that the image source was actually created by this driver and
|
sl@0
|
730 |
exists in the array of image sources.
|
sl@0
|
731 |
|
sl@0
|
732 |
@param aHandle A valid handle to a RDirectGdiDrawableSource object.
|
sl@0
|
733 |
@return A pointer to a CDirectGdiImageSourceImpl object that the handle represents.
|
sl@0
|
734 |
*/
|
sl@0
|
735 |
CDirectGdiImageSourceImpl* CDirectGdiDriverImpl::GetImageSourceFromHandle(TInt aHandle) const
|
sl@0
|
736 |
{
|
sl@0
|
737 |
#ifdef _DEBUG
|
sl@0
|
738 |
CheckSourceIsValid(aHandle);
|
sl@0
|
739 |
#endif // _DEBUG
|
sl@0
|
740 |
|
sl@0
|
741 |
CDirectGdiImageSourceImpl* source = reinterpret_cast<CDirectGdiImageSourceImpl*>(aHandle);
|
sl@0
|
742 |
return source;
|
sl@0
|
743 |
}
|
sl@0
|
744 |
|
sl@0
|
745 |
/**
|
sl@0
|
746 |
Helper function to convert a handle for a RDirectGdiImageTarget object to a CDirectGdiImageTargetImpl
|
sl@0
|
747 |
object. In debug builds, it also checks that the image target was actually created by this driver and
|
sl@0
|
748 |
exists in the array of image target.
|
sl@0
|
749 |
|
sl@0
|
750 |
@param aHandle A valid handle to a RDirectGdiImageTarget object.
|
sl@0
|
751 |
@return A pointer to a CDirectGdiImageTargetImpl object that the handle represents.
|
sl@0
|
752 |
*/
|
sl@0
|
753 |
CDirectGdiImageTargetImpl* CDirectGdiDriverImpl::GetImageTargetFromHandle(TInt aHandle) const
|
sl@0
|
754 |
{
|
sl@0
|
755 |
#ifdef _DEBUG
|
sl@0
|
756 |
CheckTargetIsValid(aHandle);
|
sl@0
|
757 |
#endif // _DEBUG
|
sl@0
|
758 |
|
sl@0
|
759 |
CDirectGdiImageTargetImpl* target = reinterpret_cast<CDirectGdiImageTargetImpl*>(aHandle);
|
sl@0
|
760 |
return target;
|
sl@0
|
761 |
}
|
sl@0
|
762 |
|
sl@0
|
763 |
/**
|
sl@0
|
764 |
Allows the engine to check whether a resource is an image source or not, given its handle.
|
sl@0
|
765 |
If the image is an image source, it will be in the array of image sources.
|
sl@0
|
766 |
|
sl@0
|
767 |
@param aHandle The handle to check for being an image source.
|
sl@0
|
768 |
@return ETrue if the passed handle is for an image source, EFalse otherwise.
|
sl@0
|
769 |
*/
|
sl@0
|
770 |
TBool CDirectGdiDriverImpl::IsImageSource(TInt aHandle) const
|
sl@0
|
771 |
{
|
sl@0
|
772 |
CDirectGdiImageRef* source = reinterpret_cast<CDirectGdiImageRef*>(aHandle);
|
sl@0
|
773 |
TInt index = -1;
|
sl@0
|
774 |
return (iSourceArray.FindInAddressOrder(source, index) == KErrNone);
|
sl@0
|
775 |
}
|
sl@0
|
776 |
|
sl@0
|
777 |
#ifdef _DEBUG
|
sl@0
|
778 |
/**
|
sl@0
|
779 |
Debug-only helper function to check that a source object has been created by this driver.
|
sl@0
|
780 |
If it has been created by this driver it will exist in the source array.
|
sl@0
|
781 |
|
sl@0
|
782 |
@panic DGDIAdapter 32, if the source can not be found in the source array.
|
sl@0
|
783 |
*/
|
sl@0
|
784 |
void CDirectGdiDriverImpl::CheckSourceIsValid(TInt aHandle) const
|
sl@0
|
785 |
{
|
sl@0
|
786 |
// Debug only check to make sure the handle exists in the array of source objects
|
sl@0
|
787 |
// that have been created by this driver
|
sl@0
|
788 |
CDirectGdiImageRef* source = reinterpret_cast<CDirectGdiImageRef*>(aHandle);
|
sl@0
|
789 |
TInt index = -1;
|
sl@0
|
790 |
TInt err = iSourceArray.FindInAddressOrder(source, index);
|
sl@0
|
791 |
GRAPHICS_ASSERT_ALWAYS(err == KErrNone, EDirectGdiPanicResourceHandleNotFound);
|
sl@0
|
792 |
}
|
sl@0
|
793 |
|
sl@0
|
794 |
/**
|
sl@0
|
795 |
Debug-only helper function to check that a target object has been created by this driver.
|
sl@0
|
796 |
If it has been created by this driver it will exist in the target array.
|
sl@0
|
797 |
|
sl@0
|
798 |
@panic DGDIAdapter 32, if the target is not found in the target array.
|
sl@0
|
799 |
*/
|
sl@0
|
800 |
void CDirectGdiDriverImpl::CheckTargetIsValid(TInt aHandle) const
|
sl@0
|
801 |
{
|
sl@0
|
802 |
// Debug only check to make sure the handle exists in the array of target objects
|
sl@0
|
803 |
// that have been created by this driver
|
sl@0
|
804 |
CDirectGdiImageRef* target = reinterpret_cast<CDirectGdiImageRef*>(aHandle);
|
sl@0
|
805 |
TInt index = -1;
|
sl@0
|
806 |
TInt err = iTargetArray.FindInAddressOrder(target, index);
|
sl@0
|
807 |
GRAPHICS_ASSERT_ALWAYS(err == KErrNone, EDirectGdiPanicResourceHandleNotFound);
|
sl@0
|
808 |
}
|
sl@0
|
809 |
#endif // _DEBUG
|
sl@0
|
810 |
|
sl@0
|
811 |
// VGImage cache APIs
|
sl@0
|
812 |
|
sl@0
|
813 |
/**
|
sl@0
|
814 |
@see CVgImageCache::GetVgImageFromCache()
|
sl@0
|
815 |
*/
|
sl@0
|
816 |
VGImage CDirectGdiDriverImpl::GetVgImageFromCache(const CFbsBitmap& aBitmap, const TPoint& aOrigin) const
|
sl@0
|
817 |
{
|
sl@0
|
818 |
return iVgImageCache->GetVgImageFromBitmap(aBitmap, aOrigin);
|
sl@0
|
819 |
}
|
sl@0
|
820 |
|
sl@0
|
821 |
/**
|
sl@0
|
822 |
@see CVgImageCache::AddImage()
|
sl@0
|
823 |
*/
|
sl@0
|
824 |
TBool CDirectGdiDriverImpl::AddVgImageToCache(const CFbsBitmap& aBitmap, VGImage& aImage, const TPoint& aOrigin)
|
sl@0
|
825 |
{
|
sl@0
|
826 |
return iVgImageCache->AddImage(aBitmap, aImage, aOrigin);
|
sl@0
|
827 |
}
|
sl@0
|
828 |
|
sl@0
|
829 |
/**
|
sl@0
|
830 |
Gets the VGImage cache.
|
sl@0
|
831 |
@return The VGImage cache.
|
sl@0
|
832 |
*/
|
sl@0
|
833 |
CVgImageCache* CDirectGdiDriverImpl::VgImageCache() const
|
sl@0
|
834 |
{
|
sl@0
|
835 |
return iVgImageCache;
|
sl@0
|
836 |
}
|
sl@0
|
837 |
|
sl@0
|
838 |
/**
|
sl@0
|
839 |
Gets the Glyph image storage.
|
sl@0
|
840 |
@return The Glyph image storage.
|
sl@0
|
841 |
*/
|
sl@0
|
842 |
CFontGlyphImageStorage* CDirectGdiDriverImpl::FontGlyphImageStorage() const
|
sl@0
|
843 |
{
|
sl@0
|
844 |
return iGlyphImageStorage;
|
sl@0
|
845 |
}
|
sl@0
|
846 |
|
sl@0
|
847 |
/**
|
sl@0
|
848 |
Creates VG images which will be used to draw glyphs if the system runs out of memory
|
sl@0
|
849 |
*/
|
sl@0
|
850 |
TInt CDirectGdiDriverImpl::PreAllocateFontGlyphImages()
|
sl@0
|
851 |
{
|
sl@0
|
852 |
TInt res = KErrNotReady;
|
sl@0
|
853 |
if(iGlyphImageStorage)
|
sl@0
|
854 |
{
|
sl@0
|
855 |
res = iGlyphImageStorage->PreAllocateImages();
|
sl@0
|
856 |
if(res == KErrNoMemory)
|
sl@0
|
857 |
{//try to clean bitmap cache
|
sl@0
|
858 |
iVgImageCache->ResetCache();
|
sl@0
|
859 |
res = iGlyphImageStorage->PreAllocateImages();
|
sl@0
|
860 |
if(res == KErrNoMemory)
|
sl@0
|
861 |
{//try to clean glyph image cache
|
sl@0
|
862 |
iGlyphImageStorage->CleanGlyphImageCache();
|
sl@0
|
863 |
res = iGlyphImageStorage->PreAllocateImages();
|
sl@0
|
864 |
}
|
sl@0
|
865 |
}
|
sl@0
|
866 |
}
|
sl@0
|
867 |
return res;
|
sl@0
|
868 |
}
|
sl@0
|
869 |
|
sl@0
|
870 |
/**
|
sl@0
|
871 |
Registers the image source with this driver, by adding it to a list of internal image sources.
|
sl@0
|
872 |
@param aImage The image to register.
|
sl@0
|
873 |
@return KErrNone if successful, otherwise on of the system-wide error codes.
|
sl@0
|
874 |
*/
|
sl@0
|
875 |
TInt CDirectGdiDriverImpl::RegisterSourceImage(const CDirectGdiImageSourceImpl& aImage)
|
sl@0
|
876 |
{
|
sl@0
|
877 |
return iSourceArray.InsertInAddressOrder(&aImage);
|
sl@0
|
878 |
}
|
sl@0
|
879 |
|
sl@0
|
880 |
/**
|
sl@0
|
881 |
Registers the image target with this driver, by adding it to a list of internal image targets.
|
sl@0
|
882 |
@param aImage The image to register.
|
sl@0
|
883 |
@return KErrNone if successful, otherwise on of the system-wide error codes.
|
sl@0
|
884 |
*/
|
sl@0
|
885 |
TInt CDirectGdiDriverImpl::RegisterTargetImage(const CDirectGdiImageTargetImpl& aImage)
|
sl@0
|
886 |
{
|
sl@0
|
887 |
return iTargetArray.InsertInAddressOrder(&aImage);
|
sl@0
|
888 |
}
|
sl@0
|
889 |
|
sl@0
|
890 |
/**
|
sl@0
|
891 |
@see MDirectGdiDriverCacheSize::SetMaxImageCacheSize()
|
sl@0
|
892 |
*/
|
sl@0
|
893 |
TInt CDirectGdiDriverImpl::SetMaxImageCacheSize(TInt aSize)
|
sl@0
|
894 |
{
|
sl@0
|
895 |
return iVgImageCache->SetMaxCacheSize(aSize);
|
sl@0
|
896 |
}
|
sl@0
|
897 |
|
sl@0
|
898 |
/**
|
sl@0
|
899 |
@see MDirectGdiDriverCacheSize::MaxImageCacheSize()
|
sl@0
|
900 |
*/
|
sl@0
|
901 |
TInt CDirectGdiDriverImpl::MaxImageCacheSize() const
|
sl@0
|
902 |
{
|
sl@0
|
903 |
return iVgImageCache->MaxCacheSize();
|
sl@0
|
904 |
}
|
sl@0
|
905 |
|
sl@0
|
906 |
/**
|
sl@0
|
907 |
@see MDirectGdiDriverCacheSize::SetMaxGlyphCacheSize()
|
sl@0
|
908 |
*/
|
sl@0
|
909 |
TInt CDirectGdiDriverImpl::SetMaxGlyphCacheSize(TInt aSize)
|
sl@0
|
910 |
{
|
sl@0
|
911 |
return iGlyphImageStorage->SetMaxGlyphCacheSize(aSize);
|
sl@0
|
912 |
}
|
sl@0
|
913 |
|
sl@0
|
914 |
/**
|
sl@0
|
915 |
@see MDirectGdiDriverCacheSize::MaxGlyphCacheSize()
|
sl@0
|
916 |
*/
|
sl@0
|
917 |
TInt CDirectGdiDriverImpl::MaxGlyphCacheSize() const
|
sl@0
|
918 |
{
|
sl@0
|
919 |
return iGlyphImageStorage->MaxGlyphCacheSize();
|
sl@0
|
920 |
}
|