os/graphics/graphicscomposition/openwfsupport/inc/surfacestream.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 1995-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
// SurfaceStream.h
sl@0
    15
// CSurfaceStream declaration
sl@0
    16
sl@0
    17
#ifndef SURFACESTREAM_H
sl@0
    18
#define SURFACESTREAM_H
sl@0
    19
sl@0
    20
// INCLUDES
sl@0
    21
#include <e32base.h>
sl@0
    22
#include <e32def.h>
sl@0
    23
#include <e32debug.h>
sl@0
    24
#include <graphics/surface.h>
sl@0
    25
#include <pixelformats.h>
sl@0
    26
#include <graphics/surfacemanager.h>
sl@0
    27
#include "symbianstream.h"
sl@0
    28
sl@0
    29
#if defined(ENABLE_NF_LOGGING)
sl@0
    30
#define NFLOG(X)  RDebug::Printf X
sl@0
    31
#else
sl@0
    32
#define NFLOG(X)
sl@0
    33
#endif
sl@0
    34
sl@0
    35
// CLASS DECLARATION
sl@0
    36
sl@0
    37
// Each surface buffer has its corresponding TBufferInfo to hold reference count and memory offset
sl@0
    38
struct TBufferInfo
sl@0
    39
	{
sl@0
    40
	TInt iRefCount;
sl@0
    41
	TInt iOffset;
sl@0
    42
	};
sl@0
    43
sl@0
    44
// Notification data
sl@0
    45
struct TNotificationBase
sl@0
    46
    {
sl@0
    47
    TRequestStatus* iStatus;
sl@0
    48
    TThreadId       iThreadId;
sl@0
    49
    TInt            iBufferNumber;
sl@0
    50
    TInt            iSerialNumber;
sl@0
    51
    TInt            iGlobalIndex;
sl@0
    52
    };
sl@0
    53
sl@0
    54
struct TNotificationDisplayed: public TNotificationBase
sl@0
    55
    {
sl@0
    56
    TUint32*        iTimeStamp;
sl@0
    57
    };
sl@0
    58
sl@0
    59
struct TNotificationDisplayedX: public TNotificationBase
sl@0
    60
    {
sl@0
    61
    TInt            iCount;
sl@0
    62
    };
sl@0
    63
sl@0
    64
struct TNotificationAvailable: public TNotificationBase
sl@0
    65
    {
sl@0
    66
    TRequestStatus* iNewStatus;
sl@0
    67
    TThreadId       iNewThreadId;
sl@0
    68
    TInt            iNewBufferNumber;
sl@0
    69
    TInt            iNewGlobalIndex;
sl@0
    70
    };
sl@0
    71
sl@0
    72
sl@0
    73
class COpenWfcStreamMap;
sl@0
    74
/**
sl@0
    75
 *  CSurfaceStream
sl@0
    76
 * 	internal
sl@0
    77
 */
sl@0
    78
NONSHARABLE_CLASS( CSurfaceStream ) : public CBase
sl@0
    79
	{
sl@0
    80
    struct TNewGlobalNotifications;
sl@0
    81
    
sl@0
    82
	private:
sl@0
    83
	    class Guard
sl@0
    84
	        {
sl@0
    85
	        public:
sl@0
    86
	        Guard(RFastLock& aLock);
sl@0
    87
	        ~Guard();
sl@0
    88
	        private:
sl@0
    89
	            RFastLock& iLock;
sl@0
    90
	            RHeap* iHeap;
sl@0
    91
	        };
sl@0
    92
	    
sl@0
    93
	    struct ContentUpdatedParams
sl@0
    94
	        {
sl@0
    95
	        ContentUpdatedParams(TInt aBuffer,
sl@0
    96
	                             TRequestStatus* aStatusDisplayed, TUint32* aTimeStamp,
sl@0
    97
	                             TRequestStatus* aStatusDispXTimes, TInt* aDisplayedXTimes,
sl@0
    98
	                             TRequestStatus* aStatusConsumed, const TRegion* aRegion, 
sl@0
    99
	                             TBool aImmediateAvailable,
sl@0
   100
	                             TInt32 aImmediateVisibility, const TNewGlobalNotifications& aGlobalNotifications);
sl@0
   101
	        TInt iBuffer;
sl@0
   102
	        TRequestStatus* iStatusDisplayed;
sl@0
   103
	        TUint32* iTimeStamp;
sl@0
   104
	        TRequestStatus* iStatusDispXTimes;
sl@0
   105
	        TInt* iDisplayedXTimes;
sl@0
   106
	        TRequestStatus* iStatusConsumed;
sl@0
   107
	        const TRegion* iRegion;
sl@0
   108
	        TBool iImmediateAvailable;
sl@0
   109
	        TInt32 iImmediateVisibility;
sl@0
   110
	        const TNewGlobalNotifications& iGlobalNotifications;
sl@0
   111
	        };
sl@0
   112
	    
sl@0
   113
public:
sl@0
   114
    enum CallBackOperations
sl@0
   115
        {
sl@0
   116
        EDefaultOperation,
sl@0
   117
        ECheckVisibleOperation
sl@0
   118
        };
sl@0
   119
public:
sl@0
   120
	// Constructors and destructor
sl@0
   121
sl@0
   122
	/**
sl@0
   123
	 * Destructor.
sl@0
   124
	 */
sl@0
   125
	~CSurfaceStream();
sl@0
   126
sl@0
   127
	/**
sl@0
   128
	 * Two-phased constructor.
sl@0
   129
	 */
sl@0
   130
	static CSurfaceStream* NewL(const TSurfaceId& aId);
sl@0
   131
sl@0
   132
	/**
sl@0
   133
	 * Two-phased constructor.
sl@0
   134
	 */
sl@0
   135
	static CSurfaceStream* NewLC(const TSurfaceId& aId);
sl@0
   136
	
sl@0
   137
	/**
sl@0
   138
		Helper to resolve handle to stream object
sl@0
   139
	**/
sl@0
   140
    static CSurfaceStream* FromHandle(SymbianStreamType aNativeStreamHandle);
sl@0
   141
	
sl@0
   142
    /**
sl@0
   143
     * A helper function that returns the bytes per pixel for a given pixel format UID
sl@0
   144
     * @param aPixelFormat Pixel format UID to convert
sl@0
   145
     * @return Positive: bytes per pixel; negative is pixels per byte; 0 is error 
sl@0
   146
     */
sl@0
   147
    
sl@0
   148
    static TInt BytesPerPixel(TUidPixelFormat aPixelFormat);
sl@0
   149
    /**
sl@0
   150
		Helper to resolve handle to stream object
sl@0
   151
	**/
sl@0
   152
	SymbianStreamType ToHandle();
sl@0
   153
			
sl@0
   154
public:
sl@0
   155
	//Internal helpers
sl@0
   156
	/**	Returns internal surface ID.
sl@0
   157
	 * 	
sl@0
   158
	 * @return surface id asociated with this stream
sl@0
   159
	 **/
sl@0
   160
	const TSurfaceId& SurfaceId()const;
sl@0
   161
	
sl@0
   162
public:
sl@0
   163
	//OpenWF-C SI/CT/MIG API implementation
sl@0
   164
sl@0
   165
	/**
sl@0
   166
	 * Increase stream's reference count by one.
sl@0
   167
	 *
sl@0
   168
	 */
sl@0
   169
	 void
sl@0
   170
	AddReference();
sl@0
   171
sl@0
   172
	/**
sl@0
   173
	 * Decrease stream's reference count by one and destroy
sl@0
   174
	 * the stream, if the reference count goes to zero.
sl@0
   175
	 *
sl@0
   176
	 * All acquired read & write buffers must be released
sl@0
   177
	 * before calling WFC_Native_Destroy.
sl@0
   178
	 *
sl@0
   179
	 */
sl@0
   180
	void
sl@0
   181
	ReleaseReference();
sl@0
   182
sl@0
   183
	/**
sl@0
   184
	 * internal
sl@0
   185
	 *
sl@0
   186
	 * @return flag if reference count is now zero.
sl@0
   187
	 *
sl@0
   188
	 */
sl@0
   189
	TBool
sl@0
   190
	RemainingReference();
sl@0
   191
sl@0
   192
    /**
sl@0
   193
     * internal
sl@0
   194
     *
sl@0
   195
     * Sets flipped state.
sl@0
   196
     *
sl@0
   197
     */
sl@0
   198
    void
sl@0
   199
    SetFlipState(TBool aFlip);
sl@0
   200
sl@0
   201
    /**
sl@0
   202
	 * Get stream "frame header". Can be used to query
sl@0
   203
	 * all or some of the frame properties.
sl@0
   204
	 *
sl@0
   205
	 * @param width Pointer to location where width parameter should be saved
sl@0
   206
	 * @param height Pointer to location where height parameter should be saved
sl@0
   207
	 * @param stride Pointer to location where stride (row size in bytes)
sl@0
   208
	 * parameter should be saved
sl@0
   209
	 * @param pixelSize Pointer to location where pizelSize (pixel size in bytes)
sl@0
   210
	 * parameter should be saved
sl@0
   211
sl@0
   212
	 * Passing a NULL pointer implies that particular
sl@0
   213
	 * value is of no interest to caller. E.g.
sl@0
   214
	 *   GetHeader(stream, &w, &h, NULL, NULL, NULL);
sl@0
   215
	 * would only fetch width & height parameters.
sl@0
   216
	 */
sl@0
   217
	void
sl@0
   218
	GetHeader(khronos_int32_t* width,
sl@0
   219
	                           khronos_int32_t* height,
sl@0
   220
	                           khronos_int32_t* stride,
sl@0
   221
	                           SymOwfPixelFormat* format,
sl@0
   222
	                           khronos_int32_t* pixelSize);
sl@0
   223
sl@0
   224
	/**
sl@0
   225
	 * Acquires read buffer for stream. For > 1 buffer
sl@0
   226
	 * streams this function doesn't block, but simply returns
sl@0
   227
	 * WFC_INVALID_HANDLE if no buffer is available for reading.
sl@0
   228
	 * For 1 buffer stream the caller is blocked until the buffer
sl@0
   229
	 * is ready for reading (the reader has committed the buffer,
sl@0
   230
	 * that is.)
sl@0
   231
	 *
sl@0
   232
	 *
sl@0
   233
	 * @return WFC_INVALID_HANDLE if no buffer is available or
sl@0
   234
	 * handle to last committed buffer.
sl@0
   235
	 *
sl@0
   236
	 * An example sequence for 3 buffer stream where
sl@0
   237
	 * producer produces frames approx. after every ~5th time unit.
sl@0
   238
	 * Consumer consumes buffers at constant rate of 1buf/time unit.
sl@0
   239
	 * Pframe is the number/handle of buffer that is being written by
sl@0
   240
	 * the producer (let's assume that it takes 2 time units
sl@0
   241
	 * for producer to produce a frame/buffer.) Cframe is the number/
sl@0
   242
	 * handle of the buffer the consumer receives from AcquireReadBuffer().
sl@0
   243
	 * "i" stands for WFC_INVALID_HANDLE:
sl@0
   244
	 *
sl@0
   245
	 * Time:   0    5    10   15   20   25
sl@0
   246
	 * Pframe: 0    1    2    0    1    ...
sl@0
   247
	 * Cframe: ii00000111112222200000111...
sl@0
   248
	 */
sl@0
   249
	SymbianStreamBuffer
sl@0
   250
	AcquireReadBuffer();
sl@0
   251
sl@0
   252
	/**
sl@0
   253
	 * Releases read buffer.
sl@0
   254
	 *
sl@0
   255
	 * When read buffer is released, it is marked as clean to
sl@0
   256
	 * be written again, unless it is the only committed buffer
sl@0
   257
	 * in which case it is recycled so that the same buffer
sl@0
   258
	 * can be read again (as long as no new buffers are committed
sl@0
   259
	 * by the producer)
sl@0
   260
	 *
sl@0
   261
	 * @param buf Buffer handle. Must be valid read buffer handle for
sl@0
   262
	 * given stream.
sl@0
   263
     * @return KErrNone if succeessful or KErrBadHandle if buf is not a currently
sl@0
   264
     *          open write buffer on this stream;
sl@0
   265
	 */
sl@0
   266
	TInt
sl@0
   267
	ReleaseReadBuffer(SymbianStreamBuffer buf);
sl@0
   268
sl@0
   269
	/**
sl@0
   270
	 * Acquires write buffer for stream.
sl@0
   271
	 *
sl@0
   272
	 * Returns handle to a buffer that can be used to write
sl@0
   273
	 * data into stream. If no clean buffer is available,
sl@0
   274
	 * invalid handle is returned.
sl@0
   275
	 *
sl@0
   276
	 *
sl@0
   277
	 * @return Handle to a writable buffer
sl@0
   278
	 */
sl@0
   279
	SymbianStreamBuffer
sl@0
   280
	AcquireWriteBuffer();
sl@0
   281
sl@0
   282
	/**
sl@0
   283
	 * Releases write buffer to stream.
sl@0
   284
	 * Released buffer is made new front buffer, i.e., producer is expected
sl@0
   285
	 * to release buffer is the same order they were acquired.
sl@0
   286
	 *
sl@0
   287
	 * @param buf Buffer handle. Must be valid write buffer handle
sl@0
   288
	 * for given stream.
sl@0
   289
	 */
sl@0
   290
	void
sl@0
   291
	ReleaseWriteBuffer(SymbianStreamBuffer buf);
sl@0
   292
sl@0
   293
	/**
sl@0
   294
	 *  Add event observer for stream. Observers are served in
sl@0
   295
	 *  first-come-first-serve fashion. That is, newest observer
sl@0
   296
	 *  is always placed at the end of the chain. If the observer
sl@0
   297
	 *  is already in the chain, it's popped out and moved to
sl@0
   298
	 *  the end of the chain.
sl@0
   299
	 *
sl@0
   300
	 *  @param observer Observer (callback function) who should
sl@0
   301
	 *  be notified when something interesting happens in the stream.
sl@0
   302
	 *  @param data Additional data to pass to callback function
sl@0
   303
	 *
sl@0
   304
	 *  @return 0 if successful, -1 if stream handle is invalid, -2 if
sl@0
   305
	 *  OOM situation occurs.
sl@0
   306
	 */
sl@0
   307
	int AddObserver(SymOwfStreamCallback observer,
sl@0
   308
	                           void* data,MultipleSymbianStreamEventBits aEvents);
sl@0
   309
sl@0
   310
	/**
sl@0
   311
	 *  Remove stream event observer. Observer is removed from
sl@0
   312
	 *  the stream's event nofitication chain and won't receive
sl@0
   313
	 *  any events from the stream afterwards.
sl@0
   314
	 *
sl@0
   315
	 *  @param observer Observer (callback function)
sl@0
   316
	 *
sl@0
   317
	 *  @param 0 if successful, -1 otherwise
sl@0
   318
	 */
sl@0
   319
	int RemoveObserver(SymOwfStreamCallback observer,
sl@0
   320
            		void* aData,MultipleSymbianStreamEventBits aEvents);
sl@0
   321
	
sl@0
   322
	/** 
sl@0
   323
	 * Returns pointer to pixel buffer.
sl@0
   324
	 *
sl@0
   325
	 * @param buffer Handle of buffer
sl@0
   326
	 */
sl@0
   327
	void*
sl@0
   328
	GetBufferPtrL(SymbianStreamBuffer buffer);
sl@0
   329
	
sl@0
   330
	/**  
sl@0
   331
	 * Undocumented protection flag
sl@0
   332
	 *
sl@0
   333
	 * @param flag enable disable protection
sl@0
   334
	 */
sl@0
   335
	void
sl@0
   336
	SetProtectionFlag(TBool flag);
sl@0
   337
sl@0
   338
    TInt BufferHandleToIndex(SymbianStreamBuffer aBuff);
sl@0
   339
    
sl@0
   340
    /**
sl@0
   341
     *  Add event observer for stream. Observers are served in
sl@0
   342
     *  first-come-first-serve fashion. That is, newest observer
sl@0
   343
     *  is always placed at the end of the chain. 
sl@0
   344
     *
sl@0
   345
     *  @param observer Observer (callback function) who should
sl@0
   346
     *  be notified when something interesting happens in the stream.
sl@0
   347
     *  @aEvent The event corresponding to the observer
sl@0
   348
     *  @aScreenNumber The context identifier (screen number)
sl@0
   349
     *  @param data Additional data to pass to callback function
sl@0
   350
     *
sl@0
   351
     *  @return KErrNone if successful
sl@0
   352
     *          KErrArgument if un unknown event is registered
sl@0
   353
     *          KErrOverflow if the observer was already registered
sl@0
   354
     *          An other system wide error if container couldn't be appended
sl@0
   355
     *  OOM situation occurs.
sl@0
   356
     */
sl@0
   357
    int AddObserver(SymbianStreamCallback aObserver, 
sl@0
   358
                    TInt32 aEvent,
sl@0
   359
                    TInt32 aScreenNumber,
sl@0
   360
                    void* aData);
sl@0
   361
sl@0
   362
    /**
sl@0
   363
     *  Remove stream event observer. Observer is removed from
sl@0
   364
     *  the stream's event nofitication chain and won't receive
sl@0
   365
     *  any events from the stream afterwards.
sl@0
   366
     *
sl@0
   367
     *  @param aObserver The callback function
sl@0
   368
     *  @param aEvent The event id corresponding to the observer
sl@0
   369
     *  @param aScreenNumber The screen number
sl@0
   370
     *  @param aData Data must uniquely identify the observer
sl@0
   371
     *
sl@0
   372
     *  @param KErrNone if successful, -1 otherwise
sl@0
   373
     *         KErrArgument if un unknown event passed as parameter
sl@0
   374
     *         KErrNotFount if the event is not found
sl@0
   375
     */
sl@0
   376
    int RemoveObserver(TInt32 aEvents, void* aData);
sl@0
   377
    
sl@0
   378
    /*!
sl@0
   379
     *  Notifies the observers not associated with a context.
sl@0
   380
     *  The aim is to support legacy SI behavior.
sl@0
   381
     *  
sl@0
   382
     *  @param aEvent Observer identifier
sl@0
   383
     *
sl@0
   384
     */
sl@0
   385
    int NotifyObservers(TInt32 aEvent);
sl@0
   386
sl@0
   387
    /**
sl@0
   388
     *  Implements surface content notifications.
sl@0
   389
     *
sl@0
   390
     *  When the contents of a surface change, this function gets called
sl@0
   391
     *  MCompositionSurfaceUpdate implementation. 
sl@0
   392
     *
sl@0
   393
     * @param   aSurface            The surface that has been updated.
sl@0
   394
     * @param   aBuffer             The buffer of the surface to be used in
sl@0
   395
     *                              composition. Integer starting from 0.
sl@0
   396
     * @param   aRegion             The sub-area that has the updates. If NULL, the
sl@0
   397
     *                              whole surface is considered changed.
sl@0
   398
     * @param   aStatusConsumed     A request status object or NULL. If not NULL, then the
sl@0
   399
     *                              request status is completed once the backend
sl@0
   400
     *                              does not anymore need the contents of the
sl@0
   401
     *                              surface to render the update. This may happen
sl@0
   402
     *                              before actually displaying the finished frame.
sl@0
   403
     * @param   aStatusDisplayed    This is signaled after the composited frame
sl@0
   404
     *                              is posted the to display for the first time after
sl@0
   405
     *                              the update. After this the value in
sl@0
   406
     *                              aTimeStamp is valid, if the value in the
sl@0
   407
     *                              status object is KErrNone. Can be NULL, if
sl@0
   408
     *                              no signal is desired.
sl@0
   409
     * @param   aTimeStamp          Value of the User::FastCounter() right after the
sl@0
   410
     *                              display refresh that signaled aStatusDisplayed.
sl@0
   411
     * @param   aStatusDispXTimes   This is signaled when the surface has been on
sl@0
   412
     *                              the screen for aDisplayedXTimes refreshes,
sl@0
   413
     *                              including the update that signaled aStatusDisplayed.
sl@0
   414
     *                              Can be NULL, if no signal is wanted.
sl@0
   415
     * @param   aDisplayedXTimes    The number of refreshes after which aStatusDispXTimes
sl@0
   416
     *                              is signaled or NULL. If values is provided, it must be
sl@0
   417
     *                              >= 1.
sl@0
   418
     * @param   aScreenNumber       Uniquelly identifies the context (composer)
sl@0
   419
     */
sl@0
   420
    void SetNewNotifications(TInt            aBuffer,
sl@0
   421
                             TRequestStatus* aStatusDisplayed, TUint32* aTimeStamp,
sl@0
   422
                             TRequestStatus* aStatusDispXTimes, TInt* aDisplayedXTimes,
sl@0
   423
                             TRequestStatus* aStatusConsumed, const TRegion* aRegion, 
sl@0
   424
                             TInt32 aScreenNumber);
sl@0
   425
    
sl@0
   426
    /**
sl@0
   427
     *  Implements surface content notifications.
sl@0
   428
     *
sl@0
   429
     *  When the contents of a surface change, this function gets called
sl@0
   430
     *  MCompositionSurfaceUpdate implementation. 
sl@0
   431
     *
sl@0
   432
     * @param   aSurface            The surface that has been updated.
sl@0
   433
     * @param   aBuffer             The buffer of the surface to be used in
sl@0
   434
     *                              composition. Integer starting from 0.
sl@0
   435
     * @param   aRegion             The sub-area that has the updates. If NULL, the
sl@0
   436
     *                              whole surface is considered changed.
sl@0
   437
     * @param   aStatusConsumed     A request status object or NULL. If not NULL, then the
sl@0
   438
     *                              request status is completed once the backend
sl@0
   439
     *                              does not anymore need the contents of the
sl@0
   440
     *                              surface to render the update. This may happen
sl@0
   441
     *                              before actually displaying the finished frame.
sl@0
   442
     * @param   aStatusDisplayed    This is signaled after the composited frame
sl@0
   443
     *                              is posted the to display for the first time after
sl@0
   444
     *                              the update. After this the value in
sl@0
   445
     *                              aTimeStamp is valid, if the value in the
sl@0
   446
     *                              status object is KErrNone. Can be NULL, if
sl@0
   447
     *                              no signal is desired.
sl@0
   448
     * @param   aTimeStamp          Value of the User::FastCounter() right after the
sl@0
   449
     *                              display refresh that signaled aStatusDisplayed.
sl@0
   450
     * @param   aStatusDispXTimes   This is signaled when the surface has been on
sl@0
   451
     *                              the screen for aDisplayedXTimes refreshes,
sl@0
   452
     *                              including the update that signaled aStatusDisplayed.
sl@0
   453
     *                              Can be NULL, if no signal is wanted.
sl@0
   454
     * @param   aDisplayedXTimes    The number of refreshes after which aStatusDispXTimes
sl@0
   455
     *                              is signaled or NULL. If values is provided, it must be
sl@0
   456
     *                              >= 1.
sl@0
   457
     * @param   aScreenNumber       Uniquelly identifies the context (composer)
sl@0
   458
     */
sl@0
   459
    void SetAllNotifications(TInt            aBuffer,
sl@0
   460
                             TRequestStatus* aStatusDisplayed, TUint32* aTimeStamp,
sl@0
   461
                             TRequestStatus* aStatusDispXTimes, TInt* aDisplayedXTimes,
sl@0
   462
                             TRequestStatus* aStatusConsumed, const TRegion* aRegion);
sl@0
   463
    
sl@0
   464
    /**
sl@0
   465
     *   Process the notifications by accessing the information stored in the observer container.
sl@0
   466
     *  
sl@0
   467
     *  This method is expected to be called from the observer context every time composer has finished processing
sl@0
   468
     *  a stream and the rigger condition is met.
sl@0
   469
     *  
sl@0
   470
     *  @param aEvent        Events map to identify the observer to be processed.
sl@0
   471
     *  @param aScreenNumber Screen ID used to identify the target composer that invokes the method
sl@0
   472
     *  @param aOperation    The Operation expected to be executed
sl@0
   473
     *  @param aSerialNumber A number used to identify the composition operation
sl@0
   474
     *  @param aReturnMask  Parameter to be retrieved by composer, representing the event to be processed
sl@0
   475
     *                       when composed next time. A new composition is automatically triggered.
sl@0
   476
     *
sl@0
   477
     */
sl@0
   478
    void ProcessNotifications(TInt32 aEvent, TInt32 aScreenNumber, TInt32 aOperation, TInt32 aSerialNumber, TInt32* aReturnMask);
sl@0
   479
sl@0
   480
    /**
sl@0
   481
     *    A function that checks the validity of the new buffer provided by SUS
sl@0
   482
     * 
sl@0
   483
     *
sl@0
   484
     * When the contents of a surface change, this function gets called by the MCompositionSurfaceUpdate implementation.
sl@0
   485
     * If the buffer is invalid all request statuses will be completed with KErrArgument
sl@0
   486
     *
sl@0
   487
     * @param   aBuffer             The buffer of the surface to be used in
sl@0
   488
     *                              composition. Integer starting from 0.
sl@0
   489
     * @param   aStatusConsumed     A request status object or NULL.
sl@0
   490
     * @param   aStatusDisplayed    A request status object or NULL.
sl@0
   491
     * @param   aStatusDispXTimes   A request status object or NULL.
sl@0
   492
     * 
sl@0
   493
     * @return  KErrNone if successful
sl@0
   494
     *          KErrArgument if aBuffer parameter is invalid
sl@0
   495
     *
sl@0
   496
     */
sl@0
   497
    TInt CheckBufferNumber(TInt aBuffer,
sl@0
   498
                           TRequestStatus* aStatusDisplayed,
sl@0
   499
                           TRequestStatus* aStatusDispXTimes,
sl@0
   500
                           TRequestStatus* aStatusConsumed);
sl@0
   501
    
sl@0
   502
    TInt GetChunkHandle();
sl@0
   503
    
sl@0
   504
private:
sl@0
   505
    /**
sl@0
   506
     *   Notifies the composer that the content has been updated.
sl@0
   507
     *  
sl@0
   508
     *  
sl@0
   509
     *  @param aScreenNumber Screen ID used to identify the target composer
sl@0
   510
     *  @param aOp The Operation expected the callback to execute
sl@0
   511
     *  @param aParam Parameter containing aaditional information to push/pop from targetet composer
sl@0
   512
     *
sl@0
   513
     */
sl@0
   514
    TBool NotifyComposerContext(TInt32 aScreenNumber, TInt aOp, SYMOWF_CONTENT_UPDATED_PARAM* aParam);
sl@0
   515
    
sl@0
   516
    /**
sl@0
   517
     *   Notifies the composer that the content is in process to be updated. The composer will have to not access
sl@0
   518
     *  observer related information
sl@0
   519
     *  
sl@0
   520
     *  
sl@0
   521
     *  Note that while calling the callback the context update mutex is acquired.
sl@0
   522
     *  
sl@0
   523
     *  @param aScreenNumber Screen ID used to identify the target composer
sl@0
   524
     *  @param aBufferNum The buffer number to be updated 
sl@0
   525
     *  @param aUpdatedFlags The events that triggers this function call
sl@0
   526
     *  @param aRegion The sub-area that has the updates. If NULL, the whole surface is considered changed.
sl@0
   527
     */
sl@0
   528
    TBool StartUpdateNotifications(TInt aScreenNumber, SYMOWF_CONTENT_UPDATED_PARAM& param);
sl@0
   529
    
sl@0
   530
    /**
sl@0
   531
     *   Notifies the composer that process of updating the content has finisshed
sl@0
   532
     *  
sl@0
   533
     *  The composer releases the content mutex and triggers a new composition
sl@0
   534
     *  
sl@0
   535
     *  @param aScreenNumber Screen ID used to identify the target composer
sl@0
   536
     *  @param aBufferNum The buffer number to be updated 
sl@0
   537
     *  @param aUpdatedFlags The events that triggers this function call
sl@0
   538
     *  @param aRegion The sub-area that has the updates. If NULL, the whole surface is considered changed.
sl@0
   539
     */
sl@0
   540
    TBool EndUpdateNotifications(TInt aScreenNum, 
sl@0
   541
                                 TInt aBufferNum, 
sl@0
   542
                                 TInt32 aUpdatedFlags, 
sl@0
   543
                                 const TRegion* aRegion);
sl@0
   544
    
sl@0
   545
    /**
sl@0
   546
     *   Notifies the composer that content has been updated
sl@0
   547
     *  
sl@0
   548
     *  It is used to support old SI behaviour. The content update mutex is acuired 
sl@0
   549
     *  and released while a new composition is triggered
sl@0
   550
     *  
sl@0
   551
     *  @param aScreenNumber Screen ID used to identify the target composer
sl@0
   552
     *  @param aBufferNum The buffer number to be updated 
sl@0
   553
     *  @param aUpdatedFlags The events that triggers this function call
sl@0
   554
     *  @param aRegion The sub-area that has the updates. If NULL, the whole surface is considered changed.
sl@0
   555
     */
sl@0
   556
    TBool UpdateNotifications(TInt aScreenNum, 
sl@0
   557
                              TInt aBufferNum, 
sl@0
   558
                              TInt32 aUpdatedFlags, 
sl@0
   559
                              const TRegion* aRegion);
sl@0
   560
    
sl@0
   561
    /**
sl@0
   562
     *   Processes the available observer
sl@0
   563
     *  
sl@0
   564
     *  @param aEvent               Events map to identify the operation to be executed.
sl@0
   565
     *  @param aSerialNumber        A number used to identify the composition operation
sl@0
   566
     *  @param ContentUpdatedParams Packs the information used when a new request from SUS has to be processed
sl@0
   567
     *  @param aCallBackData        The observer data stored in the container of observers
sl@0
   568
     *  @param aReturnMask         Parameter to be retrieved by composer, representing the event to be processed
sl@0
   569
     */
sl@0
   570
    void Available(TInt32 aEvent, TInt32 aSerialNumber, ContentUpdatedParams* aParams, void* aCallBackData, TInt32* aReturnMask);
sl@0
   571
    /**
sl@0
   572
     *   Processes the available observer
sl@0
   573
     *  
sl@0
   574
     *  @param aEvent               Events map to identify the operation to be executed.
sl@0
   575
     *  @param aSerialNumber        A number used to identify the composition operation
sl@0
   576
     *  @param ContentUpdatedParams Packs the information used when a new request from SUS has to be processed
sl@0
   577
     *  @param aCallBackData        The observer data stored in the container of observers
sl@0
   578
     *  @param aReturnMask         Parameter to be retrieved by composer, representing the event to be processed
sl@0
   579
     */
sl@0
   580
    void Displayed(TInt32 aEvent, TInt32 aSerialNumber, ContentUpdatedParams* aParams, void* aCallBackData, TInt32* aReturnMask);
sl@0
   581
    /**
sl@0
   582
     *   Processes the available observer
sl@0
   583
     *  
sl@0
   584
     *  @param aEvent               Events map to identify the operation to be executed.
sl@0
   585
     *  @param aSerialNumber        A number used to identify the composition operation
sl@0
   586
     *  @param ContentUpdatedParams Packs the information used when a new request from SUS has to be processed
sl@0
   587
     *  @param aCallBackData        The observer data stored in the container of observers
sl@0
   588
     *  @param aReturnMask         Parameter to be retrieved by composer, representing the event to be processed
sl@0
   589
     */
sl@0
   590
    void DisplayedXTimes(TInt32 aEvent, TInt32 aSerialNumber, ContentUpdatedParams* aParams, void* aCallBackData, TInt32* aReturnMask);
sl@0
   591
    /**
sl@0
   592
     *   Function used to reset observer data fields
sl@0
   593
     *  
sl@0
   594
     *  @param aEvent               Event identifier for whis the operation is to be executed.
sl@0
   595
     *  @param aCallBackData        The observer data stored in the container of observers
sl@0
   596
     */
sl@0
   597
    void ResetCallBackData(void* aCallBackData, TInt32 aEvent);
sl@0
   598
    /**
sl@0
   599
     *   Cancels all active notifications by completeting the associated requests
sl@0
   600
     */
sl@0
   601
    void CancelNotifications();
sl@0
   602
	
sl@0
   603
    void SetNotifications(TInt            aBuffer,
sl@0
   604
                          TRequestStatus* aStatusDisplayed, TUint32* aTimeStamp,
sl@0
   605
                          TRequestStatus* aStatusDispXTimes, TInt* aDisplayedXTimes,
sl@0
   606
                          TRequestStatus* aStatusConsumed, const TRegion* aRegion, 
sl@0
   607
                          TInt32 aScreenNumber, const TNewGlobalNotifications& aGlobalNotifications);
sl@0
   608
    
sl@0
   609
	void RequestComplete(TThreadId& aThreadId, TRequestStatus*& aRequestStatus, TInt& aGlobalIndexArray, TInt aStatus);
sl@0
   610
	/**
sl@0
   611
	 * Constructor for performing 1st stage construction
sl@0
   612
	 */
sl@0
   613
	CSurfaceStream();
sl@0
   614
sl@0
   615
	/**
sl@0
   616
	 * Symbian's default constructor for performing 2nd stage construction
sl@0
   617
	 */
sl@0
   618
	void ConstructL(const TSurfaceId& aId);
sl@0
   619
	
sl@0
   620
	TInt AddNewGlobalNotification(TRequestStatus* aStatusDisplayed, TInt aAssociatedScreens);
sl@0
   621
	void SetReadBufferIndex(TInt aIndex);
sl@0
   622
	TInt GetReadBufferIndex();
sl@0
   623
	TInt GetWriteBufferIndex();
sl@0
   624
	TInt Stride(TInt aWidth, TUidPixelFormat aPixelFormat);	
sl@0
   625
	static SymbianStreamBuffer IndexToReadHandle(TInt aIndex);
sl@0
   626
	static SymbianStreamBuffer IndexToWriteHandle(TInt aIndex);
sl@0
   627
	
sl@0
   628
	static COpenWfcStreamMap& GetSingletonL();
sl@0
   629
	
sl@0
   630
	void SurfaceInfoL(const TSurfaceId& aSurface, RSurfaceManager::TInfoBuf& aInfo);
sl@0
   631
private:
sl@0
   632
    enum FlippedTarget
sl@0
   633
        {
sl@0
   634
        EFlipNotSet,
sl@0
   635
        EFlippedTargetNormal,
sl@0
   636
        EFlippedTargetFlipped
sl@0
   637
        };
sl@0
   638
    
sl@0
   639
private:
sl@0
   640
	// Each surface buffer has its corresponding TBufferInfo to hold reference count and memory offset
sl@0
   641
	struct TBufferInfo
sl@0
   642
		{
sl@0
   643
		TInt iRefCount;
sl@0
   644
		TInt iOffset;
sl@0
   645
		};
sl@0
   646
	
sl@0
   647
private:
sl@0
   648
	struct TCallBackEntry;
sl@0
   649
    struct TGlobalNotification;
sl@0
   650
	TSurfaceId	iSurfaceId;				//< Surface ID associated with stream.
sl@0
   651
	TSurfaceId  iStreamProxySurfaceId;	//< Surface ID generated to represent stream 
sl@0
   652
	TInt		iRefCount;
sl@0
   653
	RFastLock	iRefCountMutex;
sl@0
   654
	TInt		iReadBuffer;
sl@0
   655
    RChunk      iBufferChunk;
sl@0
   656
	TBufferInfo* iBufferInfo; //< Array of buffer info
sl@0
   657
	RSurfaceManager::TSurfaceInfoV01 iInfo;
sl@0
   658
	static const TInt BUFFER_READ_HANDLE_BASE = 0x100;
sl@0
   659
	static const TInt BUFFER_WRITE_HANDLE_BASE = 0x200;
sl@0
   660
	static const TInt BUFFER_WRITE_UPDATE_OVERWRITE = -1;
sl@0
   661
	TInt iAcquiredWriteBuffer;
sl@0
   662
	TAny*		iCallBackHighestPriority;
sl@0
   663
	RArray<TCallBackEntry>	iCallBacks;
sl@0
   664
    RFastLock   iCallBacksMutex;
sl@0
   665
	TBool		iProtected;
sl@0
   666
    RArray<TGlobalNotification>  iGlobalNotifications;
sl@0
   667
    TInt        iNumberOfScreenAttachedAvailableNotif;
sl@0
   668
    TInt        iNumberOfScreenAttachedDisplayedNotif;
sl@0
   669
    TInt        iNumberOfScreenAttachedDisplayedXNotif;
sl@0
   670
    FlippedTarget iFlipState;
sl@0
   671
    FlippedTarget iNewFlip;
sl@0
   672
	};
sl@0
   673
sl@0
   674
#endif // SURFACESTREAM_H