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 
27 #include <ui/FrameStats.h>
28 #include <ui/PixelFormat.h>
29 #include <ui/Region.h>
30 
31 #include <gui/ISurfaceComposerClient.h>
32 #include <math/vec3.h>
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:
47     static sp<SurfaceControl> readFromParcel(const Parcel* parcel);
48     void writeToParcel(Parcel* parcel);
49 
isValid(const sp<SurfaceControl> & surface)50     static bool isValid(const sp<SurfaceControl>& surface) {
51         return (surface != nullptr) && surface->isValid();
52     }
53 
isValid()54     bool isValid() {
55         return mHandle!=nullptr && mClient!=nullptr;
56     }
57 
58     static bool isSameSurface(
59             const sp<SurfaceControl>& lhs, const sp<SurfaceControl>& rhs);
60 
61     // Reparent off-screen and release. This is invoked by the destructor.
62     void destroy();
63 
64     // disconnect any api that's connected
65     void        disconnect();
66 
67     static status_t writeSurfaceToParcel(
68             const sp<SurfaceControl>& control, Parcel* parcel);
69 
70     sp<Surface> getSurface() const;
71     sp<Surface> createSurface() const;
72     sp<IBinder> getHandle() const;
73 
74     sp<IGraphicBufferProducer> getIGraphicBufferProducer() const;
75 
76     status_t clearLayerFrameStats() const;
77     status_t getLayerFrameStats(FrameStats* outStats) const;
78 
79     sp<SurfaceComposerClient> getClient() const;
80 
81     uint32_t getTransformHint() const;
82 
83     void setTransformHint(uint32_t hint);
84 
85     explicit SurfaceControl(const sp<SurfaceControl>& other);
86 
87     SurfaceControl(const sp<SurfaceComposerClient>& client, const sp<IBinder>& handle,
88                    const sp<IGraphicBufferProducer>& gbp, uint32_t transformHint = 0);
89 
90 private:
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 
98     ~SurfaceControl();
99 
100     sp<Surface> generateSurfaceLocked() const;
101     status_t validate() const;
102 
103     sp<SurfaceComposerClient>   mClient;
104     sp<IBinder>                 mHandle;
105     sp<IGraphicBufferProducer>  mGraphicBufferProducer;
106     mutable Mutex               mLock;
107     mutable sp<Surface>         mSurfaceData;
108     uint32_t mTransformHint;
109 };
110 
111 }; // namespace android
112 
113 #endif // ANDROID_GUI_SURFACE_CONTROL_H
114