ISurfaceTexture.h revision c10d9d90b2088a3304076e0dc4bf05cdbb5d45ab
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
31namespace android {
32// ----------------------------------------------------------------------------
33
34class SurfaceTextureClient;
35
36class ISurfaceTexture : public IInterface
37{
38public:
39    DECLARE_META_INTERFACE(SurfaceTexture);
40
41protected:
42    friend class SurfaceTextureClient;
43
44    enum {
45        BUFFER_NEEDS_REALLOCATION = 0x1,
46        RELEASE_ALL_BUFFERS       = 0x2,
47    };
48
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.
54    virtual sp<GraphicBuffer> requestBuffer(int slot) = 0;
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.
68    // If dequeueBuffer return BUFFER_NEEDS_REALLOCATION, the client is
69    // expected to call requestBuffer immediately.
70    virtual status_t dequeueBuffer(int *slot, uint32_t w, uint32_t h,
71            uint32_t format, uint32_t usage) = 0;
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
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.
81    //
82    // outWidth, outHeight and outTransform are filled with the default width
83    // and height of the window and current transform applied to buffers,
84    // respectively.
85    virtual status_t queueBuffer(int slot, int64_t timestamp,
86            uint32_t* outWidth, uint32_t* outHeight, uint32_t* outTransform) = 0;
87
88    // cancelBuffer indicates that the client does not wish to fill in the
89    // buffer associated with slot and transfers ownership of the slot back to
90    // the server.
91    virtual void cancelBuffer(int slot) = 0;
92
93    virtual status_t setCrop(const Rect& reg) = 0;
94    virtual status_t setTransform(uint32_t transform) = 0;
95    virtual status_t setScalingMode(int mode) = 0;
96
97    // getAllocator retrieves the binder object that must be referenced as long
98    // as the GraphicBuffers dequeued from this ISurfaceTexture are referenced.
99    // Holding this binder reference prevents SurfaceFlinger from freeing the
100    // buffers before the client is done with them.
101    virtual sp<IBinder> getAllocator() = 0;
102
103    // query retrieves some information for this surface
104    // 'what' tokens allowed are that of android_natives.h
105    virtual int query(int what, int* value) = 0;
106
107    // setSynchronousMode set whether dequeueBuffer is synchronous or
108    // asynchronous. In synchronous mode, dequeueBuffer blocks until
109    // a buffer is available, the currently bound buffer can be dequeued and
110    // queued buffers will be retired in order.
111    // The default mode is asynchronous.
112    virtual status_t setSynchronousMode(bool enabled) = 0;
113
114    // connect attempts to connect a client API to the SurfaceTexture.  This
115    // must be called before any other ISurfaceTexture methods are called except
116    // for getAllocator.
117    //
118    // This method will fail if the connect was previously called on the
119    // SurfaceTexture and no corresponding disconnect call was made.
120    virtual status_t connect(int api) = 0;
121
122    // disconnect attempts to disconnect a client API from the SurfaceTexture.
123    // Calling this method will cause any subsequent calls to other
124    // ISurfaceTexture methods to fail except for getAllocator and connect.
125    // Successfully calling connect after this will allow the other methods to
126    // succeed again.
127    //
128    // This method will fail if the the SurfaceTexture is not currently
129    // connected to the specified client API.
130    virtual status_t disconnect(int api) = 0;
131};
132
133// ----------------------------------------------------------------------------
134
135class BnSurfaceTexture : public BnInterface<ISurfaceTexture>
136{
137public:
138    virtual status_t    onTransact( uint32_t code,
139                                    const Parcel& data,
140                                    Parcel* reply,
141                                    uint32_t flags = 0);
142};
143
144// ----------------------------------------------------------------------------
145}; // namespace android
146
147#endif // ANDROID_GUI_ISURFACETEXTURE_H
148