graphicsdeviceinterface/directgdiadaptation/swsrc/swdirectgdiimagetargetimpl.cpp
changeset 0 5d03bc08d59c
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     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".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include "swdirectgdiimagetargetimpl.h"
       
    17 #include "swdirectgdidriverimpl.h"
       
    18 #include <bitdraw.h>
       
    19 
       
    20 /**
       
    21 Constructs a CSwDirectGdiImageTargetImpl.
       
    22 @param	aDriver		The driver implementation which created this target.
       
    23 @param	aDrawDevice A pointer to the draw device associated with this target. 
       
    24 				   This class takes ownership of aDrawDevice.
       
    25 */
       
    26 CSwDirectGdiImageTargetImpl::CSwDirectGdiImageTargetImpl(CSwDirectGdiDriverImpl& aDriver, CFbsDrawDevice* aDrawDevice):
       
    27 	iDriver(aDriver),
       
    28 	iDrawDevice(aDrawDevice)	
       
    29 	{	
       
    30 	}
       
    31 
       
    32 /**
       
    33 Destroys a CSwDirectGdiImageTargetImpl.
       
    34 @post This image target is removed from the associated driver's list of target images.
       
    35 */
       
    36 CSwDirectGdiImageTargetImpl::~CSwDirectGdiImageTargetImpl()
       
    37 	{
       
    38 	iDriver.UnregisterTargetImage(*this);
       
    39 	delete iDrawDevice;
       
    40 	}
       
    41 
       
    42 /**
       
    43 Two-phase construction of a CSwDirectGdiImageTarget object.
       
    44 
       
    45 @param aImage On success, holds a pointer to the newly-created image.
       
    46 @param aDriver The driver to register this image with.
       
    47 @param aDrawDevice The draw device to associate with this target. This target will take ownership
       
    48 of the draw device if this method returns without an error, if the method returns with an error
       
    49 then the caller still owns the draw device.
       
    50 @param aSgImage The RSgImage which this image will be based upon.
       
    51 
       
    52 @return KErrNone if successful, KErrNoMemory if not enough memory could be allocated, otherwise a return
       
    53         value from Construct().
       
    54 */
       
    55 TInt CSwDirectGdiImageTargetImpl::New(CSwDirectGdiImageTargetImpl*& aImage, CSwDirectGdiDriverImpl& aDriver, CFbsDrawDevice* aDrawDevice, const RSgImage& aSgImage)
       
    56 	{
       
    57 	CSwDirectGdiImageTargetImpl* image = new CSwDirectGdiImageTargetImpl(aDriver, aDrawDevice);
       
    58 	if (!image)
       
    59 		return KErrNoMemory;
       
    60 	TInt err = image->Construct(aSgImage);
       
    61 	if (err == KErrNone)
       
    62 		aImage = image;
       
    63 	else
       
    64 		{
       
    65 		image->iDrawDevice = NULL;
       
    66 		delete image;
       
    67 		}
       
    68 	return err;
       
    69 	}
       
    70 
       
    71 /**
       
    72 Obtains a draw device pointer that is associated with this target
       
    73 @return A pointer to the draw device.
       
    74 */
       
    75 CFbsDrawDevice* CSwDirectGdiImageTargetImpl::DrawDevice() const
       
    76 	{
       
    77 	return iDrawDevice;
       
    78 	}
       
    79 
       
    80 /**
       
    81 Gets the supplied image structure and sets the internal data. If it fails for any reason, it will
       
    82 delete itself.
       
    83 
       
    84 @param aSgImage The RSgImage to create the source image from.
       
    85 @return KErrNone if successful, KErrNotSupported if the RSgImage doesn't have the required interface,
       
    86         otherwise an error from CDirectGdiImageRef::Construct().
       
    87 */ 
       
    88 TInt CSwDirectGdiImageTargetImpl::Construct(const RSgImage& aSgImage)
       
    89 	{	
       
    90 	TInt err = CDirectGdiImageRef::Construct(aSgImage);
       
    91 	
       
    92 	if (err == KErrNone)
       
    93 		{		
       
    94 		err = iDriver.RegisterTargetImage(*this);
       
    95 		}
       
    96 	
       
    97 	if (err == KErrNone)
       
    98 		{
       
    99 		Open();
       
   100 		}
       
   101 	
       
   102 	return err;	
       
   103 	}