os/graphics/graphicsdeviceinterface/directgdiadaptation/cmnsrc/directgdiimageref.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/graphicsdeviceinterface/directgdiadaptation/cmnsrc/directgdiimageref.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,67 @@
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 "directgdiimageref.h"
1.20 +#include <graphics/sgresourceinternal.h>
1.21 +
1.22 +CDirectGdiImageRef::CDirectGdiImageRef()
1.23 + {
1.24 + }
1.25 +
1.26 +/**
1.27 +Second phase construction. If the object has not been opened before,
1.28 +the passed RSgImage handle is shared with the member RSgImage and the size of the
1.29 +shared RSgImage is stored.
1.30 +
1.31 +@return KErrNone if successful, otherwise an error from RSgDrawable::Open() or
1.32 +RSgImage::GetInfo()
1.33 + */
1.34 +TInt CDirectGdiImageRef::Construct(const RSgImage& aSgImage)
1.35 + {
1.36 + TInt err = KErrNone;
1.37 +
1.38 + // Share the passed RSgImage handle with our own RSgImage
1.39 + err = iSgImage.Open(aSgImage.Id(), ESgDoNotRestrictUsage);
1.40 +
1.41 + if (err == KErrNone)
1.42 + {
1.43 + // Save our image size, only need to do this the first time we are created
1.44 + TSgImageInfo info;
1.45 + err = iSgImage.GetInfo(info);
1.46 + if (err == KErrNone)
1.47 + {
1.48 + iImageSize = info.iSizeInPixels;
1.49 + iImagePixelFormat = info.iPixelFormat;
1.50 + iSgImageOpen = ETrue;
1.51 + }
1.52 + else
1.53 + {
1.54 + iSgImage.Close();
1.55 + }
1.56 + }
1.57 +
1.58 + return err;
1.59 + }
1.60 +
1.61 +/**
1.62 +Destructor, close the RSgImage being held open if it had been opened it successfully.
1.63 + */
1.64 +CDirectGdiImageRef::~CDirectGdiImageRef()
1.65 + {
1.66 + if (iSgImageOpen)
1.67 + {
1.68 + iSgImage.Close();
1.69 + }
1.70 + }