• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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(Parcel* parcel);
48     void writeToParcel(Parcel* parcel);
49 
isValid(const sp<SurfaceControl> & surface)50     static bool isValid(const sp<SurfaceControl>& surface) {
51         return (surface != 0) && surface->isValid();
52     }
53 
isValid()54     bool isValid() {
55         return mHandle!=0 && mClient!=0;
56     }
57 
58     static bool isSameSurface(
59             const sp<SurfaceControl>& lhs, const sp<SurfaceControl>& rhs);
60 
61     // release surface data from java
62     void        clear();
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     status_t clearLayerFrameStats() const;
75     status_t getLayerFrameStats(FrameStats* outStats) const;
76 
77     sp<SurfaceComposerClient> getClient() const;
78 
79     SurfaceControl(const sp<SurfaceComposerClient>& client,
80                    const sp<IBinder>& handle,
81                    const sp<IGraphicBufferProducer>& gbp,
82                    bool owned);
83 private:
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 
93     sp<Surface> generateSurfaceLocked() const;
94     status_t validate() const;
95     void destroy();
96 
97     sp<SurfaceComposerClient>   mClient;
98     sp<IBinder>                 mHandle;
99     sp<IGraphicBufferProducer>  mGraphicBufferProducer;
100     mutable Mutex               mLock;
101     mutable sp<Surface>         mSurfaceData;
102     bool                        mOwned;
103 };
104 
105 }; // namespace android
106 
107 #endif // ANDROID_GUI_SURFACE_CONTROL_H
108