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