|
1 /* |
|
2 * Copyright (c) 2002-2009 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 Files |
|
20 #include <e32def.h> |
|
21 #include <fbs.h> |
|
22 #include <jdebug.h> |
|
23 |
|
24 #include "cmmaplayerevent.h" |
|
25 #include "mmmaguiplayer.h" |
|
26 #include "mmmadisplaywindow.h" |
|
27 #include "cmmadcdisplay.h" |
|
28 #include "mmmacontainer.h" |
|
29 #include "cmmaeventsource.h" |
|
30 #include "cmmadcrepaintevent.h" |
|
31 #include "cmmadcfullscreenevent.h" |
|
32 #include "cmmadcinvalidateevent.h" |
|
33 |
|
34 // CONSTRUCTION |
|
35 // Static constructor, leaves pointer to cleanup-stack |
|
36 CMMADCDisplay* CMMADCDisplay::NewLC(MMMAGuiPlayer* aPlayer, |
|
37 CMMAEventSource* aEventSource, |
|
38 jobject aGUIObject) |
|
39 { |
|
40 CMMADCDisplay* self = |
|
41 new(ELeave) CMMADCDisplay(aPlayer, aEventSource, aGUIObject); |
|
42 CleanupStack::PushL(self); |
|
43 self->iRepaint = new(ELeave) CMMADCRepaintEvent(aGUIObject); |
|
44 return self; |
|
45 } |
|
46 |
|
47 // Destructor (virtual by CBase) |
|
48 CMMADCDisplay::~CMMADCDisplay() |
|
49 { |
|
50 if (iContainer) |
|
51 { |
|
52 iContainer->MdcRemoveContent(); |
|
53 } |
|
54 delete iBitmap; |
|
55 delete iRepaint; |
|
56 } |
|
57 |
|
58 // interface MMMADisplay |
|
59 void CMMADCDisplay::DrawFrameL(const CFbsBitmap* aBitmap) |
|
60 { |
|
61 // This method is called only if bitmap is used. |
|
62 TInt err = InitBitmapMode(); |
|
63 |
|
64 if (iVisible && iWindow && |
|
65 iContainer && iContainer->MdcContainerVisibility() && |
|
66 err == KErrNone) |
|
67 { |
|
68 iWindow->DrawFrameL(aBitmap); |
|
69 |
|
70 // container will draw bitmap obtained with MdcFrameBuffer method |
|
71 if (!iRepaint->IsActive()) |
|
72 { |
|
73 iRepaint->SetActive(); |
|
74 iEventSource->PostEvent(iRepaint, CJavaEventBase::EEventPriority); |
|
75 } |
|
76 } |
|
77 } |
|
78 |
|
79 // interface MMMADisplay |
|
80 void CMMADCDisplay::SetDisplaySizeL(const TSize& aSize) |
|
81 { |
|
82 DEBUG_INT2("CMMADCDisplay::SetDisplaySizeL w %d h %d", |
|
83 aSize.iWidth, aSize.iHeight); |
|
84 // user rect contains size set from java. |
|
85 iUserRect.SetSize(aSize); |
|
86 |
|
87 if (iContainer) |
|
88 { |
|
89 CMMADCInvalidateEvent* event = |
|
90 new(ELeave)CMMADCInvalidateEvent(iGUIObject, aSize); |
|
91 iEventSource->PostEvent(event, CJavaEventBase::EEventPriority); |
|
92 } |
|
93 } |
|
94 |
|
95 // interface MMMADisplay |
|
96 void CMMADCDisplay::SetDisplayLocationL(const TPoint& /*aPosition*/) |
|
97 { |
|
98 DEBUG("CMMADCDisplay::SetDisplayLocationL"); |
|
99 // This method only works when the USE_DIRECT_VIDEO mode is set. |
|
100 // In USE_GUI_PRIMITIVE mode, this call will be ignored. |
|
101 } |
|
102 |
|
103 // interface MMMADisplay |
|
104 TPoint CMMADCDisplay::DisplayLocation() |
|
105 { |
|
106 DEBUG("CMMADCDisplay::DisplayLocation"); |
|
107 // This method returns always (0,0), |
|
108 // because SetDisplayLocationL call is ignored. |
|
109 return TPoint(0, 0); |
|
110 } |
|
111 |
|
112 // interface MMMADisplay |
|
113 void CMMADCDisplay::SetFullScreenL(TBool aFullScreen) |
|
114 { |
|
115 DEBUG_INT("CMMADCDisplay::SetFullScreenL %d", aFullScreen); |
|
116 // This method tries to set eSWT Widget size to its parent size. |
|
117 // If real full screen mode is needed parent Composite must be in |
|
118 // fullscreen mode (for example with MobileShell's setFullScreenMode method). |
|
119 if (iContainer) |
|
120 { |
|
121 CMMADCFullScreenEvent* event = |
|
122 new(ELeave)CMMADCFullScreenEvent(iGUIObject, aFullScreen); |
|
123 iEventSource->PostEvent(event, CJavaEventBase::EEventPriority); |
|
124 } |
|
125 } |
|
126 |
|
127 // interface MMMADisplay |
|
128 void CMMADCDisplay::SourceSizeChanged(const TSize& aSourceSize) |
|
129 { |
|
130 DEBUG_INT2("CMMADCDisplay::SourceSizeChanged %d %d", |
|
131 aSourceSize.iWidth, |
|
132 aSourceSize.iHeight); |
|
133 |
|
134 #ifdef RD_JAVA_NGA_ENABLED |
|
135 if (iWindow) |
|
136 { |
|
137 TPoint topLeft(0, 0); |
|
138 iWindow->SetVideoCropRegion(TRect(topLeft,aSourceSize)); |
|
139 } |
|
140 #endif |
|
141 |
|
142 if (iWindow) |
|
143 { |
|
144 TRect tmp(TPoint(0, 0), aSourceSize); |
|
145 iWindow->SetDrawRect(tmp); |
|
146 iWindow->SetWindowRect(tmp,MMMADisplay::EMmaThread); |
|
147 |
|
148 // set visibility without using event server because this is called |
|
149 // from MMA thread |
|
150 if (iContainer) |
|
151 { |
|
152 if (iContainer->MdcContainerVisibility()) |
|
153 { |
|
154 iWindow->SetVisible(ETrue, EFalse); |
|
155 } |
|
156 } |
|
157 } |
|
158 } |
|
159 |
|
160 // interface MMMADisplay |
|
161 TBool CMMADCDisplay::IsVisible() |
|
162 { |
|
163 TBool visible = EFalse; |
|
164 if (iContainer) |
|
165 { |
|
166 visible = iContainer->MdcContainerVisibility(); |
|
167 } |
|
168 // else invisible |
|
169 |
|
170 // return true if both are visible |
|
171 return iVisible && visible; |
|
172 } |
|
173 |
|
174 |
|
175 // interface MMMADisplay |
|
176 TBool CMMADCDisplay::HasContainer() |
|
177 { |
|
178 return iContainer != NULL; |
|
179 } |
|
180 |
|
181 |
|
182 // interface MMMADirectContent |
|
183 void CMMADCDisplay::MdcContainerVisibilityChanged(TBool aVisible) |
|
184 { |
|
185 DEBUG_INT("CMMADCDisplay::MdcContainerVisibilityChanged aVisible %d", |
|
186 aVisible); |
|
187 if (iWindow) |
|
188 { |
|
189 iWindow->SetVisible(aVisible && iVisible); |
|
190 } |
|
191 DEBUG("CMMADCDisplay::MdcContainerVisibilityChanged OK"); |
|
192 } |
|
193 |
|
194 // interface MMMADirectContent |
|
195 void CMMADCDisplay::MdcContentRectChanged(const TRect& aContentRect, |
|
196 const TRect& aParentRect) |
|
197 { |
|
198 DEBUG("MMA::CMMADCDisplay::MdcContentRectChanged"); |
|
199 if (iWindow) |
|
200 { |
|
201 TSize size = aContentRect.Size(); |
|
202 iWindow->SetDrawRectThread(TRect(size)); |
|
203 TInt err = iEventSource->ExecuteTrap(CMMADCDisplay::SetDrawRectL, |
|
204 this, |
|
205 &size); |
|
206 if (err == KErrNone) |
|
207 { |
|
208 // bitmap window ignores window rect and position |
|
209 iWindow->SetWindowRect(aParentRect,MMMADisplay::EUiThread); |
|
210 iWindow->SetPosition(aContentRect.iTl - aParentRect.iTl); |
|
211 } |
|
212 } |
|
213 } |
|
214 |
|
215 void CMMADCDisplay::MdcContainerWindowRectChanged(const TRect& |
|
216 #ifdef RD_JAVA_NGA_ENABLED |
|
217 aRect |
|
218 #endif |
|
219 ) |
|
220 { |
|
221 DEBUG("CMMADCDisplay::MdcContainerWindowRectChanged"); |
|
222 |
|
223 #ifdef RD_JAVA_NGA_ENABLED |
|
224 if (iWindow) |
|
225 { |
|
226 iWindow->SetRWindowRect(aRect, MMMADisplay::EUiThread); |
|
227 } |
|
228 #endif |
|
229 } |
|
230 |
|
231 // interface MMMADirectContent |
|
232 void CMMADCDisplay::MdcContainerDestroyed() |
|
233 { |
|
234 DEBUG("MMA::CMMADCDisplay::MdcContainerDestroyed"); |
|
235 if (iContainer) |
|
236 { |
|
237 iContainer->MdcRemoveContent(); |
|
238 } |
|
239 |
|
240 iContainer = NULL; |
|
241 if (iWindow) |
|
242 { |
|
243 iWindow->SetVisible(EFalse); |
|
244 iWindow->ContainerDestroyed(); |
|
245 } |
|
246 } |
|
247 |
|
248 // interface MMMADirectContent |
|
249 void CMMADCDisplay::MdcSetContainer(MMMAContainer* aContainer) |
|
250 { |
|
251 iContainer = aContainer; |
|
252 TSize sourceSize = iPlayer->SourceSize(); |
|
253 DEBUG_INT2("CMMADCDisplay::MdcSetContainer source size %d %d", |
|
254 sourceSize.iWidth, sourceSize.iHeight); |
|
255 aContainer->MdcInvalidate(sourceSize); |
|
256 if (iWindow) |
|
257 { |
|
258 // Notify window that container has been set |
|
259 iWindow->ContainerSet(); |
|
260 |
|
261 TRect controlRect; |
|
262 TRect parentRect; |
|
263 iContainer->MdcGetContentRect(controlRect, parentRect); |
|
264 |
|
265 // bitmap window ignores window rect and position |
|
266 iWindow->SetWindowRect(parentRect,MMMADisplay::EUiThread); |
|
267 iWindow->SetPosition(controlRect.iTl - parentRect.iTl); |
|
268 |
|
269 DEBUG_INT("CMMADCDisplay::MdcSetContainer container visible %d", |
|
270 aContainer->MdcContainerVisibility()); |
|
271 DEBUG_INT("CMMADCDisplay::MdcSetContainer content visible %d", |
|
272 iVisible); |
|
273 |
|
274 iWindow->SetVisible(aContainer->MdcContainerVisibility() && |
|
275 iVisible); |
|
276 } |
|
277 } |
|
278 |
|
279 // interface MMMADirectContent |
|
280 CFbsBitmap* CMMADCDisplay::MdcFrameBuffer() const |
|
281 { |
|
282 return iBitmap; |
|
283 } |
|
284 |
|
285 // interface MMMADirectContent |
|
286 TSize CMMADCDisplay::MdcSourceSize() |
|
287 { |
|
288 return iPlayer->SourceSize(); |
|
289 } |
|
290 |
|
291 void CMMADCDisplay::MdcContentBoundsChanged(const TRect& /*aRect*/) |
|
292 { |
|
293 } |
|
294 |
|
295 void CMMADCDisplay::UIGetDSAResources( |
|
296 MUiEventConsumer& aConsumer, |
|
297 MMMADisplay::TThreadType aThreadType) |
|
298 { |
|
299 if (iContainer) |
|
300 { |
|
301 iContainer->MdcGetDSAResources(aConsumer, aThreadType); |
|
302 } |
|
303 } |
|
304 |
|
305 void CMMADCDisplay::UIGetCallback( |
|
306 MUiEventConsumer& aConsumer, |
|
307 TInt aCallbackId) |
|
308 { |
|
309 if (iContainer) |
|
310 { |
|
311 iContainer->MdcGetUICallback(aConsumer, aCallbackId); |
|
312 } |
|
313 } |
|
314 |
|
315 TInt CMMADCDisplay::InitBitmapMode() |
|
316 { |
|
317 TInt errCode = KErrNone; |
|
318 // If there is no bitmap, create one and set it to window |
|
319 if (!iBitmap && iWindow) |
|
320 { |
|
321 iBitmap = new CFbsBitmap; |
|
322 if (iBitmap) |
|
323 { |
|
324 errCode = iBitmap->Create(iPlayer->SourceSize(), |
|
325 EColor16MA); |
|
326 } |
|
327 else |
|
328 { |
|
329 errCode = KErrNoMemory; |
|
330 } |
|
331 |
|
332 if (errCode == KErrNone) |
|
333 { |
|
334 TRAP(errCode, |
|
335 iWindow->SetDestinationBitmapL(iBitmap)); |
|
336 } |
|
337 } |
|
338 return errCode; |
|
339 } |
|
340 |
|
341 void CMMADCDisplay::SetDrawRectL(CMMADCDisplay* aDisplay, TSize* aSize) |
|
342 { |
|
343 if (aDisplay->iBitmap) |
|
344 { |
|
345 User::LeaveIfError(aDisplay->iBitmap->Resize(*aSize)); |
|
346 aDisplay->iWindow->SetDestinationBitmapL(aDisplay->iBitmap); |
|
347 } |
|
348 } |
|
349 |
|
350 CMMADCDisplay::CMMADCDisplay(MMMAGuiPlayer* aPlayer, |
|
351 CMMAEventSource* aEventSource, |
|
352 jobject aGUIObject) |
|
353 { |
|
354 iPlayer = aPlayer; |
|
355 iEventSource = aEventSource; |
|
356 iGUIObject = aGUIObject; |
|
357 // GUI_PRIMITIVE is visible by default. |
|
358 iVisible = ETrue; |
|
359 } |
|
360 |
|
361 // END OF FILE |