Update contrib.
1 // Copyright (c) 1994-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // GC and Graphics functions
21 #include "backedupwindow.h"
22 #include "windowgroup.h"
26 #include "Graphics/WSGRAPHICDRAWER.H"
29 CFbsBitmap *CWsGc::iScratchBitmap=NULL;
30 CFbsBitmap *CWsGc::iScratchMaskBitmap=NULL;
32 GLREF_C TInt ExternalizeRegionL(RWriteStream& aWriteStream, const RWsRegion& aRegion);
36 CWsGc* CWsGc::NewL(CWsClient *aOwner)
38 CWsGc* self = new(ELeave) CWsGc(aOwner);
39 CleanupStack::PushL(self);
41 CleanupStack::Pop(self);
45 void CWsGc::InitStaticsL()
47 iScratchBitmap=new(ELeave) CFbsBitmap();
48 iScratchMaskBitmap=new(ELeave) CFbsBitmap();
51 void CWsGc::DeleteStatics()
53 delete iScratchBitmap;
54 delete iScratchMaskBitmap;
57 CWsGc::CWsGc(CWsClient *owner) : CWsObject(owner,WS_HANDLE_GC)
59 __DECLARE_NAME(_S("CWsGc"));
62 void CWsGc::ConstructL()
65 iGdi=CFbsBitGc::NewL();
68 void CWsGc::Activate(CWsClientWindow *win)
72 if (CWsClient::iCurrentCommand.iOpcode==0)
74 WS_PANIC_ALWAYS(EWsPanicDrawCommandsInvalidState);
78 OwnerPanic(EWservPanicGcActive);
82 iGdi->ActivateNoJustAutoUpdate(iWin->Redraw()->OutputDevice());
83 iWin->GcActivated(this);
84 iGdi->SetBrushColor(iWin->BackColor());
89 CWsWindowGroup *winGp = iWin->WinGroup();
91 OwnerPanic(EWservPanicGroupWinScreenDeviceDeleted);
92 SetReply(winGp->Device()->ClientDevicePointer());
96 void CWsGc::Activate(const TInt &aHandle)
99 iWsOwner->HandleToClientWindow(aHandle,&win);
100 if (!win->BaseParent())
101 OwnerPanic(EWservPanicParentDeleted);
105 void CWsGc::Reactivate()
107 WS_ASSERT_DEBUG(iWin != NULL, EWsPanicDrawCommandsInvalidState);
108 iGdi->ActivateNoJustAutoUpdate(iWin->Redraw()->OutputDevice());
119 void CWsGc::Deactivate()
121 if (iWin) // Protect against deactivating an already deactivated GC, this is allowed to aid clean up code.
123 CWsFontCache::Instance()->ReleaseFont(iFont);
125 iWin->GcDeactivated(this);
126 CancelClippingRegion();
127 iWin->Redraw()->GcDeactivate(this);
137 void CWsGc::SetClippingRect(const TRect &aRect)
140 iClippingRect.Move(iOrigin);
141 iClippingRectSet=ETrue;
144 void CWsGc::ResetClippingRect()
146 iClippingRectSet=EFalse;
149 void CWsGc::SetClippingRegionL(TInt aRegionCount)
151 RWsRegion *newRegion=GetRegionFromClientL(iWsOwner, aRegionCount);
152 CancelClippingRegion();
153 iUserDefinedClippingRegion=newRegion;
155 if (iUserDefinedClippingRegion)
157 iUserDefinedClippingRegion->Offset(iOrigin);
161 void CWsGc::CancelClippingRegion()
163 if (iUserDefinedClippingRegion)
165 iUserDefinedClippingRegion->Destroy();
166 iUserDefinedClippingRegion=NULL;
170 void CWsGc::CheckPolyData(const TAny* aDataPtr, TInt aHeaderSize, TInt aNumPoints)
173 if (CWsClient::iCurrentCommand.iOpcode>0)
175 maxDataLen=CWsClient::EndOfCommandBuffer()-static_cast<const TUint8*>(aDataPtr);
177 else // Playing back from redraw store
179 maxDataLen=CWsClient::iCurrentCommand.iCmdLength;
181 const TInt dataSize=aHeaderSize+aNumPoints*sizeof(TPoint);
182 if (dataSize>maxDataLen)
183 GcOwnerPanic(EWservPanicBadPolyData);
186 void CWsGc::DoDrawPolygon(const TWsGcCmdDrawPolygon *aDrawPolygon)
188 CheckPolyData(aDrawPolygon,sizeof(TWsGcCmdDrawPolygon),aDrawPolygon->numPoints);
189 iGdi->DrawPolygon((TPoint *)(aDrawPolygon+1),aDrawPolygon->numPoints,aDrawPolygon->fillRule);
192 void CWsGc::StartSegmentedDrawPolygonL(const TWsGcCmdStartSegmentedDrawPolygon* aDrawPolygon)
194 if (iPolyPoints || !Rng(0, aDrawPolygon->totalNumPoints, KMaxTInt/2 - 1)) // Restarting without finishing old polygon or invalid size
195 GcOwnerPanic(EWservPanicBadPolyData);
196 iPolyPoints=(TPoint *)User::AllocL(aDrawPolygon->totalNumPoints*sizeof(TPoint));
197 iPolyPointListSize=aDrawPolygon->totalNumPoints;
200 void CWsGc::SegmentedDrawPolygonData(const TWsGcCmdSegmentedDrawPolygonData* aDrawPolygon)
202 if (aDrawPolygon->index<0 || (aDrawPolygon->index+aDrawPolygon->numPoints)>iPolyPointListSize)
203 GcOwnerPanic(EWservPanicBadPolyData);
204 Mem::Copy(iPolyPoints+aDrawPolygon->index,aDrawPolygon+1,aDrawPolygon->numPoints*sizeof(TPoint));
207 void CWsGc::EndSegmentedPolygon()
211 iPolyPointListSize = 0;
214 void CWsGc::DoDrawPolyLine(const TWsGcCmdDrawPolyLine *aDrawPolyLine, TBool aContinued)
216 TInt numPoints=aDrawPolyLine->numPoints;
217 CheckPolyData(aDrawPolyLine,sizeof(TWsGcCmdDrawPolyLine),numPoints);
218 const TPoint *points=(TPoint *)(aDrawPolyLine+1);
222 points=&aDrawPolyLine->last;
224 if (aDrawPolyLine->more) // more to come so don't draw the end point
225 iGdi->DrawPolyLineNoEndPoint(points,numPoints);
227 iGdi->DrawPolyLine(points,numPoints);
230 void CWsGc::GcOwnerPanic(TClientPanic aPanic)
232 iGdi->SetClippingRegion(NULL);
233 EndSegmentedPolygon();
234 iWin->WsOwner()->PPanic(aPanic);
237 TPtrC CWsGc::BufferTPtr(TText* aStart,TInt aLen)
240 if (!CWsClient::BufferTPtrGc(aStart,aLen,gcPtr))
241 GcOwnerPanic(EWservPanicBufferPtr);
245 void CWsGc::DoDrawCommand(TWsGcOpcodes aOpcode, const TWsGcCmdUnion &pData, const TRegion *aRegion)
249 WS_ASSERT_DEBUG(iWin,EWsPanicWindowNull);
250 if (aRegion->Count()==0)
252 if (aRegion->IsContainedBy(TRect(TPoint(0,0), iGdi->Device()->SizeInPixels())))
254 iGdi->SetClippingRegion(aRegion);
259 case EWsGcOpDrawWsGraphic:
260 case EWsGcOpDrawWsGraphicPtr:
262 // CWsGc doesn't support CRPs. CPlaybackGc does. This means backedup windows
263 // don't get to play with them yet.
266 case EWsGcOpMapColorsLocal:
267 iGdi->MapColors(pData.MapColorsLocal->rect, pData.MapColorsLocal->colors,pData.MapColorsLocal->numPairs,pData.MapColorsLocal->mapForwards);
269 case EWsGcOpDrawPolyLineLocalBufLen:
270 iGdi->DrawPolyLine(pData.DrawPolyLineLocalBufLen->points,pData.DrawPolyLineLocalBufLen->length);
272 case EWsGcOpDrawPolyLineLocal:
273 iGdi->DrawPolyLine(pData.PointList);
275 case EWsGcOpDrawPolygonLocalBufLen:
276 iGdi->DrawPolygon(pData.DrawPolygonLocalBufLen->points,pData.DrawPolygonLocalBufLen->length,pData.DrawPolygonLocalBufLen->fillRule);
278 case EWsGcOpDrawPolygonLocal:
279 iGdi->DrawPolygon(pData.DrawPolygonLocal->pointList,pData.DrawPolygonLocal->fillRule);
281 case EWsGcOpDrawBitmapLocal:
282 iGdi->DrawBitmap(pData.BitmapLocal->pos, pData.BitmapLocal->bitmap);
284 case EWsGcOpDrawBitmap2Local:
285 iGdi->DrawBitmap(pData.Bitmap2Local->rect, pData.Bitmap2Local->bitmap);
287 case EWsGcOpDrawBitmap3Local:
288 iGdi->DrawBitmap(pData.Bitmap3Local->rect, pData.Bitmap3Local->bitmap, pData.Bitmap3Local->srcRect);
290 case EWsGcOpDrawBitmapMaskedLocal:
291 iGdi->DrawBitmapMasked(pData.iBitmapMaskedLocal->iRect, pData.iBitmapMaskedLocal->iBitmap, pData.iBitmapMaskedLocal->iSrcRect, pData.iBitmapMaskedLocal->iMaskBitmap,pData.iBitmapMaskedLocal->iInvertMask);
293 case EWsGcOpAlphaBlendBitmapsLocal:
294 iGdi->AlphaBlendBitmaps(pData.AlphaBlendBitmapsLocal->point,pData.AlphaBlendBitmapsLocal->iBitmap,
295 pData.AlphaBlendBitmapsLocal->source, pData.AlphaBlendBitmapsLocal->iAlpha,
296 pData.AlphaBlendBitmapsLocal->alphaPoint);
299 case EWsGcOpDrawText:
300 iGdi->DrawText(BufferTPtr((TText *)(pData.DrawText+1),pData.DrawText->length),pData.DrawText->pos);
302 case EWsGcOpDrawBoxTextOptimised1:
303 iGdi->DrawText(BufferTPtr((TText *)(pData.BoxTextO1+1),pData.BoxTextO1->length),pData.BoxTextO1->box,
304 pData.BoxTextO1->baselineOffset,CGraphicsContext::ELeft,0);
306 case EWsGcOpDrawBoxTextOptimised2:
307 iGdi->DrawText(BufferTPtr((TText *)(pData.BoxTextO2+1),pData.BoxTextO2->length),pData.BoxTextO2->box,
308 pData.BoxTextO2->baselineOffset,pData.BoxTextO2->horiz,pData.BoxTextO2->leftMrg);
310 case EWsGcOpDrawTextPtr:
311 iGdi->DrawText(*pData.DrawTextPtr->text,pData.DrawTextPtr->pos);
313 case EWsGcOpDrawTextPtr1:
314 iGdi->DrawText(*pData.DrawTextPtr->text);
316 case EWsGcOpDrawBoxText:
317 iGdi->DrawText(BufferTPtr((TText *)(pData.BoxText+1),pData.BoxText->length),pData.BoxText->box,pData.BoxText->baselineOffset,pData.BoxText->width,pData.BoxText->horiz,pData.BoxText->leftMrg);
319 case EWsGcOpDrawBoxTextPtr:
320 iGdi->DrawText(*pData.DrawBoxTextPtr->text,pData.DrawBoxTextPtr->box,pData.DrawBoxTextPtr->baselineOffset,pData.DrawBoxTextPtr->width,pData.DrawBoxTextPtr->horiz,pData.DrawBoxTextPtr->leftMrg);
322 case EWsGcOpDrawBoxTextPtr1:
323 iGdi->DrawText(*pData.DrawBoxTextPtr->text,pData.DrawBoxTextPtr->box);
325 case EWsGcOpDrawTextVertical:
326 iGdi->DrawTextVertical(BufferTPtr((TText *)(pData.DrawTextVertical+1),pData.DrawTextVertical->length),pData.DrawTextVertical->pos
327 ,pData.DrawTextVertical->up);
329 case EWsGcOpDrawTextVerticalPtr:
330 iGdi->DrawTextVertical(*pData.DrawTextVerticalPtr->text,pData.DrawTextVerticalPtr->pos,pData.DrawTextVerticalPtr->up);
332 case EWsGcOpDrawTextVerticalPtr1:
333 iGdi->DrawTextVertical(*pData.DrawTextVerticalPtr->text,pData.DrawTextVerticalPtr->up);
335 case EWsGcOpDrawBoxTextVertical:
336 iGdi->DrawTextVertical(BufferTPtr((TText *)(pData.DrawBoxTextVertical+1),pData.DrawBoxTextVertical->length),
337 pData.DrawBoxTextVertical->box, pData.DrawBoxTextVertical->baselineOffset,
338 pData.DrawBoxTextVertical->up,(CGraphicsContext::TTextAlign)pData.DrawBoxTextVertical->vert,pData.DrawBoxTextVertical->margin);
340 case EWsGcOpDrawBoxTextVerticalPtr:
341 iGdi->DrawTextVertical(*pData.DrawBoxTextVerticalPtr->text,pData.DrawBoxTextVerticalPtr->box,pData.DrawBoxTextVerticalPtr->baselineOffset
342 ,pData.DrawBoxTextVerticalPtr->width,pData.DrawBoxTextVerticalPtr->up,pData.DrawBoxTextVerticalPtr->vert,pData.DrawBoxTextVerticalPtr->margin);
344 case EWsGcOpDrawBoxTextVerticalPtr1:
345 iGdi->DrawTextVertical(*pData.DrawBoxTextVerticalPtr->text,pData.DrawBoxTextVerticalPtr->box,pData.DrawBoxTextVerticalPtr->up);
347 case EWsGcOpDrawTextLocal:
348 iGdi->DrawText(*pData.DrawTextLocal->desc,pData.DrawTextLocal->pos);
350 case EWsGcOpDrawBoxTextLocal:
351 iGdi->DrawText(*pData.BoxTextLocal->desc,pData.BoxTextLocal->box,pData.BoxTextLocal->baselineOffset,
352 pData.BoxTextLocal->horiz,pData.BoxTextLocal->leftMrg);
354 case EWsGcOpDrawLine:
355 iGdi->DrawLine(pData.DrawLine->pnt1,pData.DrawLine->pnt2);
358 iGdi->DrawLine(iLinePos,*pData.Point);
361 iGdi->DrawLine(iLinePos,iLinePos+(*pData.Point));
364 iGdi->Plot(*pData.Point);
369 case EWsGcOpGdiBlt2Local:
370 iGdi->BitBlt(pData.GdiBlt2Local->pos,pData.GdiBlt2Local->bitmap);
372 case EWsGcOpGdiBlt3Local:
373 iGdi->BitBlt(pData.GdiBlt3Local->pos,pData.GdiBlt3Local->bitmap, pData.GdiBlt3Local->rect);
375 case EWsGcOpGdiBltMaskedLocal:
376 iGdi->BitBltMasked(pData.GdiBltMaskedLocal->pos,pData.GdiBltMaskedLocal->bitmap,
377 pData.GdiBltMaskedLocal->rect,pData.GdiBltMaskedLocal->maskBitmap,
378 pData.GdiBltMaskedLocal->invertMask);
380 case EWsGcOpGdiWsBlt2:
381 case EWsGcOpGdiWsBlt3:
382 case EWsGcOpGdiWsBltMasked:
383 case EWsGcOpGdiWsAlphaBlendBitmaps:
384 case EWsGcOpWsDrawBitmapMasked:
386 CFbsBitmap* scratchBimap=iScratchBitmap;
387 CFbsBitmap* scratchMaskBimap=iScratchMaskBitmap;
389 TInt handle=WsBitmapHandle(aOpcode,pData, maskHandle);
390 CWsClient* owner=iWin->WsOwner(); // We can't just use iWsOwner - it can be null for stored commands
393 DWsBitmap *bitmap=(DWsBitmap *)owner->HandleToObj(handle, WS_HANDLE_BITMAP);
395 GcOwnerPanic(EWservPanicBitmap);
396 scratchBimap=bitmap->FbsBitmap();
397 if (aOpcode==EWsGcOpGdiWsBltMasked || aOpcode==EWsGcOpGdiWsAlphaBlendBitmaps || aOpcode==EWsGcOpWsDrawBitmapMasked)
399 DWsBitmap *bitmap2=(DWsBitmap *)owner->HandleToObj(maskHandle, WS_HANDLE_BITMAP);
401 GcOwnerPanic(EWservPanicBitmap);
402 scratchMaskBimap=bitmap2->FbsBitmap();
407 GcOwnerPanic(EWservPanicBitmap);
411 case EWsGcOpGdiWsBlt2:
412 iGdi->BitBlt(pData.GdiBlt2->pos,scratchBimap);
414 case EWsGcOpGdiWsBlt3:
415 iGdi->BitBlt(pData.GdiBlt3->pos,scratchBimap, pData.GdiBlt3->rect);
417 case EWsGcOpGdiWsBltMasked:
419 iGdi->BitBltMasked(pData.GdiBltMasked->destination,scratchBimap,
420 pData.GdiBltMasked->source, scratchMaskBimap,
421 pData.GdiBltMasked->invertMask);
424 case EWsGcOpGdiWsAlphaBlendBitmaps:
426 iGdi->AlphaBlendBitmaps(pData.AlphaBlendBitmaps->point,scratchBimap,
427 pData.AlphaBlendBitmaps->source, scratchMaskBimap,
428 pData.AlphaBlendBitmaps->alphaPoint);
431 case EWsGcOpWsDrawBitmapMasked:
433 iGdi->DrawBitmapMasked(pData.iBitmapMasked->iRect,scratchBimap,
434 pData.iBitmapMasked->iSrcRect,scratchMaskBimap,
435 pData.iBitmapMasked->iInvertMask);
443 case EWsGcOpGdiBltMasked:
444 case EWsGcOpGdiAlphaBlendBitmaps:
445 case EWsGcOpDrawBitmap:
446 case EWsGcOpDrawBitmap2:
447 case EWsGcOpDrawBitmap3:
448 case EWsGcOpDrawBitmapMasked:
451 TInt ret = iScratchBitmap->Duplicate(FbsBitmapHandle(aOpcode, pData,maskHandle));
452 if(ret == KErrNoMemory)
455 GcOwnerPanic(EWservPanicBitmap);
460 iGdi->BitBlt(pData.GdiBlt2->pos,iScratchBitmap);
463 iGdi->BitBlt(pData.GdiBlt3->pos,iScratchBitmap, pData.GdiBlt3->rect);
465 case EWsGcOpGdiBltMasked:
467 TInt ret = iScratchMaskBitmap->Duplicate(pData.GdiBltMasked->maskHandle);
468 if(ret == KErrNoMemory)
471 GcOwnerPanic(EWservPanicBitmap);
473 iGdi->BitBltMasked(pData.GdiBltMasked->destination,iScratchBitmap,
474 pData.GdiBltMasked->source, iScratchMaskBitmap,
475 pData.GdiBltMasked->invertMask);
476 iScratchMaskBitmap->Reset();
479 case EWsGcOpGdiAlphaBlendBitmaps:
481 TInt ret = iScratchMaskBitmap->Duplicate(pData.AlphaBlendBitmaps->alphaHandle);
482 if (ret == KErrNoMemory)
485 GcOwnerPanic(EWservPanicBitmap);
487 iGdi->AlphaBlendBitmaps(pData.AlphaBlendBitmaps->point, iScratchBitmap,
488 pData.AlphaBlendBitmaps->source, iScratchMaskBitmap,
489 pData.AlphaBlendBitmaps->alphaPoint);
490 iScratchMaskBitmap->Reset();
493 case EWsGcOpDrawBitmap:
494 iGdi->DrawBitmap(pData.Bitmap->pos, iScratchBitmap);
496 case EWsGcOpDrawBitmap2:
497 iGdi->DrawBitmap(pData.Bitmap2->rect, iScratchBitmap);
499 case EWsGcOpDrawBitmap3:
500 iGdi->DrawBitmap(pData.Bitmap3->rect, iScratchBitmap, pData.Bitmap3->srcRect);
502 case EWsGcOpDrawBitmapMasked:
504 TInt ret = iScratchMaskBitmap->Duplicate(pData.iBitmapMasked->iMaskHandle);
505 if (ret == KErrNoMemory)
508 GcOwnerPanic(EWservPanicBitmap);
510 iGdi->DrawBitmapMasked(pData.iBitmapMasked->iRect, iScratchBitmap,
511 pData.iBitmapMasked->iSrcRect, iScratchMaskBitmap,
512 pData.iBitmapMasked->iInvertMask);
513 iScratchMaskBitmap->Reset();
517 iScratchBitmap->Reset();
520 case EWsGcOpDrawSegmentedPolygon:
521 iGdi->DrawPolygon(iPolyPoints,iPolyPointListSize,pData.DrawSegmentedPolygon->fillRule);
523 case EWsGcOpDrawPolygon:
524 DoDrawPolygon(pData.Polygon);
526 case EWsGcOpDrawPolyLine:
527 DoDrawPolyLine(pData.PolyLine, EFalse);
529 case EWsGcOpDrawPolyLineContinued:
530 DoDrawPolyLine(pData.PolyLine, ETrue);
533 iGdi->Clear(TRect(iWin->Size()));
535 case EWsGcOpClearRect:
536 iGdi->Clear(*pData.Rect);
538 case EWsGcOpDrawRect:
539 iGdi->DrawRect(*pData.Rect);
541 case EWsGcOpDrawEllipse:
542 iGdi->DrawEllipse(*pData.Rect);
544 case EWsGcOpDrawRoundRect:
545 iGdi->DrawRoundRect(*pData.Rect,pData.RoundRect->ellipse);
548 iGdi->DrawArc(*pData.Rect,pData.ArcOrPie->start,pData.ArcOrPie->end);
551 iGdi->DrawPie(*pData.Rect,pData.ArcOrPie->start,pData.ArcOrPie->end);
553 case EWsGcOpCopyRect:
554 iGdi->CopyRect(pData.CopyRect->pos,*pData.Rect);
556 case EWsGcOpMapColors:
557 iGdi->MapColors(pData.MapColors->rect,(TRgb *)(pData.MapColors+1),pData.MapColors->numPairs,pData.MapColors->mapForwards);
561 GcOwnerPanic(EWservPanicOpcode);
563 iGdi->SetClippingRegion(NULL);
566 TInt CWsGc::WsBitmapHandle(TInt aOpcode, const TWsGcCmdUnion &pData, TInt& aMaskHandle)
571 case EWsGcOpGdiWsBlt2:
572 handle=pData.GdiBlt2->handle;
574 case EWsGcOpGdiWsBlt3:
575 handle=pData.GdiBlt3->handle;
577 case EWsGcOpGdiWsBltMasked:
578 handle=pData.GdiBltMasked->handle;
579 aMaskHandle = pData.GdiBltMasked->maskHandle;
581 case EWsGcOpGdiWsAlphaBlendBitmaps:
582 handle=pData.AlphaBlendBitmaps->bitmapHandle;
583 aMaskHandle = pData.AlphaBlendBitmaps->alphaHandle;
585 case EWsGcOpWsDrawBitmapMasked:
586 handle=pData.iBitmapMasked->iHandle;
587 aMaskHandle=pData.iBitmapMasked->iMaskHandle;
590 OwnerPanic(EWservPanicOpcode);
595 TInt CWsGc::FbsBitmapHandle(TInt aOpcode, const TWsGcCmdUnion &pData, TInt& aMaskHandle)
602 handle=pData.GdiBlt2->handle;
605 handle=pData.GdiBlt3->handle;
607 case EWsGcOpGdiBltMasked:
608 handle=pData.GdiBltMasked->handle;
609 aMaskHandle=pData.GdiBltMasked->maskHandle;
611 case EWsGcOpGdiAlphaBlendBitmaps:
612 handle=pData.AlphaBlendBitmaps->bitmapHandle;
613 aMaskHandle=pData.AlphaBlendBitmaps->alphaHandle;
615 case EWsGcOpDrawBitmap:
616 handle=pData.Bitmap->handle;
618 case EWsGcOpDrawBitmap2:
619 handle=pData.Bitmap2->handle;
621 case EWsGcOpDrawBitmap3:
622 handle=pData.Bitmap3->handle;
624 case EWsGcOpDrawBitmapMasked:
625 handle=pData.iBitmapMasked->iHandle;
626 aMaskHandle=pData.iBitmapMasked->iMaskHandle;
629 OwnerPanic(EWservPanicOpcode);
635 void CWsGc::UpdateJustification(TText* aText,TInt aLen)
637 iGdi->UpdateJustification(BufferTPtr(aText,aLen));
640 void CWsGc::DoDrawing2(TWsGcOpcodes aOpcode, const TWsGcCmdUnion &pData)
642 iGdi->SetUserDisplayMode(iWin->DisplayMode());
643 if (iClippingRectSet)
645 iGdi->SetOrigin(TPoint(0,0));
646 iGdi->SetClippingRect(iClippingRect);
648 iGdi->SetOrigin(iOrigin);
650 DoDrawCommand(aOpcode,pData,iUserDefinedClippingRegion);
652 iGdi->SetUserDisplayMode(ENone);
653 iGdi->CancelClippingRect();
656 case EWsGcOpDrawLine:
657 iLinePos=pData.DrawLine->pnt2;
662 iLinePos=(*pData.Point);
666 iLinePos+=(*pData.Point);
668 case EWsGcOpDrawSegmentedPolygon:
669 EndSegmentedPolygon();
671 case EWsGcOpDrawText:
672 UpdateJustification((TText *)(pData.DrawText+1),pData.DrawText->length);
674 case EWsGcOpDrawTextVertical:
675 UpdateJustification((TText *)(pData.DrawTextVertical+1),pData.DrawTextVertical->length);
677 case EWsGcOpDrawBoxText:
678 UpdateJustification((TText *)(pData.BoxText+1),pData.BoxText->length);
680 case EWsGcOpDrawBoxTextOptimised1:
681 UpdateJustification((TText *)(pData.BoxTextO1+1),pData.BoxTextO1->length);
683 case EWsGcOpDrawBoxTextOptimised2:
684 UpdateJustification((TText *)(pData.BoxTextO2+1),pData.BoxTextO2->length);
686 case EWsGcOpDrawBoxTextVertical:
687 UpdateJustification((TText *)(pData.DrawBoxTextVertical+1),pData.DrawBoxTextVertical->length);
689 case EWsGcOpDrawTextLocal:
690 iGdi->UpdateJustification(*pData.DrawTextLocal->desc);
692 case EWsGcOpDrawBoxTextLocal:
693 iGdi->UpdateJustification(*pData.BoxTextLocal->desc);
695 case EWsGcOpDrawTextPtr:
696 iGdi->UpdateJustification(*pData.DrawTextPtr->text);
698 case EWsGcOpDrawTextVerticalPtr:
699 iGdi->UpdateJustification(*pData.DrawTextVerticalPtr->text);
701 case EWsGcOpDrawBoxTextPtr:
702 iGdi->UpdateJustification(*pData.DrawBoxTextPtr->text);
704 case EWsGcOpDrawBoxTextVerticalPtr:
705 iGdi->UpdateJustification(*pData.DrawBoxTextVerticalPtr->text);
710 void CWsGc::DoDrawing1(TWsGcOpcodes aOpcode, const TWsGcCmdUnion &pData)
712 TWsGcLargeStruct newData;
713 TWsGcCmdUnion pNewData;
717 pNewData.LargeStruct=&newData;
720 case EWsGcOpDrawTextPtr:
721 WS_ASSERT_DEBUG(sizeof(TWsGcLargeStruct)>=sizeof(TWsGcCmdDrawTextPtr), EWsPanicGcStructSizeError);
722 opcode=EWsGcOpDrawTextPtr1;
723 toGo=pData.DrawText->length;
724 pNewData.DrawTextPtr->pos=pData.DrawText->pos;
725 string=&(pNewData.DrawTextPtr->text);
727 case EWsGcOpDrawTextVerticalPtr:
728 WS_ASSERT_DEBUG(sizeof(TWsGcLargeStruct)>=sizeof(TWsGcCmdDrawTextVerticalPtr), EWsPanicGcStructSizeError);
729 opcode=EWsGcOpDrawTextVerticalPtr1;
730 toGo=pData.DrawTextVertical->length;
731 pNewData.DrawTextVerticalPtr->pos=pData.DrawTextVertical->pos;
732 pNewData.DrawTextVerticalPtr->up=pData.DrawTextVertical->up;
733 string=&(pNewData.DrawTextVerticalPtr->text);
736 case EWsGcOpDrawBoxTextPtr:
737 WS_ASSERT_DEBUG(sizeof(TWsGcLargeStruct)>=sizeof(TWsGcCmdBoxTextPtr), EWsPanicGcStructSizeError);
738 opcode=EWsGcOpDrawBoxTextPtr1;
739 toGo=pData.BoxText->length;
740 pNewData.DrawBoxTextPtr->box=pData.BoxText->box;
741 pNewData.DrawBoxTextPtr->baselineOffset=pData.BoxText->baselineOffset;
742 pNewData.DrawBoxTextPtr->horiz=pData.BoxText->horiz;
743 pNewData.DrawBoxTextPtr->leftMrg=pData.BoxText->leftMrg;
744 pNewData.DrawBoxTextPtr->width=pData.BoxText->width;
745 string=&(pNewData.DrawBoxTextPtr->text);
748 case EWsGcOpDrawBoxTextVerticalPtr:
749 WS_ASSERT_DEBUG(sizeof(TWsGcLargeStruct)>=sizeof(TWsGcCmdBoxTextVerticalPtr), EWsPanicGcStructSizeError);
750 opcode=EWsGcOpDrawBoxTextVerticalPtr1;
751 toGo=pData.DrawBoxTextVertical->length;
752 pNewData.DrawBoxTextVerticalPtr->box=pData.DrawBoxTextVertical->box;
753 pNewData.DrawBoxTextVerticalPtr->baselineOffset=pData.DrawBoxTextVertical->baselineOffset;
754 pNewData.DrawBoxTextVerticalPtr->up=pData.DrawBoxTextVertical->up;
755 pNewData.DrawBoxTextVerticalPtr->vert=pData.DrawBoxTextVertical->vert;
756 pNewData.DrawBoxTextVerticalPtr->margin=pData.DrawBoxTextVertical->margin;
757 pNewData.DrawBoxTextVerticalPtr->width=pData.DrawBoxTextVertical->width;
758 string=&(pNewData.DrawBoxTextVerticalPtr->text);
762 DoDrawing2(aOpcode,pData);
766 TBuf<ETextPtrBufLen> buf;
767 TInt len=ETextPtrBufLen;
774 iWsOwner->RemoteRead(buf,bufOffset);
775 DoDrawing2(aOpcode,pNewData);
782 void CWsGc::SetGcAttribute(TInt aOpcode, TWsGcCmdUnion pData)
786 case EWsGcOpSetDrawMode:
787 iGdi->SetDrawMode((CGraphicsContext::TDrawMode)*pData.UInt);
790 if (CWsFontCache::Instance()->UseFont(iFont, *pData.UInt))
791 { // Couldn't cache it
792 TInt ret = iGdi->UseFont(*pData.UInt);
793 if (ret == KErrNoMemory)
796 OwnerPanic(EWservPanicFont);
801 OwnerPanic(EWservPanicFont);
802 iGdi->UseFontNoDuplicate(iFont);
805 case EWsGcOpDiscardFont:
806 CWsFontCache::Instance()->ReleaseFont(iFont);
809 case EWsGcOpSetUnderlineStyle:
810 iGdi->SetUnderlineStyle(*pData.SetUnderlineStyle);
812 case EWsGcOpSetStrikethroughStyle:
813 iGdi->SetStrikethroughStyle(*pData.SetStrikethroughStyle);
815 case EWsGcOpUseBrushPattern:
817 TInt ret = iGdi->UseBrushPattern(*pData.handle);
818 if (ret == KErrNoMemory)
821 OwnerPanic(EWservPanicBitmap);
824 case EWsGcOpDiscardBrushPattern:
825 iGdi->DiscardBrushPattern();
827 case EWsGcOpSetBrushColor:
828 iGdi->SetBrushColor(*pData.rgb);
830 case EWsGcOpSetPenColor:
831 iGdi->SetPenColor(*pData.rgb);
833 case EWsGcOpSetPenStyle:
834 iGdi->SetPenStyle((CGraphicsContext::TPenStyle)*pData.UInt);
836 case EWsGcOpSetPenSize:
837 iGdi->SetPenSize(*pData.Size);
839 case EWsGcOpSetBrushStyle:
840 if ((CGraphicsContext::TBrushStyle)*pData.UInt==CGraphicsContext::EPatternedBrush &&
841 !iGdi->IsBrushPatternUsed())
842 OwnerPanic(EWservPanicNoBrush);
843 iGdi->SetBrushStyle((CGraphicsContext::TBrushStyle)*pData.UInt);
846 CWsFontCache::Instance()->ReleaseFont(iFont);
850 iGdi->SetBrushColor(iWin->BackColor());
852 case EWsGcOpSetBrushOrigin:
853 iGdi->SetBrushOrigin(*pData.Point);
855 case EWsGcOpSetDitherOrigin:
856 iGdi->SetDitherOrigin(*pData.Point);
858 case EWsGcOpSetWordJustification:
859 iGdi->SetWordJustification(pData.SetJustification->excessWidth, pData.SetJustification->numGaps);
861 case EWsGcOpSetCharJustification:
862 iGdi->SetCharJustification(pData.SetJustification->excessWidth, pData.SetJustification->numGaps);
864 case EWsGcOpSetOrigin:
865 SetOrigin(*pData.Point);
867 case EWsGcOpSetOpaque:
868 //SetOpaque(*pData.Bool);
870 case EWsGcOpSetShadowColor:
871 iGdi->SetShadowColor(*pData.rgb);
876 void CWsGc::DoDrawing0L(TWsGcOpcodes aOpcode, const TWsGcCmdUnion &pData)
880 OwnerPanic(EWservPanicGcNotActive);
886 case EWsGcOpStartSegmentedDrawPolygon:
887 // Andy - why are these two special cased like this?
888 //tell Redraw Store about the drawing data, so that it is stored and CWsGc::ExternalizeL can be called if required
889 if (iWin->Redraw()->DrawCommand(this,pData.any))
890 StartSegmentedDrawPolygonL(pData.StartSegmentedDrawPolygon);
892 case EWsGcOpSegmentedDrawPolygonData:
893 //tell Redraw Store about the drawing data, so that it is stored and CWsGc::ExternalizeL can be called if required
894 if (iWin->Redraw()->DrawCommand(this,pData.any))
895 SegmentedDrawPolygonData(pData.SegmentedDrawPolygonData);
897 case EWsGcOpSetClippingRegion:
898 SetClippingRegionL(*pData.Int);
900 case EWsGcOpSetClippingRect:
901 SetClippingRect(*pData.Rect);
903 case EWsGcOpCancelClippingRect:
906 case EWsGcOpCancelClippingRegion:
907 CancelClippingRegion();
909 case EWsGcOpSetFaded:
910 iGdi->SetFaded(*pData.Bool);
912 case EWsGcOpSetFadeParams:
913 iGdi->SetFadingParameters(WservEncoding::ExtractFirst8BitValue(*pData.UInt),WservEncoding::ExtractSecond8BitValue(*pData.UInt));
915 case EWsGcOpSetDrawMode:
917 case EWsGcOpDiscardFont:
918 case EWsGcOpUseBrushPattern:
919 case EWsGcOpDiscardBrushPattern:
920 case EWsGcOpSetBrushColor:
921 case EWsGcOpSetPenColor:
922 case EWsGcOpSetPenStyle:
923 case EWsGcOpSetPenSize:
924 case EWsGcOpSetBrushStyle:
926 case EWsGcOpSetBrushOrigin:
927 case EWsGcOpSetDitherOrigin:
928 case EWsGcOpSetUnderlineStyle:
929 case EWsGcOpSetStrikethroughStyle:
930 case EWsGcOpSetWordJustification:
931 case EWsGcOpSetCharJustification:
932 case EWsGcOpSetOrigin:
933 case EWsGcOpSetOpaque:
934 case EWsGcOpSetShadowColor:
936 SetGcAttribute(aOpcode,pData);
939 case EWsGcOpDrawBoxText:
940 case EWsGcOpDrawBoxTextOptimised1:
941 case EWsGcOpDrawBoxTextOptimised2:
942 case EWsGcOpDrawBoxTextPtr:
943 case EWsGcOpDrawBoxTextPtr1:
944 case EWsGcOpDrawTextPtr:
945 case EWsGcOpDrawTextPtr1:
946 case EWsGcOpDrawText:
947 case EWsGcOpDrawTextVertical:
948 case EWsGcOpDrawTextVerticalPtr:
949 case EWsGcOpDrawTextVerticalPtr1:
950 case EWsGcOpDrawBoxTextVertical:
951 case EWsGcOpDrawBoxTextVerticalPtr:
952 case EWsGcOpDrawBoxTextVerticalPtr1:
953 case EWsGcOpDrawTextLocal:
954 case EWsGcOpDrawBoxTextLocal:
956 //Make sure a font is set before any text related opcodes are used.
957 if (!iGdi->IsFontUsed())
958 OwnerPanic(EWservPanicNoFont);
961 default: // Assume remaining functions will draw
963 if (iWin->WinType()!=EWinTypeRoot)
965 if (!iWin->BaseParent())
966 OwnerPanic(EWservPanicParentDeleted);
967 if (iWin->WinType()!=EWinTypeClient)
968 OwnerPanic(EWservPanicReadOnlyDrawable);
970 if (iWin->Redraw()->DrawCommand(this,pData.any))
971 DoDrawing1(aOpcode,pData);
975 iWin->Redraw()->GcAttributeChange(this,pData.any);
978 void CWsGc::CommandL(TInt aOpcode, const TAny *aCmdData)
980 TWsGcOpcodes opcode = static_cast<TWsGcOpcodes>(aOpcode);
986 case EWsGcOpActivate:
987 Activate(*pData.handle);
989 case EWsGcOpDeactivate:
995 case EWsGcOpTestInvariant:
998 DoDrawing0L(opcode,pData);
1003 void CWsGc::SetOrigin(const TPoint &aOrigin)
1009 void CWsGc::SetOpaque(TBool /*aDrawOpaque*/)
1013 /*------------------------------------------------------------------------------
1014 Description: Saves graphics context information into a given buffer from a
1015 given start position rather than just streaming data to the end.
1016 This variant allows for buffers that are not fully utilised.
1017 -----------------------------------------------------------------------------*/
1018 TInt CWsGc::ExternalizeL(CBufBase& aBuffer, TInt aStartPos)
1020 WS_ASSERT_DEBUG(!IsPolyPointData(), EWsPanicDrawCommandsInvalidState);
1022 // Open the stream used for the output from the given start position
1024 RBufWriteStream bufWriteStream;
1025 bufWriteStream.Open(aBuffer, aStartPos);
1026 CleanupClosePushL(bufWriteStream);
1028 // Font/Bitmap Server data is serialised below in a call to
1029 // CFbsBitGc::ExternalizeL(). As this method does not return the amount of
1030 // the data externalised we use methods in the underlying stream to
1031 // calculate it. We do this because we need to return an accurate count of
1032 // data serialised from this method so that the caller can update its
1033 // buffer write counter.
1034 MStreamBuf* ptrToRawStream = bufWriteStream.Sink(); // This is the real stream
1036 // Position of read seek pointer before externalise
1037 TStreamPos size1 = ptrToRawStream->TellL(MStreamBuf::EWrite);
1039 // Save the font/bitmap server data
1040 iGdi->ExternalizeL(bufWriteStream);
1042 bufWriteStream.WriteInt32L(iOrigin.iX);
1043 bufWriteStream.WriteInt32L(iOrigin.iY);
1045 bufWriteStream.WriteInt8L(iClippingRectSet);
1047 // If there is a clipping rectangle output that too.
1048 if (iClippingRectSet)
1050 bufWriteStream << iClippingRect;
1053 // Save clipping region data.
1054 ExternalizeClippingRegionL(bufWriteStream);
1056 // Save the Alpha values for Brush and Pen colors.
1057 ExternalizeAlphaValueL(bufWriteStream);
1059 // Position of read seek pointer after externalise
1060 TStreamPos size2 = ptrToRawStream->TellL(MStreamBuf::EWrite);
1061 CleanupStack::PopAndDestroy(&bufWriteStream);
1063 // Return actual size of data serialized
1064 return (size2 - size1);
1067 /*------------------------------------------------------------------------------
1068 Description: Saves TRgb::alpha value information into a given buffer.
1069 ----------------------------------------------------------------------------*/
1070 void CWsGc::ExternalizeAlphaValueL(RWriteStream& aWriteStream)
1072 aWriteStream.WriteUint8L(iGdi->BrushColor().Alpha());
1073 aWriteStream.WriteUint8L(iGdi->PenColor().Alpha());
1076 /*------------------------------------------------------------------------------
1077 Description: Helper method to store clipping region data to a given
1079 -----------------------------------------------------------------------------*/
1080 TInt CWsGc::ExternalizeClippingRegionL(RWriteStream& aWriteStream)
1082 TBool clipRegion = (iUserDefinedClippingRegion != NULL);
1083 // Store flag to indicate if client has defined a clipping region
1084 aWriteStream.WriteInt8L(clipRegion);
1085 // Store client clipping region data if it exists
1088 return ExternalizeRegionL(aWriteStream, *iUserDefinedClippingRegion) + sizeof(TInt8);
1090 return sizeof(TInt8);