|
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: Draws to Canvas. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // Include Files |
|
20 #include <logger.h> |
|
21 //#include <lcdui.h> // MMIDCanvas |
|
22 |
|
23 #ifdef EXTENDED_LCDUI_CANVAS |
|
24 #include <MMIDCanvasExtended.h> |
|
25 #endif |
|
26 |
|
27 #include "cmmacanvasdisplay.h" |
|
28 #include "cmmabitmapwindow.h" |
|
29 #include "mmafunctionserver.h" |
|
30 |
|
31 // CONSTRUCTION |
|
32 // Static constructor, leaves pointer to cleanup-stack |
|
33 CMMACanvasDisplay* CMMACanvasDisplay::NewLC(MMAFunctionServer* aEventSource, jobject obj/*MMIDCanvas* aCanvas*/) |
|
34 { |
|
35 CMMACanvasDisplay* self = |
|
36 new(ELeave) CMMACanvasDisplay(); |
|
37 |
|
38 CleanupStack::PushL(self); |
|
39 self->Construct(aEventSource,NULL,obj); |
|
40 return self; |
|
41 } |
|
42 |
|
43 // Destructor (virtual by CBase) |
|
44 CMMACanvasDisplay::~CMMACanvasDisplay() |
|
45 { |
|
46 } |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 /* |
|
52 void CMMACanvasDisplay::SourceSizeChanged(const TSize& aSourceSize) |
|
53 { |
|
54 LOG(EJavaMMAPI,EInfo,"CMMACanvasDisplay::SourceSizeChanged"); |
|
55 |
|
56 #ifdef RD_JAVA_NGA_ENABLED |
|
57 if ( iWindow ) |
|
58 { |
|
59 iWindow->SetVideoCropRegion( TRect( iUserRect.iTl, aSourceSize ) ); |
|
60 } |
|
61 #endif |
|
62 |
|
63 iSourceSize = aSourceSize; |
|
64 jmethodID getDisplayWidthID = iJni->GetMethodID( |
|
65 iJavaDisplayClass, |
|
66 "getDisplayWidth", |
|
67 "()I"); |
|
68 |
|
69 jmethodID getDisplayHeightID = iJni->GetMethodID( |
|
70 iJavaDisplayClass, |
|
71 "getDisplayHeight", |
|
72 "()I"); |
|
73 |
|
74 |
|
75 TInt x = iJni->CallIntMethod(iJavaDisplayObject,getDisplayWidthID); |
|
76 TInt y = iJni->CallIntMethod(iJavaDisplayObject,getDisplayHeightID); |
|
77 |
|
78 // TSize iFullScreenSize(100,100); // TO-Do remove hardcoded with the relevent one |
|
79 LOG2(EJavaMMAPI,EInfo,"CMMACanvasdisplay.cpp : SourceSizeChanged () iFullScreenSize is x = %d ,y = %d ",x,y); |
|
80 // get the ScreenSize from canvas in java |
|
81 TSize canvasSize(x, y); |
|
82 iFullScreenSize = canvasSize; |
|
83 TBool sourceIsBigger = (aSourceSize.iWidth > iFullScreenSize.iWidth || |
|
84 aSourceSize.iHeight > iFullScreenSize.iHeight); |
|
85 |
|
86 if (sourceIsBigger) |
|
87 { |
|
88 // Source is larger than display area. |
|
89 // Shrink draw are to fit in display. |
|
90 iWindow->SetDrawRect(ScaleToFullScreen(iFullScreenSize, iSourceSize)); |
|
91 } |
|
92 else |
|
93 { |
|
94 // source is smaller than display area |
|
95 iWindow->SetDrawRect(TRect(iUserRect.iTl, iSourceSize)); |
|
96 } |
|
97 |
|
98 SetClippingRegion(); |
|
99 |
|
100 if (iUserRect.IsEmpty()) |
|
101 { |
|
102 // Java side hasn't set size. |
|
103 iUserRect = iWindow->DrawRect(); |
|
104 |
|
105 if (!sourceIsBigger) |
|
106 { |
|
107 // Addjusting rect to top left corner. |
|
108 iUserRect = TRect(iUserRect.Size()); |
|
109 } |
|
110 } |
|
111 } |
|
112 |
|
113 */ |
|
114 |
|
115 void CMMACanvasDisplay::SourceSizeChanged(TInt aJavaControlWidth, TInt aJavaControlHeight,TInt /*x*/, TInt /*y*/,TRect /*aBoundsRect*/) |
|
116 { |
|
117 JELOG2(EJavaMMAPI); |
|
118 LOG2(EJavaMMAPI,EInfo,"CMMACanvasDisplay::SourceSizeChanged(aSourceSize,aJavaControlWidth,aJavaControlHeight) + aJavaControlWidth = %d ,aJavaControlHeight = %d",aJavaControlWidth,aJavaControlHeight); |
|
119 iSourceSize = SourceSize(); |
|
120 LOG2(EJavaMMAPI,EInfo,"CMMACanvasDisplay::SourceSizeChanged(aSourceSize,aJavaControlWidth,aJavaControlHeight) + sourcesize = %d X %d",iSourceSize.iWidth , iSourceSize.iHeight); |
|
121 #ifdef RD_JAVA_NGA_ENABLED |
|
122 if (iWindow) |
|
123 { |
|
124 iWindow->SetVideoCropRegion(TRect(iUserRect.iTl, iSourceSize)); |
|
125 } |
|
126 #endif |
|
127 |
|
128 // size of canvas in java |
|
129 TSize canvasSize(aJavaControlWidth, aJavaControlHeight); |
|
130 iFullScreenSize = canvasSize; |
|
131 TBool sourceIsBigger = (iSourceSize.iWidth > iFullScreenSize.iWidth || |
|
132 iSourceSize.iHeight > iFullScreenSize.iHeight); |
|
133 |
|
134 if (sourceIsBigger) |
|
135 { |
|
136 // Source is larger than display area. |
|
137 // Shrink draw are to fit in display. |
|
138 LOG(EJavaMMAPI,EInfo,"CMMACanvasDisplay::SourceSizeChanged - source is bigger than display area"); |
|
139 iWindow->SetDrawRect(ScaleToFullScreen(iFullScreenSize, iSourceSize)); |
|
140 LOG(EJavaMMAPI,EInfo,"CMMACanvasDisplay::SourceSizeChanged - source is bigger than display area - after SetDrawRect"); |
|
141 |
|
142 } |
|
143 else |
|
144 { |
|
145 // source is smaller than display area |
|
146 LOG(EJavaMMAPI,EInfo,"CMMACanvasDisplay::SourceSizeChanged - source is smaller than display area"); |
|
147 iWindow->SetDrawRect(TRect(iUserRect.iTl, iSourceSize)); |
|
148 } |
|
149 |
|
150 SetClippingRegion(); |
|
151 |
|
152 if (iUserRect.IsEmpty()) |
|
153 { |
|
154 // Java side hasn't set size. |
|
155 iUserRect = iWindow->DrawRect(); |
|
156 |
|
157 if (!sourceIsBigger) |
|
158 { |
|
159 // Addjusting rect to top left corner. |
|
160 iUserRect = TRect(iUserRect.Size()); |
|
161 } |
|
162 } |
|
163 LOG(EJavaMMAPI,EInfo,"CMMACanvasDisplay::SourceSizeChanged(aJavaControlWidth,aJavaControlHeight)-"); |
|
164 } |
|
165 |
|
166 |
|
167 void CMMACanvasDisplay::SetFullScreenL(TBool aFullScreen) |
|
168 { |
|
169 LOG(EJavaMMAPI,EInfo,"CMMACanvasDisplay::SetFullScreenL +"); |
|
170 iFullScreen = aFullScreen; |
|
171 if (iContainerVisible) |
|
172 { |
|
173 LOG2(EJavaMMAPI,EInfo,"CMMACanvasDisplay::SetFullScreenL widht=%d height=%d", iFullScreenSize.iWidth, |
|
174 iFullScreenSize.iHeight); |
|
175 RemoveClippingRegion(); |
|
176 LOG2(EJavaMMAPI,EInfo,"CMMACanvasDisplay::SetFullScreenL widht=%d height=%d", iFullScreenSize.iWidth, |
|
177 iFullScreenSize.iHeight); |
|
178 LOG2(EJavaMMAPI,EInfo,"CMMACanvasDisplay::SetFullScreenL::iSourceSize widht=%d height=%d", iSourceSize.iWidth, |
|
179 iSourceSize.iHeight); |
|
180 if (aFullScreen) |
|
181 { |
|
182 // use new scaled rect |
|
183 // iWindow->SetDrawRect(ScaleToFullScreen(fullScreenSize, iSourceSize)); |
|
184 LOG(EJavaMMAPI,EInfo,"CMMACanvasDisplay::SetFullScreenL - true scale to fullscreen"); |
|
185 iWindow->SetDrawRect(ScaleToFullScreen(iFullScreenSize, iSourceSize)); |
|
186 } |
|
187 else |
|
188 { |
|
189 // use size set from java |
|
190 LOG(EJavaMMAPI,EInfo,"CMMACanvasDisplay::SetFullScreenL - false - draw the user rect set previously"); |
|
191 LOG2(EJavaMMAPI,EInfo,"CMMACanvasDisplay::SetFullScreenL iUserRect = (%d,%d) ",iUserRect.Width(),iUserRect.Height()); |
|
192 iWindow->SetDrawRect(iUserRect); |
|
193 } |
|
194 |
|
195 AddClippingRegion(); |
|
196 } |
|
197 LOG(EJavaMMAPI,EInfo,"CMMACanvasDisplay::SetFullScreenL -"); |
|
198 } |
|
199 |
|
200 void CMMACanvasDisplay::SetWindowL(MMMADisplayWindow* aWindow) |
|
201 { |
|
202 LOG(EJavaMMAPI, EInfo, "CMMACanvasDisplay::SetWindowL"); |
|
203 CMMADisplay::SetWindowL(aWindow); |
|
204 if (!iWindow) |
|
205 { |
|
206 LOG(EJavaMMAPI, EInfo, "CMMACanvasDisplay::SetWindowL: NULL window, returning"); |
|
207 return; |
|
208 } |
|
209 /* |
|
210 CFbsBitmap* bitmap = iCanvas->FrameBuffer(); |
|
211 |
|
212 __ASSERT_DEBUG(bitmap, |
|
213 User::Panic(_L("Canvas has no bitmap"), |
|
214 KErrNotFound)); |
|
215 |
|
216 iWindow->SetDestinationBitmapL(bitmap); |
|
217 |
|
218 // Check that container exists |
|
219 User::LeaveIfNull(iDirectContainer); |
|
220 |
|
221 LOG2( EJavaMMAPI, EInfo, "MMA::CMMACanvasDisplay::SetWindowL iDirectContainer->MdcContentBounds() TL %d %d", iDirectContainer->MdcContentBounds().iTl.iX, iDirectContainer->MdcContentBounds().iTl.iY); |
|
222 LOG2( EJavaMMAPI, EInfo, "MMA::CMMACanvasDisplay::SetWindowL iDirectContainer->MdcContentBounds() BR %d %d", iDirectContainer->MdcContentBounds().iBr.iX, iDirectContainer->MdcContentBounds().iBr.iY); |
|
223 */ |
|
224 LOG(EJavaMMAPI,EInfo,"MMA::CMMACanvasDisplay::before calling BoundRect"); |
|
225 TRect boundrect = BoundRect(); |
|
226 iWindow->SetWindowRect(boundrect/*iDirectContainer->MdcContentBounds()*/, MMMADisplay::EMmaThread); |
|
227 |
|
228 #ifdef RD_JAVA_NGA_ENABLED |
|
229 //iWindow->SetRWindowRect( iDirectContainer->MdcContainerWindowRect(), |
|
230 // MMMADisplay::EMmaThread ); |
|
231 iWindow->SetRWindowRect(boundrect, |
|
232 MMMADisplay::EMmaThread); |
|
233 #endif |
|
234 |
|
235 SetClippingRegion(); |
|
236 } |
|
237 |
|
238 |
|
239 |
|
240 TRect CMMACanvasDisplay::BoundRect() |
|
241 { |
|
242 LOG(EJavaMMAPI,EInfo,"MMA::CMMACanvasDisplay::BoundRect +"); |
|
243 jmethodID getBoundRectID = iJni->GetMethodID( |
|
244 iJavaDisplayClass, |
|
245 "getBoundRect", |
|
246 "()V"); |
|
247 |
|
248 LOG(EJavaMMAPI,EInfo,"MMA::CMMACanvasDisplay::BoundRect --1"); |
|
249 // set the value to java,so that we can access those from array |
|
250 iJni->CallVoidMethod(iJavaDisplayObject,getBoundRectID); |
|
251 jfieldID field = iJni->GetFieldID(iJavaDisplayClass, "displayboundarr", "[I"); |
|
252 if (field == NULL) |
|
253 { |
|
254 // handle error |
|
255 } |
|
256 /* Read the instance field s */ |
|
257 jintArray javaboundinfoarr = (jintArray)iJni->GetObjectField(iJavaDisplayObject, field); |
|
258 LOG(EJavaMMAPI,EInfo,"MMA::CMMACanvasDisplay::BoundRect --2"); |
|
259 jint* nativeboundinfoarr = iJni->GetIntArrayElements(javaboundinfoarr, NULL); |
|
260 LOG(EJavaMMAPI,EInfo,"MMA::CMMACanvasDisplay::BoundRect --3"); |
|
261 if (!nativeboundinfoarr) |
|
262 { |
|
263 // outputBuffer was already allocated |
|
264 iJni->ReleaseIntArrayElements(javaboundinfoarr, nativeboundinfoarr, JNI_ABORT); |
|
265 // return invalid rect. |
|
266 TRect rect(0,0,0,0); |
|
267 return rect; |
|
268 } |
|
269 LOG(EJavaMMAPI,EInfo,"MMA::CMMACanvasDisplay::BoundRect --4"); |
|
270 // create TRect |
|
271 TInt xcoordinate = nativeboundinfoarr[0]; |
|
272 TInt ycoordinate = nativeboundinfoarr[1]; |
|
273 TInt width = nativeboundinfoarr[2]; |
|
274 TInt height = nativeboundinfoarr[3]; |
|
275 LOG2(EJavaMMAPI,EInfo,"CMMACanvasDisplay: BoundRect() co-ordinate of topleftcorner is x = %d,y =%d",xcoordinate,ycoordinate); |
|
276 LOG2(EJavaMMAPI,EInfo,"CMMACanvasDisplay: BoundRect() size of bound rect is width = %d,height =%d",width,height); |
|
277 TPoint topleft(xcoordinate,ycoordinate); |
|
278 TSize rectsize(width,height); |
|
279 TRect boundRect(topleft,rectsize); |
|
280 iJni->ReleaseIntArrayElements(javaboundinfoarr, nativeboundinfoarr,0); |
|
281 LOG(EJavaMMAPI,EInfo,"MMA::CMMACanvasDisplay::BoundRect -"); |
|
282 return boundRect; |
|
283 } |
|
284 |
|
285 // ask java side peer about the container rect size |
|
286 // currently assuming the boundrect and containerrect will be same in case of canvas |
|
287 TRect CMMACanvasDisplay::ContainerWindowRect() |
|
288 { |
|
289 |
|
290 return BoundRect(); |
|
291 |
|
292 } |
|
293 |
|
294 |
|
295 void CMMACanvasDisplay::SetDisplayLocationL(const TPoint& aPosition) |
|
296 { |
|
297 // Move iUserRect top left corner to aPosition. |
|
298 TSize size(iUserRect.Size()); |
|
299 iUserRect.iTl = aPosition; |
|
300 iUserRect.SetSize(size); |
|
301 |
|
302 if (iContainerVisible && !iFullScreen && iWindow) |
|
303 { |
|
304 iWindow->SetDrawRect(iUserRect); |
|
305 SetClippingRegion(); |
|
306 } |
|
307 else |
|
308 { |
|
309 iResetDrawRect = ETrue; |
|
310 } |
|
311 } |
|
312 |
|
313 TPoint CMMACanvasDisplay::DisplayLocation() |
|
314 { |
|
315 if (iWindow && iFullScreen) |
|
316 { |
|
317 return iWindow->DrawRect().iTl; |
|
318 } |
|
319 else |
|
320 { |
|
321 return iUserRect.iTl; |
|
322 } |
|
323 } |
|
324 |
|
325 |
|
326 |
|
327 |
|
328 |
|
329 /* |
|
330 void CMMACanvasDisplay::MdcContentBoundsChanged(const TRect& aRect) |
|
331 { |
|
332 LOG2(EJavaMMAPI,EInfo,"MID::CMMACanvasDisplay::MdcContentBoundsChanged aRect TL %d %d", |
|
333 aRect.iTl.iX, aRect.iTl.iY); |
|
334 LOG2(EJavaMMAPI,EInfo,"MID::CMMACanvasDisplay::MdcContentBoundsChanged aRect BR %d %d", |
|
335 aRect.iBr.iX, aRect.iBr.iY); |
|
336 |
|
337 if (iWindow) |
|
338 { |
|
339 // Set new rect to window. |
|
340 iWindow->SetWindowRect(aRect, MMMADisplay::EUiThread); |
|
341 |
|
342 if (iFullScreen) |
|
343 { |
|
344 TRect fullRect = ScaleToFullScreen(iCanvas->ContentSize(), |
|
345 iSourceSize); |
|
346 |
|
347 // use SetDrawRectThread because this code is executed |
|
348 // in lcdui thread |
|
349 iWindow->SetDrawRectThread(fullRect); |
|
350 } |
|
351 else |
|
352 { |
|
353 // move to user defined position. |
|
354 iWindow->SetPosition(iUserRect.iTl); |
|
355 } |
|
356 } |
|
357 SetClippingRegion(); |
|
358 } |
|
359 */ |
|
360 |
|
361 // END OF FILE |