os/graphics/graphicsdeviceinterface/directgdiadaptation/hwsrc/directgdidriverimpl.cpp
Update contrib.
1 // Copyright (c) 2007-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.
16 #include "directgdidriverimpl.h"
17 #include "directgdiimagetargetimpl.h"
18 #include "directgdiimagesourceimpl.h"
19 #include "directgdiadapter.h"
20 #include "directgdiimageref.h"
22 #include "confighelper.h"
23 #include <graphics/directgdiimagetarget.h>
24 #include <graphics/sgresource.h>
29 // Static member variable
30 XDirectGdiDriverProcessState CDirectGdiDriverImpl::gProcessState;
34 Handles an EGL failure. It may either set the passed-in TInt to a Symbian OS-mapped error code,
35 or panic the specified panic code, depending on the egl failure. Done as a macro so the line number is reported.
37 #define HANDLE_EGL_ERROR(err, panic) \
39 const EGLint eglError = eglGetError(); \
40 if (eglError == EGL_BAD_ALLOC) \
42 else if (eglError == EGL_CONTEXT_LOST) \
44 else if (eglError != EGL_SUCCESS) \
46 TBuf16<256> _message; \
47 _message.Format(_L16("EGL Error: %x\n"), eglError); \
48 GRAPHICS_LOGD_DEBUG(_message); \
49 GRAPHICS_ASSERT_DEBUG(eglError == EGL_SUCCESS, panic); \
54 Populates the config hash map with matching EGL configs, based on the supported pixel types.
56 @param aDisplay A valid EGL display to retrieve EGL configs for.
58 @panic DGDIAdapter 24, if no suitable EGL configs are present (debug-only).
59 @panic DGDIAdapter 25, if no exact matching EGL config can be found.
60 @panic DGDIAdapter 29, if RSgImage::GetPixelFormats returns pixel count <= 0.
62 @pre EGL has been initialised by eglInitialize().
63 @post The supported EGL configs are stored in the hash map.
65 @return KErrNoError if successful, KErrNotReady if EGL was not initialised, otherwise one of the
66 system-wide error codes.
68 TInt CDirectGdiDriverImpl::InitializeEglConfigs(EGLDisplay aDisplay)
70 #ifdef _DEBUG_DIRECTGDI
71 GRAPHICS_LOG_DEBUG("InitializeEglConfigs");
75 // Get EGL configs upfront and store them in a hash map
76 EGLint configSize = 0;
77 EGLConfig *configs = NULL;
79 // Query RsgImage for the number of supported target pixel formats. Then we know how much memory should be
80 // allocated to the pixelformats array.
82 TSgImageInfo imageInfo;
83 imageInfo.iUsage = ESgUsageDirectGdiTarget;
84 imageInfo.iSizeInPixels = TSize(1,1);
85 TUidPixelFormat* pixelFormats = NULL;
86 err = RSgImage::GetPixelFormats(imageInfo, NULL, count);
87 GRAPHICS_ASSERT_DEBUG(count > 0, EDirectGdiPanicNoValidPixelFormats);
91 pixelFormats = new TUidPixelFormat[count];
92 if (pixelFormats == NULL)
100 err = RSgImage::GetPixelFormats(imageInfo, pixelFormats, count);
101 if (!eglGetConfigs(aDisplay, configs, 0, &configSize) && configSize)
103 HANDLE_EGL_ERROR(err, EDirectGdiPanicNoAvailableConfigs);
109 configs = new EGLConfig[configSize];
116 for (TInt i = 0; (i < count) && (err == KErrNone); ++i)
118 // Finds a suitable config to map to this bitmap.
119 TInt selPixmapAttribs = TConfigHelper::MatchPixelType(pixelFormats[i]);
120 EGLint numConfigs = 0;
121 if (!eglChooseConfig(aDisplay, TConfigHelper::KSurfaceAttribs[selPixmapAttribs], configs, configSize, &numConfigs))
123 HANDLE_EGL_ERROR(err, EDirectGdiPanicNoMatchingConfig);
126 GRAPHICS_ASSERT_ALWAYS(numConfigs >= 1, EDirectGdiPanicNoAvailableConfigs);
127 // Find an exact matching config from the available configs.
128 TInt match = TConfigHelper::GetSuitablePixmapConfigIndex(aDisplay, configs, numConfigs, selPixmapAttribs);
129 GRAPHICS_ASSERT_ALWAYS(match >= 0, EDirectGdiPanicNoMatchingConfig);
130 EGLConfig currentConfig = configs[match];
132 // Store this matching config and the pixel type in the hash map.
133 err = iPixelConfigMap.Insert(selPixmapAttribs, currentConfig);
137 delete [] pixelFormats;
143 Constructor to allocate memory to CDirectGdiDriverImpl object.
145 @param aInternal On success, will store a pointer to the newly created CDirectGdiDriverImpl.
147 @return KErrNone if successful, otherwise one of the system-wide error codes.
149 TInt CDirectGdiDriverImpl::New(CDirectGdiDriverInternal*& aInternal, RLibrary aLibrary)
151 CDirectGdiDriverImpl* self = new CDirectGdiDriverImpl(aLibrary);
154 TInt err = self->Construct();
166 Destructor - frees the memory for the hashmaps and the source and target arrays.
168 @panic DGDIAdapter 45, if images are still in the source or target image array (debug-only).
170 CDirectGdiDriverImpl::~CDirectGdiDriverImpl()
172 // Check that there are no drawbles left in the drawable array
173 GRAPHICS_ASSERT_DEBUG(iSourceArray.Count() == 0, EDirectGdiPanicItemsLeftInImageArray);
174 GRAPHICS_ASSERT_DEBUG(iTargetArray.Count() == 0, EDirectGdiPanicItemsLeftInImageArray);
176 iSourceArray.Close();
177 iTargetArray.Close();
179 delete iVgImageCache;
181 THashMapIter<TInt, EGLContext> contextIter(iPixelContextMap);
182 const EGLContext* context = contextIter.NextValue();
185 eglDestroyContext(iDisplay, *context);
186 context = contextIter.NextValue();
188 iPixelContextMap.Close();
189 iPixelConfigMap.Close();
190 delete iGlyphImageStorage;
192 eglMakeCurrent(iDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
193 // This will terminate the display if it is the last driver.
194 ProcessState().CloseDriver(iDisplay);
201 @see CDirectGdiDriver::Flush()
203 void CDirectGdiDriverImpl::Flush()
209 @see CDirectGdiDriver::Finish()
211 void CDirectGdiDriverImpl::Finish()
213 // Call eglWaitClient() instead of vgFinish() because MBX EGL implementation currently
214 // does nothing with a vgFinish().
215 if (eglWaitClient() == EGL_FALSE)
218 HANDLE_EGL_ERROR(err, EDirectGdiPanicFinish);
225 @see CDirectGdiDriver::GetError()
227 If no error has been reported explicitly, or SetError() has not been called, it will instead return
228 the first (if any) OpenVG error to occur since GetError() was last called.
230 TInt CDirectGdiDriverImpl::GetError()
232 // Call vgGetError() even when iErrorCode is already set, so that any OpenVG error state is
233 // cleared and not reported in future.
234 const TInt vgErrorCode = GetVgError();
236 if (iErrorCode == KErrNone)
238 iErrorCode = vgErrorCode;
240 TInt error = iErrorCode;
241 iErrorCode = KErrNone;
246 @see CDirectGdiDriver::CreateDrawableSource()
248 For image resource creates a DirectGDI adaptation-specific resource from the given RSgDrawable resource so
249 it can be drawn using the DirectGDI rendering API. Creates an EGLImage, then a VGImage from the
250 passed RSgImage and associates the new source with these images. Sources that are successfully created
251 are added to an array of sources so that they can be closed and deleted correctly at a later stage.
252 Note that an image source cannot be created before an image target has been created and activated.
253 This is a limitation of OpenVG as a VG context must exist before an image source can be created.
255 @param aHandleRet Handle of newly created drawable source, must be KNullHandle (is checked by generic driver).
256 @param aSgDrawable The RSgDrawable object to use when creating the drawable source. An attempt is made to
257 match the pixel format of the new EGL surface with the pixel format of this RSgImage.
259 @pre CDirectGdiDriver object has been initialised from the calling thread and a target has been activated.
260 aHandleRet is KNullHandle.
261 @post The DirectGDI adaptation-specific resource that is bound to the given
262 drawable resource is created and this handle is now associated with it. The reference
263 counter on the drawable resource is incremented. The CDirectGdiDriver for this thread
264 is now aware of and owns the adaptation-specific resource.
266 @return KErrNone if successful, KErrArgument if the drawable resource is not valid,
267 KErrNotSupported if the drawable resource is not created with the type (KSgImageTypeUid),
268 otherwise one of the system-wide error codes.
270 TInt CDirectGdiDriverImpl::CreateDrawableSource(TInt& aHandleRet, const RSgDrawable& aSgDrawable)
272 TUid typeUid = aSgDrawable.DrawableType();
273 if(typeUid != KSgImageTypeUid)
275 return KErrNotSupported;
277 const RSgImage* image = reinterpret_cast<const RSgImage*>(&aSgDrawable);
278 CDirectGdiImageSourceImpl* imageSource = NULL;
279 TInt err = CDirectGdiImageSourceImpl::New(imageSource, *this, *image);
283 aHandleRet = reinterpret_cast<TInt>(imageSource);
290 @see CDirectGdiDriver::CreateDrawableSource()
292 Destroys the DirectGDI adaptation-specific resource associated with this handle.
293 Calling this method on a handle that is not associated with any DirectGDI specific
294 resource will do nothing. Once Close() is called, this handle can be reused. The handle
295 is set to KNullHandle.
297 @param aHandle A reference to a valid handle to a RDirectGdiDrawableSource object which is
300 @pre CDirectGdiDriver object has been initialised from the calling thread.
301 @post The DirectGDI adaptation-specific resource associated with this handle will
302 be destroyed (at any time preferred by the adaptation). This handle is no longer
303 associated with a DirectGDI adaptation-specific resource. The reference counter of
304 the underlying drawable resource is decremented. aHandle is set to KNullHandle.
306 @panic DGDIAdapter 37, if an image source cannot be created from the passed handle.
308 void CDirectGdiDriverImpl::CloseDrawableSource(TInt& aHandle)
310 CDirectGdiImageSourceImpl* imageSource = GetImageSourceFromHandle(aHandle);
311 GRAPHICS_ASSERT_ALWAYS(imageSource, EDirectGdiPanicCloseDrawableHandleFailure);
313 // Decrement the reference count on this image source. If it reaches zero, it will
314 // remove itself from the source array and delete itself.
315 imageSource->Close();
316 aHandle = KNullHandle;
321 @see CDirectGdiDriver::CreateImageTarget()
323 Allocates and constructs a CDirectGdiImageTargetImpl object, and associates it with aHandleRet.
325 @param aHandleRet Handle of newly created Image Target, must be KNullHandle (is checked by generic driver).
326 @param aSgImage The RSgImage to associate with the created image target. An attempt is made to match
327 the pixel format of the new EGL surface with the pixel format of this RSgImage.
329 @pre CDirectGdiDriver object has been initialised from the calling thread.
330 The image resource has been fully constructed and created with the correct usage
331 that allows it to be used as a DirectGDI target. aHandleRet is KNullHandle.
333 @post The DirectGDI adaptation-specific resource that is bound to the given image
334 resource is created and this handle is now associated with it. The reference counter
335 on the image resource is incremented.
337 @return KErrNone if successful, KErrArgument if the image resource is not valid,
338 KErrNotSupported if the image resource is not created with the correct
339 usage, otherwise one of the system-wide error codes.
341 TInt CDirectGdiDriverImpl::CreateImageTarget(TInt& aHandleRet, const RSgImage& aSgImage)
343 CDirectGdiImageTargetImpl* imageTarget = NULL;
344 TInt err = CDirectGdiImageTargetImpl::New(imageTarget, *this, aSgImage, iPixelContextMap, iPixelConfigMap, iSharedContext);
348 // Return the handle to the newly created image target.
349 aHandleRet = reinterpret_cast<TInt>(imageTarget);
356 Destroys the DirectGDI adaptation-specific resource associated with this handle.
357 Calling this method on a handle that is not associated with any DirectGDI adaptation-
358 specific resource will do nothing. Once Close() is called, this handle can be reused.
360 @param aHandle A handle to a RDirectGdiImageTarget object to be closed.
362 @pre CDirectGdiDriver object has been initialised from the calling thread.
364 @post The DirectGDI specific resource associated with this handle will be destroyed
365 if the reference count falls to zero. This handle is no longer associated with
366 a DirectGDI specific resource. The reference counter of the underlying image
367 resource is decremented. aHandle is set to KNullHandle.
369 @panic DGDIAdapter 37, if the image source associated with aHandle is NULL.
371 void CDirectGdiDriverImpl::CloseImageTarget(TInt& aHandle)
373 CDirectGdiImageTargetImpl* imageTarget = GetImageTargetFromHandle(aHandle);
374 GRAPHICS_ASSERT_ALWAYS(imageTarget, EDirectGdiPanicCloseDrawableHandleFailure);
376 // Decrement the reference count on this image target. If the reference count reaches zero,
377 // it is deleted and removed from the targets array.
378 imageTarget->Close();
379 aHandle = KNullHandle;
383 Instantiates an adaptation-specific rendering engine.
385 @param aDirectGdiEngine Reference to instantiated engine.
387 @pre CDirectGdiDriver object has been initialised from the calling thread.
389 @return KErrNone if the engine is constructed, else KErrNoMemory.
391 TInt CDirectGdiDriverImpl::CreateEngine(MDirectGdiEngine*& aDirectGdiEngine)
393 TInt result = KErrNone;
394 aDirectGdiEngine = new CVgEngine(*this);
395 if (aDirectGdiEngine == NULL)
397 result = KErrNoMemory;
403 Unbinds target from rendering engine and marks it for deletion.
404 NOTE: Currently this means just deleting the engine.
406 @param aDirectGdiEngine Engine to operate on.
408 @pre CDirectGdiDriver object has been initialised from the calling thread.
410 @panic DGDIAdapter 38, if the engine is NULL.
412 void CDirectGdiDriverImpl::DestroyEngine(MDirectGdiEngine* aDirectGdiEngine)
414 GRAPHICS_ASSERT_ALWAYS(aDirectGdiEngine, EDirectGdiPanicDestroyNullEngine);
415 CVgEngine* actualEngine = static_cast<CVgEngine*>(aDirectGdiEngine);
420 The only extension interface supported by this implementation is MDirectGdiDriverCacheSize.
422 @see CDirectGdiDriver::GetInterface()
424 TInt CDirectGdiDriverImpl::GetInterface(TUid aInterfaceId, TAny*& aInterface)
428 switch (aInterfaceId.iUid)
430 case KDirectGdiDriverCacheSizeUid:
432 aInterface = static_cast<MDirectGdiDriverCacheSize*>(this);
436 err = KErrExtensionNotSupported;
442 CDirectGdiDriverImpl::CDirectGdiDriverImpl(RLibrary aLibrary)
443 : CDirectGdiDriverInternal(aLibrary),
444 iDisplay(EGL_NO_DISPLAY)
448 Performs the second phase of construction.
450 @pre CDirectGdiDriver object has been initialised from the calling thread.
451 @post EGL has been initialised. SgDriver has been opened.
453 @panic DGDIAdapter 36, if eglGetDisplay() fails.
454 @panic DGDIAdapter 35, if eglInitialize() fails.
455 @panic DGDIAdapter 23, if eglBindAPI() fails.
456 @return KErrNone if successful, KErrNotFound if no implementation of the Graphics Resource API is found,
457 KErrNotSupported if the version of EGL is less than required (1.2), otherwise one of the
458 system-wide error codes.
460 TInt CDirectGdiDriverImpl::Construct()
463 iSharedContext = EGL_NO_CONTEXT;
465 // First thing is to check whether the mutex for the Process State was successfully created.
466 // If not, it's a fatal error. If it is, we must increment the reference count on the mutex as
467 // early as possible to make the creation/destruction of the display thread-safe.
468 err = ProcessState().MutexCreationStatus();
471 ProcessState().OpenDriver();
476 err = SgDriver::Open();
481 // Create display object
482 iDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
483 GRAPHICS_ASSERT_ALWAYS(iDisplay != EGL_NO_DISPLAY, EDirectGdiPanicNoDisplay);
485 // Initialise the display. If it is already initialised, EGL will return quickly.
487 if (!eglInitialize(iDisplay, &major, &minor))
489 iDisplay = EGL_NO_DISPLAY;
490 HANDLE_EGL_ERROR(err, EDirectGdiPanicInitializeDisplay);
492 else if (major < 1 || (major == 1 && minor < 2))
494 // Atleast EGL 1.2 needs to be available.
495 err = KErrNotSupported;
501 // Let EGL know we will use it for OpenVG
502 if(!eglBindAPI(EGL_OPENVG_API))
504 HANDLE_EGL_ERROR(err, EDirectGdiPanicBindApi);
510 iGlyphImageStorage = new CFontGlyphImageStorage(KDirectGdiAdapterDefaultMaxGlyphImageCacheSize);
511 if(!iGlyphImageStorage)
519 iVgImageCache = new CVgImageCache(KDirectGdiAdapterDefaultMaxImageCacheSize);
528 err = ProcessState().Initialize(iDisplay);
533 err = InitializeEglConfigs(iDisplay);
540 @see CDirectGdiDriver::SetError()
542 In the event that OpenVG's error state has been set, it will be used as the driver's error state,
545 @param aErr The error code to be set.
546 @pre CDirectGdiDriver object has been initialised from the calling thread.
547 @post The error state is set to the current OpenVG error state, otherwise aErr, if the current error state
550 void CDirectGdiDriverImpl::SetError(TInt aErr)
552 if( iErrorCode == KErrNone )
554 iErrorCode = GetVgError();
555 if (iErrorCode == KErrNone)
563 Static function. Converts the current OpenVG error state (if any) to a standard Symbian error code.
565 @panic DGDIAdapter 64, if the error code received from OpenVG is due to misuse of OpenVG rather
566 than a runtime error.
567 @return KErrGeneral if the OpenVG error code not recognised, otherwise a system-wide error
568 code converted from the OpenVG error code.
570 TInt CDirectGdiDriverImpl::GetVgError()
572 TInt error = KErrGeneral;
578 case VG_BAD_HANDLE_ERROR:
579 error = KErrBadHandle;
581 case VG_ILLEGAL_ARGUMENT_ERROR:
582 error = KErrArgument;
584 case VG_OUT_OF_MEMORY_ERROR:
585 error = KErrNoMemory;
588 // Any other error is due to DirectGDI using OpenVG incorrectly somewhere.
589 GRAPHICS_PANIC_DEBUG(EDirectGdiPanicVgError);
595 Sets the current engine as the most recent engine which has been activated.
597 @param aCurrentEngine The pointer to the most recent engine.
599 void CDirectGdiDriverImpl::SetCurrentEngine(CVgEngine* aCurrentEngine)
601 iCurrentEngine = aCurrentEngine;
605 Checks whether the given engine is current or not, so that the OpenVG state can be reset.
607 @param aCurrentEngine The pointer to an engine.
608 @return ETrue if it is the current engine, else EFalse.
610 TBool CDirectGdiDriverImpl::IsCurrentEngine(const CVgEngine* aCurrentEngine) const
612 return (iCurrentEngine == aCurrentEngine);
616 Checks whether this target is current or not, so that the EGL state can be reset.
618 @param aCurrentTarget The pointer to a target.
619 @return ETrue if it is the current target, else EFalse.
621 TBool CDirectGdiDriverImpl::IsCurrentTarget(const CDirectGdiImageTargetImpl* aCurrentTarget) const
623 return (iCurrentTarget == aCurrentTarget);
627 Sets the current target as the most recent target which has been activated.
629 @param aCurrentTarget The pointer to the most recent target.
631 void CDirectGdiDriverImpl::SetCurrentTarget(CDirectGdiImageTargetImpl* aCurrentTarget)
633 iCurrentTarget = aCurrentTarget;
637 Activates the specified target and increments its reference count as it can be shared across many
640 @param aRenderingTarget The target object which is to be activated.
642 void CDirectGdiDriverImpl::Activate(CDirectGdiImageTargetImpl* aRenderingTarget)
644 // Reactivate() does the same activation
645 Reactivate(aRenderingTarget);
646 aRenderingTarget->Open();
650 Reactivates the specified target, without affecting its reference count.
652 @param aRenderingTarget The target to be reactivated.
654 @panic DGDIAdapter 2, if eglGetError() returns an error we can't handle.
656 void CDirectGdiDriverImpl::Reactivate(CDirectGdiImageTargetImpl* aRenderingTarget)
658 if(!aRenderingTarget->Activate())
660 TInt error = KErrNone;
661 HANDLE_EGL_ERROR(error, EDirectGdiPanicUnexpectedError);
662 if(error == KErrNoMemory)
666 // Can check here whether error == KErrDied, which signifies an EGL_CONTEXT_LOST error.
667 // due to a power management event. Then need to destroy and recreate all EGLContexts used.
668 // This is not implemented as the EGL used with this reference adaptation does not produce this error.
669 // Following pseudocode will achieve this:
670 // 1. For each context stored in iPixelMapContext:
671 // 1a. Destroy context.
672 // 1b. Create replacement context with same parameters.
673 // 1c. Search through all rendering targets replacing the context stored (if it matches with the one just destroyed) with the new one.
674 // 2. Try activating the rendering target again.
679 Deactivates the target if it was the current target, and decrements its reference count as it can
680 be shared across many DirectGDI contexts.
682 @param aRenderingTarget The target object which you want to deactivate.
684 void CDirectGdiDriverImpl::Deactivate(CDirectGdiImageTargetImpl* aRenderingTarget)
686 aRenderingTarget->Close();
690 Helper function for removing a pointer to a CDirectGdiImageRef object from the source image array.
691 @param aImage A pointer to a CDirectGdiImageRef source object.
692 @return KErrNone if successful, KErrNotFound if no suitable object pointer can be found,
693 otherwise one of the other system wide error codes.
695 TInt CDirectGdiDriverImpl::UnregisterSourceImage(const CDirectGdiImageSourceImpl& aImage)
698 TInt err = iSourceArray.FindInAddressOrder(&aImage, index);
701 iSourceArray.Remove(index);
702 iSourceArray.GranularCompress();
709 Helper function for removing a pointer to a CDirectGdiImageRef object from the target image array.
710 @param aImage A pointer to a CDirectGdiImageRef source object.
711 @return KErrNone if successful, KErrNotFound if no suitable object pointer can be found,
712 otherwise one of the other system wide error codes.
714 TInt CDirectGdiDriverImpl::UnregisterTargetImage(const CDirectGdiImageTargetImpl& aImage)
717 TInt err = iTargetArray.FindInAddressOrder(&aImage, index);
720 iTargetArray.Remove(index);
721 iTargetArray.GranularCompress();
728 Helper function to convert a handle for a RDirectGdiDrawableSource object to a CDirectGdiImageSourceImpl
729 object. In debug builds, it also checks that the image source was actually created by this driver and
730 exists in the array of image sources.
732 @param aHandle A valid handle to a RDirectGdiDrawableSource object.
733 @return A pointer to a CDirectGdiImageSourceImpl object that the handle represents.
735 CDirectGdiImageSourceImpl* CDirectGdiDriverImpl::GetImageSourceFromHandle(TInt aHandle) const
738 CheckSourceIsValid(aHandle);
741 CDirectGdiImageSourceImpl* source = reinterpret_cast<CDirectGdiImageSourceImpl*>(aHandle);
746 Helper function to convert a handle for a RDirectGdiImageTarget object to a CDirectGdiImageTargetImpl
747 object. In debug builds, it also checks that the image target was actually created by this driver and
748 exists in the array of image target.
750 @param aHandle A valid handle to a RDirectGdiImageTarget object.
751 @return A pointer to a CDirectGdiImageTargetImpl object that the handle represents.
753 CDirectGdiImageTargetImpl* CDirectGdiDriverImpl::GetImageTargetFromHandle(TInt aHandle) const
756 CheckTargetIsValid(aHandle);
759 CDirectGdiImageTargetImpl* target = reinterpret_cast<CDirectGdiImageTargetImpl*>(aHandle);
764 Allows the engine to check whether a resource is an image source or not, given its handle.
765 If the image is an image source, it will be in the array of image sources.
767 @param aHandle The handle to check for being an image source.
768 @return ETrue if the passed handle is for an image source, EFalse otherwise.
770 TBool CDirectGdiDriverImpl::IsImageSource(TInt aHandle) const
772 CDirectGdiImageRef* source = reinterpret_cast<CDirectGdiImageRef*>(aHandle);
774 return (iSourceArray.FindInAddressOrder(source, index) == KErrNone);
779 Debug-only helper function to check that a source object has been created by this driver.
780 If it has been created by this driver it will exist in the source array.
782 @panic DGDIAdapter 32, if the source can not be found in the source array.
784 void CDirectGdiDriverImpl::CheckSourceIsValid(TInt aHandle) const
786 // Debug only check to make sure the handle exists in the array of source objects
787 // that have been created by this driver
788 CDirectGdiImageRef* source = reinterpret_cast<CDirectGdiImageRef*>(aHandle);
790 TInt err = iSourceArray.FindInAddressOrder(source, index);
791 GRAPHICS_ASSERT_ALWAYS(err == KErrNone, EDirectGdiPanicResourceHandleNotFound);
795 Debug-only helper function to check that a target object has been created by this driver.
796 If it has been created by this driver it will exist in the target array.
798 @panic DGDIAdapter 32, if the target is not found in the target array.
800 void CDirectGdiDriverImpl::CheckTargetIsValid(TInt aHandle) const
802 // Debug only check to make sure the handle exists in the array of target objects
803 // that have been created by this driver
804 CDirectGdiImageRef* target = reinterpret_cast<CDirectGdiImageRef*>(aHandle);
806 TInt err = iTargetArray.FindInAddressOrder(target, index);
807 GRAPHICS_ASSERT_ALWAYS(err == KErrNone, EDirectGdiPanicResourceHandleNotFound);
811 // VGImage cache APIs
814 @see CVgImageCache::GetVgImageFromCache()
816 VGImage CDirectGdiDriverImpl::GetVgImageFromCache(const CFbsBitmap& aBitmap, const TPoint& aOrigin) const
818 return iVgImageCache->GetVgImageFromBitmap(aBitmap, aOrigin);
822 @see CVgImageCache::AddImage()
824 TBool CDirectGdiDriverImpl::AddVgImageToCache(const CFbsBitmap& aBitmap, VGImage& aImage, const TPoint& aOrigin)
826 return iVgImageCache->AddImage(aBitmap, aImage, aOrigin);
830 Gets the VGImage cache.
831 @return The VGImage cache.
833 CVgImageCache* CDirectGdiDriverImpl::VgImageCache() const
835 return iVgImageCache;
839 Gets the Glyph image storage.
840 @return The Glyph image storage.
842 CFontGlyphImageStorage* CDirectGdiDriverImpl::FontGlyphImageStorage() const
844 return iGlyphImageStorage;
848 Creates VG images which will be used to draw glyphs if the system runs out of memory
850 TInt CDirectGdiDriverImpl::PreAllocateFontGlyphImages()
852 TInt res = KErrNotReady;
853 if(iGlyphImageStorage)
855 res = iGlyphImageStorage->PreAllocateImages();
856 if(res == KErrNoMemory)
857 {//try to clean bitmap cache
858 iVgImageCache->ResetCache();
859 res = iGlyphImageStorage->PreAllocateImages();
860 if(res == KErrNoMemory)
861 {//try to clean glyph image cache
862 iGlyphImageStorage->CleanGlyphImageCache();
863 res = iGlyphImageStorage->PreAllocateImages();
871 Registers the image source with this driver, by adding it to a list of internal image sources.
872 @param aImage The image to register.
873 @return KErrNone if successful, otherwise on of the system-wide error codes.
875 TInt CDirectGdiDriverImpl::RegisterSourceImage(const CDirectGdiImageSourceImpl& aImage)
877 return iSourceArray.InsertInAddressOrder(&aImage);
881 Registers the image target with this driver, by adding it to a list of internal image targets.
882 @param aImage The image to register.
883 @return KErrNone if successful, otherwise on of the system-wide error codes.
885 TInt CDirectGdiDriverImpl::RegisterTargetImage(const CDirectGdiImageTargetImpl& aImage)
887 return iTargetArray.InsertInAddressOrder(&aImage);
891 @see MDirectGdiDriverCacheSize::SetMaxImageCacheSize()
893 TInt CDirectGdiDriverImpl::SetMaxImageCacheSize(TInt aSize)
895 return iVgImageCache->SetMaxCacheSize(aSize);
899 @see MDirectGdiDriverCacheSize::MaxImageCacheSize()
901 TInt CDirectGdiDriverImpl::MaxImageCacheSize() const
903 return iVgImageCache->MaxCacheSize();
907 @see MDirectGdiDriverCacheSize::SetMaxGlyphCacheSize()
909 TInt CDirectGdiDriverImpl::SetMaxGlyphCacheSize(TInt aSize)
911 return iGlyphImageStorage->SetMaxGlyphCacheSize(aSize);
915 @see MDirectGdiDriverCacheSize::MaxGlyphCacheSize()
917 TInt CDirectGdiDriverImpl::MaxGlyphCacheSize() const
919 return iGlyphImageStorage->MaxGlyphCacheSize();