blob: ae4a14690fa3332f768bf71baa1de74ac41dd0cd [file] [log] [blame]
Mathias Agopiane3c697f2013-02-14 17:11:02 -08001/*
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
Svetoslavd85084b2014-03-20 10:28:31 -070027#include <ui/FrameStats.h>
Mathias Agopiane3c697f2013-02-14 17:11:02 -080028#include <ui/PixelFormat.h>
29#include <ui/Region.h>
30
Mathias Agopiane3c697f2013-02-14 17:11:02 -080031#include <gui/ISurfaceComposerClient.h>
chaviw13fdc492017-06-27 12:40:18 -070032#include <math/vec3.h>
Mathias Agopiane3c697f2013-02-14 17:11:02 -080033
34namespace android {
35
36// ---------------------------------------------------------------------------
37
38class IGraphicBufferProducer;
39class Surface;
40class SurfaceComposerClient;
41
42// ---------------------------------------------------------------------------
43
44class SurfaceControl : public RefBase
45{
46public:
Vishnu Nair621102e2019-06-12 14:16:57 -070047 static sp<SurfaceControl> readFromParcel(const Parcel* parcel);
Jorim Jaggif3cf4bc2017-11-30 14:19:23 +010048 void writeToParcel(Parcel* parcel);
49
Mathias Agopiane3c697f2013-02-14 17:11:02 -080050 static bool isValid(const sp<SurfaceControl>& surface) {
Yi Konga03e0442018-07-17 11:16:57 -070051 return (surface != nullptr) && surface->isValid();
Mathias Agopiane3c697f2013-02-14 17:11:02 -080052 }
Mathias Agopian4d9b8222013-03-12 17:11:48 -070053
Mathias Agopiane3c697f2013-02-14 17:11:02 -080054 bool isValid() {
Yi Konga03e0442018-07-17 11:16:57 -070055 return mHandle!=nullptr && mClient!=nullptr;
Mathias Agopiane3c697f2013-02-14 17:11:02 -080056 }
Mathias Agopian4d9b8222013-03-12 17:11:48 -070057
Mathias Agopiane3c697f2013-02-14 17:11:02 -080058 static bool isSameSurface(
59 const sp<SurfaceControl>& lhs, const sp<SurfaceControl>& rhs);
Svetoslavd85084b2014-03-20 10:28:31 -070060
Robert Carr87246532019-02-04 15:20:26 -080061 // Release the handles assosciated with the SurfaceControl, without reparenting
62 // them off-screen. At the moment if this isn't executed before ~SurfaceControl
63 // is called then the destructor will reparent the layer off-screen for you.
64 void release();
65 // Reparent off-screen and release. This is invoked by the destructor.
66 void destroy();
Svetoslavd85084b2014-03-20 10:28:31 -070067
Chong Zhang1b3a9ac2016-02-29 16:47:47 -080068 // disconnect any api that's connected
69 void disconnect();
70
Mathias Agopiane3c697f2013-02-14 17:11:02 -080071 static status_t writeSurfaceToParcel(
72 const sp<SurfaceControl>& control, Parcel* parcel);
73
74 sp<Surface> getSurface() const;
Bryce Lee4e623e22017-06-16 07:06:17 -070075 sp<Surface> createSurface() const;
Dan Stoza7dde5992015-05-22 09:51:44 -070076 sp<IBinder> getHandle() const;
Mathias Agopiane3c697f2013-02-14 17:11:02 -080077
Robert Carra35ef9f2019-01-25 14:29:21 -080078 sp<IGraphicBufferProducer> getIGraphicBufferProducer() const;
79
Svetoslavd85084b2014-03-20 10:28:31 -070080 status_t clearLayerFrameStats() const;
81 status_t getLayerFrameStats(FrameStats* outStats) const;
82
Robert Carr4cdc58f2017-08-23 14:22:20 -070083 sp<SurfaceComposerClient> getClient() const;
Vishnu Nair621102e2019-06-12 14:16:57 -070084
Robert Carrb89ea9d2018-12-10 13:01:14 -080085 explicit SurfaceControl(const sp<SurfaceControl>& other);
Robert Carr4cdc58f2017-08-23 14:22:20 -070086
Robert Carrc0df3122019-04-11 13:18:21 -070087 SurfaceControl(const sp<SurfaceComposerClient>& client, const sp<IBinder>& handle,
88 const sp<IGraphicBufferProducer>& gbp, bool owned);
89
Mathias Agopiane3c697f2013-02-14 17:11:02 -080090private:
91 // can't be copied
92 SurfaceControl& operator = (SurfaceControl& rhs);
93 SurfaceControl(const SurfaceControl& rhs);
94
95 friend class SurfaceComposerClient;
96 friend class Surface;
97
Mathias Agopiane3c697f2013-02-14 17:11:02 -080098 ~SurfaceControl();
99
Bryce Lee4e623e22017-06-16 07:06:17 -0700100 sp<Surface> generateSurfaceLocked() const;
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800101 status_t validate() const;
Svetoslavd85084b2014-03-20 10:28:31 -0700102
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800103 sp<SurfaceComposerClient> mClient;
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700104 sp<IBinder> mHandle;
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800105 sp<IGraphicBufferProducer> mGraphicBufferProducer;
106 mutable Mutex mLock;
107 mutable sp<Surface> mSurfaceData;
Jorim Jaggi0b267102018-01-29 16:39:21 +0100108 bool mOwned;
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800109};
110
111}; // namespace android
112
113#endif // ANDROID_GUI_SURFACE_CONTROL_H