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