SurfaceComposerClient.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. /*
  2. * Copyright (C) 2007 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef ANDROID_GUI_SURFACE_COMPOSER_CLIENT_H
  17. #define ANDROID_GUI_SURFACE_COMPOSER_CLIENT_H
  18. #include <stdint.h>
  19. #include <sys/types.h>
  20. #include <binder/IBinder.h>
  21. #include <binder/IMemory.h>
  22. #include <utils/RefBase.h>
  23. #include <utils/Singleton.h>
  24. #include <utils/SortedVector.h>
  25. #include <utils/threads.h>
  26. #include <ui/FrameStats.h>
  27. #include <ui/PixelFormat.h>
  28. #include <gui/CpuConsumer.h>
  29. #include <gui/SurfaceControl.h>
  30. namespace android {
  31. // ---------------------------------------------------------------------------
  32. class DisplayInfo;
  33. class Composer;
  34. class ISurfaceComposerClient;
  35. class IGraphicBufferProducer;
  36. class Region;
  37. // ---------------------------------------------------------------------------
  38. class SurfaceComposerClient : public RefBase
  39. {
  40. friend class Composer;
  41. public:
  42. SurfaceComposerClient();
  43. virtual ~SurfaceComposerClient();
  44. // Always make sure we could initialize
  45. status_t initCheck() const;
  46. // Return the connection of this client
  47. sp<IBinder> connection() const;
  48. // Forcibly remove connection before all references have gone away.
  49. void dispose();
  50. // callback when the composer is dies
  51. status_t linkToComposerDeath(const sp<IBinder::DeathRecipient>& recipient,
  52. void* cookie = NULL, uint32_t flags = 0);
  53. // Get a list of supported configurations for a given display
  54. static status_t getDisplayConfigs(const sp<IBinder>& display,
  55. Vector<DisplayInfo>* configs);
  56. // Get the DisplayInfo for the currently-active configuration
  57. static status_t getDisplayInfo(const sp<IBinder>& display,
  58. DisplayInfo* info);
  59. // Get the index of the current active configuration (relative to the list
  60. // returned by getDisplayInfo)
  61. static int getActiveConfig(const sp<IBinder>& display);
  62. // Set a new active configuration using an index relative to the list
  63. // returned by getDisplayInfo
  64. static status_t setActiveConfig(const sp<IBinder>& display, int id);
  65. /* Triggers screen on/off or low power mode and waits for it to complete */
  66. static void setDisplayPowerMode(const sp<IBinder>& display, int mode);
  67. // ------------------------------------------------------------------------
  68. // surface creation / destruction
  69. //! Create a surface
  70. sp<SurfaceControl> createSurface(
  71. const String8& name,// name of the surface
  72. uint32_t w, // width in pixel
  73. uint32_t h, // height in pixel
  74. PixelFormat format, // pixel-format desired
  75. uint32_t flags = 0 // usage flags
  76. );
  77. //! Create a virtual display
  78. static sp<IBinder> createDisplay(const String8& displayName, bool secure);
  79. //! Destroy a virtual display
  80. static void destroyDisplay(const sp<IBinder>& display);
  81. //! Get the token for the existing default displays.
  82. //! Possible values for id are eDisplayIdMain and eDisplayIdHdmi.
  83. static sp<IBinder> getBuiltInDisplay(int32_t id);
  84. // ------------------------------------------------------------------------
  85. // Composer parameters
  86. // All composer parameters must be changed within a transaction
  87. // several surfaces can be updated in one transaction, all changes are
  88. // committed at once when the transaction is closed.
  89. // closeGlobalTransaction() requires an IPC with the server.
  90. //! Open a composer transaction on all active SurfaceComposerClients.
  91. static void openGlobalTransaction();
  92. //! Close a composer transaction on all active SurfaceComposerClients.
  93. static void closeGlobalTransaction(bool synchronous = false);
  94. //! Flag the currently open transaction as an animation transaction.
  95. static void setAnimationTransaction();
  96. status_t hide(const sp<IBinder>& id);
  97. status_t show(const sp<IBinder>& id);
  98. status_t setFlags(const sp<IBinder>& id, uint32_t flags, uint32_t mask);
  99. status_t setTransparentRegionHint(const sp<IBinder>& id, const Region& transparent);
  100. status_t setLayer(const sp<IBinder>& id, uint32_t layer);
  101. status_t setAlpha(const sp<IBinder>& id, float alpha=1.0f);
  102. status_t setMatrix(const sp<IBinder>& id, float dsdx, float dtdx, float dsdy, float dtdy);
  103. status_t setPosition(const sp<IBinder>& id, float x, float y);
  104. status_t setSize(const sp<IBinder>& id, uint32_t w, uint32_t h);
  105. status_t setCrop(const sp<IBinder>& id, const Rect& crop);
  106. status_t setLayerStack(const sp<IBinder>& id, uint32_t layerStack);
  107. status_t destroySurface(const sp<IBinder>& id);
  108. status_t clearLayerFrameStats(const sp<IBinder>& token) const;
  109. status_t getLayerFrameStats(const sp<IBinder>& token, FrameStats* outStats) const;
  110. static status_t clearAnimationFrameStats();
  111. static status_t getAnimationFrameStats(FrameStats* outStats);
  112. static void setDisplaySurface(const sp<IBinder>& token,
  113. const sp<IGraphicBufferProducer>& bufferProducer);
  114. static void setDisplayLayerStack(const sp<IBinder>& token,
  115. uint32_t layerStack);
  116. static void setDisplaySize(const sp<IBinder>& token, uint32_t width, uint32_t height);
  117. /* setDisplayProjection() defines the projection of layer stacks
  118. * to a given display.
  119. *
  120. * - orientation defines the display's orientation.
  121. * - layerStackRect defines which area of the window manager coordinate
  122. * space will be used.
  123. * - displayRect defines where on the display will layerStackRect be
  124. * mapped to. displayRect is specified post-orientation, that is
  125. * it uses the orientation seen by the end-user.
  126. */
  127. static void setDisplayProjection(const sp<IBinder>& token,
  128. uint32_t orientation,
  129. const Rect& layerStackRect,
  130. const Rect& displayRect);
  131. status_t setBlur(const sp<IBinder>& id, float blur);
  132. status_t setBlurMaskSurface(const sp<IBinder>& id, const sp<IBinder>& maskSurfaceId);
  133. status_t setBlurMaskSampling(const sp<IBinder>& id, uint32_t blurMaskSampling);
  134. status_t setBlurMaskAlphaThreshold(const sp<IBinder>& id, float alpha);
  135. private:
  136. virtual void onFirstRef();
  137. Composer& getComposer();
  138. mutable Mutex mLock;
  139. status_t mStatus;
  140. sp<ISurfaceComposerClient> mClient;
  141. Composer& mComposer;
  142. };
  143. // ---------------------------------------------------------------------------
  144. class ScreenshotClient
  145. {
  146. public:
  147. // if cropping isn't required, callers may pass in a default Rect, e.g.:
  148. // capture(display, producer, Rect(), reqWidth, ...);
  149. static status_t capture(
  150. const sp<IBinder>& display,
  151. const sp<IGraphicBufferProducer>& producer,
  152. Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
  153. uint32_t minLayerZ, uint32_t maxLayerZ,
  154. bool useIdentityTransform);
  155. private:
  156. mutable sp<CpuConsumer> mCpuConsumer;
  157. mutable sp<IGraphicBufferProducer> mProducer;
  158. CpuConsumer::LockedBuffer mBuffer;
  159. bool mHaveBuffer;
  160. public:
  161. ScreenshotClient();
  162. ~ScreenshotClient();
  163. // frees the previous screenshot and captures a new one
  164. // if cropping isn't required, callers may pass in a default Rect, e.g.:
  165. // update(display, Rect(), useIdentityTransform);
  166. status_t update(const sp<IBinder>& display,
  167. Rect sourceCrop, bool useIdentityTransform);
  168. status_t update(const sp<IBinder>& display,
  169. Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
  170. bool useIdentityTransform);
  171. status_t update(const sp<IBinder>& display,
  172. Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
  173. uint32_t minLayerZ, uint32_t maxLayerZ,
  174. bool useIdentityTransform);
  175. status_t update(const sp<IBinder>& display,
  176. Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
  177. uint32_t minLayerZ, uint32_t maxLayerZ,
  178. bool useIdentityTransform, uint32_t rotation);
  179. sp<CpuConsumer> getCpuConsumer() const;
  180. // release memory occupied by the screenshot
  181. void release();
  182. // pixels are valid until this object is freed or
  183. // release() or update() is called
  184. void const* getPixels() const;
  185. uint32_t getWidth() const;
  186. uint32_t getHeight() const;
  187. PixelFormat getFormat() const;
  188. uint32_t getStride() const;
  189. // size of allocated memory in bytes
  190. size_t getSize() const;
  191. };
  192. // ---------------------------------------------------------------------------
  193. }; // namespace android
  194. #endif // ANDROID_GUI_SURFACE_COMPOSER_CLIENT_H