sl@0: // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: /** sl@0: @file sl@0: @publishedPartner sl@0: @prototype sl@0: */ sl@0: sl@0: #include sl@0: #include "mmfsubtitlegraphic.h" sl@0: #include "mmfsubtitlegraphicmessage.h" sl@0: sl@0: // Constants sl@0: const TUid KSubtitleGraphicDrawerImplId = {0x10285C9C}; sl@0: const TUint KMaxSupportedFrames = 2; sl@0: sl@0: /** sl@0: Standard constructor for CMMFSubtitleGraphic sl@0: */ sl@0: CMMFSubtitleGraphic::CMMFSubtitleGraphic() sl@0: { sl@0: sl@0: } sl@0: sl@0: /** sl@0: Standard destructor sl@0: */ sl@0: EXPORT_C CMMFSubtitleGraphic::~CMMFSubtitleGraphic() sl@0: { sl@0: delete iTempBitmap; sl@0: } sl@0: sl@0: /** sl@0: Allocates and constructs a CMMFSubtitleGraphic object sl@0: */ sl@0: EXPORT_C CMMFSubtitleGraphic* CMMFSubtitleGraphic::NewL() sl@0: { sl@0: CMMFSubtitleGraphic* self = new(ELeave) CMMFSubtitleGraphic; sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: /** sl@0: Performs 2nd phase construction for CMMFSubtitleGraphic sl@0: */ sl@0: void CMMFSubtitleGraphic::ConstructL() sl@0: { sl@0: CWsGraphic::BaseConstructL(KSubtitleGraphicDrawerImplId, KNullDesC8); sl@0: sl@0: iTempBitmap = new (ELeave) CFbsBitmap(); sl@0: } sl@0: sl@0: sl@0: // From CWsGraphic sl@0: void CMMFSubtitleGraphic::OnReplace() sl@0: { sl@0: sl@0: } sl@0: sl@0: void CMMFSubtitleGraphic::HandleMessage(const TDesC8& /*aData*/) sl@0: { sl@0: sl@0: } sl@0: // End from CWsGraphic sl@0: sl@0: /** sl@0: Requests that the content rendering plugin clears all content from the window sl@0: */ sl@0: EXPORT_C void CMMFSubtitleGraphic::Clear() sl@0: { sl@0: TSubtitleCrpMsgClear clear; sl@0: sl@0: const TPckgC message(clear); sl@0: sl@0: SendMessage(message); sl@0: sl@0: // Flush window server msg queue.. msg will sit there otherwise... sl@0: Flush(); sl@0: } sl@0: sl@0: /** sl@0: Draws the bitmap frame indicated by aFrameHandle sl@0: sl@0: @param aFrameHandle A CFbsBitmap handle, used as a source framebuffer by the CRP. sl@0: @param aDisplayDuration The time in microseconds that this frame should be sl@0: displayed for. The CRP will clear this frame after sl@0: aDisplayDuration microseconds. Note if the display duration sl@0: is 0 the frame will be cleared when a subsequent frame is drawn, sl@0: or when Clear() is called. sl@0: @param aDirtyRegion The decoder returns the region of the subtitle frame sl@0: that has been updated. i.e. the region that contains sl@0: new subtitle content sl@0: @return KErrNone if successful, otherwise KErrArgument on an invalid sl@0: aDirtyRegion/aFrameHandle, or KErrNotReady if the corresponding sl@0: Initialize() function has not been called sl@0: */ sl@0: EXPORT_C TInt CMMFSubtitleGraphic::DrawFrame(TInt aFrameHandle, const TRect& aDirtyRegion, const TTimeIntervalMicroSeconds& aDisplayDuration) sl@0: { sl@0: if ((aDirtyRegion.Width()==0)||(aDirtyRegion.Height()==0)) sl@0: { sl@0: return KErrArgument; sl@0: } sl@0: sl@0: if ( KErrNone!=CheckBitmapHandle(aFrameHandle) ) sl@0: { sl@0: return KErrArgument; sl@0: } sl@0: sl@0: if ( ESubtitleGraphicStateInitSimple!=iState ) sl@0: { sl@0: return KErrNotReady; sl@0: } sl@0: sl@0: TSubtitleCrpMsgDrawFrame messageContent(aFrameHandle, aDirtyRegion, aDisplayDuration); sl@0: TPckgBuf message(messageContent); sl@0: sl@0: SendMessage(message); sl@0: sl@0: // Flush window server msg queue.. msg will sit there otherwise... sl@0: Flush(); sl@0: sl@0: return KErrNone; sl@0: } sl@0: sl@0: /** sl@0: Requests that the CRP initializes. The reference CRP duplicates and stores sl@0: both bitmap handles for future DrawFrame requests. This function is to be sl@0: used in conjunction with SwapFrame() only. sl@0: sl@0: @param aBuffer1 A CFbsBitmap handle, will require duplication before use. sl@0: The reference CRP implementation treats this as the primary buffer sl@0: on startup, i.e. this handle should be used for the initial subtitle frame. sl@0: @param aBuffer2 A CFbsBitmap handle, will require duplication before use. sl@0: @return KErrNone if successful, otherwise KErrArgument on an invalid aBuffer1/aBuffer2 sl@0: @see CFbsBitmap::Duplicate(TInt) sl@0: */ sl@0: EXPORT_C TInt CMMFSubtitleGraphic::Initialize(TInt aBuffer1, TInt aBuffer2) sl@0: { sl@0: if ( (CheckBitmapHandle(aBuffer1)!=KErrNone) || sl@0: (CheckBitmapHandle(aBuffer2)!=KErrNone)) sl@0: { sl@0: return KErrArgument; sl@0: } sl@0: sl@0: iState = ESubtitleGraphicStateInit; sl@0: sl@0: TSubtitleCrpMsgInit messageContent(aBuffer1, aBuffer2); sl@0: TPckgBuf message(messageContent); sl@0: sl@0: SendMessage(message); sl@0: sl@0: // Flush window server msg queue.. msg will sit there otherwise... sl@0: Flush(); sl@0: sl@0: return KErrNone; sl@0: } sl@0: sl@0: /** sl@0: Requests that the CRP initializes. The reference CRP does nothing on sl@0: receiving this request. This function is to be used in conjunction with sl@0: DrawFrame() only. sl@0: */ sl@0: EXPORT_C void CMMFSubtitleGraphic::Initialize() sl@0: { sl@0: TSubtitleCrpMsgInitSimple simple; sl@0: TPckgBuf message(simple); sl@0: sl@0: iState = ESubtitleGraphicStateInitSimple; sl@0: sl@0: SendMessage(message); sl@0: sl@0: // Flush window server msg queue.. msg will sit there otherwise... sl@0: Flush(); sl@0: } sl@0: sl@0: /** sl@0: Requests that the CRP draws the requested internal buffer. sl@0: The CRP maintains two internal buffers the handle for which are provided at initialisation sl@0: time. See CMMFSubtitleGraphic::Initialize(TInt aBuffer1, TInt aBuffer2). sl@0: sl@0: @param aExpectedBuffer The index number of the internal frame the crp should draw. sl@0: @param aDisplayDuration The time in microseconds that this frame should be displayed for. sl@0: The CRP will clear this frame after aDisplayDuration microseconds sl@0: @param aDirtyRegion The decoder returns the region of the subtitle frame that has been sl@0: updated. i.e. the region that contains new subtitle content sl@0: @return KErrNone if successful. KErrArgument if an invalid aExpectedBuffer, aDirtyRegion, or sl@0: aDisplayDuration are given. KErrNotReady if the corresponding Initialize() function has not been called. sl@0: */ sl@0: EXPORT_C TInt CMMFSubtitleGraphic::SwapFrame(TUint aExpectedBuffer, const TRect& aDirtyRegion, const TTimeIntervalMicroSeconds& aDisplayDuration) sl@0: { sl@0: if ((aExpectedBuffer > KMaxSupportedFrames) || (aExpectedBuffer == 0)) sl@0: { sl@0: return KErrArgument; sl@0: } sl@0: sl@0: if ((aDirtyRegion.Width() <= 0)||(aDirtyRegion.Height() <= 0)) sl@0: { sl@0: return KErrArgument; sl@0: } sl@0: sl@0: if (ESubtitleGraphicStateInit!=iState) sl@0: { sl@0: return KErrNotReady; sl@0: } sl@0: sl@0: if (aDisplayDuration < 0) sl@0: { sl@0: return KErrArgument; sl@0: } sl@0: sl@0: TSubtitleCrpMsgRenderSwapFrame messageData(aExpectedBuffer, aDirtyRegion, aDisplayDuration); sl@0: TPckgBuf message(messageData); sl@0: sl@0: SendMessage(message); sl@0: sl@0: // Flush window server msg queue.. msg will sit there otherwise... sl@0: Flush(); sl@0: sl@0: return KErrNone; sl@0: } sl@0: sl@0: /** sl@0: Checks that the given handle is valid sl@0: @param aHandle A bitmap handle sl@0: @return KErrNone if successful, otherwise KErrArgument if aHandle is invalid sl@0: @see CFbsBitmap::Handle() sl@0: */ sl@0: TInt CMMFSubtitleGraphic::CheckBitmapHandle(TInt aHandle) sl@0: { sl@0: // Check framehandle is valid. sl@0: TInt err = iTempBitmap->Duplicate(aHandle); sl@0: sl@0: if ( KErrUnknown==err ) sl@0: { sl@0: return KErrArgument; sl@0: } sl@0: sl@0: return err; sl@0: }