blob: fe9b04917ed8bfdf8ac54dac87a1bce46ae7de99 [file] [log] [blame]
Jamie Gennis8ba32fa2010-12-20 11:27:26 -08001/*
2 * Copyright (C) 2010 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_SURFACETEXTURECLIENT_H
18#define ANDROID_GUI_SURFACETEXTURECLIENT_H
19
20#include <gui/ISurfaceTexture.h>
21#include <gui/SurfaceTexture.h>
22
23#include <ui/egl/android_natives.h>
24
25#include <utils/RefBase.h>
26#include <utils/threads.h>
27
28namespace android {
29
Mathias Agopian7a042bf2011-04-11 21:19:55 -070030class Surface;
31
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080032class SurfaceTextureClient
33 : public EGLNativeBase<ANativeWindow, SurfaceTextureClient, RefBase>
34{
35public:
36 SurfaceTextureClient(const sp<ISurfaceTexture>& surfaceTexture);
37
Jamie Gennisbae774e2011-03-14 15:08:53 -070038 sp<ISurfaceTexture> getISurfaceTexture() const;
39
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080040private:
Mathias Agopian7a042bf2011-04-11 21:19:55 -070041 friend class Surface;
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080042
43 // can't be copied
44 SurfaceTextureClient& operator = (const SurfaceTextureClient& rhs);
45 SurfaceTextureClient(const SurfaceTextureClient& rhs);
46
47 // ANativeWindow hooks
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080048 static int cancelBuffer(ANativeWindow* window, android_native_buffer_t* buffer);
Jamie Gennis9d4d6c12011-02-27 14:10:20 -080049 static int dequeueBuffer(ANativeWindow* window, android_native_buffer_t** buffer);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080050 static int lockBuffer(ANativeWindow* window, android_native_buffer_t* buffer);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080051 static int perform(ANativeWindow* window, int operation, ...);
Jamie Gennis9d4d6c12011-02-27 14:10:20 -080052 static int query(ANativeWindow* window, int what, int* value);
53 static int queueBuffer(ANativeWindow* window, android_native_buffer_t* buffer);
54 static int setSwapInterval(ANativeWindow* window, int interval);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080055
Jamie Gennis9d4d6c12011-02-27 14:10:20 -080056 int cancelBuffer(android_native_buffer_t* buffer);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080057 int dequeueBuffer(android_native_buffer_t** buffer);
58 int lockBuffer(android_native_buffer_t* buffer);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080059 int perform(int operation, va_list args);
Jamie Gennis9d4d6c12011-02-27 14:10:20 -080060 int query(int what, int* value);
61 int queueBuffer(android_native_buffer_t* buffer);
62 int setSwapInterval(int interval);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080063
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080064 int dispatchConnect(va_list args);
65 int dispatchDisconnect(va_list args);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080066 int dispatchSetBufferCount(va_list args);
67 int dispatchSetBuffersGeometry(va_list args);
68 int dispatchSetBuffersTransform(va_list args);
Eino-Ville Talvala1d01a122011-02-18 11:02:42 -080069 int dispatchSetBuffersTimestamp(va_list args);
Jamie Gennis9d4d6c12011-02-27 14:10:20 -080070 int dispatchSetCrop(va_list args);
71 int dispatchSetUsage(va_list args);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080072
73 int connect(int api);
74 int disconnect(int api);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080075 int setBufferCount(int bufferCount);
76 int setBuffersGeometry(int w, int h, int format);
77 int setBuffersTransform(int transform);
Eino-Ville Talvala1d01a122011-02-18 11:02:42 -080078 int setBuffersTimestamp(int64_t timestamp);
Jamie Gennis9d4d6c12011-02-27 14:10:20 -080079 int setCrop(Rect const* rect);
80 int setUsage(uint32_t reqUsage);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080081
82 void freeAllBuffers();
83
Mathias Agopian7a042bf2011-04-11 21:19:55 -070084 int getConnectedApi() const;
85
Jamie Gennis9d4d6c12011-02-27 14:10:20 -080086 enum { MIN_UNDEQUEUED_BUFFERS = SurfaceTexture::MIN_UNDEQUEUED_BUFFERS };
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080087 enum { MIN_BUFFER_SLOTS = SurfaceTexture::MIN_BUFFER_SLOTS };
88 enum { NUM_BUFFER_SLOTS = SurfaceTexture::NUM_BUFFER_SLOTS };
89 enum { DEFAULT_FORMAT = PIXEL_FORMAT_RGBA_8888 };
90
91 // mSurfaceTexture is the interface to the surface texture server. All
92 // operations on the surface texture client ultimately translate into
93 // interactions with the server using this interface.
94 sp<ISurfaceTexture> mSurfaceTexture;
95
Jamie Gennis1b20cde2011-02-02 15:31:47 -080096 // mAllocator is the binder object that is referenced to prevent the
97 // dequeued buffers from being freed prematurely.
98 sp<IBinder> mAllocator;
99
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800100 // mSlots stores the buffers that have been allocated for each buffer slot.
101 // It is initialized to null pointers, and gets filled in with the result of
102 // ISurfaceTexture::requestBuffer when the client dequeues a buffer from a
103 // slot that has not yet been used. The buffer allocated to a slot will also
104 // be replaced if the requested buffer usage or geometry differs from that
105 // of the buffer allocated to a slot.
106 sp<GraphicBuffer> mSlots[NUM_BUFFER_SLOTS];
107
108 // mReqWidth is the buffer width that will be requested at the next dequeue
109 // operation. It is initialized to 1.
110 uint32_t mReqWidth;
111
112 // mReqHeight is the buffer height that will be requested at the next deuque
113 // operation. It is initialized to 1.
114 uint32_t mReqHeight;
115
116 // mReqFormat is the buffer pixel format that will be requested at the next
117 // deuque operation. It is initialized to PIXEL_FORMAT_RGBA_8888.
118 uint32_t mReqFormat;
119
120 // mReqUsage is the set of buffer usage flags that will be requested
121 // at the next deuque operation. It is initialized to 0.
122 uint32_t mReqUsage;
123
Eino-Ville Talvala1d01a122011-02-18 11:02:42 -0800124 // mTimestamp is the timestamp that will be used for the next buffer queue
125 // operation. It defaults to NATIVE_WINDOW_TIMESTAMP_AUTO, which means that
126 // a timestamp is auto-generated when queueBuffer is called.
127 int64_t mTimestamp;
128
Mathias Agopian7a042bf2011-04-11 21:19:55 -0700129 // mConnectedApi holds the currently connected API to this surface
130 int mConnectedApi;
131
132 // mQueryWidth is the width returned by query(). It is set to width
133 // of the last dequeued buffer or to mReqWidth if no buffer was dequeued.
134 uint32_t mQueryWidth;
135
136 // mQueryHeight is the height returned by query(). It is set to height
137 // of the last dequeued buffer or to mReqHeight if no buffer was dequeued.
138 uint32_t mQueryHeight;
139
140 // mQueryFormat is the format returned by query(). It is set to the last
141 // dequeued format or to mReqFormat if no buffer was dequeued.
142 uint32_t mQueryFormat;
143
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800144 // mMutex is the mutex used to prevent concurrent access to the member
145 // variables of SurfaceTexture objects. It must be locked whenever the
146 // member variables are accessed.
Mathias Agopian7a042bf2011-04-11 21:19:55 -0700147 mutable Mutex mMutex;
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800148};
149
150}; // namespace android
151
152#endif // ANDROID_GUI_SURFACETEXTURECLIENT_H