SurfaceTextureClient.h revision 8072711307aa98ee5ee6f7369860ae38c3e19656
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 Surface; 31 32class SurfaceTextureClient 33 : public EGLNativeBase<ANativeWindow, SurfaceTextureClient, RefBase> 34{ 35public: 36 SurfaceTextureClient(const sp<ISurfaceTexture>& surfaceTexture); 37 38 sp<ISurfaceTexture> getISurfaceTexture() const; 39 40private: 41 friend class Surface; 42 43 // can't be copied 44 SurfaceTextureClient& operator = (const SurfaceTextureClient& rhs); 45 SurfaceTextureClient(const SurfaceTextureClient& rhs); 46 47 // ANativeWindow hooks 48 static int cancelBuffer(ANativeWindow* window, ANativeWindowBuffer* buffer); 49 static int dequeueBuffer(ANativeWindow* window, ANativeWindowBuffer** buffer); 50 static int lockBuffer(ANativeWindow* window, ANativeWindowBuffer* buffer); 51 static int perform(ANativeWindow* window, int operation, ...); 52 static int query(const ANativeWindow* window, int what, int* value); 53 static int queueBuffer(ANativeWindow* window, ANativeWindowBuffer* buffer); 54 static int setSwapInterval(ANativeWindow* window, int interval); 55 56 int cancelBuffer(ANativeWindowBuffer* buffer); 57 int dequeueBuffer(ANativeWindowBuffer** buffer); 58 int lockBuffer(ANativeWindowBuffer* buffer); 59 int perform(int operation, va_list args); 60 int query(int what, int* value) const; 61 int queueBuffer(ANativeWindowBuffer* buffer); 62 int setSwapInterval(int interval); 63 64 int dispatchConnect(va_list args); 65 int dispatchDisconnect(va_list args); 66 int dispatchSetBufferCount(va_list args); 67 int dispatchSetBuffersGeometry(va_list args); 68 int dispatchSetBuffersTransform(va_list args); 69 int dispatchSetBuffersTimestamp(va_list args); 70 int dispatchSetCrop(va_list args); 71 int dispatchSetUsage(va_list args); 72 73 int connect(int api); 74 int disconnect(int api); 75 int setBufferCount(int bufferCount); 76 int setBuffersGeometry(int w, int h, int format); 77 int setBuffersTransform(int transform); 78 int setBuffersTimestamp(int64_t timestamp); 79 int setCrop(Rect const* rect); 80 int setUsage(uint32_t reqUsage); 81 82 void freeAllBuffers(); 83 84 int getConnectedApi() const; 85 86 enum { MIN_UNDEQUEUED_BUFFERS = SurfaceTexture::MIN_UNDEQUEUED_BUFFERS }; 87 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 95 // mAllocator is the binder object that is referenced to prevent the 96 // dequeued buffers from being freed prematurely. 97 sp<IBinder> mAllocator; 98 99 // 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 123 // 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 128 // 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 143 // 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. 146 mutable Mutex mMutex; 147}; 148 149}; // namespace android 150 151#endif // ANDROID_GUI_SURFACETEXTURECLIENT_H 152