| 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 | 90ac799 | 2012-02-25 18:48:35 -0800 | [diff] [blame] | 17 | #ifndef ANDROID_GUI_SURFACE_COMPOSER_CLIENT_H | 
|  | 18 | #define ANDROID_GUI_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> | 
| Mathias Agopian | 6d9b9df | 2013-02-13 15:26:48 -0800 | [diff] [blame] | 24 | #include <binder/IMemory.h> | 
| Mathias Agopian | dd3423c | 2009-09-23 15:44:05 -0700 | [diff] [blame] | 25 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 26 | #include <utils/RefBase.h> | 
| Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 27 | #include <utils/Singleton.h> | 
|  | 28 | #include <utils/SortedVector.h> | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | #include <utils/threads.h> | 
|  | 30 |  | 
|  | 31 | #include <ui/PixelFormat.h> | 
| Mathias Agopian | 9cce325 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 32 |  | 
| Mathias Agopian | abe815d | 2013-03-19 22:22:21 -0700 | [diff] [blame] | 33 | #include <gui/CpuConsumer.h> | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 34 | #include <gui/SurfaceControl.h> | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 |  | 
|  | 36 | namespace android { | 
|  | 37 |  | 
|  | 38 | // --------------------------------------------------------------------------- | 
|  | 39 |  | 
| Mathias Agopian | 9cce325 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 40 | class DisplayInfo; | 
| Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 41 | class Composer; | 
| Mathias Agopian | 41f673c | 2011-11-17 17:48:35 -0800 | [diff] [blame] | 42 | class ISurfaceComposerClient; | 
| Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 43 | class IGraphicBufferProducer; | 
| Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 44 | class Region; | 
| Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 45 |  | 
|  | 46 | // --------------------------------------------------------------------------- | 
|  | 47 |  | 
| Mathias Agopian | d4784a3 | 2010-05-27 19:41:15 -0700 | [diff] [blame] | 48 | class SurfaceComposerClient : public RefBase | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 49 | { | 
| Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 50 | friend class Composer; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 51 | public: | 
|  | 52 | SurfaceComposerClient(); | 
|  | 53 | virtual     ~SurfaceComposerClient(); | 
|  | 54 |  | 
|  | 55 | // Always make sure we could initialize | 
|  | 56 | status_t    initCheck() const; | 
|  | 57 |  | 
|  | 58 | // Return the connection of this client | 
|  | 59 | sp<IBinder> connection() const; | 
|  | 60 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 61 | // Forcibly remove connection before all references have gone away. | 
|  | 62 | void        dispose(); | 
|  | 63 |  | 
| Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 64 | // callback when the composer is dies | 
|  | 65 | status_t linkToComposerDeath(const sp<IBinder::DeathRecipient>& recipient, | 
|  | 66 | void* cookie = NULL, uint32_t flags = 0); | 
|  | 67 |  | 
|  | 68 | // Get information about a display | 
| Jeff Brown | 9d4e3d2 | 2012-08-24 20:00:51 -0700 | [diff] [blame] | 69 | static status_t getDisplayInfo(const sp<IBinder>& display, DisplayInfo* info); | 
| Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 70 |  | 
| Jeff Brown | 2a09bb3 | 2012-10-08 19:13:57 -0700 | [diff] [blame] | 71 | /* triggers screen off and waits for it to complete */ | 
|  | 72 | static void blankDisplay(const sp<IBinder>& display); | 
|  | 73 |  | 
|  | 74 | /* triggers screen on and waits for it to complete */ | 
|  | 75 | static void unblankDisplay(const sp<IBinder>& display); | 
|  | 76 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | uint32_t w,         // width in pixel | 
|  | 84 | uint32_t h,         // height in pixel | 
|  | 85 | PixelFormat format, // pixel-format desired | 
|  | 86 | uint32_t flags = 0  // usage flags | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 87 | ); | 
|  | 88 |  | 
| Jeff Brown | 9d4e3d2 | 2012-08-24 20:00:51 -0700 | [diff] [blame] | 89 | //! Create a display | 
| Jamie Gennis | dd3cb84 | 2012-10-19 18:19:11 -0700 | [diff] [blame] | 90 | static sp<IBinder> createDisplay(const String8& displayName, bool secure); | 
| Mathias Agopian | 285dbde | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 91 |  | 
| Jeff Brown | 9d4e3d2 | 2012-08-24 20:00:51 -0700 | [diff] [blame] | 92 | //! Get the token for the existing default displays. | 
|  | 93 | //! Possible values for id are eDisplayIdMain and eDisplayIdHdmi. | 
|  | 94 | static sp<IBinder> getBuiltInDisplay(int32_t id); | 
|  | 95 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 96 | // ------------------------------------------------------------------------ | 
|  | 97 | // Composer parameters | 
|  | 98 | // All composer parameters must be changed within a transaction | 
|  | 99 | // several surfaces can be updated in one transaction, all changes are | 
|  | 100 | // committed at once when the transaction is closed. | 
| Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 101 | // closeGlobalTransaction() requires an IPC with the server. | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 102 |  | 
|  | 103 | //! Open a composer transaction on all active SurfaceComposerClients. | 
|  | 104 | static void openGlobalTransaction(); | 
| Jamie Gennis | 2d5e230 | 2012-10-15 18:24:43 -0700 | [diff] [blame] | 105 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 106 | //! Close a composer transaction on all active SurfaceComposerClients. | 
| Jamie Gennis | 2837839 | 2011-10-12 17:39:00 -0700 | [diff] [blame] | 107 | static void closeGlobalTransaction(bool synchronous = false); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 108 |  | 
| Jamie Gennis | 2d5e230 | 2012-10-15 18:24:43 -0700 | [diff] [blame] | 109 | //! Flag the currently open transaction as an animation transaction. | 
|  | 110 | static void setAnimationTransaction(); | 
|  | 111 |  | 
| Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 112 | status_t    hide(const sp<IBinder>& id); | 
|  | 113 | status_t    show(const sp<IBinder>& id); | 
|  | 114 | status_t    setFlags(const sp<IBinder>& id, uint32_t flags, uint32_t mask); | 
|  | 115 | status_t    setTransparentRegionHint(const sp<IBinder>& id, const Region& transparent); | 
|  | 116 | status_t    setLayer(const sp<IBinder>& id, int32_t layer); | 
|  | 117 | status_t    setAlpha(const sp<IBinder>& id, float alpha=1.0f); | 
|  | 118 | status_t    setMatrix(const sp<IBinder>& id, float dsdx, float dtdx, float dsdy, float dtdy); | 
|  | 119 | status_t    setPosition(const sp<IBinder>& id, float x, float y); | 
|  | 120 | status_t    setSize(const sp<IBinder>& id, uint32_t w, uint32_t h); | 
|  | 121 | status_t    setCrop(const sp<IBinder>& id, const Rect& crop); | 
|  | 122 | status_t    setLayerStack(const sp<IBinder>& id, uint32_t layerStack); | 
|  | 123 | status_t    destroySurface(const sp<IBinder>& id); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 124 |  | 
| Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 125 | static void setDisplaySurface(const sp<IBinder>& token, | 
| Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 126 | const sp<IGraphicBufferProducer>& bufferProducer); | 
| Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 127 | static void setDisplayLayerStack(const sp<IBinder>& token, | 
|  | 128 | uint32_t layerStack); | 
| Mathias Agopian | 00e8c7a | 2012-09-04 19:30:46 -0700 | [diff] [blame] | 129 |  | 
|  | 130 | /* setDisplayProjection() defines the projection of layer stacks | 
|  | 131 | * to a given display. | 
|  | 132 | * | 
|  | 133 | * - orientation defines the display's orientation. | 
|  | 134 | * - layerStackRect defines which area of the window manager coordinate | 
|  | 135 | * space will be used. | 
|  | 136 | * - displayRect defines where on the display will layerStackRect be | 
|  | 137 | * mapped to. displayRect is specified post-orientation, that is | 
|  | 138 | * it uses the orientation seen by the end-user. | 
|  | 139 | */ | 
|  | 140 | static void setDisplayProjection(const sp<IBinder>& token, | 
|  | 141 | uint32_t orientation, | 
|  | 142 | const Rect& layerStackRect, | 
|  | 143 | const Rect& displayRect); | 
| Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 144 |  | 
| Mathias Agopian | 631f358 | 2010-05-25 17:51:34 -0700 | [diff] [blame] | 145 | private: | 
| Mathias Agopian | d4784a3 | 2010-05-27 19:41:15 -0700 | [diff] [blame] | 146 | virtual void onFirstRef(); | 
| Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 147 | Composer& getComposer(); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 148 |  | 
| Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 149 | mutable     Mutex                       mLock; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 150 | status_t                    mStatus; | 
| Mathias Agopian | 7e27f05 | 2010-05-28 14:22:23 -0700 | [diff] [blame] | 151 | sp<ISurfaceComposerClient>  mClient; | 
| Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 152 | Composer&                   mComposer; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 153 | }; | 
|  | 154 |  | 
| Mathias Agopian | d4784a3 | 2010-05-27 19:41:15 -0700 | [diff] [blame] | 155 | // --------------------------------------------------------------------------- | 
| Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 156 |  | 
|  | 157 | class ScreenshotClient | 
|  | 158 | { | 
| Mathias Agopian | 2a9fc49 | 2013-03-01 13:42:57 -0800 | [diff] [blame] | 159 | public: | 
|  | 160 | static status_t capture( | 
|  | 161 | const sp<IBinder>& display, | 
|  | 162 | const sp<IGraphicBufferProducer>& producer, | 
|  | 163 | uint32_t reqWidth, uint32_t reqHeight, | 
|  | 164 | uint32_t minLayerZ, uint32_t maxLayerZ); | 
|  | 165 |  | 
|  | 166 | private: | 
| Mathias Agopian | abe815d | 2013-03-19 22:22:21 -0700 | [diff] [blame] | 167 | mutable sp<CpuConsumer> mCpuConsumer; | 
|  | 168 | CpuConsumer::LockedBuffer mBuffer; | 
|  | 169 | bool mHaveBuffer; | 
| Mathias Agopian | 2a9fc49 | 2013-03-01 13:42:57 -0800 | [diff] [blame] | 170 |  | 
| Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 171 | public: | 
|  | 172 | ScreenshotClient(); | 
|  | 173 |  | 
|  | 174 | // frees the previous screenshot and capture a new one | 
| Jeff Brown | 9d4e3d2 | 2012-08-24 20:00:51 -0700 | [diff] [blame] | 175 | status_t update(const sp<IBinder>& display); | 
|  | 176 | status_t update(const sp<IBinder>& display, | 
|  | 177 | uint32_t reqWidth, uint32_t reqHeight); | 
|  | 178 | status_t update(const sp<IBinder>& display, | 
|  | 179 | uint32_t reqWidth, uint32_t reqHeight, | 
| Mathias Agopian | bf2c6a6 | 2010-12-10 16:22:31 -0800 | [diff] [blame] | 180 | uint32_t minLayerZ, uint32_t maxLayerZ); | 
| Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 181 |  | 
| Mathias Agopian | abe815d | 2013-03-19 22:22:21 -0700 | [diff] [blame] | 182 | sp<CpuConsumer> getCpuConsumer() const; | 
|  | 183 |  | 
| Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 184 | // release memory occupied by the screenshot | 
|  | 185 | void release(); | 
|  | 186 |  | 
|  | 187 | // pixels are valid until this object is freed or | 
|  | 188 | // release() or update() is called | 
|  | 189 | void const* getPixels() const; | 
|  | 190 |  | 
|  | 191 | uint32_t getWidth() const; | 
|  | 192 | uint32_t getHeight() const; | 
|  | 193 | PixelFormat getFormat() const; | 
|  | 194 | uint32_t getStride() const; | 
|  | 195 | // size of allocated memory in bytes | 
|  | 196 | size_t getSize() const; | 
|  | 197 | }; | 
|  | 198 |  | 
|  | 199 | // --------------------------------------------------------------------------- | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 200 | }; // namespace android | 
|  | 201 |  | 
| Mathias Agopian | 90ac799 | 2012-02-25 18:48:35 -0800 | [diff] [blame] | 202 | #endif // ANDROID_GUI_SURFACE_COMPOSER_CLIENT_H |