ISurfaceTexture.h revision c777b0b3b9b0ea5d8e378fccde6935765e28e329
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_ISURFACETEXTURE_H 18#define ANDROID_GUI_ISURFACETEXTURE_H 19 20#include <stdint.h> 21#include <sys/types.h> 22 23#include <utils/Errors.h> 24#include <utils/RefBase.h> 25 26#include <binder/IInterface.h> 27 28#include <ui/Fence.h> 29#include <ui/GraphicBuffer.h> 30#include <ui/Rect.h> 31 32namespace android { 33// ---------------------------------------------------------------------------- 34 35class SurfaceTextureClient; 36 37class ISurfaceTexture : public IInterface 38{ 39public: 40 DECLARE_META_INTERFACE(SurfaceTexture); 41 42protected: 43 friend class SurfaceTextureClient; 44 45 enum { 46 BUFFER_NEEDS_REALLOCATION = 0x1, 47 RELEASE_ALL_BUFFERS = 0x2, 48 }; 49 50 // requestBuffer requests a new buffer for the given index. The server (i.e. 51 // the ISurfaceTexture implementation) assigns the newly created buffer to 52 // the given slot index, and the client is expected to mirror the 53 // slot->buffer mapping so that it's not necessary to transfer a 54 // GraphicBuffer for every dequeue operation. 55 virtual status_t requestBuffer(int slot, sp<GraphicBuffer>* buf) = 0; 56 57 // setBufferCount sets the number of buffer slots available. Calling this 58 // will also cause all buffer slots to be emptied. The caller should empty 59 // its mirrored copy of the buffer slots when calling this method. 60 virtual status_t setBufferCount(int bufferCount) = 0; 61 62 // dequeueBuffer requests a new buffer slot for the client to use. Ownership 63 // of the slot is transfered to the client, meaning that the server will not 64 // use the contents of the buffer associated with that slot. The slot index 65 // returned may or may not contain a buffer. If the slot is empty the client 66 // should call requestBuffer to assign a new buffer to that slot. The client 67 // is expected to either call cancelBuffer on the dequeued slot or to fill 68 // in the contents of its associated buffer contents and call queueBuffer. 69 // If dequeueBuffer return BUFFER_NEEDS_REALLOCATION, the client is 70 // expected to call requestBuffer immediately. 71 // 72 // The fence parameter will be updated to hold the fence associated with 73 // the buffer. The contents of the buffer must not be overwritten until the 74 // fence signals. If the fence is NULL, the buffer may be written 75 // immediately. 76 virtual status_t dequeueBuffer(int *slot, sp<Fence>& fence, 77 uint32_t w, uint32_t h, uint32_t format, uint32_t usage) = 0; 78 79 // queueBuffer indicates that the client has finished filling in the 80 // contents of the buffer associated with slot and transfers ownership of 81 // that slot back to the server. It is not valid to call queueBuffer on a 82 // slot that is not owned by the client or one for which a buffer associated 83 // via requestBuffer. In addition, a timestamp must be provided by the 84 // client for this buffer. The timestamp is measured in nanoseconds, and 85 // must be monotonically increasing. Its other properties (zero point, etc) 86 // are client-dependent, and should be documented by the client. 87 // 88 // outWidth, outHeight and outTransform are filled with the default width 89 // and height of the window and current transform applied to buffers, 90 // respectively. 91 92 struct QueueBufferInput : public Flattenable { 93 inline QueueBufferInput(const Parcel& parcel); 94 inline QueueBufferInput(int64_t timestamp, 95 const Rect& crop, int scalingMode, uint32_t transform, 96 sp<Fence> fence) 97 : timestamp(timestamp), crop(crop), scalingMode(scalingMode), 98 transform(transform), fence(fence) { } 99 inline void deflate(int64_t* outTimestamp, Rect* outCrop, 100 int* outScalingMode, uint32_t* outTransform, 101 sp<Fence>* outFence) const { 102 *outTimestamp = timestamp; 103 *outCrop = crop; 104 *outScalingMode = scalingMode; 105 *outTransform = transform; 106 *outFence = fence; 107 } 108 109 // Flattenable interface 110 virtual size_t getFlattenedSize() const; 111 virtual size_t getFdCount() const; 112 virtual status_t flatten(void* buffer, size_t size, 113 int fds[], size_t count) const; 114 virtual status_t unflatten(void const* buffer, size_t size, 115 int fds[], size_t count); 116 117 private: 118 int64_t timestamp; 119 Rect crop; 120 int scalingMode; 121 uint32_t transform; 122 sp<Fence> fence; 123 }; 124 125 // QueueBufferOutput must be a POD structure 126 struct QueueBufferOutput { 127 inline QueueBufferOutput() { } 128 inline void deflate(uint32_t* outWidth, 129 uint32_t* outHeight, 130 uint32_t* outTransformHint, 131 uint32_t* outNumPendingBuffers) const { 132 *outWidth = width; 133 *outHeight = height; 134 *outTransformHint = transformHint; 135 *outNumPendingBuffers = numPendingBuffers; 136 } 137 inline void inflate(uint32_t inWidth, uint32_t inHeight, 138 uint32_t inTransformHint, uint32_t inNumPendingBuffers) { 139 width = inWidth; 140 height = inHeight; 141 transformHint = inTransformHint; 142 numPendingBuffers = inNumPendingBuffers; 143 } 144 private: 145 uint32_t width; 146 uint32_t height; 147 uint32_t transformHint; 148 uint32_t numPendingBuffers; 149 }; 150 151 virtual status_t queueBuffer(int slot, 152 const QueueBufferInput& input, QueueBufferOutput* output) = 0; 153 154 // cancelBuffer indicates that the client does not wish to fill in the 155 // buffer associated with slot and transfers ownership of the slot back to 156 // the server. 157 virtual void cancelBuffer(int slot, sp<Fence> fence) = 0; 158 159 // query retrieves some information for this surface 160 // 'what' tokens allowed are that of android_natives.h 161 virtual int query(int what, int* value) = 0; 162 163 // setSynchronousMode set whether dequeueBuffer is synchronous or 164 // asynchronous. In synchronous mode, dequeueBuffer blocks until 165 // a buffer is available, the currently bound buffer can be dequeued and 166 // queued buffers will be retired in order. 167 // The default mode is asynchronous. 168 virtual status_t setSynchronousMode(bool enabled) = 0; 169 170 // connect attempts to connect a client API to the SurfaceTexture. This 171 // must be called before any other ISurfaceTexture methods are called except 172 // for getAllocator. 173 // 174 // This method will fail if the connect was previously called on the 175 // SurfaceTexture and no corresponding disconnect call was made. 176 // 177 // outWidth, outHeight and outTransform are filled with the default width 178 // and height of the window and current transform applied to buffers, 179 // respectively. 180 virtual status_t connect(int api, QueueBufferOutput* output) = 0; 181 182 // disconnect attempts to disconnect a client API from the SurfaceTexture. 183 // Calling this method will cause any subsequent calls to other 184 // ISurfaceTexture methods to fail except for getAllocator and connect. 185 // Successfully calling connect after this will allow the other methods to 186 // succeed again. 187 // 188 // This method will fail if the the SurfaceTexture is not currently 189 // connected to the specified client API. 190 virtual status_t disconnect(int api) = 0; 191}; 192 193// ---------------------------------------------------------------------------- 194 195class BnSurfaceTexture : public BnInterface<ISurfaceTexture> 196{ 197public: 198 virtual status_t onTransact( uint32_t code, 199 const Parcel& data, 200 Parcel* reply, 201 uint32_t flags = 0); 202}; 203 204// ---------------------------------------------------------------------------- 205}; // namespace android 206 207#endif // ANDROID_GUI_ISURFACETEXTURE_H 208