|
1 /* |
|
2 * Copyright (c) 2005 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 #include <fbs.h> |
|
19 #include <bitdev.h> |
|
20 #include <gdi.h> |
|
21 |
|
22 #ifdef RD_JAVA_NGA_ENABLED |
|
23 #include <coecntrl.h> |
|
24 #include <e32cmn.h> |
|
25 #include <AknLayoutFont.h> |
|
26 #include <lcdgdrv.h> // for TTransformType |
|
27 #endif // RD_JAVA_NGA_ENABLED |
|
28 |
|
29 #include "fbslcdgraphics.h" |
|
30 |
|
31 #include "CMIDGraphics.h" |
|
32 #include "CMIDImage.h" |
|
33 |
|
34 #include "MidProxyMap.h" |
|
35 #include "LcdGraphics.h" |
|
36 #include "LcdImage.h" |
|
37 #include "LcdSurface.h" |
|
38 #include "LcdBitmapSurface.h" |
|
39 #include "LcdWindowSurface.h" |
|
40 |
|
41 #define UnhandAddress(aAddress) (aAddress << 2) |
|
42 |
|
43 template <class T> |
|
44 inline T* Unhand(TInt aAddress) |
|
45 { |
|
46 return reinterpret_cast<T*>(UnhandAddress(aAddress)); |
|
47 } |
|
48 |
|
49 // --------------------------------------------------------------------------- |
|
50 // Constructor |
|
51 // --------------------------------------------------------------------------- |
|
52 // |
|
53 #ifdef RD_JAVA_NGA_ENABLED |
|
54 CMIDGraphics::CMIDGraphics( |
|
55 CMIDProxyMap& aProxyMap, CLcdGraphics* aGraphics, |
|
56 TBool aIsImageTarget, MMIDCanvas* aTarget) |
|
57 : iCanvasTarget(aTarget) |
|
58 , iProxyMap(aProxyMap) |
|
59 , iGraphics(aGraphics) |
|
60 , iIsImageTarget(aIsImageTarget) |
|
61 { |
|
62 } |
|
63 #else // !RD_JAVA_NGA_ENABLED |
|
64 CMIDGraphics::CMIDGraphics( |
|
65 CMIDProxyMap& aProxyMap, CLcdGraphics* aGraphics, TBool aIsImageTarget) |
|
66 : iProxyMap(aProxyMap) |
|
67 , iGraphics(aGraphics) |
|
68 , iIsImageTarget(aIsImageTarget) |
|
69 { |
|
70 } |
|
71 #endif // RD_JAVA_NGA_ENABLED |
|
72 |
|
73 // --------------------------------------------------------------------------- |
|
74 // Destructor |
|
75 // --------------------------------------------------------------------------- |
|
76 // |
|
77 CMIDGraphics::~CMIDGraphics() |
|
78 { |
|
79 delete iGraphics; |
|
80 } |
|
81 |
|
82 // --------------------------------------------------------------------------- |
|
83 // CMIDGraphics::Type() |
|
84 // --------------------------------------------------------------------------- |
|
85 // |
|
86 MMIDComponent::TType CMIDGraphics::Type() const |
|
87 { |
|
88 return EGraphics; |
|
89 } |
|
90 |
|
91 // --------------------------------------------------------------------------- |
|
92 // CMIDGraphics::Dispose() |
|
93 // --------------------------------------------------------------------------- |
|
94 // |
|
95 void CMIDGraphics::Dispose() |
|
96 { |
|
97 delete this; |
|
98 } |
|
99 |
|
100 // --------------------------------------------------------------------------- |
|
101 // From MMIDBufferProcessor |
|
102 // CMIDGraphics::Processor() |
|
103 // --------------------------------------------------------------------------- |
|
104 // |
|
105 MMIDBufferProcessor* CMIDGraphics::Processor() |
|
106 { |
|
107 return this; |
|
108 } |
|
109 |
|
110 // --------------------------------------------------------------------------- |
|
111 // From MMIDBufferProcessor |
|
112 // CMIDGraphics::AbortAsync() |
|
113 // --------------------------------------------------------------------------- |
|
114 // |
|
115 void CMIDGraphics::AbortAsync() |
|
116 { |
|
117 } |
|
118 |
|
119 // --------------------------------------------------------------------------- |
|
120 // From MMIDBufferProcessor |
|
121 // CMIDGraphics::ProcessL() |
|
122 // --------------------------------------------------------------------------- |
|
123 // |
|
124 #ifdef RD_JAVA_NGA_ENABLED |
|
125 TBool CMIDGraphics::ProcessL( |
|
126 const TMIDBufferOp*& aRead, const TMIDBufferOp* aEnd, |
|
127 TInt& /*aCycles*/, java::util::Monitor* /*aMonitor*/) |
|
128 { |
|
129 // Checks if EGL is availabe. |
|
130 TBool eglAvailable = EFalse; |
|
131 if (iCanvasTarget && iCanvasTarget->IsEglAvailable()) |
|
132 { |
|
133 // Egl is available so bounding boxes of 2D primitives |
|
134 // need to be calculated. |
|
135 eglAvailable = ETrue; |
|
136 } |
|
137 #else // !RD_JAVA_NGA_ENABLED |
|
138 TBool CMIDGraphics::ProcessL( |
|
139 const TMIDBufferOp*& aRead, const TMIDBufferOp* aEnd, |
|
140 TInt& /*aCycles*/, TRequestStatus* /*aStatus*/) |
|
141 { |
|
142 #endif // RD_JAVA_NGA_ENABLED |
|
143 CLcdGraphics& graphics = *iGraphics; |
|
144 |
|
145 graphics.Begin(); |
|
146 while (aRead < aEnd) |
|
147 { |
|
148 TInt opCode = aRead->OpCode(); |
|
149 |
|
150 switch (opCode) |
|
151 { |
|
152 case EGrOpSetColor: |
|
153 { |
|
154 const TLcdGrOpSetColor* setColor = (const TLcdGrOpSetColor*)(aRead); |
|
155 graphics.SetColor(setColor->iColor); |
|
156 } |
|
157 break; |
|
158 |
|
159 case EGrOpSetStroke: |
|
160 { |
|
161 const TLcdGrOpSetStrokeStyle* setStroke = |
|
162 (const TLcdGrOpSetStrokeStyle*)(aRead); |
|
163 graphics.SetStrokeStyle((TStrokeStyle)setStroke->iStyle); |
|
164 } |
|
165 break; |
|
166 |
|
167 case EGrOpSetFont: |
|
168 { |
|
169 const TLcdGrOpSetFont* setFont = (const TLcdGrOpSetFont*)(aRead); |
|
170 graphics.SetFont(setFont->iFont); |
|
171 } |
|
172 break; |
|
173 |
|
174 case EGrOpSetClipRect: |
|
175 { |
|
176 const TLcdGrOpSetClipRect* clipRect= (const TLcdGrOpSetClipRect*)(aRead); |
|
177 graphics.SetClipRect(clipRect->iPosition, clipRect->iSize); |
|
178 } |
|
179 break; |
|
180 |
|
181 case EGrOpTranslate: |
|
182 { |
|
183 const TLcdGrOpTranslate* translate = (const TLcdGrOpTranslate*)(aRead); |
|
184 graphics.Translate(translate->iVector); |
|
185 } |
|
186 break; |
|
187 |
|
188 case EGrOpReset: |
|
189 { |
|
190 const TLcdGrOpReset* reset = (const TLcdGrOpReset*)(aRead); |
|
191 graphics.Reset(reset->iSize); |
|
192 } |
|
193 break; |
|
194 |
|
195 case EGrOpDrawLine: |
|
196 { |
|
197 ASSERT(aRead->Size() >= 5); |
|
198 const TLcdGrOpDrawLine* line = (const TLcdGrOpDrawLine*)(aRead); |
|
199 graphics.DrawLine(line->iPoints[0], line->iPoints[1]); |
|
200 #ifdef RD_JAVA_NGA_ENABLED |
|
201 if (eglAvailable) |
|
202 { |
|
203 // Update bounding box |
|
204 TRect rect(line->iPoints[0], line->iPoints[1]); |
|
205 rect.Normalize(); |
|
206 // Move br by one pixel to include the end point |
|
207 ++rect.iBr.iX; |
|
208 ++rect.iBr.iY; |
|
209 UpdateRect(rect); |
|
210 } |
|
211 #endif // RD_JAVA_NGA_ENABLED |
|
212 } |
|
213 break; |
|
214 |
|
215 case EGrOpDrawRect: |
|
216 { |
|
217 const TLcdGrOpDrawRect* drawRect = (const TLcdGrOpDrawRect*)(aRead); |
|
218 graphics.DrawRect(drawRect->iPosition, drawRect->iSize); |
|
219 #ifdef RD_JAVA_NGA_ENABLED |
|
220 if (eglAvailable) |
|
221 { |
|
222 UpdateRect(TRect( |
|
223 drawRect->iPosition, |
|
224 TSize(drawRect->iSize.iWidth + 1, drawRect->iSize.iHeight + 1))); |
|
225 } |
|
226 #endif // RD_JAVA_NGA_ENABLED |
|
227 } |
|
228 break; |
|
229 |
|
230 case EGrOpFillRect: |
|
231 { |
|
232 const TLcdGrOpFillRect* fillRect = (const TLcdGrOpFillRect*)(aRead); |
|
233 #ifdef RD_JAVA_NGA_ENABLED |
|
234 if (eglAvailable) |
|
235 { |
|
236 TRect rect(fillRect->iPosition, fillRect->iSize); |
|
237 if (!FillEglSurface(rect, TRgb::Color16MA(graphics.Color()))) |
|
238 { |
|
239 graphics.FillRect(fillRect->iPosition, fillRect->iSize); |
|
240 UpdateRect(TRect( |
|
241 fillRect->iPosition, |
|
242 TSize(fillRect->iSize.iWidth + 1, |
|
243 fillRect->iSize.iHeight + 1))); |
|
244 } |
|
245 } |
|
246 else |
|
247 { |
|
248 graphics.FillRect(fillRect->iPosition, fillRect->iSize); |
|
249 } |
|
250 #else // !RD_JAVA_NGA_ENABLED |
|
251 graphics.FillRect(fillRect->iPosition, fillRect->iSize); |
|
252 #endif // RD_JAVA_NGA_ENABLED |
|
253 } |
|
254 break; |
|
255 |
|
256 case EGrOpDrawRoundRect: |
|
257 { |
|
258 const TLcdGrOpDrawRoundRect* drawRoundRect = |
|
259 (const TLcdGrOpDrawRoundRect*)(aRead); |
|
260 graphics.DrawRoundRect( |
|
261 drawRoundRect->iPosition, drawRoundRect->iSize, |
|
262 drawRoundRect->iCornerSize); |
|
263 #ifdef RD_JAVA_NGA_ENABLED |
|
264 if (eglAvailable) |
|
265 { |
|
266 UpdateRect(TRect( |
|
267 drawRoundRect->iPosition, |
|
268 TSize(drawRoundRect->iSize.iWidth + 1, |
|
269 drawRoundRect->iSize.iHeight + 1))); |
|
270 } |
|
271 #endif // RD_JAVA_NGA_ENABLED |
|
272 } |
|
273 break; |
|
274 |
|
275 case EGrOpFillRoundRect: |
|
276 { |
|
277 const TLcdGrOpFillRoundRect* fillRoundRect = |
|
278 (const TLcdGrOpFillRoundRect*)(aRead); |
|
279 graphics.FillRoundRect( |
|
280 fillRoundRect->iPosition, fillRoundRect->iSize, |
|
281 fillRoundRect->iCornerSize); |
|
282 #ifdef RD_JAVA_NGA_ENABLED |
|
283 if (eglAvailable) |
|
284 { |
|
285 UpdateRect(TRect( |
|
286 fillRoundRect->iPosition, |
|
287 TSize(fillRoundRect->iSize.iWidth + 1, |
|
288 fillRoundRect->iSize.iHeight + 1))); |
|
289 } |
|
290 #endif // RD_JAVA_NGA_ENABLED |
|
291 } |
|
292 break; |
|
293 |
|
294 case EGrOpDrawArc: |
|
295 { |
|
296 const TLcdGrOpDrawArc* drawArc = (const TLcdGrOpDrawArc*)(aRead); |
|
297 graphics.DrawArc( |
|
298 drawArc->iPosition, drawArc->iSize, drawArc->iStart, |
|
299 drawArc->iAngle); |
|
300 #ifdef RD_JAVA_NGA_ENABLED |
|
301 if (eglAvailable) |
|
302 { |
|
303 UpdateRect(TRect( |
|
304 drawArc->iPosition, |
|
305 TSize(drawArc->iSize.iWidth + 1, drawArc->iSize.iHeight + 1))); |
|
306 } |
|
307 #endif // RD_JAVA_NGA_ENABLED |
|
308 } |
|
309 break; |
|
310 |
|
311 case EGrOpFillArc: |
|
312 { |
|
313 const TLcdGrOpFillArc* fillArc = (const TLcdGrOpFillArc*)(aRead); |
|
314 graphics.FillArc( |
|
315 fillArc->iPosition, fillArc->iSize, fillArc->iStart, |
|
316 fillArc->iAngle); |
|
317 #ifdef RD_JAVA_NGA_ENABLED |
|
318 if (eglAvailable) |
|
319 { |
|
320 UpdateRect(TRect( |
|
321 fillArc->iPosition, |
|
322 TSize(fillArc->iSize.iWidth + 1, fillArc->iSize.iHeight + 1))); |
|
323 } |
|
324 #endif // RD_JAVA_NGA_ENABLED |
|
325 } |
|
326 break; |
|
327 |
|
328 case EGrOpDrawText: |
|
329 { |
|
330 const TLcdGrOpDrawText* drawText = (const TLcdGrOpDrawText*)(aRead); |
|
331 TPtrC ptr(&drawText->iText[0], drawText->iLength); |
|
332 graphics.DrawText(ptr, drawText->iPoint, drawText->iAnchor); |
|
333 #ifdef RD_JAVA_NGA_ENABLED |
|
334 if (eglAvailable) |
|
335 { |
|
336 UpdateTextRect(ptr, drawText->iPoint, drawText->iAnchor); |
|
337 } |
|
338 #endif // RD_JAVA_NGA_ENABLED |
|
339 } |
|
340 break; |
|
341 |
|
342 case EGrOpDrawImage: |
|
343 { |
|
344 const TLcdGrOpDrawImage* drawImage = (const TLcdGrOpDrawImage*)(aRead); |
|
345 MMIDComponent* component = Unhand<MMIDComponent>(drawImage->iImage); |
|
346 ASSERT(component); |
|
347 const CMIDImage& proxy = |
|
348 static_cast<const CMIDImage&>(*static_cast<MMIDImage*>(component)); |
|
349 const CLcdImage& image = proxy.Image(); |
|
350 #ifndef RD_JAVA_NGA_ENABLED |
|
351 graphics.DrawImage(image, drawImage->iPoint, drawImage->iAnchor); |
|
352 #else // RD_JAVA_NGA_ENABLED |
|
353 graphics.DrawImage(image, drawImage->iPoint, drawImage->iAnchor, eglAvailable); |
|
354 if (eglAvailable) |
|
355 { |
|
356 UpdateRect(CalcDstRect( |
|
357 drawImage->iPoint, image.Size(), ETransNone, |
|
358 (::TAnchor)drawImage->iAnchor)); |
|
359 } |
|
360 #endif // !RD_JAVA_NGA_ENABLED |
|
361 } |
|
362 break; |
|
363 |
|
364 case EGrOpDrawRegion: |
|
365 { |
|
366 const TLcdGrOpDrawRegion* drawRegion = (const TLcdGrOpDrawRegion*)(aRead); |
|
367 MMIDComponent* component = Unhand<MMIDComponent>(drawRegion->iImage); |
|
368 ASSERT(component); |
|
369 const CMIDImage& proxy = |
|
370 static_cast<const CMIDImage&>(*static_cast<MMIDImage*>(component)); |
|
371 const CLcdImage& image = proxy.Image(); |
|
372 #ifndef RD_JAVA_NGA_ENABLED |
|
373 graphics.DrawRegion( |
|
374 image, drawRegion->iSrcPosition, drawRegion->iSrcSize, |
|
375 drawRegion->iTransform, drawRegion->iDstPoint, |
|
376 drawRegion->iAnchor); |
|
377 #else // RD_JAVA_NGA_ENABLED |
|
378 graphics.DrawRegion( |
|
379 image, drawRegion->iSrcPosition, drawRegion->iSrcSize, |
|
380 drawRegion->iTransform, drawRegion->iDstPoint, |
|
381 drawRegion->iAnchor, eglAvailable); |
|
382 if (eglAvailable) |
|
383 { |
|
384 UpdateRect(CalcDstRect(drawRegion->iDstPoint, drawRegion->iSrcSize, |
|
385 (TTransformType)drawRegion->iTransform, |
|
386 (::TAnchor)drawRegion->iAnchor)); |
|
387 } |
|
388 #endif // !RD_JAVA_NGA_ENABLED |
|
389 } |
|
390 break; |
|
391 |
|
392 case EGrOpCopyArea: |
|
393 { |
|
394 // NGA: EGrOpCopyArea is not valid for canvas |
|
395 const TLcdGrOpCopyArea* copyArea = (const TLcdGrOpCopyArea*)(aRead); |
|
396 graphics.CopyArea(copyArea->iSrcPosition, copyArea->iSrcSize, |
|
397 copyArea->iPoint, copyArea->iAnchor); |
|
398 } |
|
399 break; |
|
400 |
|
401 case EGrOpFillTriangle: |
|
402 { |
|
403 ASSERT(aRead->Size() >= 5); |
|
404 const TLcdGrOpFillTriangle* triangle = (const TLcdGrOpFillTriangle*)(aRead); |
|
405 graphics.FillTriangle(triangle->iPoints); |
|
406 #ifdef RD_JAVA_NGA_ENABLED |
|
407 if (eglAvailable) |
|
408 { |
|
409 UpdateRect(TRect( |
|
410 Min3(triangle->iPoints[ 0 ].iX, triangle->iPoints[ 1 ].iX, |
|
411 triangle->iPoints[ 2 ].iX), |
|
412 Min3(triangle->iPoints[ 0 ].iY, triangle->iPoints[ 1 ].iY, |
|
413 triangle->iPoints[ 2 ].iY), |
|
414 Max3(triangle->iPoints[ 0 ].iX, triangle->iPoints[ 1 ].iX, |
|
415 triangle->iPoints[ 2 ].iX) + 1, |
|
416 Max3(triangle->iPoints[ 0 ].iY, triangle->iPoints[ 1 ].iY, |
|
417 triangle->iPoints[ 2 ].iY) + 1)); |
|
418 } |
|
419 #endif // RD_JAVA_NGA_ENABLED |
|
420 } |
|
421 break; |
|
422 case EGrOpFlush: |
|
423 { |
|
424 const TLcdGrOpFlush* flush = (const TLcdGrOpFlush*)(aRead); |
|
425 graphics.Flush(flush->iPosition, flush->iSize); |
|
426 } |
|
427 break; |
|
428 case EGrOpDrawBackground: |
|
429 { |
|
430 const TLcdGrOpDrawBackground* drawBackground = |
|
431 (const TLcdGrOpDrawBackground*)(aRead); |
|
432 MMIDCanvas* canvas = Unhand<MMIDCanvas>(drawBackground->iCanvas); |
|
433 ASSERT(canvas); |
|
434 graphics.DrawBackground(canvas, drawBackground->iPosition, drawBackground->iSize); |
|
435 #ifdef RD_JAVA_NGA_ENABLED |
|
436 if (eglAvailable) |
|
437 { |
|
438 UpdateRect(TRect(drawBackground->iPosition, drawBackground->iSize)); |
|
439 } |
|
440 #endif // RD_JAVA_NGA_ENABLED |
|
441 } |
|
442 break; |
|
443 case EGrOpCopyGraphics: |
|
444 { |
|
445 #ifdef RD_JAVA_NGA_ENABLED |
|
446 const TLcdGrOpCopyGraphics* copyGraphics = |
|
447 (const TLcdGrOpCopyGraphics*)(aRead); |
|
448 MMIDComponent* component = Unhand<MMIDComponent>(copyGraphics->iSrcGraphics); |
|
449 ASSERT(component); |
|
450 CMIDGraphics* proxy = |
|
451 static_cast<CMIDGraphics*>(static_cast<MMIDGraphics*>(component)); |
|
452 CLcdGraphics* srcGraphics = proxy->iGraphics; |
|
453 proxy->UpdateOffScreenBitmapL(ETrue); |
|
454 graphics.CopyGraphics(srcGraphics); |
|
455 |
|
456 #endif // RD_JAVA_NGA_ENABLED |
|
457 } |
|
458 break; |
|
459 default: |
|
460 #ifdef _TRACE |
|
461 RDebug::Print(_L("CMIDGraphics::ProcessL - ignoring unknown opcode %d"), opCode); |
|
462 #endif |
|
463 break; |
|
464 } |
|
465 aRead += aRead->Size(); |
|
466 } |
|
467 graphics.End(); |
|
468 return EFalse; |
|
469 } |
|
470 |
|
471 |
|
472 // --------------------------------------------------------------------------- |
|
473 // CMIDGraphics::DrawPixels() |
|
474 // --------------------------------------------------------------------------- |
|
475 // |
|
476 TInt CMIDGraphics::DrawPixels |
|
477 ( |
|
478 TInt aType, // pixel data type |
|
479 TUint8* aAddress, // pixel data array |
|
480 TInt aLength, // pixel array length - bytes |
|
481 TInt aScanLength, // always positive - vertical reflection handled by point/size |
|
482 TBool aAlpha, // true if pixel data contains alpha |
|
483 const TRect& aRect, |
|
484 TInt aTransform // transform to apply |
|
485 ) |
|
486 { |
|
487 TInt err; |
|
488 TSize size(aRect.Size()); |
|
489 iGraphics->Begin(); |
|
490 |
|
491 TBool premultiplied(EFalse); |
|
492 #ifdef RD_JAVA_NGA_ENABLED |
|
493 if (IsEglAvailable()) |
|
494 { |
|
495 premultiplied = ETrue; |
|
496 UpdateRect(aRect); |
|
497 } |
|
498 #endif |
|
499 |
|
500 err = iGraphics->DrawPixels(aType, aAddress, aLength, aScanLength, |
|
501 aAlpha, aRect.iTl, size, aTransform, premultiplied); |
|
502 iGraphics->End(); |
|
503 return err; |
|
504 } |
|
505 |
|
506 // --------------------------------------------------------------------------- |
|
507 // CMIDGraphics::DisplayColor() |
|
508 // Maps a color provided as 32bit rgb triple to the closest color representable |
|
509 // in the target devices display mode. returns the result as a 32bit rgb triple. |
|
510 // --------------------------------------------------------------------------- |
|
511 // |
|
512 TUint32 CMIDGraphics::DisplayColor(TUint32 aRGB32) |
|
513 { |
|
514 return iGraphics->QuantizeColor(aRGB32); |
|
515 } |
|
516 |
|
517 // --------------------------------------------------------------------------- |
|
518 // CMIDGraphics::Bitmap() |
|
519 // Returns a pointer to the back buffer bitmap in use by the graphics object. |
|
520 // May return NULL. |
|
521 // --------------------------------------------------------------------------- |
|
522 // |
|
523 CFbsBitmap* CMIDGraphics::Bitmap() const |
|
524 { |
|
525 CLcdSurface* surface = iGraphics->Surface(); |
|
526 if (surface->Type() == CLcdSurface::EBitmapSurface) |
|
527 { |
|
528 CLcdBitmapSurface* bitmapSurface = (CLcdBitmapSurface*)surface; |
|
529 return bitmapSurface->Bitmap(); |
|
530 } |
|
531 return NULL; |
|
532 } |
|
533 |
|
534 // --------------------------------------------------------------------------- |
|
535 // CMIDGraphics::Window() |
|
536 // --------------------------------------------------------------------------- |
|
537 // |
|
538 RWindow* CMIDGraphics::Window() const |
|
539 { |
|
540 CLcdSurface* surface = iGraphics->Surface(); |
|
541 if (surface->Type() == CLcdSurface::EWindowSurface) |
|
542 { |
|
543 CLcdWindowSurface* windowSurface = (CLcdWindowSurface*)surface; |
|
544 return windowSurface->Window(); |
|
545 } |
|
546 return NULL; |
|
547 } |
|
548 |
|
549 // --------------------------------------------------------------------------- |
|
550 // CMIDGraphics::ViewPort() |
|
551 // @return drawing surface viewport rectangle. |
|
552 // --------------------------------------------------------------------------- |
|
553 // |
|
554 TRect CMIDGraphics::ViewPort() const |
|
555 { |
|
556 return iGraphics->Surface()->Bounds(); |
|
557 } |
|
558 |
|
559 // --------------------------------------------------------------------------- |
|
560 // CMIDGraphics::IsImageTarget() |
|
561 // @return ETrue for mutable off-screen images (not for canvas/GameCanvas framebuffer) |
|
562 // or EFalse for canvas/GameCanvas framebuffer |
|
563 // --------------------------------------------------------------------------- |
|
564 // |
|
565 TBool CMIDGraphics::IsImageTarget() const |
|
566 { |
|
567 return iIsImageTarget; |
|
568 } |
|
569 |
|
570 #ifdef RD_JAVA_NGA_ENABLED |
|
571 |
|
572 // --------------------------------------------------------------------------- |
|
573 // From MMIDComponentNgaExtension |
|
574 // CMIDGraphics::UpdateEglContent() |
|
575 // --------------------------------------------------------------------------- |
|
576 // |
|
577 void CMIDGraphics::UpdateEglContent() |
|
578 { |
|
579 if (iCanvasTarget) |
|
580 { |
|
581 iCanvasTarget->UpdateEglContent(); |
|
582 } |
|
583 } |
|
584 |
|
585 // --------------------------------------------------------------------------- |
|
586 // From MMIDComponentNgaExtension |
|
587 // CMIDGraphics::IsEglAvailable() |
|
588 // --------------------------------------------------------------------------- |
|
589 // |
|
590 TBool CMIDGraphics::IsEglAvailable() const |
|
591 { |
|
592 return (iCanvasTarget ? iCanvasTarget->IsEglAvailable() : EFalse); |
|
593 } |
|
594 |
|
595 // --------------------------------------------------------------------------- |
|
596 // From MMIDComponentNgaExtension |
|
597 // CMIDGraphics::BindEglSurface() |
|
598 // --------------------------------------------------------------------------- |
|
599 // |
|
600 EGLSurface CMIDGraphics::BindEglSurface() |
|
601 { |
|
602 return (iCanvasTarget ? iCanvasTarget->BindEglSurface() : EGL_NO_SURFACE); |
|
603 } |
|
604 |
|
605 // --------------------------------------------------------------------------- |
|
606 // From MMIDComponentNgaExtension |
|
607 // CMIDGraphics::ReleaseEglSurface() |
|
608 // --------------------------------------------------------------------------- |
|
609 // |
|
610 void CMIDGraphics::ReleaseEglSurface() |
|
611 { |
|
612 if (iCanvasTarget) |
|
613 { |
|
614 iCanvasTarget->ReleaseEglSurface(); |
|
615 } |
|
616 } |
|
617 |
|
618 // --------------------------------------------------------------------------- |
|
619 // From MMIDComponentNgaExtension |
|
620 // CMIDGraphics::UpdateOffScreenBitmapL() |
|
621 // --------------------------------------------------------------------------- |
|
622 // |
|
623 void CMIDGraphics::UpdateOffScreenBitmapL(TBool aForced) |
|
624 { |
|
625 if (iCanvasTarget) |
|
626 { |
|
627 iCanvasTarget->UpdateOffScreenBitmapL(aForced); |
|
628 } |
|
629 } |
|
630 |
|
631 // --------------------------------------------------------------------------- |
|
632 // From MMIDComponentNgaExtension |
|
633 // CMIDGraphics::FillEglSurface() |
|
634 // --------------------------------------------------------------------------- |
|
635 // |
|
636 TBool CMIDGraphics::FillEglSurface(const TRect& aRect, const TRgb& aColor) |
|
637 { |
|
638 if (iCanvasTarget) |
|
639 { |
|
640 TRect rect(aRect); |
|
641 rect.Move(iGraphics->CurrentOriginInTargetCoords()); |
|
642 rect.Intersection(iGraphics->CurrentClipRectInTargetCoords()); |
|
643 TSize canvasSize = iCanvasTarget->Control().Size(); |
|
644 rect.Intersection(TRect(iCanvasTarget->Control().Size())); |
|
645 return iCanvasTarget->FillEglSurface(rect, aColor); |
|
646 } |
|
647 return EFalse; |
|
648 } |
|
649 |
|
650 |
|
651 // --------------------------------------------------------------------------- |
|
652 // CMIDGraphics::CanvasTargetSize() |
|
653 // --------------------------------------------------------------------------- |
|
654 // |
|
655 TSize CMIDGraphics::CanvasTargetSize() const |
|
656 { |
|
657 if (iCanvasTarget) |
|
658 { |
|
659 return iCanvasTarget->ContentSize(); |
|
660 } |
|
661 else |
|
662 { |
|
663 return TSize(); |
|
664 } |
|
665 } |
|
666 |
|
667 // --------------------------------------------------------------------------- |
|
668 // CMIDGraphics::GetTargetCanvas() |
|
669 // --------------------------------------------------------------------------- |
|
670 // |
|
671 MMIDCanvas* CMIDGraphics::GetTargetCanvas() const |
|
672 { |
|
673 return iCanvasTarget; |
|
674 } |
|
675 |
|
676 // --------------------------------------------------------------------------- |
|
677 // CMIDGraphics::UpdateRect() |
|
678 // Merges aRect to member TRects that are used for tracking the updated canvas |
|
679 // area. Current coordinate translation and clip rect are taken into account. |
|
680 // --------------------------------------------------------------------------- |
|
681 // |
|
682 void CMIDGraphics::UpdateRect(const TRect& aRect) |
|
683 { |
|
684 // Translate rect to target (=canvas) coordinates |
|
685 TRect rect(aRect); |
|
686 rect.Move(iGraphics->CurrentOriginInTargetCoords()); |
|
687 |
|
688 // Clip with current clip rect and canvas bounds |
|
689 rect.Intersection(iGraphics->CurrentClipRectInTargetCoords()); |
|
690 |
|
691 iCanvasTarget->UpdateRect(rect); |
|
692 } |
|
693 |
|
694 // --------------------------------------------------------------------------- |
|
695 // CMIDGraphics::UpdateTextRect() |
|
696 // Calculates bounding box for text. |
|
697 // --------------------------------------------------------------------------- |
|
698 // |
|
699 void CMIDGraphics::UpdateTextRect(TPtrC& aTextPtr, const TPoint& aP, TInt aAnchor) |
|
700 { |
|
701 CFont* font = iGraphics->CurrentFont(); |
|
702 |
|
703 // Create a bounding box for the text |
|
704 // TextWidthInPixels() seems to return few pixels too small value. |
|
705 // Width of the zero char is added to be sure that bouding box is |
|
706 // long enough. |
|
707 TRect boundingBox(aP, TSize(font->TextWidthInPixels(aTextPtr) + |
|
708 font->WidthZeroInPixels(), 0)); |
|
709 const CAknLayoutFont* layoutFont = CAknLayoutFont::AsCAknLayoutFontOrNull(font); |
|
710 |
|
711 if (layoutFont) |
|
712 { |
|
713 boundingBox.SetHeight(layoutFont->TextPaneHeight()); |
|
714 } |
|
715 else |
|
716 { |
|
717 boundingBox.SetHeight(font->FontMaxHeight()); |
|
718 } |
|
719 |
|
720 // Moving the bounding box according to the anchor. The EAnchorTop is |
|
721 // default vertically and the EAnchorLeft is default horizontally |
|
722 if (aAnchor & EAnchorBaseline) |
|
723 { |
|
724 boundingBox.Move(0, -font->FontMaxAscent()); |
|
725 } |
|
726 else if (aAnchor & EAnchorBottom) |
|
727 { |
|
728 boundingBox.Move(0, -boundingBox.Height()); |
|
729 } |
|
730 |
|
731 if (aAnchor & EAnchorHCenter) |
|
732 { |
|
733 boundingBox.Move(-(boundingBox.Width() / 2), 0); |
|
734 } |
|
735 else if (aAnchor & EAnchorRight) |
|
736 { |
|
737 boundingBox.Move(-boundingBox.Width(), 0); |
|
738 } |
|
739 UpdateRect(boundingBox); |
|
740 } |
|
741 |
|
742 #endif // RD_JAVA_NGA_ENABLED |