| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 |  | 
| Mathias Agopian | 9cce325 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 17 | #ifndef ANDROID_SF_SURFACE_COMPOSER_CLIENT_H | 
|  | 18 | #define ANDROID_SF_SURFACE_COMPOSER_CLIENT_H | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 19 |  | 
|  | 20 | #include <stdint.h> | 
|  | 21 | #include <sys/types.h> | 
|  | 22 |  | 
| Mathias Agopian | dd3423c | 2009-09-23 15:44:05 -0700 | [diff] [blame] | 23 | #include <binder/IBinder.h> | 
|  | 24 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | #include <utils/RefBase.h> | 
| Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 26 | #include <utils/Singleton.h> | 
|  | 27 | #include <utils/SortedVector.h> | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | #include <utils/threads.h> | 
|  | 29 |  | 
|  | 30 | #include <ui/PixelFormat.h> | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 31 | #include <ui/Region.h> | 
| Mathias Agopian | 9cce325 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 32 |  | 
|  | 33 | #include <surfaceflinger/Surface.h> | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 |  | 
|  | 35 | namespace android { | 
|  | 36 |  | 
|  | 37 | // --------------------------------------------------------------------------- | 
|  | 38 |  | 
| Mathias Agopian | 9cce325 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 39 | class DisplayInfo; | 
| Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 40 | class IMemoryHeap; | 
|  | 41 | class ISurfaceComposer; | 
|  | 42 | class Region; | 
| Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 43 | class surface_flinger_cblk_t; | 
|  | 44 |  | 
|  | 45 | // --------------------------------------------------------------------------- | 
|  | 46 |  | 
|  | 47 | class ComposerService : public Singleton<ComposerService> | 
|  | 48 | { | 
|  | 49 | // these are constants | 
|  | 50 | sp<ISurfaceComposer> mComposerService; | 
|  | 51 | sp<IMemoryHeap> mServerCblkMemory; | 
|  | 52 | surface_flinger_cblk_t volatile* mServerCblk; | 
|  | 53 | ComposerService(); | 
|  | 54 | friend class Singleton<ComposerService>; | 
|  | 55 | public: | 
|  | 56 | static sp<ISurfaceComposer> getComposerService(); | 
|  | 57 | static surface_flinger_cblk_t const volatile * getControlBlock(); | 
|  | 58 | }; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 59 |  | 
| Mathias Agopian | d4784a3 | 2010-05-27 19:41:15 -0700 | [diff] [blame] | 60 | // --------------------------------------------------------------------------- | 
|  | 61 |  | 
|  | 62 | class SurfaceComposerClient : public RefBase | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 63 | { | 
|  | 64 | public: | 
|  | 65 | SurfaceComposerClient(); | 
|  | 66 | virtual     ~SurfaceComposerClient(); | 
|  | 67 |  | 
|  | 68 | // Always make sure we could initialize | 
|  | 69 | status_t    initCheck() const; | 
|  | 70 |  | 
|  | 71 | // Return the connection of this client | 
|  | 72 | sp<IBinder> connection() const; | 
|  | 73 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 74 | // Forcibly remove connection before all references have gone away. | 
|  | 75 | void        dispose(); | 
|  | 76 |  | 
|  | 77 | // ------------------------------------------------------------------------ | 
|  | 78 | // surface creation / destruction | 
|  | 79 |  | 
|  | 80 | //! Create a surface | 
| Mathias Agopian | 01b7668 | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 81 | sp<SurfaceControl> createSurface( | 
| Mathias Agopian | 285dbde | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 82 | const String8& name,// name of the surface | 
| Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 83 | DisplayID display,  // Display to create this surface on | 
|  | 84 | uint32_t w,         // width in pixel | 
|  | 85 | uint32_t h,         // height in pixel | 
|  | 86 | PixelFormat format, // pixel-format desired | 
|  | 87 | uint32_t flags = 0  // usage flags | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 88 | ); | 
|  | 89 |  | 
| Mathias Agopian | 285dbde | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 90 | sp<SurfaceControl> createSurface( | 
| Mathias Agopian | 285dbde | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 91 | DisplayID display,  // Display to create this surface on | 
|  | 92 | uint32_t w,         // width in pixel | 
|  | 93 | uint32_t h,         // height in pixel | 
|  | 94 | PixelFormat format, // pixel-format desired | 
|  | 95 | uint32_t flags = 0  // usage flags | 
|  | 96 | ); | 
|  | 97 |  | 
|  | 98 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 99 | // ------------------------------------------------------------------------ | 
|  | 100 | // Composer parameters | 
|  | 101 | // All composer parameters must be changed within a transaction | 
|  | 102 | // several surfaces can be updated in one transaction, all changes are | 
|  | 103 | // committed at once when the transaction is closed. | 
|  | 104 | // CloseTransaction() usually requires an IPC with the server. | 
|  | 105 |  | 
|  | 106 | //! Open a composer transaction | 
|  | 107 | status_t    openTransaction(); | 
|  | 108 |  | 
|  | 109 | //! commit the transaction | 
|  | 110 | status_t    closeTransaction(); | 
|  | 111 |  | 
|  | 112 | //! Open a composer transaction on all active SurfaceComposerClients. | 
|  | 113 | static void openGlobalTransaction(); | 
|  | 114 |  | 
|  | 115 | //! Close a composer transaction on all active SurfaceComposerClients. | 
|  | 116 | static void closeGlobalTransaction(); | 
|  | 117 |  | 
|  | 118 | //! Freeze the specified display but not transactions. | 
|  | 119 | static status_t freezeDisplay(DisplayID dpy, uint32_t flags = 0); | 
|  | 120 |  | 
|  | 121 | //! Resume updates on the specified display. | 
|  | 122 | static status_t unfreezeDisplay(DisplayID dpy, uint32_t flags = 0); | 
|  | 123 |  | 
|  | 124 | //! Set the orientation of the given display | 
| Mathias Agopian | c08731e | 2009-03-27 18:11:38 -0700 | [diff] [blame] | 125 | static int setOrientation(DisplayID dpy, int orientation, uint32_t flags); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 126 |  | 
|  | 127 | // Query the number of displays | 
|  | 128 | static ssize_t getNumberOfDisplays(); | 
|  | 129 |  | 
|  | 130 | // Get information about a display | 
|  | 131 | static status_t getDisplayInfo(DisplayID dpy, DisplayInfo* info); | 
|  | 132 | static ssize_t getDisplayWidth(DisplayID dpy); | 
|  | 133 | static ssize_t getDisplayHeight(DisplayID dpy); | 
|  | 134 | static ssize_t getDisplayOrientation(DisplayID dpy); | 
|  | 135 |  | 
| Mathias Agopian | dd3423c | 2009-09-23 15:44:05 -0700 | [diff] [blame] | 136 | status_t linkToComposerDeath(const sp<IBinder::DeathRecipient>& recipient, | 
|  | 137 | void* cookie = NULL, uint32_t flags = 0); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 138 |  | 
| Mathias Agopian | 62185b7 | 2009-04-16 16:19:50 -0700 | [diff] [blame] | 139 | status_t    hide(SurfaceID id); | 
|  | 140 | status_t    show(SurfaceID id, int32_t layer = -1); | 
|  | 141 | status_t    freeze(SurfaceID id); | 
|  | 142 | status_t    unfreeze(SurfaceID id); | 
|  | 143 | status_t    setFlags(SurfaceID id, uint32_t flags, uint32_t mask); | 
|  | 144 | status_t    setTransparentRegionHint(SurfaceID id, const Region& transparent); | 
|  | 145 | status_t    setLayer(SurfaceID id, int32_t layer); | 
|  | 146 | status_t    setAlpha(SurfaceID id, float alpha=1.0f); | 
|  | 147 | status_t    setFreezeTint(SurfaceID id, uint32_t tint); | 
|  | 148 | status_t    setMatrix(SurfaceID id, float dsdx, float dtdx, float dsdy, float dtdy); | 
|  | 149 | status_t    setPosition(SurfaceID id, int32_t x, int32_t y); | 
|  | 150 | status_t    setSize(SurfaceID id, uint32_t w, uint32_t h); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 151 | status_t    destroySurface(SurfaceID sid); | 
|  | 152 |  | 
| Mathias Agopian | 631f358 | 2010-05-25 17:51:34 -0700 | [diff] [blame] | 153 | private: | 
| Mathias Agopian | d4784a3 | 2010-05-27 19:41:15 -0700 | [diff] [blame] | 154 | virtual void onFirstRef(); | 
| Mathias Agopian | 631f358 | 2010-05-25 17:51:34 -0700 | [diff] [blame] | 155 | inline layer_state_t*   get_state_l(SurfaceID id); | 
|  | 156 | layer_state_t*          lockLayerState(SurfaceID id); | 
|  | 157 | inline void             unlockLayerState(); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 158 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 159 | mutable     Mutex                               mLock; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 160 | SortedVector<layer_state_t>         mStates; | 
|  | 161 | int32_t                             mTransactionOpen; | 
| Mathias Agopian | d4784a3 | 2010-05-27 19:41:15 -0700 | [diff] [blame] | 162 | layer_state_t*                      mPrebuiltLayerState; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 163 |  | 
|  | 164 | // these don't need to be protected because they never change | 
|  | 165 | // after assignment | 
|  | 166 | status_t                    mStatus; | 
| Mathias Agopian | 7e27f05 | 2010-05-28 14:22:23 -0700 | [diff] [blame] | 167 | sp<ISurfaceComposerClient>  mClient; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 168 | }; | 
|  | 169 |  | 
| Mathias Agopian | d4784a3 | 2010-05-27 19:41:15 -0700 | [diff] [blame] | 170 | // --------------------------------------------------------------------------- | 
| Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 171 |  | 
|  | 172 | class ScreenshotClient | 
|  | 173 | { | 
|  | 174 | sp<IMemoryHeap> mHeap; | 
|  | 175 | uint32_t mWidth; | 
|  | 176 | uint32_t mHeight; | 
|  | 177 | PixelFormat mFormat; | 
|  | 178 | public: | 
|  | 179 | ScreenshotClient(); | 
|  | 180 |  | 
|  | 181 | // frees the previous screenshot and capture a new one | 
|  | 182 | status_t update(); | 
|  | 183 | status_t update(uint32_t reqWidth, uint32_t reqHeight); | 
| Mathias Agopian | bf2c6a6 | 2010-12-10 16:22:31 -0800 | [diff] [blame] | 184 | status_t update(uint32_t reqWidth, uint32_t reqHeight, | 
|  | 185 | uint32_t minLayerZ, uint32_t maxLayerZ); | 
| Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 186 |  | 
|  | 187 | // release memory occupied by the screenshot | 
|  | 188 | void release(); | 
|  | 189 |  | 
|  | 190 | // pixels are valid until this object is freed or | 
|  | 191 | // release() or update() is called | 
|  | 192 | void const* getPixels() const; | 
|  | 193 |  | 
|  | 194 | uint32_t getWidth() const; | 
|  | 195 | uint32_t getHeight() const; | 
|  | 196 | PixelFormat getFormat() const; | 
|  | 197 | uint32_t getStride() const; | 
|  | 198 | // size of allocated memory in bytes | 
|  | 199 | size_t getSize() const; | 
|  | 200 | }; | 
|  | 201 |  | 
|  | 202 | // --------------------------------------------------------------------------- | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 203 | }; // namespace android | 
|  | 204 |  | 
| Mathias Agopian | 9cce325 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 205 | #endif // ANDROID_SF_SURFACE_COMPOSER_CLIENT_H | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 206 |  |