| 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> | 
|  | 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> | 
| Mathias Agopian | 9cce325 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 31 |  | 
| Mathias Agopian | 90ac799 | 2012-02-25 18:48:35 -0800 | [diff] [blame] | 32 | #include <gui/Surface.h> | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 |  | 
|  | 34 | namespace android { | 
|  | 35 |  | 
|  | 36 | // --------------------------------------------------------------------------- | 
|  | 37 |  | 
| Mathias Agopian | 9cce325 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 38 | class DisplayInfo; | 
| Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 39 | class Composer; | 
| Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 40 | class IMemoryHeap; | 
| Mathias Agopian | 41f673c | 2011-11-17 17:48:35 -0800 | [diff] [blame] | 41 | class ISurfaceComposerClient; | 
| Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 42 | class Region; | 
| Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 43 |  | 
|  | 44 | // --------------------------------------------------------------------------- | 
|  | 45 |  | 
| Mathias Agopian | d4784a3 | 2010-05-27 19:41:15 -0700 | [diff] [blame] | 46 | class SurfaceComposerClient : public RefBase | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 47 | { | 
| Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 48 | friend class Composer; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 49 | public: | 
|  | 50 | SurfaceComposerClient(); | 
|  | 51 | virtual     ~SurfaceComposerClient(); | 
|  | 52 |  | 
|  | 53 | // Always make sure we could initialize | 
|  | 54 | status_t    initCheck() const; | 
|  | 55 |  | 
|  | 56 | // Return the connection of this client | 
|  | 57 | sp<IBinder> connection() const; | 
|  | 58 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 59 | // Forcibly remove connection before all references have gone away. | 
|  | 60 | void        dispose(); | 
|  | 61 |  | 
|  | 62 | // ------------------------------------------------------------------------ | 
|  | 63 | // surface creation / destruction | 
|  | 64 |  | 
|  | 65 | //! Create a surface | 
| Mathias Agopian | 01b7668 | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 66 | sp<SurfaceControl> createSurface( | 
| Mathias Agopian | 285dbde | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 67 | const String8& name,// name of the surface | 
| Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 68 | DisplayID display,  // Display to create this surface on | 
|  | 69 | uint32_t w,         // width in pixel | 
|  | 70 | uint32_t h,         // height in pixel | 
|  | 71 | PixelFormat format, // pixel-format desired | 
|  | 72 | uint32_t flags = 0  // usage flags | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 73 | ); | 
|  | 74 |  | 
| Mathias Agopian | 285dbde | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 75 | sp<SurfaceControl> createSurface( | 
| Mathias Agopian | 285dbde | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 76 | DisplayID display,  // Display to create this surface on | 
|  | 77 | uint32_t w,         // width in pixel | 
|  | 78 | uint32_t h,         // height in pixel | 
|  | 79 | PixelFormat format, // pixel-format desired | 
|  | 80 | uint32_t flags = 0  // usage flags | 
|  | 81 | ); | 
|  | 82 |  | 
|  | 83 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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. | 
| Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 89 | // closeGlobalTransaction() usually requires an IPC with the server. | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 90 |  | 
|  | 91 | //! Open a composer transaction on all active SurfaceComposerClients. | 
|  | 92 | static void openGlobalTransaction(); | 
|  | 93 |  | 
|  | 94 | //! Close a composer transaction on all active SurfaceComposerClients. | 
| Jamie Gennis | 2837839 | 2011-10-12 17:39:00 -0700 | [diff] [blame] | 95 | static void closeGlobalTransaction(bool synchronous = false); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 96 |  | 
|  | 97 | //! Set the orientation of the given display | 
| Mathias Agopian | c08731e | 2009-03-27 18:11:38 -0700 | [diff] [blame] | 98 | 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] | 99 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 100 | // Get information about a display | 
|  | 101 | static status_t getDisplayInfo(DisplayID dpy, DisplayInfo* info); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 102 |  | 
| Mathias Agopian | dd3423c | 2009-09-23 15:44:05 -0700 | [diff] [blame] | 103 | status_t linkToComposerDeath(const sp<IBinder::DeathRecipient>& recipient, | 
|  | 104 | void* cookie = NULL, uint32_t flags = 0); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 105 |  | 
| Mathias Agopian | 62185b7 | 2009-04-16 16:19:50 -0700 | [diff] [blame] | 106 | status_t    hide(SurfaceID id); | 
|  | 107 | status_t    show(SurfaceID id, int32_t layer = -1); | 
| Mathias Agopian | 62185b7 | 2009-04-16 16:19:50 -0700 | [diff] [blame] | 108 | status_t    setFlags(SurfaceID id, uint32_t flags, uint32_t mask); | 
|  | 109 | status_t    setTransparentRegionHint(SurfaceID id, const Region& transparent); | 
|  | 110 | status_t    setLayer(SurfaceID id, int32_t layer); | 
|  | 111 | status_t    setAlpha(SurfaceID id, float alpha=1.0f); | 
| Mathias Agopian | 62185b7 | 2009-04-16 16:19:50 -0700 | [diff] [blame] | 112 | status_t    setMatrix(SurfaceID id, float dsdx, float dtdx, float dsdy, float dtdy); | 
| Mathias Agopian | 41b6aab | 2011-08-30 18:51:54 -0700 | [diff] [blame] | 113 | status_t    setPosition(SurfaceID id, float x, float y); | 
| Mathias Agopian | 62185b7 | 2009-04-16 16:19:50 -0700 | [diff] [blame] | 114 | status_t    setSize(SurfaceID id, uint32_t w, uint32_t h); | 
| Jamie Gennis | f15a83f | 2012-05-10 20:43:55 -0700 | [diff] [blame] | 115 | status_t    setCrop(SurfaceID id, const Rect& crop); | 
| Mathias Agopian | 8785578 | 2012-07-24 21:41:09 -0700 | [diff] [blame] | 116 | status_t    setLayerStack(SurfaceID id, uint32_t layerStack); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 117 | status_t    destroySurface(SurfaceID sid); | 
|  | 118 |  | 
| Mathias Agopian | 631f358 | 2010-05-25 17:51:34 -0700 | [diff] [blame] | 119 | private: | 
| Mathias Agopian | d4784a3 | 2010-05-27 19:41:15 -0700 | [diff] [blame] | 120 | virtual void onFirstRef(); | 
| Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 121 | Composer& getComposer(); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 122 |  | 
| Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 123 | mutable     Mutex                       mLock; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 124 | status_t                    mStatus; | 
| Mathias Agopian | 7e27f05 | 2010-05-28 14:22:23 -0700 | [diff] [blame] | 125 | sp<ISurfaceComposerClient>  mClient; | 
| Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 126 | Composer&                   mComposer; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 127 | }; | 
|  | 128 |  | 
| Mathias Agopian | d4784a3 | 2010-05-27 19:41:15 -0700 | [diff] [blame] | 129 | // --------------------------------------------------------------------------- | 
| Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 130 |  | 
|  | 131 | class ScreenshotClient | 
|  | 132 | { | 
|  | 133 | sp<IMemoryHeap> mHeap; | 
|  | 134 | uint32_t mWidth; | 
|  | 135 | uint32_t mHeight; | 
|  | 136 | PixelFormat mFormat; | 
|  | 137 | public: | 
|  | 138 | ScreenshotClient(); | 
|  | 139 |  | 
|  | 140 | // frees the previous screenshot and capture a new one | 
|  | 141 | status_t update(); | 
|  | 142 | status_t update(uint32_t reqWidth, uint32_t reqHeight); | 
| Mathias Agopian | bf2c6a6 | 2010-12-10 16:22:31 -0800 | [diff] [blame] | 143 | status_t update(uint32_t reqWidth, uint32_t reqHeight, | 
|  | 144 | uint32_t minLayerZ, uint32_t maxLayerZ); | 
| Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 145 |  | 
|  | 146 | // release memory occupied by the screenshot | 
|  | 147 | void release(); | 
|  | 148 |  | 
|  | 149 | // pixels are valid until this object is freed or | 
|  | 150 | // release() or update() is called | 
|  | 151 | void const* getPixels() const; | 
|  | 152 |  | 
|  | 153 | uint32_t getWidth() const; | 
|  | 154 | uint32_t getHeight() const; | 
|  | 155 | PixelFormat getFormat() const; | 
|  | 156 | uint32_t getStride() const; | 
|  | 157 | // size of allocated memory in bytes | 
|  | 158 | size_t getSize() const; | 
|  | 159 | }; | 
|  | 160 |  | 
|  | 161 | // --------------------------------------------------------------------------- | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 162 | }; // namespace android | 
|  | 163 |  | 
| Mathias Agopian | 90ac799 | 2012-02-25 18:48:35 -0800 | [diff] [blame] | 164 | #endif // ANDROID_GUI_SURFACE_COMPOSER_CLIENT_H |