|
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 "directgdiimageref.h" |
|
17 #include <graphics/sgresourceinternal.h> |
|
18 |
|
19 CDirectGdiImageRef::CDirectGdiImageRef() |
|
20 { |
|
21 } |
|
22 |
|
23 /** |
|
24 Second phase construction. If the object has not been opened before, |
|
25 the passed RSgImage handle is shared with the member RSgImage and the size of the |
|
26 shared RSgImage is stored. |
|
27 |
|
28 @return KErrNone if successful, otherwise an error from RSgDrawable::Open() or |
|
29 RSgImage::GetInfo() |
|
30 */ |
|
31 TInt CDirectGdiImageRef::Construct(const RSgImage& aSgImage) |
|
32 { |
|
33 TInt err = KErrNone; |
|
34 |
|
35 // Share the passed RSgImage handle with our own RSgImage |
|
36 err = iSgImage.Open(aSgImage.Id(), ESgDoNotRestrictUsage); |
|
37 |
|
38 if (err == KErrNone) |
|
39 { |
|
40 // Save our image size, only need to do this the first time we are created |
|
41 TSgImageInfo info; |
|
42 err = iSgImage.GetInfo(info); |
|
43 if (err == KErrNone) |
|
44 { |
|
45 iImageSize = info.iSizeInPixels; |
|
46 iImagePixelFormat = info.iPixelFormat; |
|
47 iSgImageOpen = ETrue; |
|
48 } |
|
49 else |
|
50 { |
|
51 iSgImage.Close(); |
|
52 } |
|
53 } |
|
54 |
|
55 return err; |
|
56 } |
|
57 |
|
58 /** |
|
59 Destructor, close the RSgImage being held open if it had been opened it successfully. |
|
60 */ |
|
61 CDirectGdiImageRef::~CDirectGdiImageRef() |
|
62 { |
|
63 if (iSgImageOpen) |
|
64 { |
|
65 iSgImage.Close(); |
|
66 } |
|
67 } |