|
1 /* |
|
2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32base.h> |
|
20 #include <graphics/surfaceupdateclient.h> //RSurfaceUpdateSession |
|
21 #include <graphics/surfacemanager.h> //RSurfaceManager |
|
22 #include <graphics/suerror.h> //KAllScreens |
|
23 |
|
24 #include "NGAPostProcSessionManager.h" |
|
25 #include "NGAPostProcSessionManagerObserver.h" |
|
26 #include "MdfRDebug.h" |
|
27 #include "NGAPostProcNotifier.h" |
|
28 |
|
29 // --- Constants --- |
|
30 const TInt KMessageSlots = 4; |
|
31 |
|
32 //************************************************** |
|
33 |
|
34 CNGAPostProcSessionManager* CNGAPostProcSessionManager::NewL() |
|
35 { |
|
36 PP_DEBUG(_L("CNGAPostProcSessionManager:NewL() ++")); |
|
37 |
|
38 CNGAPostProcSessionManager* self = new (ELeave) CNGAPostProcSessionManager; |
|
39 CleanupStack::PushL(self); |
|
40 self->ConstructL(); |
|
41 CleanupStack::Pop(); |
|
42 |
|
43 PP_DEBUG(_L("CNGAPostProcSessionManager:NewL() --")); |
|
44 return self; |
|
45 } |
|
46 |
|
47 CNGAPostProcSessionManager::CNGAPostProcSessionManager() |
|
48 :iSurfaceUpdateSession(NULL), |
|
49 iObserver(NULL) |
|
50 |
|
51 { |
|
52 } |
|
53 |
|
54 void CNGAPostProcSessionManager::ConstructL() |
|
55 { |
|
56 PP_DEBUG(_L("CNGAPostProcSessionManager[%x]:ConstructL() ++"), this); |
|
57 |
|
58 iSurfaceUpdateSession = new (ELeave) RSurfaceUpdateSession(); |
|
59 User::LeaveIfError(iSurfaceUpdateSession->Connect(KMessageSlots)); |
|
60 |
|
61 PP_DEBUG(_L("CNGAPostProcSessionManager[%x]:ConstructL() --"), this); |
|
62 } |
|
63 |
|
64 void CNGAPostProcSessionManager::CreateNotifierL(TInt aNumSurfaceBuffers) |
|
65 { |
|
66 PP_DEBUG(_L("CNGAPostProcSessionManager[%x]:CreateNotifierL() ++"), this); |
|
67 |
|
68 CNGAPostProcNotifier* notifier; |
|
69 for(TInt index = 0; index < aNumSurfaceBuffers; ++index) |
|
70 { |
|
71 notifier = CNGAPostProcNotifier::NewL(*this); |
|
72 CleanupStack::PushL(notifier); |
|
73 |
|
74 iAOList.AppendL(notifier); |
|
75 |
|
76 CleanupStack::Pop(); |
|
77 } |
|
78 PP_DEBUG(_L("CNGAPostProcSessionManager[%x]:CreateNotifierL() --"), this); |
|
79 } |
|
80 |
|
81 CNGAPostProcSessionManager::~CNGAPostProcSessionManager() |
|
82 { |
|
83 PP_DEBUG(_L("CNGAPostProcSessionManager[%x]:~() ++"), this); |
|
84 //Its safer to destry notifiers before surfaceupdatesession object since notifiers |
|
85 //guarantee synchronous cancellation. |
|
86 iAOList.ResetAndDestroy(); |
|
87 |
|
88 if(iSurfaceUpdateSession) |
|
89 { |
|
90 CancelUpdate(); |
|
91 iSurfaceUpdateSession->Close(); |
|
92 delete iSurfaceUpdateSession; |
|
93 iSurfaceUpdateSession = NULL; |
|
94 } |
|
95 |
|
96 |
|
97 PP_DEBUG(_L("CNGAPostProcSessionManager[%x]:~() --"), this); |
|
98 } |
|
99 |
|
100 TInt CNGAPostProcSessionManager::PostPicture(const TSurfaceId& aSurfaceId, |
|
101 TInt aBufId, TBool aNotifyRequired) |
|
102 { |
|
103 PP_DEBUG(_L("CNGAPostProcSessionManager[%x]:PostPicture() ++"), this); |
|
104 TInt err = KErrNone; |
|
105 if(aNotifyRequired) |
|
106 { |
|
107 CNGAPostProcNotifier* notifier = NULL; |
|
108 for(TInt j=0; j < iAOList.Count(); j++) |
|
109 { |
|
110 //notifier = iAOList[j]; |
|
111 if(!iAOList[j]->IsActive()) |
|
112 { |
|
113 notifier = iAOList[j]; |
|
114 iAOList.Remove(j); |
|
115 //iAOList.Compress(); //why this is required? may create fragmentation. |
|
116 break; |
|
117 } |
|
118 } |
|
119 if(!notifier) |
|
120 { |
|
121 |
|
122 return KErrInUse; |
|
123 |
|
124 } |
|
125 |
|
126 notifier->SetBufferId(aBufId); |
|
127 notifier->Activate(); |
|
128 iSurfaceUpdateSession->NotifyWhenAvailable(notifier->iStatus); |
|
129 iAOList.Append(notifier); |
|
130 |
|
131 |
|
132 } |
|
133 err = iSurfaceUpdateSession->SubmitUpdate(KAllScreens, aSurfaceId, aBufId); |
|
134 |
|
135 PP_DEBUG(_L("CNGAPostProcSessionManager[%x]:PostPicture() -- err = %d"), this, err); |
|
136 return err; |
|
137 } |
|
138 |
|
139 void CNGAPostProcSessionManager::CancelUpdate() |
|
140 { |
|
141 PP_DEBUG(_L("CNGAPostProcSessionManager[%x]:CancelUpdate() ++"), this); |
|
142 iSurfaceUpdateSession->CancelAllUpdateNotifications(); |
|
143 PP_DEBUG(_L("CNGAPostProcSessionManager[%x]:CancelUpdate() --"), this); |
|
144 } |
|
145 |
|
146 void CNGAPostProcSessionManager::CancelNotifiers() |
|
147 { |
|
148 |
|
149 PP_DEBUG(_L("CNGAPostProcSessionManager[%x]:CancelNotifiers() ++"), this); |
|
150 TInt notifierCount = iAOList.Count(); |
|
151 for (TInt i = notifierCount - 1; i >= 0; --i) //reverse loop since the active notifier is appended to the list |
|
152 { |
|
153 if (iAOList[i]->IsActive()) |
|
154 { |
|
155 iAOList[i]->Cancel(); |
|
156 } |
|
157 else |
|
158 { |
|
159 break; |
|
160 } |
|
161 } |
|
162 |
|
163 |
|
164 |
|
165 PP_DEBUG(_L("CNGAPostProcSessionManager[%x]:CancelNotifiers() --"), this); |
|
166 |
|
167 |
|
168 |
|
169 } |
|
170 |
|
171 void CNGAPostProcSessionManager::HandleBufferRelease(TInt aBufId, TInt aStatus) |
|
172 { |
|
173 PP_DEBUG(_L("CNGAPostProcSessionManager[%x]:HandleBufferRelease() ++"), this); |
|
174 if(iObserver) |
|
175 { |
|
176 iObserver->BufferAvailable(aBufId, aStatus); |
|
177 } |
|
178 PP_DEBUG(_L("CNGAPostProcSessionManager[%x]:HandleBufferRelease() --"), this); |
|
179 } |
|
180 |
|
181 void CNGAPostProcSessionManager::SetObserver(MNGAPostProcSessionManagerObserver& aObserver) |
|
182 { |
|
183 PP_DEBUG(_L("CNGAPostProcSessionManager[%x]:SetClockSource() ++"), this); |
|
184 iObserver = &aObserver; |
|
185 PP_DEBUG(_L("CNGAPostProcSessionManager[%x]:SetClockSource() --"), this); |
|
186 } |
|
187 |