os/graphics/graphicsdeviceinterface/directgdiadaptation/swsrc/swdirectgdiimagetargetimpl.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/graphicsdeviceinterface/directgdiadaptation/swsrc/swdirectgdiimagetargetimpl.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,103 @@
     1.4 +// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +#include "swdirectgdiimagetargetimpl.h"
    1.20 +#include "swdirectgdidriverimpl.h"
    1.21 +#include <bitdraw.h>
    1.22 +
    1.23 +/**
    1.24 +Constructs a CSwDirectGdiImageTargetImpl.
    1.25 +@param	aDriver		The driver implementation which created this target.
    1.26 +@param	aDrawDevice A pointer to the draw device associated with this target. 
    1.27 +				   This class takes ownership of aDrawDevice.
    1.28 +*/
    1.29 +CSwDirectGdiImageTargetImpl::CSwDirectGdiImageTargetImpl(CSwDirectGdiDriverImpl& aDriver, CFbsDrawDevice* aDrawDevice):
    1.30 +	iDriver(aDriver),
    1.31 +	iDrawDevice(aDrawDevice)	
    1.32 +	{	
    1.33 +	}
    1.34 +
    1.35 +/**
    1.36 +Destroys a CSwDirectGdiImageTargetImpl.
    1.37 +@post This image target is removed from the associated driver's list of target images.
    1.38 +*/
    1.39 +CSwDirectGdiImageTargetImpl::~CSwDirectGdiImageTargetImpl()
    1.40 +	{
    1.41 +	iDriver.UnregisterTargetImage(*this);
    1.42 +	delete iDrawDevice;
    1.43 +	}
    1.44 +
    1.45 +/**
    1.46 +Two-phase construction of a CSwDirectGdiImageTarget object.
    1.47 +
    1.48 +@param aImage On success, holds a pointer to the newly-created image.
    1.49 +@param aDriver The driver to register this image with.
    1.50 +@param aDrawDevice The draw device to associate with this target. This target will take ownership
    1.51 +of the draw device if this method returns without an error, if the method returns with an error
    1.52 +then the caller still owns the draw device.
    1.53 +@param aSgImage The RSgImage which this image will be based upon.
    1.54 +
    1.55 +@return KErrNone if successful, KErrNoMemory if not enough memory could be allocated, otherwise a return
    1.56 +        value from Construct().
    1.57 +*/
    1.58 +TInt CSwDirectGdiImageTargetImpl::New(CSwDirectGdiImageTargetImpl*& aImage, CSwDirectGdiDriverImpl& aDriver, CFbsDrawDevice* aDrawDevice, const RSgImage& aSgImage)
    1.59 +	{
    1.60 +	CSwDirectGdiImageTargetImpl* image = new CSwDirectGdiImageTargetImpl(aDriver, aDrawDevice);
    1.61 +	if (!image)
    1.62 +		return KErrNoMemory;
    1.63 +	TInt err = image->Construct(aSgImage);
    1.64 +	if (err == KErrNone)
    1.65 +		aImage = image;
    1.66 +	else
    1.67 +		{
    1.68 +		image->iDrawDevice = NULL;
    1.69 +		delete image;
    1.70 +		}
    1.71 +	return err;
    1.72 +	}
    1.73 +
    1.74 +/**
    1.75 +Obtains a draw device pointer that is associated with this target
    1.76 +@return A pointer to the draw device.
    1.77 +*/
    1.78 +CFbsDrawDevice* CSwDirectGdiImageTargetImpl::DrawDevice() const
    1.79 +	{
    1.80 +	return iDrawDevice;
    1.81 +	}
    1.82 +
    1.83 +/**
    1.84 +Gets the supplied image structure and sets the internal data. If it fails for any reason, it will
    1.85 +delete itself.
    1.86 +
    1.87 +@param aSgImage The RSgImage to create the source image from.
    1.88 +@return KErrNone if successful, KErrNotSupported if the RSgImage doesn't have the required interface,
    1.89 +        otherwise an error from CDirectGdiImageRef::Construct().
    1.90 +*/ 
    1.91 +TInt CSwDirectGdiImageTargetImpl::Construct(const RSgImage& aSgImage)
    1.92 +	{	
    1.93 +	TInt err = CDirectGdiImageRef::Construct(aSgImage);
    1.94 +	
    1.95 +	if (err == KErrNone)
    1.96 +		{		
    1.97 +		err = iDriver.RegisterTargetImage(*this);
    1.98 +		}
    1.99 +	
   1.100 +	if (err == KErrNone)
   1.101 +		{
   1.102 +		Open();
   1.103 +		}
   1.104 +	
   1.105 +	return err;	
   1.106 +	}