blob: b584f36e7a745f14a3b379acf22a412e0e35e8a2 [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:
Jorim Jaggif3cf4bc2017-11-30 14:19:23 +010047 static sp<SurfaceControl> readFromParcel(Parcel* parcel);
48 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
Mathias Agopiane3c697f2013-02-14 17:11:02 -080061 // release surface data from java
62 void clear();
Svetoslavd85084b2014-03-20 10:28:31 -070063
Chong Zhang1b3a9ac2016-02-29 16:47:47 -080064 // disconnect any api that's connected
65 void disconnect();
66
Mathias Agopiane3c697f2013-02-14 17:11:02 -080067 static status_t writeSurfaceToParcel(
68 const sp<SurfaceControl>& control, Parcel* parcel);
69
70 sp<Surface> getSurface() const;
Bryce Lee4e623e22017-06-16 07:06:17 -070071 sp<Surface> createSurface() const;
Dan Stoza7dde5992015-05-22 09:51:44 -070072 sp<IBinder> getHandle() const;
Mathias Agopiane3c697f2013-02-14 17:11:02 -080073
Robert Carra35ef9f2019-01-25 14:29:21 -080074 sp<IGraphicBufferProducer> getIGraphicBufferProducer() const;
75
Svetoslavd85084b2014-03-20 10:28:31 -070076 status_t clearLayerFrameStats() const;
77 status_t getLayerFrameStats(FrameStats* outStats) const;
78
Robert Carr4cdc58f2017-08-23 14:22:20 -070079 sp<SurfaceComposerClient> getClient() const;
Robert Carrb89ea9d2018-12-10 13:01:14 -080080
81 explicit SurfaceControl(const sp<SurfaceControl>& other);
Robert Carr4cdc58f2017-08-23 14:22:20 -070082
Mathias Agopiane3c697f2013-02-14 17:11:02 -080083private:
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 Agopian4d9b8222013-03-12 17:11:48 -070093 const sp<IBinder>& handle,
Jorim Jaggi0b267102018-01-29 16:39:21 +010094 const sp<IGraphicBufferProducer>& gbp,
95 bool owned);
Mathias Agopiane3c697f2013-02-14 17:11:02 -080096
97 ~SurfaceControl();
98
Bryce Lee4e623e22017-06-16 07:06:17 -070099 sp<Surface> generateSurfaceLocked() const;
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800100 status_t validate() const;
101 void destroy();
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