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.
sl@0
     1
// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
/**
sl@0
    17
 @file
sl@0
    18
 @publishedPartner
sl@0
    19
 @prototype
sl@0
    20
*/
sl@0
    21
sl@0
    22
#include <s32mem.h>
sl@0
    23
#include "mmfsubtitlegraphic.h"
sl@0
    24
#include "mmfsubtitlegraphicmessage.h"
sl@0
    25
sl@0
    26
// Constants
sl@0
    27
const TUid KSubtitleGraphicDrawerImplId      = {0x10285C9C};
sl@0
    28
const TUint KMaxSupportedFrames				 = 2;
sl@0
    29
sl@0
    30
/**
sl@0
    31
Standard constructor for CMMFSubtitleGraphic
sl@0
    32
*/
sl@0
    33
CMMFSubtitleGraphic::CMMFSubtitleGraphic()
sl@0
    34
    {
sl@0
    35
    
sl@0
    36
    }
sl@0
    37
sl@0
    38
/**
sl@0
    39
Standard destructor
sl@0
    40
*/
sl@0
    41
EXPORT_C CMMFSubtitleGraphic::~CMMFSubtitleGraphic()
sl@0
    42
    {
sl@0
    43
	delete iTempBitmap;
sl@0
    44
    }
sl@0
    45
sl@0
    46
/**
sl@0
    47
Allocates and constructs a CMMFSubtitleGraphic object
sl@0
    48
*/
sl@0
    49
EXPORT_C CMMFSubtitleGraphic* CMMFSubtitleGraphic::NewL()
sl@0
    50
    {
sl@0
    51
    CMMFSubtitleGraphic* self = new(ELeave) CMMFSubtitleGraphic;
sl@0
    52
    CleanupStack::PushL(self);
sl@0
    53
    self->ConstructL();
sl@0
    54
    CleanupStack::Pop(self);
sl@0
    55
    return self;
sl@0
    56
    }
sl@0
    57
sl@0
    58
/**
sl@0
    59
Performs 2nd phase construction for CMMFSubtitleGraphic
sl@0
    60
*/
sl@0
    61
void CMMFSubtitleGraphic::ConstructL()
sl@0
    62
	{
sl@0
    63
	CWsGraphic::BaseConstructL(KSubtitleGraphicDrawerImplId, KNullDesC8);
sl@0
    64
	
sl@0
    65
	iTempBitmap = new (ELeave) CFbsBitmap();
sl@0
    66
	}
sl@0
    67
sl@0
    68
sl@0
    69
// From CWsGraphic
sl@0
    70
void CMMFSubtitleGraphic::OnReplace()
sl@0
    71
    {
sl@0
    72
    
sl@0
    73
    }
sl@0
    74
sl@0
    75
void CMMFSubtitleGraphic::HandleMessage(const TDesC8& /*aData*/)
sl@0
    76
	{
sl@0
    77
	
sl@0
    78
	}
sl@0
    79
// End from CWsGraphic
sl@0
    80
sl@0
    81
/**
sl@0
    82
Requests that the content rendering plugin clears all content from the window
sl@0
    83
*/
sl@0
    84
EXPORT_C void CMMFSubtitleGraphic::Clear()
sl@0
    85
	{
sl@0
    86
	TSubtitleCrpMsgClear clear;
sl@0
    87
	
sl@0
    88
    const TPckgC<TSubtitleCrpMsgClear> message(clear);
sl@0
    89
    
sl@0
    90
    SendMessage(message);
sl@0
    91
    
sl@0
    92
    // Flush window server msg queue.. msg will sit there otherwise...
sl@0
    93
    Flush();
sl@0
    94
	}
sl@0
    95
sl@0
    96
/**
sl@0
    97
Draws the bitmap frame indicated by aFrameHandle
sl@0
    98
sl@0
    99
@param aFrameHandle 	A CFbsBitmap handle, used as a source framebuffer by the CRP.
sl@0
   100
@param aDisplayDuration The time in microseconds that this frame should be 
sl@0
   101
                        displayed for.  The CRP will clear this frame after
sl@0
   102
                        aDisplayDuration microseconds.  Note if the display duration
sl@0
   103
                        is 0 the frame will be cleared when a subsequent frame is drawn,
sl@0
   104
                        or when Clear() is called.
sl@0
   105
@param aDirtyRegion 	The decoder returns the region of the subtitle frame
sl@0
   106
                     	that has been updated.  i.e. the region that contains 
sl@0
   107
                     	new subtitle content
sl@0
   108
@return  				KErrNone if successful, otherwise KErrArgument on an invalid
sl@0
   109
						aDirtyRegion/aFrameHandle, or KErrNotReady if the corresponding
sl@0
   110
						Initialize() function has not been called
sl@0
   111
*/
sl@0
   112
EXPORT_C TInt CMMFSubtitleGraphic::DrawFrame(TInt aFrameHandle, const TRect& aDirtyRegion, const TTimeIntervalMicroSeconds& aDisplayDuration)
sl@0
   113
	{
sl@0
   114
	if ((aDirtyRegion.Width()==0)||(aDirtyRegion.Height()==0))
sl@0
   115
		{
sl@0
   116
		return KErrArgument;
sl@0
   117
		}
sl@0
   118
	
sl@0
   119
	if ( KErrNone!=CheckBitmapHandle(aFrameHandle) )
sl@0
   120
		{
sl@0
   121
		return KErrArgument;
sl@0
   122
		}
sl@0
   123
		
sl@0
   124
	if ( ESubtitleGraphicStateInitSimple!=iState )
sl@0
   125
		{
sl@0
   126
		return KErrNotReady;
sl@0
   127
		}
sl@0
   128
	
sl@0
   129
	TSubtitleCrpMsgDrawFrame messageContent(aFrameHandle, aDirtyRegion, aDisplayDuration);
sl@0
   130
	TPckgBuf<TSubtitleCrpMsgDrawFrame> message(messageContent);
sl@0
   131
	
sl@0
   132
    SendMessage(message);
sl@0
   133
    
sl@0
   134
    // Flush window server msg queue.. msg will sit there otherwise...
sl@0
   135
    Flush();
sl@0
   136
    
sl@0
   137
    return KErrNone;
sl@0
   138
	}
sl@0
   139
sl@0
   140
/**
sl@0
   141
Requests that the CRP initializes.  The reference CRP duplicates and stores
sl@0
   142
both bitmap handles for future DrawFrame requests.  This function is to be 
sl@0
   143
used in conjunction with SwapFrame() only.
sl@0
   144
sl@0
   145
@param 	aBuffer1 A CFbsBitmap handle, will require duplication before use.  
sl@0
   146
		The reference CRP implementation treats this as the primary buffer 
sl@0
   147
		on startup, i.e. this handle should be used for the initial subtitle frame.
sl@0
   148
@param 	aBuffer2 A CFbsBitmap handle, will require duplication before use.
sl@0
   149
@return KErrNone if successful, otherwise KErrArgument on an invalid aBuffer1/aBuffer2
sl@0
   150
@see CFbsBitmap::Duplicate(TInt)
sl@0
   151
*/
sl@0
   152
EXPORT_C TInt CMMFSubtitleGraphic::Initialize(TInt aBuffer1, TInt aBuffer2)
sl@0
   153
	{
sl@0
   154
	if ( (CheckBitmapHandle(aBuffer1)!=KErrNone) || 
sl@0
   155
		 (CheckBitmapHandle(aBuffer2)!=KErrNone))
sl@0
   156
		{
sl@0
   157
		return KErrArgument;
sl@0
   158
		}
sl@0
   159
		
sl@0
   160
	iState = ESubtitleGraphicStateInit;
sl@0
   161
	
sl@0
   162
	TSubtitleCrpMsgInit messageContent(aBuffer1, aBuffer2);
sl@0
   163
	TPckgBuf<TSubtitleCrpMsgInit> message(messageContent);
sl@0
   164
	
sl@0
   165
    SendMessage(message);
sl@0
   166
    
sl@0
   167
    // Flush window server msg queue.. msg will sit there otherwise...
sl@0
   168
    Flush();
sl@0
   169
    
sl@0
   170
    return KErrNone;
sl@0
   171
	}
sl@0
   172
sl@0
   173
/**
sl@0
   174
Requests that the CRP initializes.  The reference CRP does nothing on 
sl@0
   175
receiving this request.  This function is to be used in conjunction with 
sl@0
   176
DrawFrame() only.
sl@0
   177
*/
sl@0
   178
EXPORT_C void CMMFSubtitleGraphic::Initialize()
sl@0
   179
	{
sl@0
   180
	TSubtitleCrpMsgInitSimple simple;
sl@0
   181
	TPckgBuf<TSubtitleCrpMsgInitSimple> message(simple);
sl@0
   182
	
sl@0
   183
	iState = ESubtitleGraphicStateInitSimple;
sl@0
   184
	   
sl@0
   185
    SendMessage(message);
sl@0
   186
    
sl@0
   187
    // Flush window server msg queue.. msg will sit there otherwise...
sl@0
   188
    Flush();
sl@0
   189
	}
sl@0
   190
sl@0
   191
/**
sl@0
   192
Requests that the CRP draws the requested internal buffer. 
sl@0
   193
The CRP maintains two internal buffers the handle for which are provided at initialisation
sl@0
   194
time. See CMMFSubtitleGraphic::Initialize(TInt aBuffer1, TInt aBuffer2).
sl@0
   195
sl@0
   196
@param 	aExpectedBuffer The index number of the internal frame the crp should draw.
sl@0
   197
@param 	aDisplayDuration The time in microseconds that this frame should be displayed for.
sl@0
   198
    					 The CRP will clear this frame after aDisplayDuration microseconds
sl@0
   199
@param   aDirtyRegion The decoder returns the region of the subtitle frame that has been
sl@0
   200
            		  updated.  i.e. the region that contains new subtitle content
sl@0
   201
@return KErrNone if successful.  KErrArgument if an invalid aExpectedBuffer, aDirtyRegion, or
sl@0
   202
aDisplayDuration are given.  KErrNotReady if the corresponding Initialize() function has not been called.
sl@0
   203
*/
sl@0
   204
EXPORT_C TInt CMMFSubtitleGraphic::SwapFrame(TUint aExpectedBuffer, const TRect& aDirtyRegion, const TTimeIntervalMicroSeconds& aDisplayDuration)
sl@0
   205
	{
sl@0
   206
	if ((aExpectedBuffer > KMaxSupportedFrames) || (aExpectedBuffer == 0))
sl@0
   207
		{
sl@0
   208
		return KErrArgument;
sl@0
   209
		}
sl@0
   210
		
sl@0
   211
	if ((aDirtyRegion.Width() <= 0)||(aDirtyRegion.Height() <= 0))
sl@0
   212
		{
sl@0
   213
		return KErrArgument;
sl@0
   214
		}
sl@0
   215
		
sl@0
   216
	if (ESubtitleGraphicStateInit!=iState)
sl@0
   217
		{
sl@0
   218
		return KErrNotReady;
sl@0
   219
		}
sl@0
   220
	
sl@0
   221
	if (aDisplayDuration < 0)
sl@0
   222
		{
sl@0
   223
		return KErrArgument;
sl@0
   224
		}
sl@0
   225
		
sl@0
   226
	TSubtitleCrpMsgRenderSwapFrame messageData(aExpectedBuffer, aDirtyRegion, aDisplayDuration);
sl@0
   227
	TPckgBuf<TSubtitleCrpMsgRenderSwapFrame> message(messageData);
sl@0
   228
		    
sl@0
   229
    SendMessage(message);
sl@0
   230
    
sl@0
   231
    // Flush window server msg queue.. msg will sit there otherwise...
sl@0
   232
    Flush();
sl@0
   233
    
sl@0
   234
    return KErrNone;
sl@0
   235
	}
sl@0
   236
	
sl@0
   237
/**
sl@0
   238
Checks that the given handle is valid
sl@0
   239
@param 	aHandle A bitmap handle
sl@0
   240
@return KErrNone if successful, otherwise KErrArgument if aHandle is invalid
sl@0
   241
@see CFbsBitmap::Handle()
sl@0
   242
*/	
sl@0
   243
TInt CMMFSubtitleGraphic::CheckBitmapHandle(TInt aHandle)
sl@0
   244
	{
sl@0
   245
	// Check framehandle is valid.
sl@0
   246
	TInt err = iTempBitmap->Duplicate(aHandle);
sl@0
   247
	
sl@0
   248
	if ( KErrUnknown==err )
sl@0
   249
		{
sl@0
   250
		return KErrArgument;
sl@0
   251
		}
sl@0
   252
	
sl@0
   253
	return err;
sl@0
   254
	}