blob: e7c6e247b20b94f04bfd4f32fcb52b572270ab5c [file] [log] [blame]
Jamie Gennis68e4a7a2010-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 Agopian27cd07c2011-04-11 21:19:55 -070030class Surface;
31
Jamie Gennis68e4a7a2010-12-20 11:27:26 -080032class SurfaceTextureClient
33 : public EGLNativeBase<ANativeWindow, SurfaceTextureClient, RefBase>
34{
35public:
36 SurfaceTextureClient(const sp<ISurfaceTexture>& surfaceTexture);
37
Jamie Gennisf95a9f02011-03-14 15:08:53 -070038 sp<ISurfaceTexture> getISurfaceTexture() const;
39
Jamie Gennis68e4a7a2010-12-20 11:27:26 -080040private:
Mathias Agopian27cd07c2011-04-11 21:19:55 -070041 friend class Surface;
Jamie Gennis68e4a7a2010-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
Iliyan Malchevb2a153a2011-05-01 11:33:26 -070048 static int cancelBuffer(ANativeWindow* window, ANativeWindowBuffer* buffer);
49 static int dequeueBuffer(ANativeWindow* window, ANativeWindowBuffer** buffer);
50 static int lockBuffer(ANativeWindow* window, ANativeWindowBuffer* buffer);
Jamie Gennis68e4a7a2010-12-20 11:27:26 -080051 static int perform(ANativeWindow* window, int operation, ...);
Iliyan Malchev4d7c1ce2011-04-14 16:54:38 -070052 static int query(const ANativeWindow* window, int what, int* value);
Iliyan Malchevb2a153a2011-05-01 11:33:26 -070053 static int queueBuffer(ANativeWindow* window, ANativeWindowBuffer* buffer);
Jamie Gennis96dcc972011-02-27 14:10:20 -080054 static int setSwapInterval(ANativeWindow* window, int interval);
Jamie Gennis68e4a7a2010-12-20 11:27:26 -080055
Iliyan Malchevb2a153a2011-05-01 11:33:26 -070056 int cancelBuffer(ANativeWindowBuffer* buffer);
57 int dequeueBuffer(ANativeWindowBuffer** buffer);
58 int lockBuffer(ANativeWindowBuffer* buffer);
Jamie Gennis68e4a7a2010-12-20 11:27:26 -080059 int perform(int operation, va_list args);
Iliyan Malchev4d7c1ce2011-04-14 16:54:38 -070060 int query(int what, int* value) const;
Iliyan Malchevb2a153a2011-05-01 11:33:26 -070061 int queueBuffer(ANativeWindowBuffer* buffer);
Jamie Gennis96dcc972011-02-27 14:10:20 -080062 int setSwapInterval(int interval);
Jamie Gennis68e4a7a2010-12-20 11:27:26 -080063
Jamie Gennis68e4a7a2010-12-20 11:27:26 -080064 int dispatchConnect(va_list args);
65 int dispatchDisconnect(va_list args);
Jamie Gennis68e4a7a2010-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 Talvalac5f94d82011-02-18 11:02:42 -080069 int dispatchSetBuffersTimestamp(va_list args);
Jamie Gennis96dcc972011-02-27 14:10:20 -080070 int dispatchSetCrop(va_list args);
71 int dispatchSetUsage(va_list args);
Jamie Gennis68e4a7a2010-12-20 11:27:26 -080072
73 int connect(int api);
74 int disconnect(int api);
Jamie Gennis68e4a7a2010-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 Talvalac5f94d82011-02-18 11:02:42 -080078 int setBuffersTimestamp(int64_t timestamp);
Jamie Gennis96dcc972011-02-27 14:10:20 -080079 int setCrop(Rect const* rect);
80 int setUsage(uint32_t reqUsage);
Jamie Gennis68e4a7a2010-12-20 11:27:26 -080081
82 void freeAllBuffers();
83
Mathias Agopian27cd07c2011-04-11 21:19:55 -070084 int getConnectedApi() const;
85
Jamie Gennis96dcc972011-02-27 14:10:20 -080086 enum { MIN_UNDEQUEUED_BUFFERS = SurfaceTexture::MIN_UNDEQUEUED_BUFFERS };
Jamie Gennis68e4a7a2010-12-20 11:27:26 -080087 enum { NUM_BUFFER_SLOTS = SurfaceTexture::NUM_BUFFER_SLOTS };
88 enum { DEFAULT_FORMAT = PIXEL_FORMAT_RGBA_8888 };
89
90 // mSurfaceTexture is the interface to the surface texture server. All
91 // operations on the surface texture client ultimately translate into
92 // interactions with the server using this interface.
93 sp<ISurfaceTexture> mSurfaceTexture;
94
Jamie Gennis83bac212011-02-02 15:31:47 -080095 // mAllocator is the binder object that is referenced to prevent the
96 // dequeued buffers from being freed prematurely.
97 sp<IBinder> mAllocator;
98
Jamie Gennis68e4a7a2010-12-20 11:27:26 -080099 // mSlots stores the buffers that have been allocated for each buffer slot.
100 // It is initialized to null pointers, and gets filled in with the result of
101 // ISurfaceTexture::requestBuffer when the client dequeues a buffer from a
102 // slot that has not yet been used. The buffer allocated to a slot will also
103 // be replaced if the requested buffer usage or geometry differs from that
104 // of the buffer allocated to a slot.
105 sp<GraphicBuffer> mSlots[NUM_BUFFER_SLOTS];
106
107 // mReqWidth is the buffer width that will be requested at the next dequeue
108 // operation. It is initialized to 1.
109 uint32_t mReqWidth;
110
111 // mReqHeight is the buffer height that will be requested at the next deuque
112 // operation. It is initialized to 1.
113 uint32_t mReqHeight;
114
115 // mReqFormat is the buffer pixel format that will be requested at the next
116 // deuque operation. It is initialized to PIXEL_FORMAT_RGBA_8888.
117 uint32_t mReqFormat;
118
119 // mReqUsage is the set of buffer usage flags that will be requested
120 // at the next deuque operation. It is initialized to 0.
121 uint32_t mReqUsage;
122
Eino-Ville Talvalac5f94d82011-02-18 11:02:42 -0800123 // mTimestamp is the timestamp that will be used for the next buffer queue
124 // operation. It defaults to NATIVE_WINDOW_TIMESTAMP_AUTO, which means that
125 // a timestamp is auto-generated when queueBuffer is called.
126 int64_t mTimestamp;
127
Mathias Agopian27cd07c2011-04-11 21:19:55 -0700128 // mConnectedApi holds the currently connected API to this surface
129 int mConnectedApi;
130
131 // mQueryWidth is the width returned by query(). It is set to width
132 // of the last dequeued buffer or to mReqWidth if no buffer was dequeued.
133 uint32_t mQueryWidth;
134
135 // mQueryHeight is the height returned by query(). It is set to height
136 // of the last dequeued buffer or to mReqHeight if no buffer was dequeued.
137 uint32_t mQueryHeight;
138
139 // mQueryFormat is the format returned by query(). It is set to the last
140 // dequeued format or to mReqFormat if no buffer was dequeued.
141 uint32_t mQueryFormat;
142
Jamie Gennis68e4a7a2010-12-20 11:27:26 -0800143 // mMutex is the mutex used to prevent concurrent access to the member
144 // variables of SurfaceTexture objects. It must be locked whenever the
145 // member variables are accessed.
Mathias Agopian27cd07c2011-04-11 21:19:55 -0700146 mutable Mutex mMutex;
Jamie Gennis68e4a7a2010-12-20 11:27:26 -0800147};
148
149}; // namespace android
150
151#endif // ANDROID_GUI_SURFACETEXTURECLIENT_H