| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -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 | |
| 17 | #ifndef ANDROID_GUI_SURFACE_CONTROL_H |
| 18 | #define ANDROID_GUI_SURFACE_CONTROL_H |
| 19 | |
| 20 | #include <stdint.h> |
| 21 | #include <sys/types.h> |
| 22 | |
| 23 | #include <utils/KeyedVector.h> |
| 24 | #include <utils/RefBase.h> |
| 25 | #include <utils/threads.h> |
| 26 | |
| Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 27 | #include <ui/FrameStats.h> |
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 28 | #include <ui/PixelFormat.h> |
| 29 | #include <ui/Region.h> |
| 30 | |
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 31 | #include <gui/ISurfaceComposerClient.h> |
| chaviw | 13fdc49 | 2017-06-27 12:40:18 -0700 | [diff] [blame] | 32 | #include <math/vec3.h> |
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 33 | |
| 34 | namespace android { |
| 35 | |
| 36 | // --------------------------------------------------------------------------- |
| 37 | |
| 38 | class IGraphicBufferProducer; |
| 39 | class Surface; |
| 40 | class SurfaceComposerClient; |
| 41 | |
| 42 | // --------------------------------------------------------------------------- |
| 43 | |
| 44 | class SurfaceControl : public RefBase |
| 45 | { |
| 46 | public: |
| Jorim Jaggi | f3cf4bc | 2017-11-30 14:19:23 +0100 | [diff] [blame] | 47 | static sp<SurfaceControl> readFromParcel(Parcel* parcel); |
| 48 | void writeToParcel(Parcel* parcel); |
| 49 | |
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 50 | static bool isValid(const sp<SurfaceControl>& surface) { |
| Yi Kong | a03e044 | 2018-07-17 11:16:57 -0700 | [diff] [blame] | 51 | return (surface != nullptr) && surface->isValid(); |
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 52 | } |
| Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 53 | |
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 54 | bool isValid() { |
| Yi Kong | a03e044 | 2018-07-17 11:16:57 -0700 | [diff] [blame] | 55 | return mHandle!=nullptr && mClient!=nullptr; |
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 56 | } |
| Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 57 | |
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 58 | static bool isSameSurface( |
| 59 | const sp<SurfaceControl>& lhs, const sp<SurfaceControl>& rhs); |
| Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 60 | |
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 61 | // release surface data from java |
| 62 | void clear(); |
| Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 63 | |
| Chong Zhang | 1b3a9ac | 2016-02-29 16:47:47 -0800 | [diff] [blame] | 64 | // disconnect any api that's connected |
| 65 | void disconnect(); |
| 66 | |
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 67 | static status_t writeSurfaceToParcel( |
| 68 | const sp<SurfaceControl>& control, Parcel* parcel); |
| 69 | |
| 70 | sp<Surface> getSurface() const; |
| Bryce Lee | 4e623e2 | 2017-06-16 07:06:17 -0700 | [diff] [blame] | 71 | sp<Surface> createSurface() const; |
| Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 72 | sp<IBinder> getHandle() const; |
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 73 | |
| Robert Carr | a35ef9f | 2019-01-25 14:29:21 -0800 | [diff] [blame^] | 74 | sp<IGraphicBufferProducer> getIGraphicBufferProducer() const; |
| 75 | |
| Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 76 | status_t clearLayerFrameStats() const; |
| 77 | status_t getLayerFrameStats(FrameStats* outStats) const; |
| 78 | |
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 79 | sp<SurfaceComposerClient> getClient() const; |
| Robert Carr | b89ea9d | 2018-12-10 13:01:14 -0800 | [diff] [blame] | 80 | |
| 81 | explicit SurfaceControl(const sp<SurfaceControl>& other); |
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 82 | |
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 83 | private: |
| 84 | // can't be copied |
| 85 | SurfaceControl& operator = (SurfaceControl& rhs); |
| 86 | SurfaceControl(const SurfaceControl& rhs); |
| 87 | |
| 88 | friend class SurfaceComposerClient; |
| 89 | friend class Surface; |
| 90 | |
| 91 | SurfaceControl( |
| 92 | const sp<SurfaceComposerClient>& client, |
| Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 93 | const sp<IBinder>& handle, |
| Jorim Jaggi | 0b26710 | 2018-01-29 16:39:21 +0100 | [diff] [blame] | 94 | const sp<IGraphicBufferProducer>& gbp, |
| 95 | bool owned); |
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 96 | |
| 97 | ~SurfaceControl(); |
| 98 | |
| Bryce Lee | 4e623e2 | 2017-06-16 07:06:17 -0700 | [diff] [blame] | 99 | sp<Surface> generateSurfaceLocked() const; |
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 100 | status_t validate() const; |
| 101 | void destroy(); |
| Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 102 | |
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 103 | sp<SurfaceComposerClient> mClient; |
| Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 104 | sp<IBinder> mHandle; |
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 105 | sp<IGraphicBufferProducer> mGraphicBufferProducer; |
| 106 | mutable Mutex mLock; |
| 107 | mutable sp<Surface> mSurfaceData; |
| Jorim Jaggi | 0b26710 | 2018-01-29 16:39:21 +0100 | [diff] [blame] | 108 | bool mOwned; |
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 109 | }; |
| 110 | |
| 111 | }; // namespace android |
| 112 | |
| 113 | #endif // ANDROID_GUI_SURFACE_CONTROL_H |