sl@0: // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include "directgdiadapter.h" sl@0: #include "swdirectgdidriverimpl.h" sl@0: #include "swdirectgdiimagesourceimpl.h" sl@0: #include "swdirectgdiimagetargetimpl.h" sl@0: #include "pixelutil.h" sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: /** sl@0: @panic DGDIAdapter 6, if the reference count to DirectGDI driver is invalid. sl@0: @panic DGDIAdapter 45, if objects are still in the source or target image array. sl@0: */ sl@0: CSwDirectGdiDriverImpl::~CSwDirectGdiDriverImpl() sl@0: { sl@0: GRAPHICS_ASSERT_DEBUG(iEngines.Count() == 0, EDirectGdiPanicDriverInvalidRefCount); sl@0: GRAPHICS_ASSERT_DEBUG(iTargets.Count() == 0, EDirectGdiPanicItemsLeftInImageArray); sl@0: GRAPHICS_ASSERT_DEBUG(iImageSources.Count() == 0, EDirectGdiPanicItemsLeftInImageArray); sl@0: sl@0: // Delete all the engines owned by this driver sl@0: iEngines.ResetAndDestroy(); sl@0: iTargets.ResetAndDestroy(); sl@0: iImageSources.ResetAndDestroy(); sl@0: } sl@0: sl@0: /** sl@0: Constructor, which initialises base class. sl@0: */ sl@0: CSwDirectGdiDriverImpl::CSwDirectGdiDriverImpl(RLibrary aLibrary) sl@0: : CDirectGdiDriverInternal(aLibrary) sl@0: { sl@0: } sl@0: sl@0: /** sl@0: Empty function as this adaptation is synchronous. sl@0: @see CDirectGdiDriverInternal::Flush() sl@0: */ sl@0: void CSwDirectGdiDriverImpl::Flush() sl@0: { sl@0: } sl@0: sl@0: /** sl@0: Empty function as this adaptation is synchronous. sl@0: @see CDirectGdiDriverInternal::Finish() sl@0: */ sl@0: void CSwDirectGdiDriverImpl::Finish() sl@0: { sl@0: } sl@0: sl@0: /** sl@0: @see CDirectGdiDriver::GetError() sl@0: */ sl@0: TInt CSwDirectGdiDriverImpl::GetError() sl@0: { sl@0: TInt err = iErrorCode; sl@0: iErrorCode = KErrNone; sl@0: return err; sl@0: } sl@0: sl@0: /** sl@0: @see CDirectGdiDriverInternal::CloseDrawableSource() sl@0: @panic DGDIAdapter 57, if aHandleRet is not KNullHandle (debug only). sl@0: */ sl@0: TInt CSwDirectGdiDriverImpl::CreateDrawableSource(TInt& aHandleRet, const RSgDrawable& aSgDrawable) sl@0: { sl@0: TInt err = KErrNotSupported; sl@0: const TUid typeUid = aSgDrawable.DrawableType(); sl@0: if(KSgImageTypeUid == typeUid) sl@0: { sl@0: CSwDirectGdiImageSourceImpl* imageSource = NULL; sl@0: RSgImage* image = (RSgImage*) (&aSgDrawable); sl@0: err = CSwDirectGdiImageSourceImpl::New(imageSource, *this, *image); sl@0: sl@0: if (err == KErrNone) sl@0: { sl@0: aHandleRet = reinterpret_cast(imageSource); sl@0: } sl@0: } sl@0: return err; sl@0: } sl@0: sl@0: /** sl@0: @see CDirectGdiDriverInternal::CreateDrawableSource() sl@0: @panic DGDIAdapter 47, if the drawable source belonging to aHandle could not be found in the internal sl@0: list of sources (debug only). sl@0: */ sl@0: void CSwDirectGdiDriverImpl::CloseDrawableSource(TInt& aHandle) sl@0: { sl@0: // Graphics Resource and DirectGDI reference implementation only support pixel based resource sl@0: CSwDirectGdiImageSourceImpl* source = reinterpret_cast(aHandle); sl@0: if (source) sl@0: source->Close(); sl@0: aHandle = KNullHandle; sl@0: } sl@0: sl@0: /** sl@0: @see CDirectGdiDriverInternal::CreateImageTarget() sl@0: @panic DGDIAdapter 58, if aHandleRet is not KNullHandle (debug only). sl@0: @panic DGDIAdapter 1023, if the attempt to get an RSgImage interface MSgImage_Sw failed. sl@0: */ sl@0: TInt CSwDirectGdiDriverImpl::CreateImageTarget(TInt& aHandleRet, const RSgImage& aImage) sl@0: { sl@0: TSgImageInfo info; sl@0: TInt ret = aImage.GetInfo(info); sl@0: if (ret != KErrNone) sl@0: { sl@0: return ret; sl@0: } sl@0: TDisplayMode displayMode = PixelFormatUtil::ConvertToDisplayMode(info.iPixelFormat); sl@0: TSize size = info.iSizeInPixels; sl@0: CFbsDrawDevice* device = NULL; sl@0: const MSgImage_Sw* pImage; sl@0: TInt err = aImage.GetInterface(pImage); sl@0: GRAPHICS_ASSERT_DEBUG((err == KErrNone) && (pImage != NULL), EDirectGdiPanicInvalidInterfaceHandle); sl@0: TRAP(err, device = CFbsDrawDevice::NewBitmapDeviceL(size, displayMode, pImage->DataStride())); sl@0: if (err != KErrNone) sl@0: { sl@0: return err; sl@0: } sl@0: sl@0: // Setup the new device with the memory from the image sl@0: device->SetBits(pImage->DataAddress()); sl@0: sl@0: // Create a new image sl@0: if (err == KErrNone) sl@0: { sl@0: CSwDirectGdiImageTargetImpl* target = NULL; sl@0: err = CSwDirectGdiImageTargetImpl::New(target, *this, device, aImage); sl@0: if (err == KErrNone) sl@0: { sl@0: // Make sure we aren't overwriting an exisiting valid handle. sl@0: GRAPHICS_ASSERT_DEBUG(aHandleRet == KNullHandle, EDirectGdiPanicTargetHandleNotNull); sl@0: aHandleRet = reinterpret_cast(target); sl@0: } sl@0: } sl@0: sl@0: if (err != KErrNone) sl@0: { sl@0: delete device; sl@0: } sl@0: sl@0: return err; sl@0: } sl@0: sl@0: /** sl@0: @see CDirectGdiDriverInternal::CloseImageTarget() sl@0: @panic DGDIAdapter 40, if the image target associated with aHandle could not be found in the sl@0: internal list of targets (debug only). sl@0: */ sl@0: void CSwDirectGdiDriverImpl::CloseImageTarget(TInt& aHandle) sl@0: { sl@0: CSwDirectGdiImageTargetImpl* target = reinterpret_cast(aHandle); sl@0: if (target) sl@0: target->Close(); sl@0: aHandle = KNullHandle; sl@0: } sl@0: sl@0: sl@0: /** sl@0: @see CDirectGdiDriverInteral::CreateEngine() sl@0: */ sl@0: TInt CSwDirectGdiDriverImpl::CreateEngine(MDirectGdiEngine*& aEngine) sl@0: { sl@0: TInt err = KErrNoMemory; sl@0: CSwDirectGdiEngine* engine = new CSwDirectGdiEngine(this); sl@0: aEngine = engine; sl@0: if(engine != NULL) sl@0: { sl@0: // Put this in an array so we can destroy it on close sl@0: err = iEngines.InsertInAddressOrder(engine); sl@0: if (KErrNone != err) sl@0: { sl@0: delete engine; sl@0: aEngine = NULL; sl@0: } sl@0: } sl@0: return err; sl@0: } sl@0: sl@0: /** sl@0: @see CDirectGdiDriverInternal::DestroyEngine() sl@0: @panic DGDIAdapter 60, if aEngine could not be found in the internal list of engines (debug only). sl@0: */ sl@0: void CSwDirectGdiDriverImpl::DestroyEngine(MDirectGdiEngine* aEngine) sl@0: { sl@0: TInt index = iEngines.FindInAddressOrder(aEngine); sl@0: GRAPHICS_ASSERT_DEBUG(index != KErrNotFound, EDirectGdiPanicEngineNotFound); sl@0: iEngines.Remove(index); sl@0: delete (static_cast(aEngine)); sl@0: } sl@0: sl@0: /** sl@0: @see CDirectGdiDriverInternal::SetError() sl@0: */ sl@0: void CSwDirectGdiDriverImpl::SetError(TInt aErr) sl@0: { sl@0: if (aErr != KErrNone && iErrorCode == KErrNone) sl@0: { sl@0: iErrorCode = aErr; sl@0: } sl@0: } sl@0: sl@0: /** sl@0: No extensions interfaces are supported. sl@0: sl@0: @see CDirectGdiDriver::GetInterface() sl@0: */ sl@0: TInt CSwDirectGdiDriverImpl::GetInterface(TUid /*aInterfaceId*/, TAny*& aInterface) sl@0: { sl@0: aInterface = NULL; sl@0: return KErrExtensionNotSupported; sl@0: } sl@0: sl@0: /** sl@0: Deactivate the target if it was the current target, decrement the reference count of the target as it can be shared sl@0: across many DirectGDI contexts. sl@0: sl@0: @param aRenderingTarget The target object which you want to deactivate. sl@0: sl@0: @panic DGDIAdapter 55, if aRengeringTarget is NULL. sl@0: */ sl@0: void CSwDirectGdiDriverImpl::Deactivate(CSwDirectGdiImageTargetImpl* aRenderingTarget) sl@0: { sl@0: GRAPHICS_ASSERT_ALWAYS(aRenderingTarget, EDirectGdiPanicNullTargetDeactivate); sl@0: aRenderingTarget->Close(); sl@0: } sl@0: sl@0: /** sl@0: Checks whether the image source handle is valid. sl@0: sl@0: @param aHandle The handle to an Image Source that should be found. sl@0: @return ETrue if aHandle is a valid handle to an image registered with the driver, otherwise EFalse. sl@0: */ sl@0: TBool CSwDirectGdiDriverImpl::ValidImageSource(TInt aHandle) const sl@0: { sl@0: CSwDirectGdiImageSourceImpl* impl = reinterpret_cast(aHandle); sl@0: return iImageSources.FindInAddressOrder(impl) != KErrNotFound; sl@0: } sl@0: sl@0: /** sl@0: Checks whether the target image handle is valid. sl@0: sl@0: @param aHandle The handle to an Image Target that should be found. sl@0: @return ETrue if aHandle is a valid handle to an image registered with the driver, otherwise EFalse. sl@0: */ sl@0: TBool CSwDirectGdiDriverImpl::ValidImageTarget(TInt aHandle) const sl@0: { sl@0: CSwDirectGdiImageTargetImpl* impl = reinterpret_cast(aHandle); sl@0: return iTargets.FindInAddressOrder(impl) != KErrNotFound; sl@0: } sl@0: sl@0: /** sl@0: Removes the specified image target from the internal list of targets. sl@0: sl@0: @param aImageTarget The image to remove. sl@0: @return KErrNotFound if it could not be found in the internal list, otherwise KErrNone. sl@0: */ sl@0: TInt CSwDirectGdiDriverImpl::UnregisterTargetImage(const CSwDirectGdiImageTargetImpl& aImageTarget) sl@0: { sl@0: TInt err = KErrNone; sl@0: TInt index = iTargets.FindInAddressOrder(&aImageTarget); sl@0: if (index == KErrNotFound) sl@0: { sl@0: err = KErrNotFound; sl@0: } sl@0: else sl@0: { sl@0: iTargets.Remove(index); sl@0: iTargets.GranularCompress(); sl@0: } sl@0: return err; sl@0: } sl@0: sl@0: /** sl@0: Removes the specified image source from the internal list of sources. sl@0: sl@0: @param aImageSource The image to remove. sl@0: @return KErrNotFound if it could not be found in the internal list, otherwise KErrNone. sl@0: */ sl@0: TInt CSwDirectGdiDriverImpl::UnregisterSourceImage(const CSwDirectGdiImageSourceImpl& aImageSource) sl@0: { sl@0: TInt err = KErrNone; sl@0: TInt index = iImageSources.FindInAddressOrder(&aImageSource); sl@0: if (index == KErrNotFound) sl@0: { sl@0: err = KErrNotFound; sl@0: } sl@0: else sl@0: { sl@0: iImageSources.Remove(index); sl@0: iImageSources.GranularCompress(); sl@0: } sl@0: return err; sl@0: } sl@0: sl@0: /** sl@0: Helper function. When an image source is constructed, it registers itself on the driver's internal sl@0: list of image sources. sl@0: @param aImageSource The image to add to the array. sl@0: @return KErrNone if successful, otherwise one of the system-wide error codes. sl@0: */ sl@0: TInt CSwDirectGdiDriverImpl::RegisterSourceImage(const CSwDirectGdiImageSourceImpl& aImageSource) sl@0: { sl@0: return iImageSources.InsertInAddressOrder(&aImageSource); sl@0: } sl@0: sl@0: /** sl@0: Helper function. When an image target is constructed, it registers itself on the driver's internal sl@0: list of image targets. sl@0: @param aImageTarget The image to add to the array. sl@0: @return KErrNone if successful, otherwise one of the system-wide error codes. sl@0: */ sl@0: TInt CSwDirectGdiDriverImpl::RegisterTargetImage(const CSwDirectGdiImageTargetImpl& aImageTarget) sl@0: { sl@0: return iTargets.InsertInAddressOrder(&aImageTarget); sl@0: } sl@0: