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