alfcompositionutility.h 13 KB

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