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 "swdirectgdiimagetargetimpl.h" sl@0: #include "swdirectgdidriverimpl.h" sl@0: #include sl@0: sl@0: /** sl@0: Constructs a CSwDirectGdiImageTargetImpl. sl@0: @param aDriver The driver implementation which created this target. sl@0: @param aDrawDevice A pointer to the draw device associated with this target. sl@0: This class takes ownership of aDrawDevice. sl@0: */ sl@0: CSwDirectGdiImageTargetImpl::CSwDirectGdiImageTargetImpl(CSwDirectGdiDriverImpl& aDriver, CFbsDrawDevice* aDrawDevice): sl@0: iDriver(aDriver), sl@0: iDrawDevice(aDrawDevice) sl@0: { sl@0: } sl@0: sl@0: /** sl@0: Destroys a CSwDirectGdiImageTargetImpl. sl@0: @post This image target is removed from the associated driver's list of target images. sl@0: */ sl@0: CSwDirectGdiImageTargetImpl::~CSwDirectGdiImageTargetImpl() sl@0: { sl@0: iDriver.UnregisterTargetImage(*this); sl@0: delete iDrawDevice; sl@0: } sl@0: sl@0: /** sl@0: Two-phase construction of a CSwDirectGdiImageTarget object. sl@0: sl@0: @param aImage On success, holds a pointer to the newly-created image. sl@0: @param aDriver The driver to register this image with. sl@0: @param aDrawDevice The draw device to associate with this target. This target will take ownership sl@0: of the draw device if this method returns without an error, if the method returns with an error sl@0: then the caller still owns the draw device. sl@0: @param aSgImage The RSgImage which this image will be based upon. sl@0: sl@0: @return KErrNone if successful, KErrNoMemory if not enough memory could be allocated, otherwise a return sl@0: value from Construct(). sl@0: */ sl@0: TInt CSwDirectGdiImageTargetImpl::New(CSwDirectGdiImageTargetImpl*& aImage, CSwDirectGdiDriverImpl& aDriver, CFbsDrawDevice* aDrawDevice, const RSgImage& aSgImage) sl@0: { sl@0: CSwDirectGdiImageTargetImpl* image = new CSwDirectGdiImageTargetImpl(aDriver, aDrawDevice); sl@0: if (!image) sl@0: return KErrNoMemory; sl@0: TInt err = image->Construct(aSgImage); sl@0: if (err == KErrNone) sl@0: aImage = image; sl@0: else sl@0: { sl@0: image->iDrawDevice = NULL; sl@0: delete image; sl@0: } sl@0: return err; sl@0: } sl@0: sl@0: /** sl@0: Obtains a draw device pointer that is associated with this target sl@0: @return A pointer to the draw device. sl@0: */ sl@0: CFbsDrawDevice* CSwDirectGdiImageTargetImpl::DrawDevice() const sl@0: { sl@0: return iDrawDevice; sl@0: } sl@0: sl@0: /** sl@0: Gets the supplied image structure and sets the internal data. If it fails for any reason, it will sl@0: delete itself. sl@0: sl@0: @param aSgImage The RSgImage to create the source image from. sl@0: @return KErrNone if successful, KErrNotSupported if the RSgImage doesn't have the required interface, sl@0: otherwise an error from CDirectGdiImageRef::Construct(). sl@0: */ sl@0: TInt CSwDirectGdiImageTargetImpl::Construct(const RSgImage& aSgImage) sl@0: { sl@0: TInt err = CDirectGdiImageRef::Construct(aSgImage); sl@0: sl@0: if (err == KErrNone) sl@0: { sl@0: err = iDriver.RegisterTargetImage(*this); sl@0: } sl@0: sl@0: if (err == KErrNone) sl@0: { sl@0: Open(); sl@0: } sl@0: sl@0: return err; sl@0: }