os/mm/mmplugins/mmfwplugins/src/Plugin/subtitle/subtitlegraphic/mmfsubtitlegraphic.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/mm/mmplugins/mmfwplugins/src/Plugin/subtitle/subtitlegraphic/mmfsubtitlegraphic.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,254 @@
1.4 +// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +/**
1.20 + @file
1.21 + @publishedPartner
1.22 + @prototype
1.23 +*/
1.24 +
1.25 +#include <s32mem.h>
1.26 +#include "mmfsubtitlegraphic.h"
1.27 +#include "mmfsubtitlegraphicmessage.h"
1.28 +
1.29 +// Constants
1.30 +const TUid KSubtitleGraphicDrawerImplId = {0x10285C9C};
1.31 +const TUint KMaxSupportedFrames = 2;
1.32 +
1.33 +/**
1.34 +Standard constructor for CMMFSubtitleGraphic
1.35 +*/
1.36 +CMMFSubtitleGraphic::CMMFSubtitleGraphic()
1.37 + {
1.38 +
1.39 + }
1.40 +
1.41 +/**
1.42 +Standard destructor
1.43 +*/
1.44 +EXPORT_C CMMFSubtitleGraphic::~CMMFSubtitleGraphic()
1.45 + {
1.46 + delete iTempBitmap;
1.47 + }
1.48 +
1.49 +/**
1.50 +Allocates and constructs a CMMFSubtitleGraphic object
1.51 +*/
1.52 +EXPORT_C CMMFSubtitleGraphic* CMMFSubtitleGraphic::NewL()
1.53 + {
1.54 + CMMFSubtitleGraphic* self = new(ELeave) CMMFSubtitleGraphic;
1.55 + CleanupStack::PushL(self);
1.56 + self->ConstructL();
1.57 + CleanupStack::Pop(self);
1.58 + return self;
1.59 + }
1.60 +
1.61 +/**
1.62 +Performs 2nd phase construction for CMMFSubtitleGraphic
1.63 +*/
1.64 +void CMMFSubtitleGraphic::ConstructL()
1.65 + {
1.66 + CWsGraphic::BaseConstructL(KSubtitleGraphicDrawerImplId, KNullDesC8);
1.67 +
1.68 + iTempBitmap = new (ELeave) CFbsBitmap();
1.69 + }
1.70 +
1.71 +
1.72 +// From CWsGraphic
1.73 +void CMMFSubtitleGraphic::OnReplace()
1.74 + {
1.75 +
1.76 + }
1.77 +
1.78 +void CMMFSubtitleGraphic::HandleMessage(const TDesC8& /*aData*/)
1.79 + {
1.80 +
1.81 + }
1.82 +// End from CWsGraphic
1.83 +
1.84 +/**
1.85 +Requests that the content rendering plugin clears all content from the window
1.86 +*/
1.87 +EXPORT_C void CMMFSubtitleGraphic::Clear()
1.88 + {
1.89 + TSubtitleCrpMsgClear clear;
1.90 +
1.91 + const TPckgC<TSubtitleCrpMsgClear> message(clear);
1.92 +
1.93 + SendMessage(message);
1.94 +
1.95 + // Flush window server msg queue.. msg will sit there otherwise...
1.96 + Flush();
1.97 + }
1.98 +
1.99 +/**
1.100 +Draws the bitmap frame indicated by aFrameHandle
1.101 +
1.102 +@param aFrameHandle A CFbsBitmap handle, used as a source framebuffer by the CRP.
1.103 +@param aDisplayDuration The time in microseconds that this frame should be
1.104 + displayed for. The CRP will clear this frame after
1.105 + aDisplayDuration microseconds. Note if the display duration
1.106 + is 0 the frame will be cleared when a subsequent frame is drawn,
1.107 + or when Clear() is called.
1.108 +@param aDirtyRegion The decoder returns the region of the subtitle frame
1.109 + that has been updated. i.e. the region that contains
1.110 + new subtitle content
1.111 +@return KErrNone if successful, otherwise KErrArgument on an invalid
1.112 + aDirtyRegion/aFrameHandle, or KErrNotReady if the corresponding
1.113 + Initialize() function has not been called
1.114 +*/
1.115 +EXPORT_C TInt CMMFSubtitleGraphic::DrawFrame(TInt aFrameHandle, const TRect& aDirtyRegion, const TTimeIntervalMicroSeconds& aDisplayDuration)
1.116 + {
1.117 + if ((aDirtyRegion.Width()==0)||(aDirtyRegion.Height()==0))
1.118 + {
1.119 + return KErrArgument;
1.120 + }
1.121 +
1.122 + if ( KErrNone!=CheckBitmapHandle(aFrameHandle) )
1.123 + {
1.124 + return KErrArgument;
1.125 + }
1.126 +
1.127 + if ( ESubtitleGraphicStateInitSimple!=iState )
1.128 + {
1.129 + return KErrNotReady;
1.130 + }
1.131 +
1.132 + TSubtitleCrpMsgDrawFrame messageContent(aFrameHandle, aDirtyRegion, aDisplayDuration);
1.133 + TPckgBuf<TSubtitleCrpMsgDrawFrame> message(messageContent);
1.134 +
1.135 + SendMessage(message);
1.136 +
1.137 + // Flush window server msg queue.. msg will sit there otherwise...
1.138 + Flush();
1.139 +
1.140 + return KErrNone;
1.141 + }
1.142 +
1.143 +/**
1.144 +Requests that the CRP initializes. The reference CRP duplicates and stores
1.145 +both bitmap handles for future DrawFrame requests. This function is to be
1.146 +used in conjunction with SwapFrame() only.
1.147 +
1.148 +@param aBuffer1 A CFbsBitmap handle, will require duplication before use.
1.149 + The reference CRP implementation treats this as the primary buffer
1.150 + on startup, i.e. this handle should be used for the initial subtitle frame.
1.151 +@param aBuffer2 A CFbsBitmap handle, will require duplication before use.
1.152 +@return KErrNone if successful, otherwise KErrArgument on an invalid aBuffer1/aBuffer2
1.153 +@see CFbsBitmap::Duplicate(TInt)
1.154 +*/
1.155 +EXPORT_C TInt CMMFSubtitleGraphic::Initialize(TInt aBuffer1, TInt aBuffer2)
1.156 + {
1.157 + if ( (CheckBitmapHandle(aBuffer1)!=KErrNone) ||
1.158 + (CheckBitmapHandle(aBuffer2)!=KErrNone))
1.159 + {
1.160 + return KErrArgument;
1.161 + }
1.162 +
1.163 + iState = ESubtitleGraphicStateInit;
1.164 +
1.165 + TSubtitleCrpMsgInit messageContent(aBuffer1, aBuffer2);
1.166 + TPckgBuf<TSubtitleCrpMsgInit> message(messageContent);
1.167 +
1.168 + SendMessage(message);
1.169 +
1.170 + // Flush window server msg queue.. msg will sit there otherwise...
1.171 + Flush();
1.172 +
1.173 + return KErrNone;
1.174 + }
1.175 +
1.176 +/**
1.177 +Requests that the CRP initializes. The reference CRP does nothing on
1.178 +receiving this request. This function is to be used in conjunction with
1.179 +DrawFrame() only.
1.180 +*/
1.181 +EXPORT_C void CMMFSubtitleGraphic::Initialize()
1.182 + {
1.183 + TSubtitleCrpMsgInitSimple simple;
1.184 + TPckgBuf<TSubtitleCrpMsgInitSimple> message(simple);
1.185 +
1.186 + iState = ESubtitleGraphicStateInitSimple;
1.187 +
1.188 + SendMessage(message);
1.189 +
1.190 + // Flush window server msg queue.. msg will sit there otherwise...
1.191 + Flush();
1.192 + }
1.193 +
1.194 +/**
1.195 +Requests that the CRP draws the requested internal buffer.
1.196 +The CRP maintains two internal buffers the handle for which are provided at initialisation
1.197 +time. See CMMFSubtitleGraphic::Initialize(TInt aBuffer1, TInt aBuffer2).
1.198 +
1.199 +@param aExpectedBuffer The index number of the internal frame the crp should draw.
1.200 +@param aDisplayDuration The time in microseconds that this frame should be displayed for.
1.201 + The CRP will clear this frame after aDisplayDuration microseconds
1.202 +@param aDirtyRegion The decoder returns the region of the subtitle frame that has been
1.203 + updated. i.e. the region that contains new subtitle content
1.204 +@return KErrNone if successful. KErrArgument if an invalid aExpectedBuffer, aDirtyRegion, or
1.205 +aDisplayDuration are given. KErrNotReady if the corresponding Initialize() function has not been called.
1.206 +*/
1.207 +EXPORT_C TInt CMMFSubtitleGraphic::SwapFrame(TUint aExpectedBuffer, const TRect& aDirtyRegion, const TTimeIntervalMicroSeconds& aDisplayDuration)
1.208 + {
1.209 + if ((aExpectedBuffer > KMaxSupportedFrames) || (aExpectedBuffer == 0))
1.210 + {
1.211 + return KErrArgument;
1.212 + }
1.213 +
1.214 + if ((aDirtyRegion.Width() <= 0)||(aDirtyRegion.Height() <= 0))
1.215 + {
1.216 + return KErrArgument;
1.217 + }
1.218 +
1.219 + if (ESubtitleGraphicStateInit!=iState)
1.220 + {
1.221 + return KErrNotReady;
1.222 + }
1.223 +
1.224 + if (aDisplayDuration < 0)
1.225 + {
1.226 + return KErrArgument;
1.227 + }
1.228 +
1.229 + TSubtitleCrpMsgRenderSwapFrame messageData(aExpectedBuffer, aDirtyRegion, aDisplayDuration);
1.230 + TPckgBuf<TSubtitleCrpMsgRenderSwapFrame> message(messageData);
1.231 +
1.232 + SendMessage(message);
1.233 +
1.234 + // Flush window server msg queue.. msg will sit there otherwise...
1.235 + Flush();
1.236 +
1.237 + return KErrNone;
1.238 + }
1.239 +
1.240 +/**
1.241 +Checks that the given handle is valid
1.242 +@param aHandle A bitmap handle
1.243 +@return KErrNone if successful, otherwise KErrArgument if aHandle is invalid
1.244 +@see CFbsBitmap::Handle()
1.245 +*/
1.246 +TInt CMMFSubtitleGraphic::CheckBitmapHandle(TInt aHandle)
1.247 + {
1.248 + // Check framehandle is valid.
1.249 + TInt err = iTempBitmap->Duplicate(aHandle);
1.250 +
1.251 + if ( KErrUnknown==err )
1.252 + {
1.253 + return KErrArgument;
1.254 + }
1.255 +
1.256 + return err;
1.257 + }