|
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 "directgdiadapter.h" |
|
17 #include "directgdiimagesourceimpl.h" |
|
18 #include "directgdidriverimpl.h" |
|
19 #include "directgdidriverprocessstate.h" |
|
20 #include <graphics/sgimage.h> |
|
21 |
|
22 /** |
|
23 Constructs a CDirectGdiImageSourceImpl. |
|
24 @param aDriver The driver implementation which created this target. |
|
25 */ |
|
26 CDirectGdiImageSourceImpl::CDirectGdiImageSourceImpl(CDirectGdiDriverImpl& aDriver) : |
|
27 iDriver(aDriver), |
|
28 iVgImage(VG_INVALID_HANDLE) |
|
29 { |
|
30 } |
|
31 |
|
32 /** |
|
33 Destructor. |
|
34 |
|
35 @post The associated VgImage (if any) is destroyed by the process state. |
|
36 This image is removed from the associated driver's list of source images. |
|
37 */ |
|
38 CDirectGdiImageSourceImpl::~CDirectGdiImageSourceImpl() |
|
39 { |
|
40 GRAPHICS_LOG_DEBUG("Destroying CDirectGdiImageSourceImpl"); |
|
41 if (iVgImage != VG_INVALID_HANDLE) |
|
42 { |
|
43 iDriver.ProcessState().DestroyVgImage(iDriver.EglDisplay(), iVgImage); |
|
44 } |
|
45 iDriver.UnregisterSourceImage(*this); |
|
46 } |
|
47 |
|
48 /** |
|
49 Two-phase construction of a CDirectGdiImageSourceImpl object. |
|
50 @param aImage On success, holds a pointer to the newly-created image. |
|
51 @param aDriver The driver to register this image with. |
|
52 @param aSgImage The RSgImage which this image will be based upon. |
|
53 @return KErrNone if successful, KErrNoMemory if not enough memory could be allocated, otherwise a return |
|
54 value from Construct(). |
|
55 */ |
|
56 TInt CDirectGdiImageSourceImpl::New(CDirectGdiImageSourceImpl*& aImage, CDirectGdiDriverImpl& aDriver, const RSgImage& aSgImage) |
|
57 { |
|
58 CDirectGdiImageSourceImpl* image = new CDirectGdiImageSourceImpl(aDriver); |
|
59 if (!image) |
|
60 return KErrNoMemory; |
|
61 TInt err = image->Construct(aSgImage); |
|
62 if (err == KErrNone) |
|
63 aImage = image; |
|
64 else |
|
65 delete image; |
|
66 return err; |
|
67 } |
|
68 |
|
69 /** |
|
70 Gets the supplied image structure and sets the internal data. |
|
71 Registers itself with the driver. |
|
72 |
|
73 @param aSgImage The RSgImage to create the source image from. |
|
74 @return KErrNone if successful, otherwise an error from CDirectGdiImageRef::Construct(). |
|
75 */ |
|
76 TInt CDirectGdiImageSourceImpl::Construct(const RSgImage& aSgImage) |
|
77 { |
|
78 TInt err = CDirectGdiImageRef::Construct(aSgImage); |
|
79 |
|
80 if (err == KErrNone) |
|
81 { |
|
82 // Let the process state create the VGImage as EGLImages and their associated VGImages |
|
83 // are shared across all threads in this process. (Only one EGLImage can be created per RSgImage |
|
84 // in a process). |
|
85 err = iDriver.ProcessState().CreateVgImage(iDriver.EglDisplay(), iVgImage, iSgImage); |
|
86 } |
|
87 |
|
88 if (err == KErrNone) |
|
89 { |
|
90 err = iDriver.RegisterSourceImage(*this); |
|
91 } |
|
92 |
|
93 if (err == KErrNone) |
|
94 { |
|
95 Open(); |
|
96 } |
|
97 |
|
98 return err; |
|
99 } |
|
100 |