blob: 1637961b6af8b076799d41a5f1761ad4e6e2d404 [file] [log] [blame]
The Android Open Source Projectedbf3b62009-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 Agopian076b1cc2009-04-10 14:24:30 -070031#include <EGL/android_natives.h>
32
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080033namespace android {
34
35// ---------------------------------------------------------------------------
36
37class Rect;
38class SurfaceComposerClient;
Mathias Agopian076b1cc2009-04-10 14:24:30 -070039struct per_client_cblk_t;
40struct layer_cblk_t;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080041
Mathias Agopian076b1cc2009-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 Projectedbf3b62009-03-03 19:31:44 -080049{
Mathias Agopian076b1cc2009-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 Projectedbf3b62009-03-03 19:31:44 -080061
Mathias Agopian076b1cc2009-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 Projectedbf3b62009-03-03 19:31:44 -080082public:
83 struct SurfaceInfo {
84 uint32_t w;
85 uint32_t h;
Mathias Agopian076b1cc2009-04-10 14:24:30 -070086 uint32_t s;
87 uint32_t usage;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080088 PixelFormat format;
89 void* bits;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080090 uint32_t reserved[2];
91 };
92
Mathias Agopian40b7f6e2009-04-14 18:21:47 -070093 static bool isValid(const sp<Surface>& surface) {
94 return (surface != 0) && surface->mToken>=0 && surface->mClient!=0;
95 }
96
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080097 SurfaceID ID() const { return mToken; }
98
Mathias Agopian40b7f6e2009-04-14 18:21:47 -070099 // release surface data from java
100 void clear();
101
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800102 status_t lock(SurfaceInfo* info, bool blocking = true);
103 status_t lock(SurfaceInfo* info, Region* dirty, bool blocking = true);
104 status_t unlockAndPost();
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700105
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800106 uint32_t getFlags() const { return mFlags; }
107
108 // setSwapRectangle() is mainly used by EGL
109 void setSwapRectangle(const Rect& r);
110 const Rect& swapRectangle() const;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800111
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800112 static sp<Surface> readFromParcel(Parcel* parcel);
113 static status_t writeToParcel(const sp<Surface>& surface, Parcel* parcel);
114 static bool isSameSurface(const sp<Surface>& lhs, const sp<Surface>& rhs);
115
116 status_t setLayer(int32_t layer);
117 status_t setPosition(int32_t x, int32_t y);
118 status_t setSize(uint32_t w, uint32_t h);
119 status_t hide();
120 status_t show(int32_t layer = -1);
121 status_t freeze();
122 status_t unfreeze();
123 status_t setFlags(uint32_t flags, uint32_t mask);
124 status_t setTransparentRegionHint(const Region& transparent);
125 status_t setAlpha(float alpha=1.0f);
126 status_t setMatrix(float dsdx, float dtdx, float dsdy, float dtdy);
127 status_t setFreezeTint(uint32_t tint);
128
129 uint32_t getIdentity() const { return mIdentity; }
130private:
131 friend class SurfaceComposerClient;
132
133 // camera and camcorder need access to the ISurface binder interface for preview
134 friend class Camera;
135 friend class MediaRecorder;
136 // mediaplayer needs access to ISurface for display
137 friend class MediaPlayer;
138 friend class Test;
139 const sp<ISurface>& getISurface() const { return mSurface; }
140
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700141 status_t getBufferLocked(int index);
142
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800143 // can't be copied
144 Surface& operator = (Surface& rhs);
145 Surface(const Surface& rhs);
146
147 Surface(const sp<SurfaceComposerClient>& client,
148 const sp<ISurface>& surface,
149 const ISurfaceFlingerClient::surface_data_t& data,
150 uint32_t w, uint32_t h, PixelFormat format, uint32_t flags,
151 bool owner = true);
152
153 Surface(Surface const* rhs);
154
155 ~Surface();
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700156
Mathias Agopian40b7f6e2009-04-14 18:21:47 -0700157 void destroy();
158
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800159 Region dirtyRegion() const;
160 void setDirtyRegion(const Region& region) const;
161
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700162
163 status_t validate(per_client_cblk_t const* cblk) const;
164 static void _send_dirty_region(layer_cblk_t* lcblk, const Region& dirty);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800165
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700166
167 static void connect(android_native_window_t* window);
168 static void disconnect(android_native_window_t* window);
169 static int setSwapInterval(android_native_window_t* window, int interval);
170 static int setSwapRectangle(android_native_window_t* window,
171 int l, int t, int w, int h);
172 static int dequeueBuffer(android_native_window_t* window, android_native_buffer_t** buffer);
173 static int lockBuffer(android_native_window_t* window, android_native_buffer_t* buffer);
174 static int queueBuffer(android_native_window_t* window, android_native_buffer_t* buffer);
175
176 int dequeueBuffer(android_native_buffer_t** buffer);
177 int lockBuffer(android_native_buffer_t* buffer);
178 int queueBuffer(android_native_buffer_t* buffer);
179
180
181 alloc_device_t* mAllocDevice;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800182 sp<SurfaceComposerClient> mClient;
183 sp<ISurface> mSurface;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700184 sp<SurfaceBuffer> mBuffers[2];
185 android_native_buffer_t* mLockedBuffer;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800186 SurfaceID mToken;
187 uint32_t mIdentity;
188 PixelFormat mFormat;
189 uint32_t mFlags;
190 const bool mOwner;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800191 mutable Region mDirtyRegion;
192 mutable Rect mSwapRectangle;
193 mutable uint8_t mBackbufferIndex;
194 mutable Mutex mSurfaceLock;
195};
196
197}; // namespace android
198
199#endif // ANDROID_UI_SURFACE_H
200