• 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 
33 namespace android {
34 
35 // ---------------------------------------------------------------------------
36 
37 class IGraphicBufferProducer;
38 class Surface;
39 class SurfaceComposerClient;
40 
41 // ---------------------------------------------------------------------------
42 
43 class SurfaceControl : public RefBase
44 {
45 public:
isValid(const sp<SurfaceControl> & surface)46     static bool isValid(const sp<SurfaceControl>& surface) {
47         return (surface != 0) && surface->isValid();
48     }
49 
isValid()50     bool isValid() {
51         return mHandle!=0 && mClient!=0;
52     }
53 
54     static bool isSameSurface(
55             const sp<SurfaceControl>& lhs, const sp<SurfaceControl>& rhs);
56 
57     // release surface data from java
58     void        clear();
59 
60     // disconnect any api that's connected
61     void        disconnect();
62 
63     status_t    setLayerStack(uint32_t layerStack);
64     status_t    setLayer(uint32_t layer);
65     status_t    setPosition(float x, float y);
66     status_t    setSize(uint32_t w, uint32_t h);
67     status_t    hide();
68     status_t    show();
69     status_t    setFlags(uint32_t flags, uint32_t mask);
70     status_t    setTransparentRegionHint(const Region& transparent);
71     status_t    setAlpha(float alpha=1.0f);
72     status_t    setMatrix(float dsdx, float dtdx, float dsdy, float dtdy);
73     status_t    setCrop(const Rect& crop);
74     status_t    setFinalCrop(const Rect& crop);
75 
76     // If the size changes in this transaction, all geometry updates specified
77     // in this transaction will not complete until a buffer of the new size
78     // arrives. As some elements normally apply immediately, this enables
79     // freezing the total geometry of a surface until a resize is completed.
80     status_t    setGeometryAppliesWithResize();
81 
82     // Defers applying any changes made in this transaction until the Layer
83     // identified by handle reaches the given frameNumber
84     status_t deferTransactionUntil(sp<IBinder> handle, uint64_t frameNumber);
85 
86     // Set an override scaling mode as documented in <system/window.h>
87     // the override scaling mode will take precedence over any client
88     // specified scaling mode. -1 will clear the override scaling mode.
89     status_t setOverrideScalingMode(int32_t overrideScalingMode);
90 
91     static status_t writeSurfaceToParcel(
92             const sp<SurfaceControl>& control, Parcel* parcel);
93 
94     sp<Surface> getSurface() const;
95     sp<IBinder> getHandle() const;
96 
97     status_t clearLayerFrameStats() const;
98     status_t getLayerFrameStats(FrameStats* outStats) const;
99 
100     status_t getTransformToDisplayInverse(bool* outTransformToDisplayInverse) const;
101 
102 private:
103     // can't be copied
104     SurfaceControl& operator = (SurfaceControl& rhs);
105     SurfaceControl(const SurfaceControl& rhs);
106 
107     friend class SurfaceComposerClient;
108     friend class Surface;
109 
110     SurfaceControl(
111             const sp<SurfaceComposerClient>& client,
112             const sp<IBinder>& handle,
113             const sp<IGraphicBufferProducer>& gbp);
114 
115     ~SurfaceControl();
116 
117     status_t validate() const;
118     void destroy();
119 
120     sp<SurfaceComposerClient>   mClient;
121     sp<IBinder>                 mHandle;
122     sp<IGraphicBufferProducer>  mGraphicBufferProducer;
123     mutable Mutex               mLock;
124     mutable sp<Surface>         mSurfaceData;
125 };
126 
127 }; // namespace android
128 
129 #endif // ANDROID_GUI_SURFACE_CONTROL_H
130