blob: 4cdece99ec29f57283b65a0431221bd34d04168a [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
30class SurfaceTextureClient
31 : public EGLNativeBase<ANativeWindow, SurfaceTextureClient, RefBase>
32{
33public:
34 SurfaceTextureClient(const sp<ISurfaceTexture>& surfaceTexture);
35
36private:
37
38 // can't be copied
39 SurfaceTextureClient& operator = (const SurfaceTextureClient& rhs);
40 SurfaceTextureClient(const SurfaceTextureClient& rhs);
41
42 // ANativeWindow hooks
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080043 static int cancelBuffer(ANativeWindow* window, android_native_buffer_t* buffer);
Jamie Gennis9d4d6c12011-02-27 14:10:20 -080044 static int dequeueBuffer(ANativeWindow* window, android_native_buffer_t** buffer);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080045 static int lockBuffer(ANativeWindow* window, android_native_buffer_t* buffer);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080046 static int perform(ANativeWindow* window, int operation, ...);
Jamie Gennis9d4d6c12011-02-27 14:10:20 -080047 static int query(ANativeWindow* window, int what, int* value);
48 static int queueBuffer(ANativeWindow* window, android_native_buffer_t* buffer);
49 static int setSwapInterval(ANativeWindow* window, int interval);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080050
Jamie Gennis9d4d6c12011-02-27 14:10:20 -080051 int cancelBuffer(android_native_buffer_t* buffer);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080052 int dequeueBuffer(android_native_buffer_t** buffer);
53 int lockBuffer(android_native_buffer_t* buffer);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080054 int perform(int operation, va_list args);
Jamie Gennis9d4d6c12011-02-27 14:10:20 -080055 int query(int what, int* value);
56 int queueBuffer(android_native_buffer_t* buffer);
57 int setSwapInterval(int interval);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080058
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080059 int dispatchConnect(va_list args);
60 int dispatchDisconnect(va_list args);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080061 int dispatchSetBufferCount(va_list args);
62 int dispatchSetBuffersGeometry(va_list args);
63 int dispatchSetBuffersTransform(va_list args);
Jamie Gennis9d4d6c12011-02-27 14:10:20 -080064 int dispatchSetCrop(va_list args);
65 int dispatchSetUsage(va_list args);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080066
67 int connect(int api);
68 int disconnect(int api);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080069 int setBufferCount(int bufferCount);
70 int setBuffersGeometry(int w, int h, int format);
71 int setBuffersTransform(int transform);
Jamie Gennis9d4d6c12011-02-27 14:10:20 -080072 int setCrop(Rect const* rect);
73 int setUsage(uint32_t reqUsage);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080074
75 void freeAllBuffers();
76
Jamie Gennis9d4d6c12011-02-27 14:10:20 -080077 enum { MIN_UNDEQUEUED_BUFFERS = SurfaceTexture::MIN_UNDEQUEUED_BUFFERS };
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080078 enum { MIN_BUFFER_SLOTS = SurfaceTexture::MIN_BUFFER_SLOTS };
79 enum { NUM_BUFFER_SLOTS = SurfaceTexture::NUM_BUFFER_SLOTS };
80 enum { DEFAULT_FORMAT = PIXEL_FORMAT_RGBA_8888 };
81
82 // mSurfaceTexture is the interface to the surface texture server. All
83 // operations on the surface texture client ultimately translate into
84 // interactions with the server using this interface.
85 sp<ISurfaceTexture> mSurfaceTexture;
86
Jamie Gennis1b20cde2011-02-02 15:31:47 -080087 // mAllocator is the binder object that is referenced to prevent the
88 // dequeued buffers from being freed prematurely.
89 sp<IBinder> mAllocator;
90
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080091 // mSlots stores the buffers that have been allocated for each buffer slot.
92 // It is initialized to null pointers, and gets filled in with the result of
93 // ISurfaceTexture::requestBuffer when the client dequeues a buffer from a
94 // slot that has not yet been used. The buffer allocated to a slot will also
95 // be replaced if the requested buffer usage or geometry differs from that
96 // of the buffer allocated to a slot.
97 sp<GraphicBuffer> mSlots[NUM_BUFFER_SLOTS];
98
99 // mReqWidth is the buffer width that will be requested at the next dequeue
100 // operation. It is initialized to 1.
101 uint32_t mReqWidth;
102
103 // mReqHeight is the buffer height that will be requested at the next deuque
104 // operation. It is initialized to 1.
105 uint32_t mReqHeight;
106
107 // mReqFormat is the buffer pixel format that will be requested at the next
108 // deuque operation. It is initialized to PIXEL_FORMAT_RGBA_8888.
109 uint32_t mReqFormat;
110
111 // mReqUsage is the set of buffer usage flags that will be requested
112 // at the next deuque operation. It is initialized to 0.
113 uint32_t mReqUsage;
114
115 // mMutex is the mutex used to prevent concurrent access to the member
116 // variables of SurfaceTexture objects. It must be locked whenever the
117 // member variables are accessed.
118 Mutex mMutex;
119};
120
121}; // namespace android
122
123#endif // ANDROID_GUI_SURFACETEXTURECLIENT_H