os/mm/mmplugins/mmfwplugins/src/Plugin/subtitle/subtitlegraphicdrawer/mmfsubtitlegraphicdrawer.cpp
Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
21 #include <graphics/wsgraphicscontext.h>
22 #include "mmfsubtitlegraphicdrawer.h"
24 // Compensation value in microseconds to account for differences in the requested callback time and the actual
25 // time the callback is delivered
26 static const TInt KClockDrift=100000;
28 CMMFSubtitleGraphicDrawer* CMMFSubtitleGraphicDrawer::NewL()
30 CMMFSubtitleGraphicDrawer* self = new(ELeave) CMMFSubtitleGraphicDrawer();
34 CMMFSubtitleGraphicDrawer::~CMMFSubtitleGraphicDrawer()
41 void CMMFSubtitleGraphicDrawer::ConstructL(MWsGraphicDrawerEnvironment& aEnv, const TGraphicDrawerId& aId, MWsClient& aOwner, const TDesC8& /*aData*/)
43 // Note this method is called by the baseclass not CMMFSubtitleGraphicDrawer
44 BaseConstructL(aEnv, aId, aOwner);
46 // Construct bitmap objects. Do this here as we can leave usefully with
47 // any construction errors
48 iBitmap1 = new (ELeave) CFbsBitmap();
49 iBitmap2 = new (ELeave) CFbsBitmap();
50 iTempBitmap = new (ELeave) CFbsBitmap();
54 // From CwsGraphicDrawer
55 void CMMFSubtitleGraphicDrawer::HandleMessage(const TDesC8& aData)
57 // Retreive message type from buffer
58 TInt8 msgType = aData[0];
62 case ESubtitleCrpMessageInit:
64 iCaptureRegion = ETrue;
65 TPckgBuf<TSubtitleCrpMsgInit> message;
67 ProcessMessageInit(message());
71 case ESubtitleCrpMessageInitSimple:
72 iCaptureRegion = ETrue;
75 iTempBitmapValid=ETrue;
78 case ESubtitleCrpMessageDrawFrame:
80 iState = ESubtitleGraphicStateDrawFrame;
81 TPckgBuf<TSubtitleCrpMsgDrawFrame> message;
83 ProcessMessageDrawFrame(message());
87 case ESubtitleCrpMessageSwapFrame:
89 iState = ESubtitleGraphicStateSwapFrame;
90 TPckgBuf<TSubtitleCrpMsgRenderSwapFrame> message;
92 ProcessMessageSwapFrame(message());
96 case ESubtitleCrpMessageClear:
97 iDisplayClearDue.UniversalTime();
98 iState = ESubtitleGraphicStateClear;
102 // Silently ignore unrecognised messages
103 // Clear messages for example require no further processing
104 // Set the state to waiting so DoDraw will do nothing.
105 iState = ESubtitleGraphicStateWaiting;
109 // Note clear messages require no further processing we just need to invalidate the display
111 // Ask WSERV to redraw the CRP
115 void CMMFSubtitleGraphicDrawer::DoDraw(MWsGc& aGc, const TRect& aRect, const TDesC8& /*aData*/) const
117 // For some crp rendering states we need to ensure that this DoDraw has been called
118 // in response to Invalidate() and not generated in response to a portion of the CRP
119 // becoming invald for some reason (menus, dialogs etc)
121 // Store the invalid region as our subtitle region to complete initialization.
124 iSubtitleRegion = aRect;
125 iCaptureRegion = EFalse;
128 // If the current state is waiting we do dont need to do anything
129 if ((iSubtitleRegion.IsEmpty())||(iState==ESubtitleGraphicStateWaiting))
136 case ESubtitleGraphicStateDrawFrame:
137 case ESubtitleGraphicStateSwapFrame:
139 DoBitBlt(aGc, iDirtyRegion);
141 if ( iDisplayDuration.Int64() > 0 )
143 // Schedule a clear frame to remove this subtitle after the requested time
144 // Note clear messages require no further processing we just need to schedule a redraw
145 aGc.ScheduleAnimation(iSubtitleRegion, iDisplayDuration.Int64());
146 iDisplayClearDue.UniversalTime();
147 iDisplayClearDue=iDisplayDuration.Int64()+iDisplayClearDue.Int64()-KClockDrift;
148 iState = ESubtitleGraphicStateClear;
152 // Redraw this frames content until instructed to stop
153 iState = ESubtitleGraphicStateRefreshContent;
157 case ESubtitleGraphicStateRefreshContent:
158 // Refresh current frame content
159 DoBitBlt(aGc, iDirtyRegion);
162 case ESubtitleGraphicStateClear:
164 // Clear is due, check to see if the clear is due now
166 timeNow.UniversalTime();
167 TInt diff=iDisplayClearDue.Int64()-timeNow.Int64();
171 // Clear is not due do a standard bitblt
172 DoBitBlt(aGc, iDirtyRegion);
176 // No further processing required as WSERV clears the region for us
177 iState = ESubtitleGraphicStateWaiting;
183 // Should never happen
185 RDebug::Printf("CMMFSubtitleGraphicDrawer::DoDraw() - Invalid State in Drawer should never happen");
193 Renders the current bitmap frame
195 void CMMFSubtitleGraphicDrawer::DoBitBlt(MWsGc& aGc, const TRect& aRect) const
197 MWsGraphicsContext* context = aGc.ObjectInterface<MWsGraphicsContext>();
200 RDebug::Printf("CMMFSubtitleGraphicDrawer::DoBitBlt can not get MWsGraphicsContext");
205 switch (iCurrentFrame)
207 case ESubtitleGraphicFrame1:
210 context->BitBlt(iSubtitleRegion.iTl + aRect.iTl, *iBitmap1, aRect);
214 case ESubtitleGraphicFrame2:
217 context->BitBlt(iSubtitleRegion.iTl + aRect.iTl, *iBitmap2, aRect);
221 case ESubtitleGraphicFrame3:
222 if (iTempBitmapValid)
224 context->BitBlt(iSubtitleRegion.iTl + aRect.iTl, *iTempBitmap, aRect);
236 Process initialization message from client. Readies the CRP for drawing
237 @param aMessage Message data received from client
239 void CMMFSubtitleGraphicDrawer::ProcessMessageInit(TSubtitleCrpMsgInit& aMessage)
241 // Duplicate client bitmap handles
242 // These are verified by the client before they are sent
244 TInt err = iBitmap1->Duplicate(aMessage.iBitmapHandle1);
246 // This should never be a problem but check in debug modes just in case
247 // We dont do this in release mode as it panics the window server...
248 __ASSERT_DEBUG(KErrNone==err, User::Invariant());
251 err = iBitmap2->Duplicate(aMessage.iBitmapHandle2);
252 // This should never be a problem but check in debug modes just in case
253 // We dont do this in release mode as it panics the window server...
254 __ASSERT_DEBUG(KErrNone==err, User::Invariant());
256 iCurrentFrame=ESubtitleGraphicFrame1;
259 iTempBitmapValid=EFalse;
263 Process draw frame message from client. Draw the bitmap provided.
264 @param aMessage Message data received from client
266 void CMMFSubtitleGraphicDrawer::ProcessMessageDrawFrame(TSubtitleCrpMsgDrawFrame& aMessage)
268 // Duplicate client bitmap handle
269 iTempBitmap->Reset();
270 iTempBitmap->Duplicate(aMessage.iBitmapHandle);
272 iOldDirtyRegion=iDirtyRegion;
273 iDirtyRegion=aMessage.iDirtyRegion;
275 iDisplayDuration=aMessage.iDisplayDuration;
276 iCurrentFrame=ESubtitleGraphicFrame3;
280 Process swap frame message from client. Draws the current backbuffer provided.
281 @param aMessage Message data received from client
283 void CMMFSubtitleGraphicDrawer::ProcessMessageSwapFrame(TSubtitleCrpMsgRenderSwapFrame& aMessage)
285 __ASSERT_DEBUG((aMessage.iExpectedFrame==ESubtitleGraphicFrame1)||(aMessage.iExpectedFrame==ESubtitleGraphicFrame2), User::Invariant());
287 iDisplayDuration = aMessage.iDisplayDuration;
288 iOldDirtyRegion=iDirtyRegion;
289 iDirtyRegion = aMessage.iDirtyRegion;
291 // Swap the frame pointer
292 iCurrentFrame = static_cast<TSubtitleGraphicFrame>(aMessage.iExpectedFrame);