|
0
|
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 |
/**
|
|
|
17 |
@file
|
|
|
18 |
@internalComponent
|
|
|
19 |
*/
|
|
|
20 |
|
|
|
21 |
#include <graphics/wsgraphicscontext.h>
|
|
|
22 |
#include "mmfsubtitlegraphicdrawer.h"
|
|
|
23 |
|
|
|
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;
|
|
|
27 |
|
|
|
28 |
CMMFSubtitleGraphicDrawer* CMMFSubtitleGraphicDrawer::NewL()
|
|
|
29 |
{
|
|
|
30 |
CMMFSubtitleGraphicDrawer* self = new(ELeave) CMMFSubtitleGraphicDrawer();
|
|
|
31 |
return self;
|
|
|
32 |
}
|
|
|
33 |
|
|
|
34 |
CMMFSubtitleGraphicDrawer::~CMMFSubtitleGraphicDrawer()
|
|
|
35 |
{
|
|
|
36 |
delete iBitmap1;
|
|
|
37 |
delete iBitmap2;
|
|
|
38 |
delete iTempBitmap;
|
|
|
39 |
}
|
|
|
40 |
|
|
|
41 |
void CMMFSubtitleGraphicDrawer::ConstructL(MWsGraphicDrawerEnvironment& aEnv, const TGraphicDrawerId& aId, MWsClient& aOwner, const TDesC8& /*aData*/)
|
|
|
42 |
{
|
|
|
43 |
// Note this method is called by the baseclass not CMMFSubtitleGraphicDrawer
|
|
|
44 |
BaseConstructL(aEnv, aId, aOwner);
|
|
|
45 |
|
|
|
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();
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
|
|
|
54 |
// From CwsGraphicDrawer
|
|
|
55 |
void CMMFSubtitleGraphicDrawer::HandleMessage(const TDesC8& aData)
|
|
|
56 |
{
|
|
|
57 |
// Retreive message type from buffer
|
|
|
58 |
TInt8 msgType = aData[0];
|
|
|
59 |
|
|
|
60 |
switch (msgType)
|
|
|
61 |
{
|
|
|
62 |
case ESubtitleCrpMessageInit:
|
|
|
63 |
{
|
|
|
64 |
iCaptureRegion = ETrue;
|
|
|
65 |
TPckgBuf<TSubtitleCrpMsgInit> message;
|
|
|
66 |
message.Copy(aData);
|
|
|
67 |
ProcessMessageInit(message());
|
|
|
68 |
}
|
|
|
69 |
break;
|
|
|
70 |
|
|
|
71 |
case ESubtitleCrpMessageInitSimple:
|
|
|
72 |
iCaptureRegion = ETrue;
|
|
|
73 |
iBitmap1Valid=EFalse;
|
|
|
74 |
iBitmap2Valid=EFalse;
|
|
|
75 |
iTempBitmapValid=ETrue;
|
|
|
76 |
break;
|
|
|
77 |
|
|
|
78 |
case ESubtitleCrpMessageDrawFrame:
|
|
|
79 |
{
|
|
|
80 |
iState = ESubtitleGraphicStateDrawFrame;
|
|
|
81 |
TPckgBuf<TSubtitleCrpMsgDrawFrame> message;
|
|
|
82 |
message.Copy(aData);
|
|
|
83 |
ProcessMessageDrawFrame(message());
|
|
|
84 |
}
|
|
|
85 |
break;
|
|
|
86 |
|
|
|
87 |
case ESubtitleCrpMessageSwapFrame:
|
|
|
88 |
{
|
|
|
89 |
iState = ESubtitleGraphicStateSwapFrame;
|
|
|
90 |
TPckgBuf<TSubtitleCrpMsgRenderSwapFrame> message;
|
|
|
91 |
message.Copy(aData);
|
|
|
92 |
ProcessMessageSwapFrame(message());
|
|
|
93 |
}
|
|
|
94 |
break;
|
|
|
95 |
|
|
|
96 |
case ESubtitleCrpMessageClear:
|
|
|
97 |
iDisplayClearDue.UniversalTime();
|
|
|
98 |
iState = ESubtitleGraphicStateClear;
|
|
|
99 |
break;
|
|
|
100 |
|
|
|
101 |
default:
|
|
|
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;
|
|
|
106 |
break;
|
|
|
107 |
}
|
|
|
108 |
|
|
|
109 |
// Note clear messages require no further processing we just need to invalidate the display
|
|
|
110 |
|
|
|
111 |
// Ask WSERV to redraw the CRP
|
|
|
112 |
Invalidate();
|
|
|
113 |
}
|
|
|
114 |
|
|
|
115 |
void CMMFSubtitleGraphicDrawer::DoDraw(MWsGc& aGc, const TRect& aRect, const TDesC8& /*aData*/) const
|
|
|
116 |
{
|
|
|
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)
|
|
|
120 |
|
|
|
121 |
// Store the invalid region as our subtitle region to complete initialization.
|
|
|
122 |
if (iCaptureRegion)
|
|
|
123 |
{
|
|
|
124 |
iSubtitleRegion = aRect;
|
|
|
125 |
iCaptureRegion = EFalse;
|
|
|
126 |
}
|
|
|
127 |
|
|
|
128 |
// If the current state is waiting we do dont need to do anything
|
|
|
129 |
if ((iSubtitleRegion.IsEmpty())||(iState==ESubtitleGraphicStateWaiting))
|
|
|
130 |
{
|
|
|
131 |
return;
|
|
|
132 |
}
|
|
|
133 |
|
|
|
134 |
switch(iState)
|
|
|
135 |
{
|
|
|
136 |
case ESubtitleGraphicStateDrawFrame:
|
|
|
137 |
case ESubtitleGraphicStateSwapFrame:
|
|
|
138 |
// Blt new content
|
|
|
139 |
DoBitBlt(aGc, iDirtyRegion);
|
|
|
140 |
|
|
|
141 |
if ( iDisplayDuration.Int64() > 0 )
|
|
|
142 |
{
|
|
|
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;
|
|
|
149 |
}
|
|
|
150 |
else
|
|
|
151 |
{
|
|
|
152 |
// Redraw this frames content until instructed to stop
|
|
|
153 |
iState = ESubtitleGraphicStateRefreshContent;
|
|
|
154 |
}
|
|
|
155 |
break;
|
|
|
156 |
|
|
|
157 |
case ESubtitleGraphicStateRefreshContent:
|
|
|
158 |
// Refresh current frame content
|
|
|
159 |
DoBitBlt(aGc, iDirtyRegion);
|
|
|
160 |
break;
|
|
|
161 |
|
|
|
162 |
case ESubtitleGraphicStateClear:
|
|
|
163 |
{
|
|
|
164 |
// Clear is due, check to see if the clear is due now
|
|
|
165 |
TTime timeNow;
|
|
|
166 |
timeNow.UniversalTime();
|
|
|
167 |
TInt diff=iDisplayClearDue.Int64()-timeNow.Int64();
|
|
|
168 |
|
|
|
169 |
if ( diff > 0 )
|
|
|
170 |
{
|
|
|
171 |
// Clear is not due do a standard bitblt
|
|
|
172 |
DoBitBlt(aGc, iDirtyRegion);
|
|
|
173 |
}
|
|
|
174 |
else
|
|
|
175 |
{
|
|
|
176 |
// No further processing required as WSERV clears the region for us
|
|
|
177 |
iState = ESubtitleGraphicStateWaiting;
|
|
|
178 |
}
|
|
|
179 |
}
|
|
|
180 |
break;
|
|
|
181 |
|
|
|
182 |
default:
|
|
|
183 |
// Should never happen
|
|
|
184 |
#ifdef _DEBUG
|
|
|
185 |
RDebug::Printf("CMMFSubtitleGraphicDrawer::DoDraw() - Invalid State in Drawer should never happen");
|
|
|
186 |
User::Invariant();
|
|
|
187 |
#endif
|
|
|
188 |
break;
|
|
|
189 |
}
|
|
|
190 |
}
|
|
|
191 |
|
|
|
192 |
/**
|
|
|
193 |
Renders the current bitmap frame
|
|
|
194 |
*/
|
|
|
195 |
void CMMFSubtitleGraphicDrawer::DoBitBlt(MWsGc& aGc, const TRect& aRect) const
|
|
|
196 |
{
|
|
|
197 |
MWsGraphicsContext* context = aGc.ObjectInterface<MWsGraphicsContext>();
|
|
|
198 |
if(!context)
|
|
|
199 |
{
|
|
|
200 |
RDebug::Printf("CMMFSubtitleGraphicDrawer::DoBitBlt can not get MWsGraphicsContext");
|
|
|
201 |
return;
|
|
|
202 |
}
|
|
|
203 |
context->Push();
|
|
|
204 |
|
|
|
205 |
switch (iCurrentFrame)
|
|
|
206 |
{
|
|
|
207 |
case ESubtitleGraphicFrame1:
|
|
|
208 |
if (iBitmap1Valid)
|
|
|
209 |
{
|
|
|
210 |
context->BitBlt(iSubtitleRegion.iTl + aRect.iTl, *iBitmap1, aRect);
|
|
|
211 |
}
|
|
|
212 |
break;
|
|
|
213 |
|
|
|
214 |
case ESubtitleGraphicFrame2:
|
|
|
215 |
if (iBitmap2Valid)
|
|
|
216 |
{
|
|
|
217 |
context->BitBlt(iSubtitleRegion.iTl + aRect.iTl, *iBitmap2, aRect);
|
|
|
218 |
}
|
|
|
219 |
break;
|
|
|
220 |
|
|
|
221 |
case ESubtitleGraphicFrame3:
|
|
|
222 |
if (iTempBitmapValid)
|
|
|
223 |
{
|
|
|
224 |
context->BitBlt(iSubtitleRegion.iTl + aRect.iTl, *iTempBitmap, aRect);
|
|
|
225 |
}
|
|
|
226 |
break;
|
|
|
227 |
|
|
|
228 |
default:
|
|
|
229 |
break;
|
|
|
230 |
}
|
|
|
231 |
|
|
|
232 |
context->Pop();
|
|
|
233 |
}
|
|
|
234 |
|
|
|
235 |
/**
|
|
|
236 |
Process initialization message from client. Readies the CRP for drawing
|
|
|
237 |
@param aMessage Message data received from client
|
|
|
238 |
*/
|
|
|
239 |
void CMMFSubtitleGraphicDrawer::ProcessMessageInit(TSubtitleCrpMsgInit& aMessage)
|
|
|
240 |
{
|
|
|
241 |
// Duplicate client bitmap handles
|
|
|
242 |
// These are verified by the client before they are sent
|
|
|
243 |
iBitmap1->Reset();
|
|
|
244 |
TInt err = iBitmap1->Duplicate(aMessage.iBitmapHandle1);
|
|
|
245 |
|
|
|
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());
|
|
|
249 |
|
|
|
250 |
iBitmap2->Reset();
|
|
|
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());
|
|
|
255 |
|
|
|
256 |
iCurrentFrame=ESubtitleGraphicFrame1;
|
|
|
257 |
iBitmap1Valid=ETrue;
|
|
|
258 |
iBitmap2Valid=ETrue;
|
|
|
259 |
iTempBitmapValid=EFalse;
|
|
|
260 |
}
|
|
|
261 |
|
|
|
262 |
/**
|
|
|
263 |
Process draw frame message from client. Draw the bitmap provided.
|
|
|
264 |
@param aMessage Message data received from client
|
|
|
265 |
*/
|
|
|
266 |
void CMMFSubtitleGraphicDrawer::ProcessMessageDrawFrame(TSubtitleCrpMsgDrawFrame& aMessage)
|
|
|
267 |
{
|
|
|
268 |
// Duplicate client bitmap handle
|
|
|
269 |
iTempBitmap->Reset();
|
|
|
270 |
iTempBitmap->Duplicate(aMessage.iBitmapHandle);
|
|
|
271 |
|
|
|
272 |
iOldDirtyRegion=iDirtyRegion;
|
|
|
273 |
iDirtyRegion=aMessage.iDirtyRegion;
|
|
|
274 |
|
|
|
275 |
iDisplayDuration=aMessage.iDisplayDuration;
|
|
|
276 |
iCurrentFrame=ESubtitleGraphicFrame3;
|
|
|
277 |
}
|
|
|
278 |
|
|
|
279 |
/**
|
|
|
280 |
Process swap frame message from client. Draws the current backbuffer provided.
|
|
|
281 |
@param aMessage Message data received from client
|
|
|
282 |
*/
|
|
|
283 |
void CMMFSubtitleGraphicDrawer::ProcessMessageSwapFrame(TSubtitleCrpMsgRenderSwapFrame& aMessage)
|
|
|
284 |
{
|
|
|
285 |
__ASSERT_DEBUG((aMessage.iExpectedFrame==ESubtitleGraphicFrame1)||(aMessage.iExpectedFrame==ESubtitleGraphicFrame2), User::Invariant());
|
|
|
286 |
|
|
|
287 |
iDisplayDuration = aMessage.iDisplayDuration;
|
|
|
288 |
iOldDirtyRegion=iDirtyRegion;
|
|
|
289 |
iDirtyRegion = aMessage.iDirtyRegion;
|
|
|
290 |
|
|
|
291 |
// Swap the frame pointer
|
|
|
292 |
iCurrentFrame = static_cast<TSubtitleGraphicFrame>(aMessage.iExpectedFrame);
|
|
|
293 |
}
|