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