os/mm/mmplugins/mmfwplugins/src/Plugin/subtitle/subtitlegraphic/mmfsubtitlegraphic.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.
23 #include "mmfsubtitlegraphic.h"
24 #include "mmfsubtitlegraphicmessage.h"
27 const TUid KSubtitleGraphicDrawerImplId = {0x10285C9C};
28 const TUint KMaxSupportedFrames = 2;
31 Standard constructor for CMMFSubtitleGraphic
33 CMMFSubtitleGraphic::CMMFSubtitleGraphic()
41 EXPORT_C CMMFSubtitleGraphic::~CMMFSubtitleGraphic()
47 Allocates and constructs a CMMFSubtitleGraphic object
49 EXPORT_C CMMFSubtitleGraphic* CMMFSubtitleGraphic::NewL()
51 CMMFSubtitleGraphic* self = new(ELeave) CMMFSubtitleGraphic;
52 CleanupStack::PushL(self);
54 CleanupStack::Pop(self);
59 Performs 2nd phase construction for CMMFSubtitleGraphic
61 void CMMFSubtitleGraphic::ConstructL()
63 CWsGraphic::BaseConstructL(KSubtitleGraphicDrawerImplId, KNullDesC8);
65 iTempBitmap = new (ELeave) CFbsBitmap();
70 void CMMFSubtitleGraphic::OnReplace()
75 void CMMFSubtitleGraphic::HandleMessage(const TDesC8& /*aData*/)
79 // End from CWsGraphic
82 Requests that the content rendering plugin clears all content from the window
84 EXPORT_C void CMMFSubtitleGraphic::Clear()
86 TSubtitleCrpMsgClear clear;
88 const TPckgC<TSubtitleCrpMsgClear> message(clear);
92 // Flush window server msg queue.. msg will sit there otherwise...
97 Draws the bitmap frame indicated by aFrameHandle
99 @param aFrameHandle A CFbsBitmap handle, used as a source framebuffer by the CRP.
100 @param aDisplayDuration The time in microseconds that this frame should be
101 displayed for. The CRP will clear this frame after
102 aDisplayDuration microseconds. Note if the display duration
103 is 0 the frame will be cleared when a subsequent frame is drawn,
104 or when Clear() is called.
105 @param aDirtyRegion The decoder returns the region of the subtitle frame
106 that has been updated. i.e. the region that contains
108 @return KErrNone if successful, otherwise KErrArgument on an invalid
109 aDirtyRegion/aFrameHandle, or KErrNotReady if the corresponding
110 Initialize() function has not been called
112 EXPORT_C TInt CMMFSubtitleGraphic::DrawFrame(TInt aFrameHandle, const TRect& aDirtyRegion, const TTimeIntervalMicroSeconds& aDisplayDuration)
114 if ((aDirtyRegion.Width()==0)||(aDirtyRegion.Height()==0))
119 if ( KErrNone!=CheckBitmapHandle(aFrameHandle) )
124 if ( ESubtitleGraphicStateInitSimple!=iState )
129 TSubtitleCrpMsgDrawFrame messageContent(aFrameHandle, aDirtyRegion, aDisplayDuration);
130 TPckgBuf<TSubtitleCrpMsgDrawFrame> message(messageContent);
132 SendMessage(message);
134 // Flush window server msg queue.. msg will sit there otherwise...
141 Requests that the CRP initializes. The reference CRP duplicates and stores
142 both bitmap handles for future DrawFrame requests. This function is to be
143 used in conjunction with SwapFrame() only.
145 @param aBuffer1 A CFbsBitmap handle, will require duplication before use.
146 The reference CRP implementation treats this as the primary buffer
147 on startup, i.e. this handle should be used for the initial subtitle frame.
148 @param aBuffer2 A CFbsBitmap handle, will require duplication before use.
149 @return KErrNone if successful, otherwise KErrArgument on an invalid aBuffer1/aBuffer2
150 @see CFbsBitmap::Duplicate(TInt)
152 EXPORT_C TInt CMMFSubtitleGraphic::Initialize(TInt aBuffer1, TInt aBuffer2)
154 if ( (CheckBitmapHandle(aBuffer1)!=KErrNone) ||
155 (CheckBitmapHandle(aBuffer2)!=KErrNone))
160 iState = ESubtitleGraphicStateInit;
162 TSubtitleCrpMsgInit messageContent(aBuffer1, aBuffer2);
163 TPckgBuf<TSubtitleCrpMsgInit> message(messageContent);
165 SendMessage(message);
167 // Flush window server msg queue.. msg will sit there otherwise...
174 Requests that the CRP initializes. The reference CRP does nothing on
175 receiving this request. This function is to be used in conjunction with
178 EXPORT_C void CMMFSubtitleGraphic::Initialize()
180 TSubtitleCrpMsgInitSimple simple;
181 TPckgBuf<TSubtitleCrpMsgInitSimple> message(simple);
183 iState = ESubtitleGraphicStateInitSimple;
185 SendMessage(message);
187 // Flush window server msg queue.. msg will sit there otherwise...
192 Requests that the CRP draws the requested internal buffer.
193 The CRP maintains two internal buffers the handle for which are provided at initialisation
194 time. See CMMFSubtitleGraphic::Initialize(TInt aBuffer1, TInt aBuffer2).
196 @param aExpectedBuffer The index number of the internal frame the crp should draw.
197 @param aDisplayDuration The time in microseconds that this frame should be displayed for.
198 The CRP will clear this frame after aDisplayDuration microseconds
199 @param aDirtyRegion The decoder returns the region of the subtitle frame that has been
200 updated. i.e. the region that contains new subtitle content
201 @return KErrNone if successful. KErrArgument if an invalid aExpectedBuffer, aDirtyRegion, or
202 aDisplayDuration are given. KErrNotReady if the corresponding Initialize() function has not been called.
204 EXPORT_C TInt CMMFSubtitleGraphic::SwapFrame(TUint aExpectedBuffer, const TRect& aDirtyRegion, const TTimeIntervalMicroSeconds& aDisplayDuration)
206 if ((aExpectedBuffer > KMaxSupportedFrames) || (aExpectedBuffer == 0))
211 if ((aDirtyRegion.Width() <= 0)||(aDirtyRegion.Height() <= 0))
216 if (ESubtitleGraphicStateInit!=iState)
221 if (aDisplayDuration < 0)
226 TSubtitleCrpMsgRenderSwapFrame messageData(aExpectedBuffer, aDirtyRegion, aDisplayDuration);
227 TPckgBuf<TSubtitleCrpMsgRenderSwapFrame> message(messageData);
229 SendMessage(message);
231 // Flush window server msg queue.. msg will sit there otherwise...
238 Checks that the given handle is valid
239 @param aHandle A bitmap handle
240 @return KErrNone if successful, otherwise KErrArgument if aHandle is invalid
241 @see CFbsBitmap::Handle()
243 TInt CMMFSubtitleGraphic::CheckBitmapHandle(TInt aHandle)
245 // Check framehandle is valid.
246 TInt err = iTempBitmap->Duplicate(aHandle);
248 if ( KErrUnknown==err )