uiaccelerator_plat/alf_visual_api/inc/alf/alfcompositionclient.h
changeset 0 15bf7259bb7c
child 8 10534483575f
child 14 83d2d132aa58
equal deleted inserted replaced
-1:000000000000 0:15bf7259bb7c
       
     1 /*
       
     2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:   
       
    15 *
       
    16 */
       
    17 #ifndef __ALFCOMPOSITIONCLIENT_H__
       
    18 #define __ALFCOMPOSITIONCLIENT_H__
       
    19 
       
    20 #include <e32hashtab.h>
       
    21 #include <alf/alfcompositionutility.h>
       
    22 
       
    23 const TInt KAlfCompositionControllerIfUid(0x2002bcfc);
       
    24 
       
    25 /** Interface for class that actually controls the composition singleton **/
       
    26 class MAlfCompositionController: public MAlfCompositionControl
       
    27     {
       
    28 public:
       
    29     virtual TInt CreateTargetL(TInt aTarget, TInt aClientHandle, TInt aGrpHandle ) = 0;    
       
    30     virtual void SetTargetL(TInt aTarget) = 0;    
       
    31     virtual void SetExtentSurfaceId(const TSurfaceId& aSurfaceId) = 0;
       
    32     virtual TInt SetOrder(TInt aTarget, TInt aTop, TBool aAbove, TBool aCombineTargets) =0;
       
    33     virtual void DeleteTarget(TInt aTarget)=0;
       
    34     virtual void LowOnGraphicsMemory()=0;
       
    35     virtual void GraphicsMemoryGood(){}
       
    36     
       
    37     virtual void AlfBridgeCallback(TInt, TAny*){};
       
    38     }; 
       
    39 
       
    40 /** Wrapper class IPC <-> MAlfCompositionController **/
       
    41 NONSHARABLE_CLASS(CAlfCompositionCntrlClient): public CAlfCompositionClientBase
       
    42     {
       
    43 public:
       
    44     CAlfCompositionCntrlClient(MAlfCompositionController* aController):iController(aController){}
       
    45     IMPORT_C static CAlfCompositionCntrlClient* NewL(RAlfBridgerClient* aClient, MAlfCompositionController* aController);
       
    46     IMPORT_C ~CAlfCompositionCntrlClient();
       
    47     
       
    48     // From base
       
    49     void HandleEventL(TInt aEventType, TAny* aEventData);
       
    50     // from CActive
       
    51     TInt RunError(TInt aError);
       
    52 private:
       
    53     MAlfCompositionController* iController;
       
    54     
       
    55     RHashMap<TInt, TInt> iHostBindingsHash;
       
    56     RHashMap<TInt, TInt32> iHostPermittedOpsHash;
       
    57     
       
    58     };
       
    59     
       
    60 
       
    61 /**
       
    62 Example1:
       
    63 * // to set target from other app semitransparent 
       
    64 * CAlfCompositionHost* me = CAlfCompositionHost::NewL(tokenFromSource, myCompositionKey);
       
    65 * me->EnableAlpha(); 
       
    66 * me->SetOpacity(0.5f);
       
    67 * //...
       
    68 **/
       
    69 class CAlfCompositionHost: public CAlfCompositionSource
       
    70     {
       
    71 public:
       
    72     /** 
       
    73     * Constructor for application that wishes modify 
       
    74     * composition information for some other process, see CreatePermissionToken()
       
    75     *
       
    76     * Leaves using KErrNotFound, if token is not valid
       
    77     * 
       
    78     * If the binded target layer is destroyed by its owner, any Set operations 
       
    79     * will have no effect.
       
    80     */
       
    81     IMPORT_C static CAlfCompositionHost* NewL(TInt aToken, TInt aKey);
       
    82 
       
    83     void ConstructL(TInt aToken, TInt aKey);
       
    84     
       
    85 //private: // data
       
    86 //    class CAlfCompositionHostData;
       
    87 //    CAlfCompositionHostData* iData;
       
    88     };
       
    89 
       
    90 
       
    91 // ================ Posting like SW interface ============================================
       
    92 // 
       
    93 // =======================================================================================
       
    94 
       
    95 /** Inferface for the pixel buffer provider to provide information, frames and get events concerning context events **/
       
    96 class MAlfBufferProvider
       
    97     {
       
    98 public:
       
    99     
       
   100     enum TBufferFormat
       
   101         {
       
   102         ESourceFormatRGB_565 = 0,
       
   103         ESourceFormatXRGB_8888 = 1, 
       
   104         ESourceFormatARGB_8888 = 2,
       
   105         ESourceFormatARGB_8888_PRE = 3
       
   106         };
       
   107 
       
   108     struct TBufferCreationAttributes
       
   109         {
       
   110         /*
       
   111          * Buffer size
       
   112          */
       
   113         TInt iWidth;
       
   114         TInt iHeight;
       
   115         /**
       
   116          * iStride should be at least bytes * width.
       
   117          * iStride may still be adjusted by CAlfCompositionPixelSource for the target HW driver implementation
       
   118          * Client should always use iStride value available after CAlfCompositionPixelSource::ActivateL call.
       
   119          **/
       
   120         TInt iStride;
       
   121         
       
   122         TInt iAlignment;
       
   123         TBufferFormat iFormat;
       
   124         };
       
   125 
       
   126     /**
       
   127      * Called by framework when the next buffer is ready and available for the client to draw.
       
   128      * @param aVisibleRegion is currently visible surface region
       
   129      * 
       
   130      * @return ETrue to continue drawing of frames. EFalse to pause drawing.
       
   131      *          After pausing drawing client needs to call CAlfCompositionPixelSource::ActivateL to
       
   132      *          continue drawing of frames 
       
   133      **/
       
   134     virtual TBool ProduceNewFrameL(const TRegion& aVisibleRegion, TUint8*& aBuffer) = 0;
       
   135 
       
   136     /**
       
   137      * Called by framework when new buffer is been created. Client should provide desired creation attributes.
       
   138      **/
       
   139     virtual TBufferCreationAttributes& BufferAttributes() = 0;
       
   140     
       
   141     /**
       
   142      * Notification from FW 
       
   143      **/
       
   144     virtual void ContextAboutToSuspend() =0;
       
   145     virtual void OnActivation() = 0;
       
   146     };
       
   147 
       
   148 /**
       
   149 * Example1:
       
   150 * // to draw frames with CAlfCompositionPixelSource API
       
   151 * class CMyClass: public CBase, public MAlfBufferProvider
       
   152 *     { 
       
   153 *     private:
       
   154 *         CAlfCompositionPixelSource* iAlfCompositionPixelSource;
       
   155 *         MAlfBufferProvider::TBufferCreationAttributes iAttributes;
       
   156 *     public:
       
   157 *     
       
   158 *     CMyClass() {}
       
   159 *     
       
   160 *     ConstructL()
       
   161 *       {
       
   162 *       // ...
       
   163 *       iAttributes.iWidth = width;
       
   164 *       iAttributes.iHeight = height;
       
   165 *       iAttributes.iFormat = MAlfBufferProvider::ESourceFormatARGB_8888;
       
   166 *       iAttributes.iStride =  iAttributes.iWidth * 4;
       
   167 *       iAttributes.iAlignment = 32;
       
   168 *       
       
   169 *       iAlfCompositionPixelSource = CAlfCompositionPixelSource::NewL(*this, iMyDrawableWindow);
       
   170 *       iAlfCompositionPixelSource->iActivateL()
       
   171 *       }
       
   172 *     
       
   173 *    TBool ProduceNewFrameL(const TRegion& aVisibleRegion, TUint8*& aBuffer)
       
   174 *       {
       
   175 *       // ...
       
   176 *       // copy pixel data to aBuffer
       
   177 *       TUint8* from = (TUint8*)bitmap->DataAddress();
       
   178 *       TUint bytes = bitmap->SizeInPixels()*4;
       
   179 *       for (TInt y = bitmap->SizeInPixels().iHeight; y > 0; y--)
       
   180 *           {
       
   181 *           Mem::Copy(aBuffer, from, bytes);
       
   182 *           aBuffer += iAttributes.iStride;
       
   183 *           from += bitmap->DataStride();
       
   184 *           }
       
   185 *       // ...
       
   186 *       return ETrue; // to continue getting ProduceNewFrameL callbacks
       
   187 *       };
       
   188 *
       
   189 *    MAlfBufferProvider::TBufferCreationAttributes& BufferAttributes() { return iAttributes };
       
   190 *   
       
   191 *    void ContextAboutToSuspend() {};
       
   192 *    void OnActivation() {};
       
   193 *    // ...
       
   194 *    }
       
   195 *
       
   196 * Example2:
       
   197 * // client may want or need to adjust ProduceNewFrameL-callbacks inverval
       
   198 * class CMyClass: public CActive, public MAlfBufferProvider
       
   199 *     { 
       
   200 *     private:
       
   201 *         CAlfCompositionPixelSource* iAlfCompositionPixelSource;
       
   202 *         MAlfBufferProvider::TBufferCreationAttributes iAttributes;
       
   203 *         TBool iDrawNext;
       
   204 *         TTimeIntervalMicroSeconds32 iWaitTime;
       
   205 *         RTimer iTimer;
       
   206 *     public:
       
   207 *     
       
   208 *     CMyClass() {}
       
   209 *     
       
   210 *     ConstructL()
       
   211 *       {
       
   212 *       // ...
       
   213 *       iDrawNext = ETrue;
       
   214 *       iWaitTime = 25*1000; 
       
   215 *       // ...
       
   216 *       }
       
   217 *
       
   218 *    void RunL()
       
   219 *       {
       
   220 *       if( iStatus.Int() != KErrNone )
       
   221 *           {
       
   222 *           iDrawNext = ETrue;
       
   223 *           iAlfCompositionPixelSource->ActivateL();
       
   224 *           }
       
   225 *       }
       
   226 *    // ... 
       
   227 *    TBool ProduceNewFrameL(const TRegion& aVisibleRegion, TUint8*& aBuffer)
       
   228 *       {
       
   229 *       if( iDrawNext )
       
   230 *           {
       
   231 *           iDrawNext = EFalse;
       
   232 *           }
       
   233 *       else
       
   234 *           {
       
   235 *           iTimer.After( iStatus, iWaitTime );
       
   236 *           return EFalse;
       
   237 *           }
       
   238 *       // ...
       
   239 *       // copy pixel data to aBuffer
       
   240 *       // ...
       
   241 *       return ETrue; // to continue getting ProduceNewFrameL callbacks
       
   242 *       };
       
   243 *    // ...
       
   244 *    }
       
   245 *    
       
   246 * Example3:
       
   247 * // API can be used withou the actual window
       
   248 * class CMyClass: public CBase, public MAlfBufferProvider
       
   249 *     { 
       
   250 *     private:
       
   251 *         CAlfCompositionPixelSource* iAlfCompositionPixelSource;
       
   252 *         MAlfBufferProvider::TBufferCreationAttributes iAttributes;
       
   253 *     public:
       
   254 *     
       
   255 *     CMyClass() {}
       
   256 *     
       
   257 *     ConstructL()
       
   258 *       {
       
   259 *       // ...
       
   260 *       iAttributes.iWidth = width;
       
   261 *       iAttributes.iHeight = height;
       
   262 *       iAttributes.iFormat = MAlfBufferProvider::ESourceFormatARGB_8888;
       
   263 *       iAttributes.iStride =  iAttributes.iWidth * 4;
       
   264 *       iAttributes.iAlignment = 32;
       
   265 *       
       
   266 *       iAlfCompositionPixelSource = CAlfCompositionPixelSource::NewL(*this, NULL);
       
   267 *       iAlfCompositionPixelSource->SetExtent(TRect(0,0,600,300),0,1);
       
   268 *       iAlfCompositionPixelSource->iActivateL();
       
   269 *       }
       
   270 *    // ... 
       
   271 *    TBool ProduceNewFrameL(const TRegion& aVisibleRegion, TUint8*& aBuffer)
       
   272 *       {
       
   273 *       // ...
       
   274 *       // copy pixel data to aBuffer
       
   275 *       // ...
       
   276 *       return ETrue; // to continue getting ProduceNewFrameL callbacks
       
   277 *       };
       
   278 *    // ...
       
   279 *    
       
   280 *    // Notice: When activating Composition pixel source after being suspended, SetExtent needs to be called again.
       
   281 *    void ContinueAfterSuspendL()
       
   282 *       {
       
   283 *       iAlfCompositionPixelSource->SetExtent(TRect(0,0,600,300),0,1);
       
   284 *       iAlfCompositionPixelSource->iActivateL();
       
   285 *       }
       
   286 *    }
       
   287 **/
       
   288 class CAlfCompositionPixelSource: public CAlfCompositionSource
       
   289     {
       
   290 public:
       
   291     /** 
       
   292      * Constructor 
       
   293      **/
       
   294     IMPORT_C static CAlfCompositionPixelSource* NewL(MAlfBufferProvider& aProvider, RWindow* aWindow = NULL);
       
   295     
       
   296     /**
       
   297      *  Activate drawing for the first time or continue drawing if it is being paused or suspended
       
   298      **/
       
   299     IMPORT_C void ActivateL();
       
   300     
       
   301     /**
       
   302      * Suspend drawing 
       
   303      **/
       
   304     IMPORT_C void Suspend();
       
   305 
       
   306     IMPORT_C ~CAlfCompositionPixelSource();
       
   307 
       
   308     /** 
       
   309     * From base class 
       
   310     * Defines extent of the composition target on a defined screen
       
   311     * Does not affect on hit testing, keyboard focus etc. but is just additional information for composition
       
   312     **/
       
   313     IMPORT_C TInt SetExtent(const TRect& aRect, TInt aScreen);
       
   314     
       
   315     /**
       
   316      * Internal
       
   317      * For drawing one frame
       
   318      **/
       
   319     TBool DrawFrameL(TRequestStatus& aStatus, TInt aBufferNumber = 0);
       
   320 
       
   321 protected:
       
   322 
       
   323     /**
       
   324      * Internal
       
   325      * From base class 
       
   326      **/
       
   327     void HandleEventL(TInt aEventType, TAny* aEventData);                                          
       
   328 
       
   329 private: // Internal / utils
       
   330     
       
   331     void ConstructL(MAlfBufferProvider& aProvider, RWindow* aWindow);
       
   332     void ConstructSurfaceL(MAlfBufferProvider::TBufferCreationAttributes& aCreationAttributes);
       
   333     void FreeSurface();
       
   334     TUint8* Buffer(TInt aBufferNumber);
       
   335 
       
   336     
       
   337 private: // data
       
   338     
       
   339     class CAlfCompositionPixelSourceData;
       
   340     CAlfCompositionPixelSourceData* iData;
       
   341     };
       
   342 
       
   343 
       
   344 #endif // #define __ALFCOMPOSITIONCLIENT_H__