blob: 384815dad8d65c6302b00c565fdd3d9faff71045 [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:
47 static bool isValid(const sp<SurfaceControl>& surface) {
48 return (surface != 0) && surface->isValid();
49 }
Mathias Agopian4d9b8222013-03-12 17:11:48 -070050
Mathias Agopiane3c697f2013-02-14 17:11:02 -080051 bool isValid() {
Mathias Agopian4d9b8222013-03-12 17:11:48 -070052 return mHandle!=0 && mClient!=0;
Mathias Agopiane3c697f2013-02-14 17:11:02 -080053 }
Mathias Agopian4d9b8222013-03-12 17:11:48 -070054
Mathias Agopiane3c697f2013-02-14 17:11:02 -080055 static bool isSameSurface(
56 const sp<SurfaceControl>& lhs, const sp<SurfaceControl>& rhs);
Svetoslavd85084b2014-03-20 10:28:31 -070057
Mathias Agopiane3c697f2013-02-14 17:11:02 -080058 // release surface data from java
59 void clear();
Svetoslavd85084b2014-03-20 10:28:31 -070060
Chong Zhang1b3a9ac2016-02-29 16:47:47 -080061 // disconnect any api that's connected
62 void disconnect();
63
Mathias Agopiane3c697f2013-02-14 17:11:02 -080064 static status_t writeSurfaceToParcel(
65 const sp<SurfaceControl>& control, Parcel* parcel);
66
67 sp<Surface> getSurface() const;
Bryce Lee4e623e22017-06-16 07:06:17 -070068 sp<Surface> createSurface() const;
Dan Stoza7dde5992015-05-22 09:51:44 -070069 sp<IBinder> getHandle() const;
Mathias Agopiane3c697f2013-02-14 17:11:02 -080070
Svetoslavd85084b2014-03-20 10:28:31 -070071 status_t clearLayerFrameStats() const;
72 status_t getLayerFrameStats(FrameStats* outStats) const;
73
Robert Carr4cdc58f2017-08-23 14:22:20 -070074 sp<SurfaceComposerClient> getClient() const;
75
Mathias Agopiane3c697f2013-02-14 17:11:02 -080076private:
77 // can't be copied
78 SurfaceControl& operator = (SurfaceControl& rhs);
79 SurfaceControl(const SurfaceControl& rhs);
80
81 friend class SurfaceComposerClient;
82 friend class Surface;
83
84 SurfaceControl(
85 const sp<SurfaceComposerClient>& client,
Mathias Agopian4d9b8222013-03-12 17:11:48 -070086 const sp<IBinder>& handle,
87 const sp<IGraphicBufferProducer>& gbp);
Mathias Agopiane3c697f2013-02-14 17:11:02 -080088
89 ~SurfaceControl();
90
Bryce Lee4e623e22017-06-16 07:06:17 -070091 sp<Surface> generateSurfaceLocked() const;
Mathias Agopiane3c697f2013-02-14 17:11:02 -080092 status_t validate() const;
93 void destroy();
Svetoslavd85084b2014-03-20 10:28:31 -070094
Mathias Agopiane3c697f2013-02-14 17:11:02 -080095 sp<SurfaceComposerClient> mClient;
Mathias Agopian4d9b8222013-03-12 17:11:48 -070096 sp<IBinder> mHandle;
Mathias Agopiane3c697f2013-02-14 17:11:02 -080097 sp<IGraphicBufferProducer> mGraphicBufferProducer;
98 mutable Mutex mLock;
99 mutable sp<Surface> mSurfaceData;
100};
101
102}; // namespace android
103
104#endif // ANDROID_GUI_SURFACE_CONTROL_H