blob: e4a135064350a315f8690c02dbca417df6acf3b8 [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>
John Reck57f748c2022-03-17 17:23:49 -040022#include <optional>
Mathias Agopiane3c697f2013-02-14 17:11:02 -080023
Mathias Agopiane3c697f2013-02-14 17:11:02 -080024#include <utils/RefBase.h>
25#include <utils/threads.h>
26
Huihong Luod3d8f8e2022-03-08 14:48:46 -080027#include <android/gui/ISurfaceComposerClient.h>
28
Svetoslavd85084b2014-03-20 10:28:31 -070029#include <ui/FrameStats.h>
Mathias Agopiane3c697f2013-02-14 17:11:02 -080030#include <ui/PixelFormat.h>
31#include <ui/Region.h>
32
chaviw13fdc492017-06-27 12:40:18 -070033#include <math/vec3.h>
Mathias Agopiane3c697f2013-02-14 17:11:02 -080034
35namespace android {
36
37// ---------------------------------------------------------------------------
38
39class IGraphicBufferProducer;
40class Surface;
41class SurfaceComposerClient;
Robert Carr5b3b9142021-02-22 12:27:32 -080042class BLASTBufferQueue;
Mathias Agopiane3c697f2013-02-14 17:11:02 -080043
44// ---------------------------------------------------------------------------
45
46class SurfaceControl : public RefBase
47{
48public:
Pablo Gamito421dfd52020-09-22 18:11:45 +000049 static status_t readFromParcel(const Parcel& parcel, sp<SurfaceControl>* outSurfaceControl);
50 status_t writeToParcel(Parcel& parcel);
Jorim Jaggif3cf4bc2017-11-30 14:19:23 +010051
Pablo Gamito91512a02020-09-22 18:14:43 +000052 static status_t readNullableFromParcel(const Parcel& parcel,
53 sp<SurfaceControl>* outSurfaceControl);
54 static status_t writeNullableToParcel(Parcel& parcel, const sp<SurfaceControl>& surfaceControl);
55
Mathias Agopiane3c697f2013-02-14 17:11:02 -080056 static bool isValid(const sp<SurfaceControl>& surface) {
Yi Konga03e0442018-07-17 11:16:57 -070057 return (surface != nullptr) && surface->isValid();
Mathias Agopiane3c697f2013-02-14 17:11:02 -080058 }
Mathias Agopian4d9b8222013-03-12 17:11:48 -070059
Mathias Agopiane3c697f2013-02-14 17:11:02 -080060 bool isValid() {
Yi Konga03e0442018-07-17 11:16:57 -070061 return mHandle!=nullptr && mClient!=nullptr;
Mathias Agopiane3c697f2013-02-14 17:11:02 -080062 }
Mathias Agopian4d9b8222013-03-12 17:11:48 -070063
Mathias Agopiane3c697f2013-02-14 17:11:02 -080064 static bool isSameSurface(
65 const sp<SurfaceControl>& lhs, const sp<SurfaceControl>& rhs);
Svetoslavd85084b2014-03-20 10:28:31 -070066
Robert Carr87246532019-02-04 15:20:26 -080067 // Reparent off-screen and release. This is invoked by the destructor.
68 void destroy();
Svetoslavd85084b2014-03-20 10:28:31 -070069
Chong Zhang1b3a9ac2016-02-29 16:47:47 -080070 // disconnect any api that's connected
71 void disconnect();
72
Mathias Agopiane3c697f2013-02-14 17:11:02 -080073 static status_t writeSurfaceToParcel(
74 const sp<SurfaceControl>& control, Parcel* parcel);
75
Robert Carr5b3b9142021-02-22 12:27:32 -080076 sp<Surface> getSurface();
77 sp<Surface> createSurface();
Dan Stoza7dde5992015-05-22 09:51:44 -070078 sp<IBinder> getHandle() const;
Robert Carr5b3b9142021-02-22 12:27:32 -080079 sp<IBinder> getLayerStateHandle() const;
Pablo Gamitodbc31672020-09-01 18:28:58 +000080 int32_t getLayerId() const;
Mathias Agopiane3c697f2013-02-14 17:11:02 -080081
Robert Carr5b3b9142021-02-22 12:27:32 -080082 sp<IGraphicBufferProducer> getIGraphicBufferProducer();
Robert Carra35ef9f2019-01-25 14:29:21 -080083
Svetoslavd85084b2014-03-20 10:28:31 -070084 status_t clearLayerFrameStats() const;
85 status_t getLayerFrameStats(FrameStats* outStats) const;
86
Robert Carr4cdc58f2017-08-23 14:22:20 -070087 sp<SurfaceComposerClient> getClient() const;
Vishnu Nair621102e2019-06-12 14:16:57 -070088
Valerie Hau1acd6962019-10-28 16:35:48 -070089 uint32_t getTransformHint() const;
90
91 void setTransformHint(uint32_t hint);
Robert Carr5b3b9142021-02-22 12:27:32 -080092 void updateDefaultBufferSize(uint32_t width, uint32_t height);
Valerie Hau1acd6962019-10-28 16:35:48 -070093
Robert Carrb89ea9d2018-12-10 13:01:14 -080094 explicit SurfaceControl(const sp<SurfaceControl>& other);
Robert Carr4cdc58f2017-08-23 14:22:20 -070095
Robert Carrc0df3122019-04-11 13:18:21 -070096 SurfaceControl(const sp<SurfaceComposerClient>& client, const sp<IBinder>& handle,
Huihong Luod3d8f8e2022-03-08 14:48:46 -080097 int32_t layerId, uint32_t width = 0, uint32_t height = 0, PixelFormat format = 0,
Robert Carr5b3b9142021-02-22 12:27:32 -080098 uint32_t transformHint = 0, uint32_t flags = 0);
99
100 sp<SurfaceControl> getParentingLayer();
Robert Carrc0df3122019-04-11 13:18:21 -0700101
John Reck57f748c2022-03-17 17:23:49 -0400102 uint64_t resolveFrameNumber(const std::optional<uint64_t>& frameNumber);
103
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800104private:
105 // can't be copied
106 SurfaceControl& operator = (SurfaceControl& rhs);
107 SurfaceControl(const SurfaceControl& rhs);
108
109 friend class SurfaceComposerClient;
110 friend class Surface;
111
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800112 ~SurfaceControl();
113
Robert Carr5b3b9142021-02-22 12:27:32 -0800114 sp<Surface> generateSurfaceLocked();
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800115 status_t validate() const;
Svetoslavd85084b2014-03-20 10:28:31 -0700116
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800117 sp<SurfaceComposerClient> mClient;
Huihong Luod3d8f8e2022-03-08 14:48:46 -0800118 sp<IBinder> mHandle;
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800119 mutable Mutex mLock;
120 mutable sp<Surface> mSurfaceData;
Robert Carr5b3b9142021-02-22 12:27:32 -0800121 mutable sp<BLASTBufferQueue> mBbq;
122 mutable sp<SurfaceControl> mBbqChild;
Robert Carrc2cf02c2022-03-22 15:25:54 -0700123 int32_t mLayerId = 0;
124 uint32_t mTransformHint = 0;
125 uint32_t mWidth = 0;
126 uint32_t mHeight = 0;
127 PixelFormat mFormat = PIXEL_FORMAT_NONE;
128 uint32_t mCreateFlags = 0;
John Reck57f748c2022-03-17 17:23:49 -0400129 uint64_t mFallbackFrameNumber = 100;
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800130};
131
132}; // namespace android
133
134#endif // ANDROID_GUI_SURFACE_CONTROL_H