os/graphics/graphicsdeviceinterface/directgdiadaptation/swsrc/swdirectgdiimagesourceimpl.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/graphicsdeviceinterface/directgdiadaptation/swsrc/swdirectgdiimagesourceimpl.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,90 @@
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 "swdirectgdiimagesourceimpl.h"
1.20 +#include "swdirectgdidriverimpl.h"
1.21 +#include <graphics/sgimage_sw.h>
1.22 +
1.23 +/**
1.24 +Constructs a CSwDirectGdiImageTargetImpl
1.25 +@param aDriver The driver implementation which created this target.
1.26 +*/
1.27 +CSwDirectGdiImageSourceImpl::CSwDirectGdiImageSourceImpl(CSwDirectGdiDriverImpl& aDriver) :
1.28 + iDriver(aDriver)
1.29 + {
1.30 + }
1.31 +
1.32 +/**
1.33 +Destroys a CSwDirectGdiImageSourceImpl.
1.34 +
1.35 +@post This image source is removed from the associated driver's list of source images.
1.36 +*/
1.37 +CSwDirectGdiImageSourceImpl::~CSwDirectGdiImageSourceImpl()
1.38 + {
1.39 + iDriver.UnregisterSourceImage(*this);
1.40 + }
1.41 +
1.42 +/**
1.43 +Two-phase construction of a CDirectGdiImageSourceImpl object.
1.44 +@param aImage On success, holds a pointer to the newly-created image.
1.45 +@param aDriver The driver to register this image with.
1.46 +@param aSgImage The RSgImage which this image will be based upon.
1.47 +@return KErrNone if successful, KErrNoMemory if not enough memory could be allocated, otherwise a return
1.48 + value from Construct().
1.49 +*/
1.50 +TInt CSwDirectGdiImageSourceImpl::New(CSwDirectGdiImageSourceImpl*& aImage, CSwDirectGdiDriverImpl& aDriver, const RSgImage& aSgImage)
1.51 + {
1.52 + CSwDirectGdiImageSourceImpl* image = new CSwDirectGdiImageSourceImpl(aDriver);
1.53 + if (!image)
1.54 + return KErrNoMemory;
1.55 + TInt err = image->Construct(aSgImage);
1.56 + if (err == KErrNone)
1.57 + aImage = image;
1.58 + else
1.59 + delete image;
1.60 + return err;
1.61 + }
1.62 +
1.63 +/**
1.64 +Gets the supplied image structure and sets the internal data.
1.65 +@param aSgImage The RSgImage to create the source image from.
1.66 +@return KErrNone if successful, KErrNotSupported if the RSgImage doesn't have the required interface,
1.67 + otherwise an error from CDirectGdiImageRef::Construct().
1.68 +*/
1.69 +TInt CSwDirectGdiImageSourceImpl::Construct(const RSgImage& aSgImage)
1.70 + {
1.71 + TInt err = CDirectGdiImageRef::Construct(aSgImage);
1.72 +
1.73 + MSgImage_Sw* pImage = NULL;
1.74 + if (err == KErrNone)
1.75 + {
1.76 + RSgImage image = Image();
1.77 + err = image.GetInterface(pImage);
1.78 + }
1.79 +
1.80 + if (err == KErrNone)
1.81 + {
1.82 + err = iDriver.RegisterSourceImage(*this);
1.83 + }
1.84 +
1.85 + if (err == KErrNone)
1.86 + {
1.87 + iDataBuffer = pImage->DataAddress();
1.88 + iStride = pImage->DataStride();
1.89 + Open();
1.90 + }
1.91 +
1.92 + return err;
1.93 + }