blob: 8accb8213110fde35eaf3929633831c23c6bef3e [file] [log] [blame]
Chia-I Wue78aa1b2016-09-05 11:46:36 +08001/*
2 * Copyright (C) 2016 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
17package android.hardware.graphics.allocator@2.0;
18
19interface IAllocator {
20 enum Capability : int32_t {
21 /* reserved */
22 INVALID = 0,
23
24 /*
25 * testAllocate will always return UNDEFINED unless this capability
26 * is supported.
27 */
28 TEST_ALLOCATE = 1,
29 };
30
31 struct BufferDescriptorInfo {
32 /*
33 * The width specifies how many columns of pixels should be in the
34 * allocated buffer, but does not necessarily represent the offset in
35 * columns between the same column in adjacent rows. The rows may be
36 * padded.
37 */
38 uint32_t width;
39
40 /*
41 * The height specifies how many rows of pixels should be in the
42 * allocated buffer.
43 */
44 uint32_t height;
45
46 /* Buffer pixel format. */
47 PixelFormat format;
48
49 /*
50 * Buffer producer usage mask; valid flags can be found in the
51 * definition of ProducerUsage.
52 */
53 uint64_t producerUsageMask;
54
55 /*
56 * Buffer consumer usage mask; valid flags can be found in the
57 * definition of ConsumerUsage.
58 */
59 uint64_t consumerUsageMask;
60 };
61
62 /*
63 * Provides a list of supported capabilities (as described in the
64 * definition of Capability above). This list must not change after
65 * initialization.
66 *
67 * @return capabilities is a list of supported capabilities.
68 */
69 getCapabilities() generates (vec<Capability> capabilities);
70
71 /*
72 * Retrieves implementation-defined debug information, which will be
73 * displayed during, for example, `dumpsys SurfaceFlinger`.
74 *
75 * @return debugInfo is a string of debug information.
76 */
77 dumpDebugInfo() generates (string debugInfo);
78
79 /*
80 * Creates a new, opaque buffer descriptor.
81 *
82 * @param descriptorInfo specifies the attributes of the buffer
83 * descriptor.
84 * @return error is NONE upon success. Otherwise,
85 * BAD_VALUE when any attribute in descriptorInfo is invalid.
86 * NO_RESOURCES when no more descriptors can currently be created.
87 * @return descriptor is the newly created buffer descriptor.
88 */
89 createDescriptor(BufferDescriptorInfo descriptorInfo)
90 generates (Error error,
91 BufferDescriptor descriptor);
92
93 /*
94 * Destroys an existing buffer descriptor.
95 *
96 * @param descriptor is the descriptor to destroy.
97 * @return error is either NONE or BAD_DESCRIPTOR.
98 */
99 destroyDescriptor(BufferDescriptor descriptor) generates (Error error);
100
101 /*
102 * Tests whether a buffer allocation can succeed, ignoring potential
103 * resource contention which might lead to a NO_RESOURCES error.
104 *
105 * @param descriptors is a list of buffer descriptors.
106 * @return error is NONE or NOT_SHARED upon success;
107 * NONE when buffers can be created and share a backing store.
108 * NOT_SHARED when buffers can be created but require more than a
109 * backing store.
110 * Otherwise,
111 * BAD_DESCRIPTOR when any of the descriptors is invalid.
112 * UNSUPPORTED when any of the descriptors can never be satisfied.
113 * UNDEFINED when TEST_ALLOCATE is not listed in getCapabilities.
114 */
115 testAllocate(vec<BufferDescriptor> descriptors) generates (Error error);
116
117 /*
118 * Attempts to allocate a list of buffers sharing a backing store.
119 *
120 * Each buffer will correspond to one of the descriptors passed into the
121 * function and will hold a reference to its backing store. If the device
122 * is unable to share the backing store between the buffers, it must
123 * attempt to allocate the buffers with different backing stores and
124 * return NOT_SHARED if it is successful.
125 *
126 * @param descriptors is the buffer descriptors to attempt to allocate.
127 * @return error is NONE or NOT_SHARED upon success;
128 * NONE when buffers can be created and share a backing store.
129 * NOT_SHARED when buffers can be created but require more than a
130 * backing store.
131 * Otherwise,
132 * BAD_DESCRIPTOR when any of the descriptors is invalid.
133 * UNSUPPORTED when any of the descriptors can never be satisfied.
134 * NO_RESOURCES when any of the buffers cannot be created at this
135 * time.
136 * @return buffers is the allocated buffers.
137 */
138 allocate(vec<BufferDescriptor> descriptors)
139 generates (Error error,
140 vec<Buffer> buffers);
141
142 /*
143 * Frees a buffer.
144 *
145 * @param buffer is the buffer to be freed.
146 * @return error is NONE upon success. Otherwise,
147 * BAD_BUFFER when the buffer is invalid.
148 */
149 free(Buffer buffer) generates (Error error);
150
151 /*
152 * Exports a buffer for use in other client libraries or for cross-process
153 * sharing.
154 *
155 * The exported handle is a handle to the backing store of the buffer, not
156 * to the buffer itself. It however may not hold any reference to the
157 * backing store and may be considered invalid by client libraries. To use
158 * it and, in most cases, to save it for later use, a client must make a
159 * clone of the handle and have the cloned handle hold a reference to the
160 * backing store. Such a cloned handle will stay valid even after the
161 * original buffer is freed. Refer to native_handle_clone and IMapper for
162 * how a handle is cloned and how a reference is added.
163 *
164 * @param descriptor is the descriptor used to allocate the buffer.
165 * @param buffer is the buffer to be exported.
166 * @return error is NONE upon success. Otherwise,
167 * BAD_DESCRIPTOR when the descriptor is invalid.
168 * BAD_BUFFER when the buffer is invalid.
169 * BAD_VALUE when descriptor and buffer do not match.
170 * NO_RESOURCES when the buffer cannot be exported at this time.
171 * @return bufferHandle is the exported handle.
172 */
173 exportHandle(BufferDescriptor descriptor,
174 Buffer buffer)
175 generates (Error error,
176 handle bufferHandle);
177};