os/graphics/graphicsdeviceinterface/directgdiadaptation/swsrc/swdirectgdiimagetargetimpl.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
#include "swdirectgdiimagetargetimpl.h"
sl@0
    17
#include "swdirectgdidriverimpl.h"
sl@0
    18
#include <bitdraw.h>
sl@0
    19
sl@0
    20
/**
sl@0
    21
Constructs a CSwDirectGdiImageTargetImpl.
sl@0
    22
@param	aDriver		The driver implementation which created this target.
sl@0
    23
@param	aDrawDevice A pointer to the draw device associated with this target. 
sl@0
    24
				   This class takes ownership of aDrawDevice.
sl@0
    25
*/
sl@0
    26
CSwDirectGdiImageTargetImpl::CSwDirectGdiImageTargetImpl(CSwDirectGdiDriverImpl& aDriver, CFbsDrawDevice* aDrawDevice):
sl@0
    27
	iDriver(aDriver),
sl@0
    28
	iDrawDevice(aDrawDevice)	
sl@0
    29
	{	
sl@0
    30
	}
sl@0
    31
sl@0
    32
/**
sl@0
    33
Destroys a CSwDirectGdiImageTargetImpl.
sl@0
    34
@post This image target is removed from the associated driver's list of target images.
sl@0
    35
*/
sl@0
    36
CSwDirectGdiImageTargetImpl::~CSwDirectGdiImageTargetImpl()
sl@0
    37
	{
sl@0
    38
	iDriver.UnregisterTargetImage(*this);
sl@0
    39
	delete iDrawDevice;
sl@0
    40
	}
sl@0
    41
sl@0
    42
/**
sl@0
    43
Two-phase construction of a CSwDirectGdiImageTarget object.
sl@0
    44
sl@0
    45
@param aImage On success, holds a pointer to the newly-created image.
sl@0
    46
@param aDriver The driver to register this image with.
sl@0
    47
@param aDrawDevice The draw device to associate with this target. This target will take ownership
sl@0
    48
of the draw device if this method returns without an error, if the method returns with an error
sl@0
    49
then the caller still owns the draw device.
sl@0
    50
@param aSgImage The RSgImage which this image will be based upon.
sl@0
    51
sl@0
    52
@return KErrNone if successful, KErrNoMemory if not enough memory could be allocated, otherwise a return
sl@0
    53
        value from Construct().
sl@0
    54
*/
sl@0
    55
TInt CSwDirectGdiImageTargetImpl::New(CSwDirectGdiImageTargetImpl*& aImage, CSwDirectGdiDriverImpl& aDriver, CFbsDrawDevice* aDrawDevice, const RSgImage& aSgImage)
sl@0
    56
	{
sl@0
    57
	CSwDirectGdiImageTargetImpl* image = new CSwDirectGdiImageTargetImpl(aDriver, aDrawDevice);
sl@0
    58
	if (!image)
sl@0
    59
		return KErrNoMemory;
sl@0
    60
	TInt err = image->Construct(aSgImage);
sl@0
    61
	if (err == KErrNone)
sl@0
    62
		aImage = image;
sl@0
    63
	else
sl@0
    64
		{
sl@0
    65
		image->iDrawDevice = NULL;
sl@0
    66
		delete image;
sl@0
    67
		}
sl@0
    68
	return err;
sl@0
    69
	}
sl@0
    70
sl@0
    71
/**
sl@0
    72
Obtains a draw device pointer that is associated with this target
sl@0
    73
@return A pointer to the draw device.
sl@0
    74
*/
sl@0
    75
CFbsDrawDevice* CSwDirectGdiImageTargetImpl::DrawDevice() const
sl@0
    76
	{
sl@0
    77
	return iDrawDevice;
sl@0
    78
	}
sl@0
    79
sl@0
    80
/**
sl@0
    81
Gets the supplied image structure and sets the internal data. If it fails for any reason, it will
sl@0
    82
delete itself.
sl@0
    83
sl@0
    84
@param aSgImage The RSgImage to create the source image from.
sl@0
    85
@return KErrNone if successful, KErrNotSupported if the RSgImage doesn't have the required interface,
sl@0
    86
        otherwise an error from CDirectGdiImageRef::Construct().
sl@0
    87
*/ 
sl@0
    88
TInt CSwDirectGdiImageTargetImpl::Construct(const RSgImage& aSgImage)
sl@0
    89
	{	
sl@0
    90
	TInt err = CDirectGdiImageRef::Construct(aSgImage);
sl@0
    91
	
sl@0
    92
	if (err == KErrNone)
sl@0
    93
		{		
sl@0
    94
		err = iDriver.RegisterTargetImage(*this);
sl@0
    95
		}
sl@0
    96
	
sl@0
    97
	if (err == KErrNone)
sl@0
    98
		{
sl@0
    99
		Open();
sl@0
   100
		}
sl@0
   101
	
sl@0
   102
	return err;	
sl@0
   103
	}