|
1 // Copyright (c) 2008-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 "directgdigcwrapper.h" |
|
17 #include <s32mem.h> |
|
18 #include <graphics/lookuptable.h> |
|
19 #include <graphics/directgdidriver.h> |
|
20 #include <graphics/directgdidrawablesource.h> |
|
21 #include <graphics/sgresourceinternal.h> |
|
22 #include "mwsgraphicscontexttodirectgdimappings.h" |
|
23 #include "panic.h" |
|
24 |
|
25 CDirectGdiGcWrapper* CDirectGdiGcWrapper::NewL() |
|
26 { |
|
27 CDirectGdiGcWrapper* self = new(ELeave) CDirectGdiGcWrapper; |
|
28 CleanupStack::PushL(self); |
|
29 CDirectGdiDriver* driver = CDirectGdiDriver::Static(); |
|
30 User::LeaveIfNull(driver); |
|
31 self->iContext = CDirectGdiContext::NewL(*driver); |
|
32 self->iErrorCode = KErrNone; |
|
33 self->iGcBuf = CBufSeg::NewL(512); |
|
34 //MWsFader |
|
35 //Default in BitGdi was 128 for the blackMap and 255 for the whiteMap |
|
36 //SetFadingParameters shows how the fade color is computed |
|
37 self->iFadeColor.SetInternal(0x80FFFFFF); |
|
38 |
|
39 self->iLut = PtrTo16BitNormalisationTable(); |
|
40 CleanupStack::Pop(self); |
|
41 return self; |
|
42 } |
|
43 |
|
44 CDirectGdiGcWrapper::~CDirectGdiGcWrapper() |
|
45 { |
|
46 delete iContext; |
|
47 delete iGcBuf; |
|
48 for (TInt i = 0; i < iDrawableSources.Count(); ++i) |
|
49 { |
|
50 iDrawableSources[i]->Close(); |
|
51 } |
|
52 iDrawableSources.ResetAndDestroy(); |
|
53 iClippingRegion.Close(); |
|
54 } |
|
55 |
|
56 TAny* CDirectGdiGcWrapper::ResolveObjectInterface(TUint aTypeId) |
|
57 { |
|
58 switch(aTypeId) |
|
59 { |
|
60 case MWsGraphicsContext::EWsObjectInterfaceId: |
|
61 return static_cast<MWsGraphicsContext*>(this); |
|
62 case MWsFader::EWsObjectInterfaceId: |
|
63 return static_cast<MWsFader*>(this); |
|
64 case MWsDrawableSourceProvider::EWsObjectInterfaceId: |
|
65 return static_cast<MWsDrawableSourceProvider*>(this); |
|
66 case MWsTextCursor::EWsObjectInterfaceId: |
|
67 return static_cast<MWsTextCursor*>(this); |
|
68 } |
|
69 return NULL; |
|
70 } |
|
71 |
|
72 void CDirectGdiGcWrapper::BitBlt(const TPoint& aDestPos, const CFbsBitmap& aSourceBitmap) |
|
73 { |
|
74 iContext->BitBlt(aDestPos, aSourceBitmap); |
|
75 } |
|
76 |
|
77 void CDirectGdiGcWrapper::BitBlt(const TPoint& aDestPos, const CFbsBitmap& aSourceBitmap, const TRect& aSourceRect) |
|
78 { |
|
79 iContext->BitBlt(aDestPos, aSourceBitmap, aSourceRect); |
|
80 } |
|
81 |
|
82 void CDirectGdiGcWrapper::BitBltMasked(const TPoint& aDestPos, const CFbsBitmap& aSourceBitmap, const TRect& aSourceRect, const CFbsBitmap& aMaskBitmap, TBool aInvertMask) |
|
83 { |
|
84 iContext->BitBltMasked(aDestPos, aSourceBitmap, aSourceRect, aMaskBitmap, aInvertMask); |
|
85 } |
|
86 |
|
87 void CDirectGdiGcWrapper::BitBltMasked(const TPoint& aDestPos, const CFbsBitmap& aSourceBitmap, const TRect& aSourceRect, const CFbsBitmap& aMaskBitmap, const TPoint& aMaskPos) |
|
88 { |
|
89 iContext->BitBltMasked(aDestPos, aSourceBitmap, aSourceRect, aMaskBitmap, aMaskPos); |
|
90 } |
|
91 |
|
92 void CDirectGdiGcWrapper::ResetClippingRegion() |
|
93 { |
|
94 iContext->ResetClippingRegion(); |
|
95 } |
|
96 |
|
97 void CDirectGdiGcWrapper::Clear() |
|
98 { |
|
99 iContext->Clear(); |
|
100 } |
|
101 |
|
102 void CDirectGdiGcWrapper::Clear(const TRect& aRect) |
|
103 { |
|
104 iContext->Clear(aRect); |
|
105 } |
|
106 |
|
107 void CDirectGdiGcWrapper::ResetBrushPattern() |
|
108 { |
|
109 iContext->ResetBrushPattern(); |
|
110 } |
|
111 |
|
112 void CDirectGdiGcWrapper::ResetFont() |
|
113 { |
|
114 iContext->ResetFont(); |
|
115 } |
|
116 |
|
117 void CDirectGdiGcWrapper::DrawArc(const TRect& aRect, const TPoint& aStart, const TPoint& aEnd) |
|
118 { |
|
119 iContext->DrawArc(aRect, aStart, aEnd); |
|
120 } |
|
121 |
|
122 void CDirectGdiGcWrapper::DrawPie(const TRect& aRect, const TPoint& aStart, const TPoint& aEnd) |
|
123 { |
|
124 iContext->DrawPie(aRect, aStart, aEnd); |
|
125 } |
|
126 |
|
127 void CDirectGdiGcWrapper::DrawBitmap(const TRect& aDestRect, const CFbsBitmap& aSourceBitmap) |
|
128 { |
|
129 iContext->DrawBitmap(aDestRect, aSourceBitmap); |
|
130 } |
|
131 |
|
132 void CDirectGdiGcWrapper::DrawBitmap(const TRect& aDestRect, const CFbsBitmap& aSourceBitmap, const TRect& aSourceRect) |
|
133 { |
|
134 iContext->DrawBitmap(aDestRect, aSourceBitmap, aSourceRect); |
|
135 } |
|
136 |
|
137 void CDirectGdiGcWrapper::DrawBitmapMasked(const TRect& aDestRect, const CFbsBitmap& aSourceBitmap, const TRect& aSourceRect, const CFbsBitmap& aMaskBitmap, TBool aInvertMask) |
|
138 { |
|
139 iContext->DrawBitmapMasked(aDestRect, aSourceBitmap, aSourceRect, aMaskBitmap, aInvertMask); |
|
140 } |
|
141 |
|
142 void CDirectGdiGcWrapper::DrawRoundRect(const TRect& aRect, const TSize& aEllipse) |
|
143 { |
|
144 iContext->DrawRoundRect(aRect, aEllipse); |
|
145 } |
|
146 |
|
147 void CDirectGdiGcWrapper::DrawPolyLine(const TArray<TPoint>& aPointList) |
|
148 { |
|
149 iContext->DrawPolyLine(aPointList); |
|
150 } |
|
151 |
|
152 void CDirectGdiGcWrapper::DrawPolyLineNoEndPoint(const TArray<TPoint>& aPointList) |
|
153 { |
|
154 iContext->DrawPolyLineNoEndPoint(aPointList); |
|
155 } |
|
156 |
|
157 void CDirectGdiGcWrapper::DrawPolygon(const TArray<TPoint>& aPointList, TFillRule aFillRule) |
|
158 { |
|
159 iContext->DrawPolygon(aPointList, MWsGraphicsContextToDirectGdiMappings::Convert(aFillRule)); |
|
160 } |
|
161 |
|
162 void CDirectGdiGcWrapper::DrawEllipse(const TRect& aRect) |
|
163 { |
|
164 iContext->DrawEllipse(aRect); |
|
165 } |
|
166 |
|
167 void CDirectGdiGcWrapper::DrawLine(const TPoint& aStart, const TPoint& aEnd) |
|
168 { |
|
169 iContext->DrawLine(aStart, aEnd); |
|
170 } |
|
171 |
|
172 void CDirectGdiGcWrapper::DrawLineTo(const TPoint& aPoint) |
|
173 { |
|
174 iContext->DrawLineTo(aPoint); |
|
175 } |
|
176 |
|
177 void CDirectGdiGcWrapper::DrawLineBy(const TPoint& aVector) |
|
178 { |
|
179 iContext->DrawLineBy(aVector); |
|
180 } |
|
181 |
|
182 void CDirectGdiGcWrapper::DrawRect(const TRect& aRect) |
|
183 { |
|
184 iContext->DrawRect(aRect); |
|
185 } |
|
186 |
|
187 void CDirectGdiGcWrapper::DrawText(const TDesC& aText, const TTextParameters* aParam) |
|
188 { |
|
189 iContext->DrawText(aText, MWsGraphicsContextToDirectGdiMappings::Convert(aParam)); |
|
190 } |
|
191 |
|
192 void CDirectGdiGcWrapper::DrawText(const TDesC& aText, const TTextParameters* aParam, const TPoint& aPosition) |
|
193 { |
|
194 iContext->DrawText(aText, MWsGraphicsContextToDirectGdiMappings::Convert(aParam), aPosition); |
|
195 } |
|
196 |
|
197 void CDirectGdiGcWrapper::DrawText(const TDesC& aText, const TTextParameters* aParam, const TRect& aClipRect) |
|
198 { |
|
199 iContext->DrawText(aText, MWsGraphicsContextToDirectGdiMappings::Convert(aParam), aClipRect); |
|
200 } |
|
201 |
|
202 void CDirectGdiGcWrapper::DrawText(const TDesC& aText, const TTextParameters* aParam, const TRect& aClipFillRect, TInt aBaselineOffset, TTextAlign aHrz, TInt aMargin) |
|
203 { |
|
204 iContext->DrawText(aText, MWsGraphicsContextToDirectGdiMappings::Convert(aParam), aClipFillRect, aBaselineOffset, MWsGraphicsContextToDirectGdiMappings::Convert(aHrz), aMargin); |
|
205 } |
|
206 |
|
207 void CDirectGdiGcWrapper::DrawTextVertical(const TDesC& aText, const TTextParameters* aParam, TBool aUp) |
|
208 { |
|
209 iContext->DrawTextVertical(aText, MWsGraphicsContextToDirectGdiMappings::Convert(aParam), aUp); |
|
210 } |
|
211 |
|
212 void CDirectGdiGcWrapper::DrawTextVertical(const TDesC& aText, const TTextParameters* aParam, const TPoint& aPosition, TBool aUp) |
|
213 { |
|
214 iContext->DrawTextVertical(aText, MWsGraphicsContextToDirectGdiMappings::Convert(aParam), aPosition, aUp); |
|
215 } |
|
216 |
|
217 void CDirectGdiGcWrapper::DrawTextVertical(const TDesC& aText, const TTextParameters* aParam, const TRect& aClipRect, TBool aUp) |
|
218 { |
|
219 iContext->DrawTextVertical(aText, MWsGraphicsContextToDirectGdiMappings::Convert(aParam), aClipRect, aUp); |
|
220 } |
|
221 |
|
222 void CDirectGdiGcWrapper::DrawTextVertical(const TDesC& aText, const TTextParameters* aParam, const TRect& aClipRect, TInt aBaselineOffset, TBool aUp, TTextAlign aVert, TInt aMargin) |
|
223 { |
|
224 iContext->DrawTextVertical(aText, MWsGraphicsContextToDirectGdiMappings::Convert(aParam), aClipRect, aBaselineOffset, aUp, MWsGraphicsContextToDirectGdiMappings::Convert(aVert), aMargin); |
|
225 } |
|
226 |
|
227 void CDirectGdiGcWrapper::DrawTextVertical(const TDesC& aText, const TTextParameters* aParam, const TRect& aClipRect, TInt aBaselineOffset, TInt aTextWidth, TBool aUp, TTextAlign aVert, TInt aMargin) |
|
228 { |
|
229 iContext->DrawTextVertical(aText, MWsGraphicsContextToDirectGdiMappings::Convert(aParam), aClipRect, aBaselineOffset, aTextWidth, aUp, MWsGraphicsContextToDirectGdiMappings::Convert(aVert), aMargin); |
|
230 } |
|
231 |
|
232 void CDirectGdiGcWrapper::MoveTo(const TPoint& aPoint) |
|
233 { |
|
234 iContext->MoveTo(aPoint); |
|
235 } |
|
236 |
|
237 void CDirectGdiGcWrapper::MoveBy(const TPoint& aVector) |
|
238 { |
|
239 iContext->MoveBy(aVector); |
|
240 } |
|
241 |
|
242 void CDirectGdiGcWrapper::Plot(const TPoint& aPoint) |
|
243 { |
|
244 iContext->Plot(aPoint); |
|
245 } |
|
246 |
|
247 void CDirectGdiGcWrapper::Reset() |
|
248 { |
|
249 iContext->Reset(); |
|
250 } |
|
251 |
|
252 void CDirectGdiGcWrapper::SetBrushColor(const TRgb& aColor) |
|
253 { |
|
254 iContext->SetBrushColor(aColor); |
|
255 } |
|
256 |
|
257 void CDirectGdiGcWrapper::SetBrushOrigin(const TPoint& aOrigin) |
|
258 { |
|
259 iContext->SetBrushOrigin(aOrigin); |
|
260 } |
|
261 |
|
262 void CDirectGdiGcWrapper::SetBrushStyle(TBrushStyle aBrushStyle) |
|
263 { |
|
264 iContext->SetBrushStyle(MWsGraphicsContextToDirectGdiMappings::Convert(aBrushStyle)); |
|
265 } |
|
266 |
|
267 void CDirectGdiGcWrapper::SetClippingRegion(const TRegion& aRegion) |
|
268 { |
|
269 CDirectGdiDriver* driver = CDirectGdiDriver::Static(); |
|
270 driver->GetError(); //make sure that an error has been received |
|
271 iContext->SetClippingRegion(aRegion); |
|
272 TInt err = driver->GetError(); |
|
273 SetError(err); |
|
274 if(err == KErrNone) |
|
275 { |
|
276 iClippingRegion.Copy(aRegion); |
|
277 } |
|
278 } |
|
279 |
|
280 void CDirectGdiGcWrapper::SetDrawMode(TDrawMode aDrawMode) |
|
281 { |
|
282 iContext->SetDrawMode(MWsGraphicsContextToDirectGdiMappings::LossyConvert(aDrawMode)); |
|
283 } |
|
284 |
|
285 void CDirectGdiGcWrapper::SetOrigin(const TPoint& aPoint) |
|
286 { |
|
287 iContext->SetOrigin(aPoint); |
|
288 iOrigin = aPoint; |
|
289 } |
|
290 |
|
291 void CDirectGdiGcWrapper::SetPenColor(const TRgb& aColor) |
|
292 { |
|
293 iContext->SetPenColor(aColor); |
|
294 } |
|
295 |
|
296 void CDirectGdiGcWrapper::SetPenStyle(TPenStyle aPenStyle) |
|
297 { |
|
298 iContext->SetPenStyle(MWsGraphicsContextToDirectGdiMappings::Convert(aPenStyle)); |
|
299 } |
|
300 |
|
301 void CDirectGdiGcWrapper::SetPenSize(const TSize& aSize) |
|
302 { |
|
303 iContext->SetPenSize(aSize); |
|
304 } |
|
305 |
|
306 void CDirectGdiGcWrapper::SetTextShadowColor(const TRgb& aColor) |
|
307 { |
|
308 iContext->SetTextShadowColor(aColor); |
|
309 } |
|
310 |
|
311 void CDirectGdiGcWrapper::SetCharJustification(TInt aExcessWidth, TInt aNumChars) |
|
312 { |
|
313 iContext->SetCharJustification(aExcessWidth, aNumChars); |
|
314 } |
|
315 |
|
316 void CDirectGdiGcWrapper::SetWordJustification(TInt aExcessWidth, TInt aNumGaps) |
|
317 { |
|
318 iContext->SetWordJustification(aExcessWidth, aNumGaps); |
|
319 } |
|
320 |
|
321 void CDirectGdiGcWrapper::SetUnderlineStyle(TFontUnderline aUnderlineStyle) |
|
322 { |
|
323 iContext->SetUnderlineStyle(MWsGraphicsContextToDirectGdiMappings::Convert(aUnderlineStyle)); |
|
324 } |
|
325 |
|
326 void CDirectGdiGcWrapper::SetStrikethroughStyle(TFontStrikethrough aStrikethroughStyle) |
|
327 { |
|
328 iContext->SetStrikethroughStyle(MWsGraphicsContextToDirectGdiMappings::Convert(aStrikethroughStyle)); |
|
329 } |
|
330 |
|
331 void CDirectGdiGcWrapper::SetBrushPattern(const CFbsBitmap& aBitmap) |
|
332 { |
|
333 iContext->SetBrushPattern(aBitmap); |
|
334 } |
|
335 |
|
336 void CDirectGdiGcWrapper::SetBrushPattern(TInt aFbsBitmapHandle) |
|
337 { |
|
338 iContext->SetBrushPattern(aFbsBitmapHandle); |
|
339 } |
|
340 |
|
341 void CDirectGdiGcWrapper::SetFont(const CFont* aFont) |
|
342 { |
|
343 iContext->SetFont(aFont); |
|
344 } |
|
345 |
|
346 void CDirectGdiGcWrapper::CopyRect(const TPoint& aOffset, const TRect& aRect) |
|
347 { |
|
348 iContext->CopyRect(aOffset, aRect); |
|
349 } |
|
350 |
|
351 void CDirectGdiGcWrapper::UpdateJustification(const TDesC& aText, const TTextParameters* aParam) |
|
352 { |
|
353 iContext->UpdateJustification(aText, MWsGraphicsContextToDirectGdiMappings::Convert(aParam)); |
|
354 } |
|
355 |
|
356 void CDirectGdiGcWrapper::UpdateJustificationVertical(const TDesC& aText, const TTextParameters* aParam, TBool aUp) |
|
357 { |
|
358 iContext->UpdateJustificationVertical(aText, MWsGraphicsContextToDirectGdiMappings::Convert(aParam), aUp); |
|
359 } |
|
360 |
|
361 void CDirectGdiGcWrapper::SetFontNoDuplicate(const CFont* aFont) |
|
362 { |
|
363 iContext->SetFontNoDuplicate(static_cast<const CDirectGdiFont*>(aFont)); |
|
364 } |
|
365 |
|
366 TBool CDirectGdiGcWrapper::HasBrushPattern() const |
|
367 { |
|
368 return iContext->HasBrushPattern(); |
|
369 } |
|
370 |
|
371 TBool CDirectGdiGcWrapper::HasFont() const |
|
372 { |
|
373 return iContext->HasFont(); |
|
374 } |
|
375 |
|
376 TRgb CDirectGdiGcWrapper::BrushColor() const |
|
377 { |
|
378 return iContext->BrushColor(); |
|
379 } |
|
380 |
|
381 TRgb CDirectGdiGcWrapper::PenColor() const |
|
382 { |
|
383 return iContext->PenColor(); |
|
384 } |
|
385 |
|
386 TRgb CDirectGdiGcWrapper::TextShadowColor() const |
|
387 { |
|
388 return iContext->TextShadowColor(); |
|
389 } |
|
390 |
|
391 TInt CDirectGdiGcWrapper::CreateDrawableSource(const TSgDrawableId& aDrawableId, TAny*& aSource) |
|
392 { |
|
393 CDirectGdiDriver* driver = CDirectGdiDriver::Static(); |
|
394 if (!driver) |
|
395 { |
|
396 return KErrNotReady; |
|
397 } |
|
398 RDirectGdiDrawableSource* drawableSource = new RDirectGdiDrawableSource(*driver); |
|
399 if (!drawableSource) |
|
400 { |
|
401 return KErrNoMemory; |
|
402 } |
|
403 |
|
404 //check usage flags if the drawable is an RSgImage |
|
405 RSgImage image; |
|
406 TInt res = image.Open(aDrawableId); |
|
407 if (res == KErrNone) |
|
408 { |
|
409 TSgImageInfo info; |
|
410 res = image.GetInfo(info); |
|
411 image.Close(); |
|
412 if (res == KErrNone && !(info.iUsage & ESgUsageWindowGcSource)) |
|
413 { |
|
414 res = KErrNotSupported; |
|
415 } |
|
416 |
|
417 if (res != KErrNone) |
|
418 { |
|
419 delete drawableSource; |
|
420 return res; |
|
421 } |
|
422 } |
|
423 |
|
424 RSgDrawable drawable; |
|
425 res = drawable.Open(aDrawableId, ESgDoNotRestrictUsage); |
|
426 if (res != KErrNone) |
|
427 { |
|
428 delete drawableSource; |
|
429 return res; |
|
430 } |
|
431 res = drawableSource->Create(drawable); |
|
432 drawable.Close(); |
|
433 if (res != KErrNone) |
|
434 { |
|
435 delete drawableSource; |
|
436 return res; |
|
437 } |
|
438 res = iDrawableSources.InsertInAddressOrder(drawableSource); |
|
439 if (res != KErrNone) |
|
440 { |
|
441 drawableSource->Close(); |
|
442 delete drawableSource; |
|
443 return res; |
|
444 } |
|
445 aSource = drawableSource; |
|
446 return KErrNone; |
|
447 } |
|
448 |
|
449 void CDirectGdiGcWrapper::CloseDrawableSource(TAny* aSource) |
|
450 { |
|
451 RDirectGdiDrawableSource* drawableSource = static_cast<RDirectGdiDrawableSource*>(aSource); |
|
452 TInt index = iDrawableSources.FindInAddressOrder(drawableSource); |
|
453 if (index != KErrNotFound) |
|
454 { |
|
455 drawableSource->Close(); |
|
456 delete drawableSource; |
|
457 iDrawableSources.Remove(index); |
|
458 } |
|
459 } |
|
460 |
|
461 void CDirectGdiGcWrapper::DrawResource(const TAny* aSource, const TPoint& aPos, CWindowGc::TGraphicsRotation aRotation) |
|
462 { |
|
463 const RDirectGdiDrawableSource* drawableSource = static_cast<const RDirectGdiDrawableSource*>(aSource); |
|
464 TInt index = iDrawableSources.FindInAddressOrder(drawableSource); |
|
465 if (index == KErrNotFound) |
|
466 { |
|
467 STD_ASSERT_DEBUG(0, EPluginPanicInvalidDrawableSource); |
|
468 return; |
|
469 } |
|
470 iContext->DrawResource(aPos, *drawableSource, (DirectGdi::TGraphicsRotation)aRotation); |
|
471 } |
|
472 |
|
473 void CDirectGdiGcWrapper::DrawResource(const TAny* aSource, const TRect& aRect, CWindowGc::TGraphicsRotation aRotation) |
|
474 { |
|
475 const RDirectGdiDrawableSource* drawableSource = static_cast<const RDirectGdiDrawableSource*>(aSource); |
|
476 TInt index = iDrawableSources.FindInAddressOrder(drawableSource); |
|
477 if (index == KErrNotFound) |
|
478 { |
|
479 STD_ASSERT_DEBUG(0, EPluginPanicInvalidDrawableSource); |
|
480 return; |
|
481 } |
|
482 iContext->DrawResource(aRect, *drawableSource, (DirectGdi::TGraphicsRotation)aRotation); |
|
483 } |
|
484 |
|
485 void CDirectGdiGcWrapper::DrawResource(const TAny* aSource, const TRect& aRectDest, const TRect& aRectSrc, CWindowGc::TGraphicsRotation aRotation) |
|
486 { |
|
487 const RDirectGdiDrawableSource* drawableSource = static_cast<const RDirectGdiDrawableSource*>(aSource); |
|
488 TInt index = iDrawableSources.FindInAddressOrder(drawableSource); |
|
489 if (index == KErrNotFound) |
|
490 { |
|
491 STD_ASSERT_DEBUG(0, EPluginPanicInvalidDrawableSource); |
|
492 return; |
|
493 } |
|
494 iContext->DrawResource(aRectDest, *drawableSource, aRectSrc, (DirectGdi::TGraphicsRotation)aRotation); |
|
495 } |
|
496 |
|
497 void CDirectGdiGcWrapper::DrawResource(const TAny* aSource, const TRect& aRect, const TDesC8& aDes) |
|
498 { |
|
499 const RDirectGdiDrawableSource* drawableSource = static_cast<const RDirectGdiDrawableSource*>(aSource); |
|
500 TInt index = iDrawableSources.FindInAddressOrder(drawableSource); |
|
501 if (index == KErrNotFound) |
|
502 { |
|
503 STD_ASSERT_DEBUG(0, EPluginPanicInvalidDrawableSource); |
|
504 return; |
|
505 } |
|
506 iContext->DrawResource(aRect, *drawableSource, aDes); |
|
507 } |
|
508 |
|
509 /** |
|
510 Sets the error code. If the error code is already set to a value other |
|
511 than KErrNone, the error code will not be modified. |
|
512 |
|
513 @param aErr The error code to set. |
|
514 |
|
515 @post The error code has been set. |
|
516 */ |
|
517 void CDirectGdiGcWrapper::SetError(TInt aError) |
|
518 { |
|
519 if (aError != KErrNone && iErrorCode == KErrNone) |
|
520 { |
|
521 iErrorCode = aError; |
|
522 } |
|
523 } |
|
524 |
|
525 /** |
|
526 Returns the first error code (set as the result of calling some CDirectGdiGcWrapper API), if any, |
|
527 since the last call to this function or, if it has not previously been called, since |
|
528 the CDirectGdiGcWrapper was constructed. Calling this function clears the error code. |
|
529 |
|
530 @post The error code has been reset after being read. |
|
531 |
|
532 @return The first error code, if any, since the last call to this function or, |
|
533 if it has not previously been called, since the CDirectGdiGcWrapper was constructed. |
|
534 KErrNone will indicate that no such error has occurred. |
|
535 */ |
|
536 TInt CDirectGdiGcWrapper::GetError() |
|
537 { |
|
538 TInt err = iErrorCode; |
|
539 iErrorCode = KErrNone; |
|
540 return err; |
|
541 } |
|
542 |
|
543 TPoint CDirectGdiGcWrapper::Origin() const |
|
544 { |
|
545 return iOrigin; |
|
546 } |
|
547 |
|
548 const TRegion& CDirectGdiGcWrapper::ClippingRegion() |
|
549 { |
|
550 return iClippingRegion; |
|
551 } |
|
552 |
|
553 TInt CDirectGdiGcWrapper::Push() |
|
554 { |
|
555 // the buf format is len+data where data is written by the GC's ExternalizeL() |
|
556 iGcBuf->Reset(); |
|
557 CBufBase& buf = *iGcBuf; |
|
558 const TInt start = buf.Size(); |
|
559 RBufWriteStream out(buf,start); |
|
560 TRAPD(err,out.WriteInt32L(0)); |
|
561 if(!err) |
|
562 { |
|
563 TRAP(err,iContext->ExternalizeL(out)); |
|
564 } |
|
565 if(err) //rollback addition |
|
566 { |
|
567 buf.Delete(start,buf.Size()-start); |
|
568 } |
|
569 else //fixup len |
|
570 { |
|
571 TRAP_IGNORE(out.CommitL();) // can't see this failing |
|
572 TPckgBuf<TInt32> pckg(buf.Size()-sizeof(TInt32)-start); |
|
573 buf.Write(start,pckg); |
|
574 } |
|
575 return err; |
|
576 } |
|
577 |
|
578 void CDirectGdiGcWrapper::Pop() |
|
579 { |
|
580 CBufBase& buf = *iGcBuf; |
|
581 TInt ofs = 0; |
|
582 FOREVER |
|
583 { |
|
584 TInt chunk = 0; |
|
585 RBufReadStream in(buf,ofs); |
|
586 TRAPD(err,chunk = in.ReadInt32L()); |
|
587 if(err) |
|
588 { |
|
589 STD_ASSERT_DEBUG(err != 0, EPluginPanicPopGcSettings); |
|
590 return; |
|
591 } |
|
592 if(ofs+sizeof(TInt32)+chunk >= buf.Size()) // the last chunk? |
|
593 { |
|
594 TRAP_IGNORE(iContext->InternalizeL(in)); |
|
595 buf.Delete(ofs,buf.Size()-ofs); |
|
596 return; |
|
597 } |
|
598 ofs += chunk + sizeof(TInt32); |
|
599 } |
|
600 } |
|
601 |
|
602 //Default method of fading simply uses bitgdi to perform fading |
|
603 void CDirectGdiGcWrapper::FadeArea(const TRegion& aRegion) |
|
604 { |
|
605 if (!&aRegion || aRegion.CheckError()) |
|
606 return; |
|
607 |
|
608 iContext->Reset(); |
|
609 iContext->SetClippingRegion(aRegion); |
|
610 iContext->SetPenStyle(DirectGdi::ENullPen); |
|
611 iContext->SetBrushStyle(DirectGdi::ESolidBrush); |
|
612 iContext->SetBrushColor(iFadeColor); |
|
613 iContext->DrawRect(aRegion.BoundingRect()); |
|
614 } |
|
615 |
|
616 //Default method of fading expects two TUint8's describing the black/white map |
|
617 //as possible fading parameters |
|
618 void CDirectGdiGcWrapper::SetFadingParameters(const TDesC8& aData) |
|
619 { |
|
620 TPckgBuf<TFadingParams> buf; |
|
621 buf.Copy(aData); |
|
622 TFadingParams parameters = buf(); |
|
623 |
|
624 //Situations where blackMap > whiteMap are NOT supported |
|
625 if (parameters.blackMap > parameters.whiteMap) |
|
626 { |
|
627 TUint8 oldMap = parameters.blackMap; |
|
628 parameters.blackMap = parameters.whiteMap; |
|
629 parameters.whiteMap = oldMap; |
|
630 } |
|
631 |
|
632 //CFbsBitGc::FadeArea() does the following per color component: |
|
633 // dst = dst * (whiteMap - blackMap) + blackMap; |
|
634 |
|
635 //To achieve the same effect using MWsGraphicsContext we draw a rectangle |
|
636 //with specific intensity and alpha values: |
|
637 // dst = dst * (1 - alpha) + intensity * alpha; |
|
638 //Thus: |
|
639 // alpha = 1 - whiteMap + blackMap; |
|
640 // intensity = blackMap / alpha; |
|
641 |
|
642 // alpha = 1 - whiteMap + blackMap; |
|
643 TInt alpha = 255 - parameters.whiteMap + parameters.blackMap; |
|
644 // intensity = blackMap / alpha; |
|
645 TInt i = (parameters.blackMap * iLut[alpha]) >> 8; |
|
646 |
|
647 iFadeColor.SetInternal(i << 16 | i << 8 | i | alpha << 24); |
|
648 } |
|
649 |
|
650 void CDirectGdiGcWrapper::DrawTextCursor(const TTextCursorInfo& aTextCursorInfo) |
|
651 { |
|
652 /* |
|
653 * This function is written with the following assumption: |
|
654 * The UI Toolkit uses text entry windows with a white background |
|
655 * and black text, but always requests a white text cursor. |
|
656 * |
|
657 * We therefore ignore the KRgbWhite text cursor cursor supplied |
|
658 * and use a Black overprinting strategy instead. |
|
659 */ |
|
660 STD_ASSERT_ALWAYS( |
|
661 aTextCursorInfo.iTextCursorType == TTextCursor::ETypeRectangle || |
|
662 aTextCursorInfo.iTextCursorType == TTextCursor::ETypeHollowRectangle, |
|
663 EPluginPanicInvalidCursorType |
|
664 ); |
|
665 |
|
666 TRegionFix<1> fullWindowRegion; |
|
667 const TRegion* clippingRegion = &aTextCursorInfo.iRegion; |
|
668 if (aTextCursorInfo.iRegion.CheckError()) |
|
669 { |
|
670 fullWindowRegion.AddRect(aTextCursorInfo.iWindow->AbsRect()); |
|
671 clippingRegion = &fullWindowRegion; |
|
672 } |
|
673 |
|
674 if (clippingRegion->IsEmpty()) |
|
675 { |
|
676 return; |
|
677 } |
|
678 |
|
679 iContext->SetDrawMode(DirectGdi::EDrawModePEN); |
|
680 switch (aTextCursorInfo.iTextCursorType) |
|
681 { |
|
682 case TTextCursor::ETypeRectangle: |
|
683 { |
|
684 iContext->SetBrushStyle(DirectGdi::ESolidBrush); |
|
685 iContext->SetPenStyle(DirectGdi::ENullPen); |
|
686 iContext->SetBrushColor(KRgbBlack); |
|
687 } |
|
688 break; |
|
689 case TTextCursor::ETypeHollowRectangle: |
|
690 { |
|
691 iContext->SetBrushStyle(DirectGdi::ENullBrush); |
|
692 iContext->SetPenStyle(DirectGdi::ESolidPen); |
|
693 iContext->SetPenColor(KRgbBlack); |
|
694 } |
|
695 break; |
|
696 } |
|
697 iContext->SetClippingRegion(*clippingRegion); |
|
698 /* |
|
699 * During Sprite drawing, the GC gets reset. Possibly other code could |
|
700 * have done this also. So make sure we setup the origin so that window-relative |
|
701 * co-ordinates work as expected; iCursorRect is in window co-ordinates. |
|
702 */ |
|
703 iContext->SetOrigin(aTextCursorInfo.iWindow->Origin()); |
|
704 iContext->DrawRect(aTextCursorInfo.iCursorRect); |
|
705 } |