blob: d92da4919e63bfb90988ed900aebf343b0ec6229 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -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_UI_SURFACE_H
18#define ANDROID_UI_SURFACE_H
19
20#include <stdint.h>
21#include <sys/types.h>
22
23#include <utils/RefBase.h>
24#include <utils/threads.h>
25
26#include <ui/ISurface.h>
27#include <ui/PixelFormat.h>
28#include <ui/Region.h>
29#include <ui/ISurfaceFlingerClient.h>
30
Mathias Agopian1473f462009-04-10 14:24:30 -070031#include <EGL/android_natives.h>
32
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033namespace android {
34
35// ---------------------------------------------------------------------------
36
37class Rect;
38class SurfaceComposerClient;
Mathias Agopian1473f462009-04-10 14:24:30 -070039struct per_client_cblk_t;
40struct layer_cblk_t;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080041
Mathias Agopian1473f462009-04-10 14:24:30 -070042// ---------------------------------------------------------------------------
43
44class SurfaceBuffer
45 : public EGLNativeBase<
46 android_native_buffer_t,
47 SurfaceBuffer,
48 LightRefBase<SurfaceBuffer> >
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080049{
Mathias Agopian1473f462009-04-10 14:24:30 -070050public:
51 buffer_handle_t getHandle() const {
52 return handle;
53 }
54
55protected:
56 SurfaceBuffer();
57 SurfaceBuffer(const Parcel& reply);
58 virtual ~SurfaceBuffer();
59 buffer_handle_t handle;
60 bool mOwner;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061
Mathias Agopian1473f462009-04-10 14:24:30 -070062private:
63 friend class BpSurface;
64 friend class BnSurface;
65 friend class LightRefBase<SurfaceBuffer>;
66
67 SurfaceBuffer& operator = (const SurfaceBuffer& rhs);
68 const SurfaceBuffer& operator = (const SurfaceBuffer& rhs) const;
69
70 static status_t writeToParcel(Parcel* reply,
71 android_native_buffer_t const* buffer);
72
73 static int getHandle(android_native_buffer_t const * base,
74 buffer_handle_t* handle);
75};
76
77// ---------------------------------------------------------------------------
78
79class Surface
80 : public EGLNativeBase<android_native_window_t, Surface, RefBase>
81{
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080082public:
83 struct SurfaceInfo {
84 uint32_t w;
85 uint32_t h;
Mathias Agopian1473f462009-04-10 14:24:30 -070086 uint32_t s;
87 uint32_t usage;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080088 PixelFormat format;
89 void* bits;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080090 uint32_t reserved[2];
91 };
92
93 bool isValid() const { return this && mToken>=0 && mClient!=0; }
94 SurfaceID ID() const { return mToken; }
95
96 status_t lock(SurfaceInfo* info, bool blocking = true);
97 status_t lock(SurfaceInfo* info, Region* dirty, bool blocking = true);
98 status_t unlockAndPost();
Mathias Agopian1473f462009-04-10 14:24:30 -070099
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800100 uint32_t getFlags() const { return mFlags; }
101
102 // setSwapRectangle() is mainly used by EGL
103 void setSwapRectangle(const Rect& r);
104 const Rect& swapRectangle() const;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800105
106 sp<Surface> dup() const;
107 static sp<Surface> readFromParcel(Parcel* parcel);
108 static status_t writeToParcel(const sp<Surface>& surface, Parcel* parcel);
109 static bool isSameSurface(const sp<Surface>& lhs, const sp<Surface>& rhs);
110
111 status_t setLayer(int32_t layer);
112 status_t setPosition(int32_t x, int32_t y);
113 status_t setSize(uint32_t w, uint32_t h);
114 status_t hide();
115 status_t show(int32_t layer = -1);
116 status_t freeze();
117 status_t unfreeze();
118 status_t setFlags(uint32_t flags, uint32_t mask);
119 status_t setTransparentRegionHint(const Region& transparent);
120 status_t setAlpha(float alpha=1.0f);
121 status_t setMatrix(float dsdx, float dtdx, float dsdy, float dtdy);
122 status_t setFreezeTint(uint32_t tint);
123
124 uint32_t getIdentity() const { return mIdentity; }
125private:
126 friend class SurfaceComposerClient;
127
128 // camera and camcorder need access to the ISurface binder interface for preview
129 friend class Camera;
130 friend class MediaRecorder;
131 // mediaplayer needs access to ISurface for display
132 friend class MediaPlayer;
133 friend class Test;
134 const sp<ISurface>& getISurface() const { return mSurface; }
135
Mathias Agopian1473f462009-04-10 14:24:30 -0700136 status_t getBufferLocked(int index);
137
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800138 // can't be copied
139 Surface& operator = (Surface& rhs);
140 Surface(const Surface& rhs);
141
142 Surface(const sp<SurfaceComposerClient>& client,
143 const sp<ISurface>& surface,
144 const ISurfaceFlingerClient::surface_data_t& data,
145 uint32_t w, uint32_t h, PixelFormat format, uint32_t flags,
146 bool owner = true);
147
148 Surface(Surface const* rhs);
149
150 ~Surface();
Mathias Agopian1473f462009-04-10 14:24:30 -0700151
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800152 Region dirtyRegion() const;
153 void setDirtyRegion(const Region& region) const;
154
Mathias Agopian1473f462009-04-10 14:24:30 -0700155
156 status_t validate(per_client_cblk_t const* cblk) const;
157 static void _send_dirty_region(layer_cblk_t* lcblk, const Region& dirty);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800158
Mathias Agopian1473f462009-04-10 14:24:30 -0700159
160 static void connect(android_native_window_t* window);
161 static void disconnect(android_native_window_t* window);
162 static int setSwapInterval(android_native_window_t* window, int interval);
163 static int setSwapRectangle(android_native_window_t* window,
164 int l, int t, int w, int h);
165 static int dequeueBuffer(android_native_window_t* window, android_native_buffer_t** buffer);
166 static int lockBuffer(android_native_window_t* window, android_native_buffer_t* buffer);
167 static int queueBuffer(android_native_window_t* window, android_native_buffer_t* buffer);
168
169 int dequeueBuffer(android_native_buffer_t** buffer);
170 int lockBuffer(android_native_buffer_t* buffer);
171 int queueBuffer(android_native_buffer_t* buffer);
172
173
174 alloc_device_t* mAllocDevice;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800175 sp<SurfaceComposerClient> mClient;
176 sp<ISurface> mSurface;
Mathias Agopian1473f462009-04-10 14:24:30 -0700177 sp<SurfaceBuffer> mBuffers[2];
178 android_native_buffer_t* mLockedBuffer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800179 SurfaceID mToken;
180 uint32_t mIdentity;
181 PixelFormat mFormat;
182 uint32_t mFlags;
183 const bool mOwner;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800184 mutable Region mDirtyRegion;
185 mutable Rect mSwapRectangle;
186 mutable uint8_t mBackbufferIndex;
187 mutable Mutex mSurfaceLock;
188};
189
190}; // namespace android
191
192#endif // ANDROID_UI_SURFACE_H
193