blob: d2d3bb8f8c6c365e5114d5d58e6513bf73d8000a [file] [log] [blame]
Jamie Gennis68e4a7a2010-12-20 11:27:26 -08001/*
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 ISurfaceTexture : public IInterface
35{
36public:
37 DECLARE_META_INTERFACE(SurfaceTexture);
38
Mathias Agopiane5a1bff2011-03-31 19:10:24 -070039 enum { BUFFER_NEEDS_REALLOCATION = 1 };
40
Jamie Gennis68e4a7a2010-12-20 11:27:26 -080041 // requestBuffer requests a new buffer for the given index. The server (i.e.
42 // the ISurfaceTexture implementation) assigns the newly created buffer to
43 // the given slot index, and the client is expected to mirror the
44 // slot->buffer mapping so that it's not necessary to transfer a
45 // GraphicBuffer for every dequeue operation.
46 virtual sp<GraphicBuffer> requestBuffer(int slot, uint32_t w, uint32_t h,
47 uint32_t format, uint32_t usage) = 0;
48
49 // setBufferCount sets the number of buffer slots available. Calling this
50 // will also cause all buffer slots to be emptied. The caller should empty
51 // its mirrored copy of the buffer slots when calling this method.
52 virtual status_t setBufferCount(int bufferCount) = 0;
53
54 // dequeueBuffer requests a new buffer slot for the client to use. Ownership
55 // of the slot is transfered to the client, meaning that the server will not
56 // use the contents of the buffer associated with that slot. The slot index
57 // returned may or may not contain a buffer. If the slot is empty the client
58 // should call requestBuffer to assign a new buffer to that slot. The client
59 // is expected to either call cancelBuffer on the dequeued slot or to fill
60 // in the contents of its associated buffer contents and call queueBuffer.
Mathias Agopiane5a1bff2011-03-31 19:10:24 -070061 // If dequeueBuffer return BUFFER_NEEDS_REALLOCATION, the client is
62 // expected to call requestBuffer immediately.
Jamie Gennis68e4a7a2010-12-20 11:27:26 -080063 virtual status_t dequeueBuffer(int *slot) = 0;
64
65 // queueBuffer indicates that the client has finished filling in the
66 // contents of the buffer associated with slot and transfers ownership of
67 // that slot back to the server. It is not valid to call queueBuffer on a
68 // slot that is not owned by the client or one for which a buffer associated
Eino-Ville Talvalac5f94d82011-02-18 11:02:42 -080069 // via requestBuffer. In addition, a timestamp must be provided by the
70 // client for this buffer. The timestamp is measured in nanoseconds, and
71 // must be monotonically increasing. Its other properties (zero point, etc)
72 // are client-dependent, and should be documented by the client.
73 virtual status_t queueBuffer(int slot, int64_t timestamp) = 0;
Jamie Gennis68e4a7a2010-12-20 11:27:26 -080074
75 // cancelBuffer indicates that the client does not wish to fill in the
76 // buffer associated with slot and transfers ownership of the slot back to
77 // the server.
78 virtual void cancelBuffer(int slot) = 0;
79
80 virtual status_t setCrop(const Rect& reg) = 0;
81 virtual status_t setTransform(uint32_t transform) = 0;
Jamie Gennis83bac212011-02-02 15:31:47 -080082
83 // getAllocator retrieves the binder object that must be referenced as long
84 // as the GraphicBuffers dequeued from this ISurfaceTexture are referenced.
85 // Holding this binder reference prevents SurfaceFlinger from freeing the
86 // buffers before the client is done with them.
87 virtual sp<IBinder> getAllocator() = 0;
Jamie Gennis68e4a7a2010-12-20 11:27:26 -080088};
89
90// ----------------------------------------------------------------------------
91
92class BnSurfaceTexture : public BnInterface<ISurfaceTexture>
93{
94public:
95 virtual status_t onTransact( uint32_t code,
96 const Parcel& data,
97 Parcel* reply,
98 uint32_t flags = 0);
99};
100
101// ----------------------------------------------------------------------------
102}; // namespace android
103
104#endif // ANDROID_GUI_ISURFACETEXTURE_H