os/mm/mmplugins/mmfwplugins/src/Plugin/subtitle/subtitlegraphic/mmfsubtitlegraphic.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
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".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 /**
    17  @file
    18  @publishedPartner
    19  @prototype
    20 */
    21 
    22 #include <s32mem.h>
    23 #include "mmfsubtitlegraphic.h"
    24 #include "mmfsubtitlegraphicmessage.h"
    25 
    26 // Constants
    27 const TUid KSubtitleGraphicDrawerImplId      = {0x10285C9C};
    28 const TUint KMaxSupportedFrames				 = 2;
    29 
    30 /**
    31 Standard constructor for CMMFSubtitleGraphic
    32 */
    33 CMMFSubtitleGraphic::CMMFSubtitleGraphic()
    34     {
    35     
    36     }
    37 
    38 /**
    39 Standard destructor
    40 */
    41 EXPORT_C CMMFSubtitleGraphic::~CMMFSubtitleGraphic()
    42     {
    43 	delete iTempBitmap;
    44     }
    45 
    46 /**
    47 Allocates and constructs a CMMFSubtitleGraphic object
    48 */
    49 EXPORT_C CMMFSubtitleGraphic* CMMFSubtitleGraphic::NewL()
    50     {
    51     CMMFSubtitleGraphic* self = new(ELeave) CMMFSubtitleGraphic;
    52     CleanupStack::PushL(self);
    53     self->ConstructL();
    54     CleanupStack::Pop(self);
    55     return self;
    56     }
    57 
    58 /**
    59 Performs 2nd phase construction for CMMFSubtitleGraphic
    60 */
    61 void CMMFSubtitleGraphic::ConstructL()
    62 	{
    63 	CWsGraphic::BaseConstructL(KSubtitleGraphicDrawerImplId, KNullDesC8);
    64 	
    65 	iTempBitmap = new (ELeave) CFbsBitmap();
    66 	}
    67 
    68 
    69 // From CWsGraphic
    70 void CMMFSubtitleGraphic::OnReplace()
    71     {
    72     
    73     }
    74 
    75 void CMMFSubtitleGraphic::HandleMessage(const TDesC8& /*aData*/)
    76 	{
    77 	
    78 	}
    79 // End from CWsGraphic
    80 
    81 /**
    82 Requests that the content rendering plugin clears all content from the window
    83 */
    84 EXPORT_C void CMMFSubtitleGraphic::Clear()
    85 	{
    86 	TSubtitleCrpMsgClear clear;
    87 	
    88     const TPckgC<TSubtitleCrpMsgClear> message(clear);
    89     
    90     SendMessage(message);
    91     
    92     // Flush window server msg queue.. msg will sit there otherwise...
    93     Flush();
    94 	}
    95 
    96 /**
    97 Draws the bitmap frame indicated by aFrameHandle
    98 
    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 
   107                      	new subtitle content
   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
   111 */
   112 EXPORT_C TInt CMMFSubtitleGraphic::DrawFrame(TInt aFrameHandle, const TRect& aDirtyRegion, const TTimeIntervalMicroSeconds& aDisplayDuration)
   113 	{
   114 	if ((aDirtyRegion.Width()==0)||(aDirtyRegion.Height()==0))
   115 		{
   116 		return KErrArgument;
   117 		}
   118 	
   119 	if ( KErrNone!=CheckBitmapHandle(aFrameHandle) )
   120 		{
   121 		return KErrArgument;
   122 		}
   123 		
   124 	if ( ESubtitleGraphicStateInitSimple!=iState )
   125 		{
   126 		return KErrNotReady;
   127 		}
   128 	
   129 	TSubtitleCrpMsgDrawFrame messageContent(aFrameHandle, aDirtyRegion, aDisplayDuration);
   130 	TPckgBuf<TSubtitleCrpMsgDrawFrame> message(messageContent);
   131 	
   132     SendMessage(message);
   133     
   134     // Flush window server msg queue.. msg will sit there otherwise...
   135     Flush();
   136     
   137     return KErrNone;
   138 	}
   139 
   140 /**
   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.
   144 
   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)
   151 */
   152 EXPORT_C TInt CMMFSubtitleGraphic::Initialize(TInt aBuffer1, TInt aBuffer2)
   153 	{
   154 	if ( (CheckBitmapHandle(aBuffer1)!=KErrNone) || 
   155 		 (CheckBitmapHandle(aBuffer2)!=KErrNone))
   156 		{
   157 		return KErrArgument;
   158 		}
   159 		
   160 	iState = ESubtitleGraphicStateInit;
   161 	
   162 	TSubtitleCrpMsgInit messageContent(aBuffer1, aBuffer2);
   163 	TPckgBuf<TSubtitleCrpMsgInit> message(messageContent);
   164 	
   165     SendMessage(message);
   166     
   167     // Flush window server msg queue.. msg will sit there otherwise...
   168     Flush();
   169     
   170     return KErrNone;
   171 	}
   172 
   173 /**
   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 
   176 DrawFrame() only.
   177 */
   178 EXPORT_C void CMMFSubtitleGraphic::Initialize()
   179 	{
   180 	TSubtitleCrpMsgInitSimple simple;
   181 	TPckgBuf<TSubtitleCrpMsgInitSimple> message(simple);
   182 	
   183 	iState = ESubtitleGraphicStateInitSimple;
   184 	   
   185     SendMessage(message);
   186     
   187     // Flush window server msg queue.. msg will sit there otherwise...
   188     Flush();
   189 	}
   190 
   191 /**
   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).
   195 
   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.
   203 */
   204 EXPORT_C TInt CMMFSubtitleGraphic::SwapFrame(TUint aExpectedBuffer, const TRect& aDirtyRegion, const TTimeIntervalMicroSeconds& aDisplayDuration)
   205 	{
   206 	if ((aExpectedBuffer > KMaxSupportedFrames) || (aExpectedBuffer == 0))
   207 		{
   208 		return KErrArgument;
   209 		}
   210 		
   211 	if ((aDirtyRegion.Width() <= 0)||(aDirtyRegion.Height() <= 0))
   212 		{
   213 		return KErrArgument;
   214 		}
   215 		
   216 	if (ESubtitleGraphicStateInit!=iState)
   217 		{
   218 		return KErrNotReady;
   219 		}
   220 	
   221 	if (aDisplayDuration < 0)
   222 		{
   223 		return KErrArgument;
   224 		}
   225 		
   226 	TSubtitleCrpMsgRenderSwapFrame messageData(aExpectedBuffer, aDirtyRegion, aDisplayDuration);
   227 	TPckgBuf<TSubtitleCrpMsgRenderSwapFrame> message(messageData);
   228 		    
   229     SendMessage(message);
   230     
   231     // Flush window server msg queue.. msg will sit there otherwise...
   232     Flush();
   233     
   234     return KErrNone;
   235 	}
   236 	
   237 /**
   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()
   242 */	
   243 TInt CMMFSubtitleGraphic::CheckBitmapHandle(TInt aHandle)
   244 	{
   245 	// Check framehandle is valid.
   246 	TInt err = iTempBitmap->Duplicate(aHandle);
   247 	
   248 	if ( KErrUnknown==err )
   249 		{
   250 		return KErrArgument;
   251 		}
   252 	
   253 	return err;
   254 	}