uiaccelerator_plat/alf_visual_api/inc/alf/alfcompositionutility.h
changeset 0 15bf7259bb7c
child 8 46927d61fef3
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 __ALFCOMPOSITIONUTILITY_H__
       
    18 #define __ALFCOMPOSITIONUTILITY_H__
       
    19 
       
    20 #include <e32base.h>
       
    21 #include <w32std.h>
       
    22 
       
    23 
       
    24 class RAlfBridgerClient;
       
    25 /*
       
    26  * CAlfRsSendBuffer creates in construction one CAlfCompositionClient. That client 
       
    27  * will wait for request completion. Request is completed, when an application communicaties 
       
    28  * to CAlfRenderStage via CAlfCompositionSource client. After request is completed, the 
       
    29  * CAlfCompositionClient (owned by CAlfRsSendBuffer) is again set active and it waits for 
       
    30  * the next message.
       
    31  */
       
    32 
       
    33 /** Base classes for logistics **/
       
    34 class CAlfCompositionClientBase: public CActive
       
    35     {
       
    36 public:
       
    37     
       
    38     enum TAlfCompositionPermission
       
    39         {
       
    40         EAlfAllowChangeExtent           = 1,
       
    41         EAlfAllowChangeAlpha            = 2,
       
    42         EAlfAllowChangeOpacity          = 4,
       
    43         EAlfAllowChangeRotation         = 8,
       
    44         EAlfAllowChangeBackgroundAnim   = 16
       
    45         }; 
       
    46     
       
    47 protected:
       
    48     CAlfCompositionClientBase(TInt aPriority = CActive::EPriorityHigh):CActive(aPriority)
       
    49         {
       
    50         CActiveScheduler::Add(this);
       
    51         }
       
    52         
       
    53     IMPORT_C ~CAlfCompositionClientBase();
       
    54     IMPORT_C void RequestEventL(TInt aBufferSize, RAlfBridgerClient* aClient = 0);        
       
    55     IMPORT_C TInt SendEvent(TInt aOp, const TAny* aEventData, TInt aEventSize);
       
    56     IMPORT_C void SetHandleL(TInt aHandle);
       
    57     
       
    58     // Virtuals
       
    59     IMPORT_C virtual void HandleEventL(TInt aEventType, TAny* aEventData);
       
    60     // from CActive
       
    61     IMPORT_C TInt RunError(TInt aError);
       
    62 
       
    63 private: // from CActive
       
    64     void RunL();
       
    65     void DoCancel();
       
    66 
       
    67 public: // for utils
       
    68     TInt Handle() const;
       
    69         
       
    70 private: // data
       
    71     class CAlfCompositionClientBaseData;
       
    72     CAlfCompositionClientBaseData* iData;
       
    73     };
       
    74 
       
    75 NONSHARABLE_CLASS(CAlfCompositionClientBase::CAlfCompositionClientBaseData):public CBase
       
    76     {
       
    77     public:
       
    78     static CAlfCompositionClientBaseData* NewL(TInt aBufferSize, RAlfBridgerClient* aClient);
       
    79 
       
    80     void ConstructL(TInt aBufferSize, RAlfBridgerClient* aClient);
       
    81 
       
    82     ~CAlfCompositionClientBaseData();
       
    83 
       
    84     RAlfBridgerClient* iClient;
       
    85     TBool iOwnsClient;
       
    86     TBuf8<60> iBuffer;
       
    87     TBool* iDeleted;
       
    88     TInt iBufferSize;
       
    89     TInt iHandle;
       
    90     };
       
    91 
       
    92 class MAlfCompositionControl
       
    93     {
       
    94     public:
       
    95         /** 
       
    96     * Enables / disables alpha on composition target 
       
    97     **/
       
    98     virtual TInt EnableAlpha(TBool aEnable = ETrue) = 0;
       
    99     
       
   100     /** 
       
   101     * Set constant opacity (0..255) multiplier that will be applied to 
       
   102     * composition target <in practice, only 256 different shades supported> 
       
   103     **/
       
   104     virtual TInt SetOpacity(TReal32 aOpacity) __SOFTFP = 0;
       
   105     
       
   106     /** 
       
   107     * rotation of composition target
       
   108     * <in practice, only 90 degree steps supported, value given will be rounded to closest rotation> 
       
   109     **/
       
   110     virtual TInt SetRotation(TInt aRotationInDegrees) = 0;
       
   111         
       
   112     /** 
       
   113     * Defines extent of the composition target on a defined screen
       
   114     * Does not affect on hit testing, keyboard focus etc. but is just additional information for composition
       
   115     **/
       
   116     virtual TInt SetExtent(const TRect& aRect, TInt aScreen) = 0;
       
   117 
       
   118     /** 
       
   119     * Makes this composition target system wide background surface 
       
   120     **/
       
   121     virtual void SetIsBackgroundAnim(TBool ETrue) = 0;    
       
   122 
       
   123     /** 
       
   124     * Defines extent of the composition source rectangle
       
   125     **/
       
   126     virtual TInt SetSourceRect(const TRect& aRect) = 0;
       
   127     };   
       
   128 
       
   129 
       
   130 /** Client interface for composition fw information **/
       
   131 class MAlfCompositionObserver
       
   132     {
       
   133 public:
       
   134     /**
       
   135     * Called by framework when composition framework has completed a frame and thus can 
       
   136     * efficiently handle changes and/or new content
       
   137     **/    
       
   138     virtual void FrameReady(TInt aScreenNumber) = 0;
       
   139 
       
   140     /**
       
   141     * Notifications from FW
       
   142     **/    
       
   143     virtual void RunningLowOnGraphicsMemory() = 0; // running low on resources, clear cahces etc.
       
   144     virtual void CompositionTargetHidden() = 0; // target is no more visible on composition scene, 
       
   145                                                 // free at least slack resources 
       
   146     virtual void GraphicsMemoryGood(){}         // graphics memory status is normal again  
       
   147 	virtual void CompositionTargetVisible() {}  // target is visible again after first being hidden                                  
       
   148     };
       
   149 
       
   150 /**
       
   151 * Example1:
       
   152 * // to set target semitransparent 
       
   153 * CAlfCompositionSource* me = CAlfCompositionSource::NewL(iMyDrawableWindow);
       
   154 * me->EnableAlpha(); 
       
   155 * me->SetOpacity(0.5f);
       
   156 * //...
       
   157 * delete me; // deletion of client will restore state to original
       
   158 *
       
   159 * Example2:
       
   160 * // to fade in for composition target
       
   161 * class CMyClass: public CBase, private MAlfCompositionObserver
       
   162 *     { 
       
   163 *     CMyClass():iOpacity(0)
       
   164 *       {
       
   165 *       }
       
   166 *     ConstructL()
       
   167 *       {
       
   168 *       // ...
       
   169 *       iAlfCompositionSource = CAlfCompositionSource::NewL(iMyDrawableWindow);
       
   170 *       iAlfCompositionSource->EnableAlpha(); 
       
   171 *       iAlfCompositionSource->SetOpacity(iOpacity);
       
   172 *       }
       
   173 *     
       
   174 *     void FrameReady(TInt aScreenNumber)
       
   175 *       {
       
   176 *       if (iOpacity < 1)
       
   177 *           { 
       
   178 *           iOpacity += 0.03; // just follow refresh linearly      
       
   179 *           iAlfCompositionSource->SetOpacity(iOpacity);
       
   180 *           }
       
   181 *        else
       
   182 *           { // fade in complete, no need to have composition cntrl anymore
       
   183 *           delete iAlfCompositionSource;
       
   184 *           iAlfCompositionSource = 0;
       
   185 *           }       
       
   186 *       }    
       
   187 *
       
   188 * Example 3:       
       
   189 * // To grant other application / process a priviledged rights to modify composition target
       
   190 * const TInt mySuperSecretKeyForHost1 = 0x000FAB10;
       
   191 * const TInt flagsForHost1 = EAlfAllowChangeExtent | EAlfAllowChangeAlpha; // but not rotation  
       
   192 *
       
   193 * CAlfCompositionSource* me = CAlfCompositionSource::NewL(iMyDrawableWindow);
       
   194 * TInt generatedKey = me->CreatePermissionToken(0x000FAB10, flagsForHost1);
       
   195 * 
       
   196 * PassGeneratedKeyToHost(generatedKey); // it already knows the other key..
       
   197 *
       
   198 * TBD, will the generates key work even after composition source destroys the
       
   199 * CAlfCompositionSource instance
       
   200 *      
       
   201 **/
       
   202 class CAlfCompositionSource: public CAlfCompositionClientBase, MAlfCompositionControl
       
   203     {
       
   204 public:
       
   205 
       
   206     /** 
       
   207     * Constructor 
       
   208     **/
       
   209     IMPORT_C static CAlfCompositionSource* NewL(RWindow& aClientWindow);
       
   210 
       
   211     /** 
       
   212     * Creates handle based on key
       
   213     * Flags define which kind of operations are allowed by host application
       
   214     * using the token. Same token can be used multiple times for different clients.
       
   215     *
       
   216     **/
       
   217     IMPORT_C TInt CreatePermissionToken(TInt aKey, TInt aPermissionFlags);
       
   218 
       
   219     /** 
       
   220     * Enables / disables alpha on composition target 
       
   221     **/
       
   222     IMPORT_C TInt EnableAlpha(TBool aEnable = ETrue);
       
   223     
       
   224     /** 
       
   225     * Set constant opacity 0.0 - 1.0f multiplier that will be applied to composition target
       
   226     * <in practice, only 256 different shades supported> 
       
   227     **/
       
   228     IMPORT_C TInt SetOpacity(TReal32 aOpacity) __SOFTFP;
       
   229     
       
   230     /** 
       
   231     * rotation of composition target
       
   232     * <in practice, only 90 degree steps supported, value given will be rounded to closest rotation> 
       
   233     **/
       
   234     IMPORT_C TInt SetRotation(TInt aRotationInDegrees);
       
   235     
       
   236     /** 
       
   237     * @prototype Consult owner about the usage and restrictions
       
   238     *
       
   239     * Defines the composition order. On success returns token
       
   240     * that can be used to create new CAlfCompositionSource object to
       
   241     * control union of theses two composition targets as single object 
       
   242     * for convenience
       
   243     *
       
   244     * Does not affect on hit testing, keyboard focus etc.
       
   245     * 
       
   246     * @return new token to control the union of composition objects (assume key different from default)
       
   247     * 
       
   248     **/
       
   249     IMPORT_C TInt SetZOrder(const CAlfCompositionClientBase& aNode, TBool aAbove, TInt aKey = -1); // todo magic
       
   250     
       
   251     /** 
       
   252     * Defines extent of the composition target on a defined screen
       
   253     * Does not affect on hit testing, keyboard focus etc. but is just additional information for composition
       
   254     **/
       
   255     IMPORT_C TInt SetExtent(const TRect& aRect, TInt aScreen);
       
   256 
       
   257     /** 
       
   258     * Adds composition observer for better synchronization
       
   259     **/
       
   260     IMPORT_C void AddCompositionObserverL(MAlfCompositionObserver& aObserver, TInt aScreenNumber = 0); // Todo: KMainScreen);
       
   261 
       
   262     /** 
       
   263     * Removes composition observer
       
   264     **/
       
   265     IMPORT_C void RemoveObserver(MAlfCompositionObserver& aObserver);
       
   266 
       
   267     /** 
       
   268     * Makes this composition target system wide background surface 
       
   269     * any other target that was previously used as bg anim will be discarded
       
   270     * < should this require some capability like WriteDeviceData ?>
       
   271     **/
       
   272     IMPORT_C void SetIsBackgroundAnim(TBool aIsBg);
       
   273     
       
   274     /** 
       
   275     * Defines extent of the composition source rectangle
       
   276     **/
       
   277     IMPORT_C TInt SetSourceRect(const TRect& aRect);
       
   278     
       
   279     /** 
       
   280     * Internal
       
   281     * For testing applications on extrenal screen 
       
   282     **/
       
   283     IMPORT_C void EnableKeyboard(TBool aEnable, TInt aScreen);
       
   284 
       
   285     IMPORT_C ~CAlfCompositionSource();
       
   286 
       
   287 protected: // utils / baseclass
       
   288     IMPORT_C virtual void HandleEventL(TInt aEventType, TAny* aEventData);
       
   289     virtual void ConstructL(TInt aHandle1, TInt aHandle2, TInt  aScreenNumber);
       
   290     virtual void ConstructL(RWindow& aClientWindow);
       
   291     TInt Handle();
       
   292 
       
   293 protected: // data
       
   294     class CAlfCompositionSourceData;
       
   295     CAlfCompositionSourceData* iData;
       
   296     };
       
   297 
       
   298 #endif // #define __ALFCOMPOSITIONUTILITY_H__