|
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 "swdirectgdiimagesourceimpl.h" |
|
17 #include "swdirectgdidriverimpl.h" |
|
18 #include <graphics/sgimage_sw.h> |
|
19 |
|
20 /** |
|
21 Constructs a CSwDirectGdiImageTargetImpl |
|
22 @param aDriver The driver implementation which created this target. |
|
23 */ |
|
24 CSwDirectGdiImageSourceImpl::CSwDirectGdiImageSourceImpl(CSwDirectGdiDriverImpl& aDriver) : |
|
25 iDriver(aDriver) |
|
26 { |
|
27 } |
|
28 |
|
29 /** |
|
30 Destroys a CSwDirectGdiImageSourceImpl. |
|
31 |
|
32 @post This image source is removed from the associated driver's list of source images. |
|
33 */ |
|
34 CSwDirectGdiImageSourceImpl::~CSwDirectGdiImageSourceImpl() |
|
35 { |
|
36 iDriver.UnregisterSourceImage(*this); |
|
37 } |
|
38 |
|
39 /** |
|
40 Two-phase construction of a CDirectGdiImageSourceImpl object. |
|
41 @param aImage On success, holds a pointer to the newly-created image. |
|
42 @param aDriver The driver to register this image with. |
|
43 @param aSgImage The RSgImage which this image will be based upon. |
|
44 @return KErrNone if successful, KErrNoMemory if not enough memory could be allocated, otherwise a return |
|
45 value from Construct(). |
|
46 */ |
|
47 TInt CSwDirectGdiImageSourceImpl::New(CSwDirectGdiImageSourceImpl*& aImage, CSwDirectGdiDriverImpl& aDriver, const RSgImage& aSgImage) |
|
48 { |
|
49 CSwDirectGdiImageSourceImpl* image = new CSwDirectGdiImageSourceImpl(aDriver); |
|
50 if (!image) |
|
51 return KErrNoMemory; |
|
52 TInt err = image->Construct(aSgImage); |
|
53 if (err == KErrNone) |
|
54 aImage = image; |
|
55 else |
|
56 delete image; |
|
57 return err; |
|
58 } |
|
59 |
|
60 /** |
|
61 Gets the supplied image structure and sets the internal data. |
|
62 @param aSgImage The RSgImage to create the source image from. |
|
63 @return KErrNone if successful, KErrNotSupported if the RSgImage doesn't have the required interface, |
|
64 otherwise an error from CDirectGdiImageRef::Construct(). |
|
65 */ |
|
66 TInt CSwDirectGdiImageSourceImpl::Construct(const RSgImage& aSgImage) |
|
67 { |
|
68 TInt err = CDirectGdiImageRef::Construct(aSgImage); |
|
69 |
|
70 MSgImage_Sw* pImage = NULL; |
|
71 if (err == KErrNone) |
|
72 { |
|
73 RSgImage image = Image(); |
|
74 err = image.GetInterface(pImage); |
|
75 } |
|
76 |
|
77 if (err == KErrNone) |
|
78 { |
|
79 err = iDriver.RegisterSourceImage(*this); |
|
80 } |
|
81 |
|
82 if (err == KErrNone) |
|
83 { |
|
84 iDataBuffer = pImage->DataAddress(); |
|
85 iStride = pImage->DataStride(); |
|
86 Open(); |
|
87 } |
|
88 |
|
89 return err; |
|
90 } |