blob: 2bb66d104701cf3747260e15c52caa90583a653a [file] [log] [blame]
Prabhanjan Kandula96e92342016-03-24 21:03:35 +05301/*
Naseer Ahmede69031e2016-11-22 20:05:16 -05002 * Copyright (c) 2016-2017, The Linux Foundation. All rights reserved.
Prabhanjan Kandula96e92342016-03-24 21:03:35 +05303
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above
10 * copyright notice, this list of conditions and the following
11 * disclaimer in the documentation and/or other materials provided
12 * with the distribution.
13 * * Neither the name of The Linux Foundation nor the names of its
14 * contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30#include <cutils/log.h>
31#include <sync/sync.h>
Naseer Ahmede69031e2016-11-22 20:05:16 -050032#include <sstream>
33#include <string>
Prabhanjan Kandula96e92342016-03-24 21:03:35 +053034
35#include "gr_device_impl.h"
36#include "gr_buf_descriptor.h"
37#include "gralloc_priv.h"
38#include "qd_utils.h"
39#include "qdMetaData.h"
40#include "gr_utils.h"
41
42int gralloc_device_open(const struct hw_module_t *module, const char *name, hw_device_t **device);
43
44int gralloc_device_close(struct hw_device_t *device);
45
46static struct hw_module_methods_t gralloc_module_methods = {.open = gralloc_device_open};
47
Naseer Ahmede69031e2016-11-22 20:05:16 -050048struct gralloc_module_t HAL_MODULE_INFO_SYM = {
49 .common = {
Prabhanjan Kandula96e92342016-03-24 21:03:35 +053050 .tag = HARDWARE_MODULE_TAG,
Naseer Ahmede69031e2016-11-22 20:05:16 -050051 .module_api_version = GRALLOC_MODULE_API_VERSION_1_0,
52 .hal_api_version = HARDWARE_HAL_API_VERSION,
Prabhanjan Kandula96e92342016-03-24 21:03:35 +053053 .id = GRALLOC_HARDWARE_MODULE_ID,
54 .name = "Graphics Memory Module",
55 .author = "Code Aurora Forum",
56 .methods = &gralloc_module_methods,
57 .dso = 0,
58 .reserved = {0},
59 },
60};
61
62int gralloc_device_open(const struct hw_module_t *module, const char *name, hw_device_t **device) {
63 int status = -EINVAL;
64 if (!strcmp(name, GRALLOC_HARDWARE_MODULE_ID)) {
Naseer Ahmede69031e2016-11-22 20:05:16 -050065 gralloc1::GrallocImpl * /*gralloc1_device_t*/ dev = gralloc1::GrallocImpl::GetInstance(module);
Prabhanjan Kandula96e92342016-03-24 21:03:35 +053066 *device = reinterpret_cast<hw_device_t *>(dev);
Prabhanjan Kandula96e92342016-03-24 21:03:35 +053067 if (dev->Init()) {
68 status = 0;
69 } else {
70 ALOGE(" Error in opening gralloc1 device");
Prabhanjan Kandula96e92342016-03-24 21:03:35 +053071 }
72 }
Prabhanjan Kandula96e92342016-03-24 21:03:35 +053073 return status;
74}
75
76namespace gralloc1 {
77
Naseer Ahmede69031e2016-11-22 20:05:16 -050078GrallocImpl::GrallocImpl(const hw_module_t *module) {
Prabhanjan Kandula96e92342016-03-24 21:03:35 +053079 common.tag = HARDWARE_DEVICE_TAG;
Naseer Ahmede69031e2016-11-22 20:05:16 -050080 common.version = GRALLOC_MODULE_API_VERSION_1_0;
81 common.module = const_cast<hw_module_t *>(module);
Prabhanjan Kandula96e92342016-03-24 21:03:35 +053082 common.close = CloseDevice;
83 getFunction = GetFunction;
84 getCapabilities = GetCapabilities;
85}
86
87bool GrallocImpl::Init() {
Naseer Ahmede69031e2016-11-22 20:05:16 -050088 buf_mgr_ = BufferManager::GetInstance();
89 return true;
Prabhanjan Kandula96e92342016-03-24 21:03:35 +053090}
91
92GrallocImpl::~GrallocImpl() {
Prabhanjan Kandula96e92342016-03-24 21:03:35 +053093}
94
95int GrallocImpl::CloseDevice(hw_device_t *device) {
96 GrallocImpl *impl = reinterpret_cast<GrallocImpl *>(device);
97 delete impl;
98
99 return 0;
100}
101
102void GrallocImpl::GetCapabilities(struct gralloc1_device *device, uint32_t *out_count,
Naseer Ahmed8f9c7c32017-02-21 16:45:14 -0500103 int32_t /*gralloc1_capability_t*/ *out_capabilities) {
104 if (device != nullptr) {
105 if (out_capabilities != nullptr && *out_count > 0) {
106 out_capabilities[0] = GRALLOC1_CAPABILITY_TEST_ALLOCATE;
Prabhanjan Kandula96e92342016-03-24 21:03:35 +0530107 }
Naseer Ahmed8f9c7c32017-02-21 16:45:14 -0500108 *out_count = 1;
Prabhanjan Kandula96e92342016-03-24 21:03:35 +0530109 }
Prabhanjan Kandula96e92342016-03-24 21:03:35 +0530110 return;
111}
112
113gralloc1_function_pointer_t GrallocImpl::GetFunction(gralloc1_device_t *device, int32_t function) {
114 if (!device) {
115 return NULL;
116 }
117
118 switch (function) {
Naseer Ahmede69031e2016-11-22 20:05:16 -0500119 case GRALLOC1_FUNCTION_DUMP:
120 return reinterpret_cast<gralloc1_function_pointer_t>(Dump);
Prabhanjan Kandula96e92342016-03-24 21:03:35 +0530121 case GRALLOC1_FUNCTION_CREATE_DESCRIPTOR:
122 return reinterpret_cast<gralloc1_function_pointer_t>(CreateBufferDescriptor);
123 case GRALLOC1_FUNCTION_DESTROY_DESCRIPTOR:
124 return reinterpret_cast<gralloc1_function_pointer_t>(DestroyBufferDescriptor);
125 case GRALLOC1_FUNCTION_SET_CONSUMER_USAGE:
126 return reinterpret_cast<gralloc1_function_pointer_t>(SetConsumerUsage);
127 case GRALLOC1_FUNCTION_SET_DIMENSIONS:
128 return reinterpret_cast<gralloc1_function_pointer_t>(SetBufferDimensions);
129 case GRALLOC1_FUNCTION_SET_FORMAT:
130 return reinterpret_cast<gralloc1_function_pointer_t>(SetColorFormat);
131 case GRALLOC1_FUNCTION_SET_PRODUCER_USAGE:
132 return reinterpret_cast<gralloc1_function_pointer_t>(SetProducerUsage);
133 case GRALLOC1_FUNCTION_GET_BACKING_STORE:
134 return reinterpret_cast<gralloc1_function_pointer_t>(GetBackingStore);
135 case GRALLOC1_FUNCTION_GET_CONSUMER_USAGE:
136 return reinterpret_cast<gralloc1_function_pointer_t>(GetConsumerUsage);
137 case GRALLOC1_FUNCTION_GET_DIMENSIONS:
138 return reinterpret_cast<gralloc1_function_pointer_t>(GetBufferDimensions);
139 case GRALLOC1_FUNCTION_GET_FORMAT:
140 return reinterpret_cast<gralloc1_function_pointer_t>(GetColorFormat);
141 case GRALLOC1_FUNCTION_GET_PRODUCER_USAGE:
142 return reinterpret_cast<gralloc1_function_pointer_t>(GetProducerUsage);
143 case GRALLOC1_FUNCTION_GET_STRIDE:
144 return reinterpret_cast<gralloc1_function_pointer_t>(GetBufferStride);
145 case GRALLOC1_FUNCTION_ALLOCATE:
146 return reinterpret_cast<gralloc1_function_pointer_t>(AllocateBuffers);
147 case GRALLOC1_FUNCTION_RETAIN:
148 return reinterpret_cast<gralloc1_function_pointer_t>(RetainBuffer);
149 case GRALLOC1_FUNCTION_RELEASE:
150 return reinterpret_cast<gralloc1_function_pointer_t>(ReleaseBuffer);
Naseer Ahmede69031e2016-11-22 20:05:16 -0500151 case GRALLOC1_FUNCTION_GET_NUM_FLEX_PLANES:
152 return reinterpret_cast<gralloc1_function_pointer_t>(GetNumFlexPlanes);
Prabhanjan Kandula96e92342016-03-24 21:03:35 +0530153 case GRALLOC1_FUNCTION_LOCK:
154 return reinterpret_cast<gralloc1_function_pointer_t>(LockBuffer);
Naseer Ahmede69031e2016-11-22 20:05:16 -0500155 case GRALLOC1_FUNCTION_LOCK_FLEX:
156 return reinterpret_cast<gralloc1_function_pointer_t>(LockFlex);
Prabhanjan Kandula96e92342016-03-24 21:03:35 +0530157 case GRALLOC1_FUNCTION_UNLOCK:
158 return reinterpret_cast<gralloc1_function_pointer_t>(UnlockBuffer);
159 case GRALLOC1_FUNCTION_PERFORM:
160 return reinterpret_cast<gralloc1_function_pointer_t>(Gralloc1Perform);
161 default:
162 ALOGE("%s:Gralloc Error. Client Requested for unsupported function", __FUNCTION__);
163 return NULL;
164 }
165
166 return NULL;
167}
168
Naseer Ahmede69031e2016-11-22 20:05:16 -0500169gralloc1_error_t GrallocImpl::Dump(gralloc1_device_t *device, uint32_t *out_size,
170 char *out_buffer) {
171 if (!device) {
172 ALOGE("Gralloc Error : device=%p", (void *)device);
Prabhanjan Kandula96e92342016-03-24 21:03:35 +0530173 return GRALLOC1_ERROR_BAD_DESCRIPTOR;
174 }
Naseer Ahmede69031e2016-11-22 20:05:16 -0500175 if (out_buffer == nullptr) {
176 *out_size = 1024;
177 } else {
178 std::ostringstream os;
179 // TODO(user): implement in buffer manager
180 os << "-------------------------------" << std::endl;
181 os << "QTI gralloc dump:" << std::endl;
182 os << "-------------------------------" << std::endl;
183 auto copy_size = os.str().size() < *out_size ? os.str().size() : *out_size;
184 std::copy_n(out_buffer, copy_size, os.str().begin());
185 *out_size = static_cast<uint32_t>(copy_size);
186 }
Prabhanjan Kandula96e92342016-03-24 21:03:35 +0530187
188 return GRALLOC1_ERROR_NONE;
189}
190
191gralloc1_error_t GrallocImpl::CheckDeviceAndHandle(gralloc1_device_t *device,
192 buffer_handle_t buffer) {
193 const private_handle_t *hnd = PRIV_HANDLE_CONST(buffer);
194 if (!device || (private_handle_t::validate(hnd) != 0)) {
195 ALOGE("Gralloc Error : device= %p, buffer-handle=%p", (void *)device, (void *)buffer);
196 return GRALLOC1_ERROR_BAD_HANDLE;
197 }
198
199 return GRALLOC1_ERROR_NONE;
200}
201
202gralloc1_error_t GrallocImpl::CreateBufferDescriptor(gralloc1_device_t *device,
203 gralloc1_buffer_descriptor_t *out_descriptor) {
204 if (!device) {
205 return GRALLOC1_ERROR_BAD_DESCRIPTOR;
206 }
Naseer Ahmede69031e2016-11-22 20:05:16 -0500207 GrallocImpl const *dev = GRALLOC_IMPL(device);
208 return dev->buf_mgr_->CreateBufferDescriptor(out_descriptor);
Prabhanjan Kandula96e92342016-03-24 21:03:35 +0530209}
210
211gralloc1_error_t GrallocImpl::DestroyBufferDescriptor(gralloc1_device_t *device,
212 gralloc1_buffer_descriptor_t descriptor) {
Naseer Ahmede69031e2016-11-22 20:05:16 -0500213 if (!device) {
214 return GRALLOC1_ERROR_BAD_DESCRIPTOR;
Prabhanjan Kandula96e92342016-03-24 21:03:35 +0530215 }
Naseer Ahmede69031e2016-11-22 20:05:16 -0500216 GrallocImpl const *dev = GRALLOC_IMPL(device);
217 return dev->buf_mgr_->DestroyBufferDescriptor(descriptor);
Prabhanjan Kandula96e92342016-03-24 21:03:35 +0530218}
219
220gralloc1_error_t GrallocImpl::SetConsumerUsage(gralloc1_device_t *device,
221 gralloc1_buffer_descriptor_t descriptor,
222 gralloc1_consumer_usage_t usage) {
Naseer Ahmede69031e2016-11-22 20:05:16 -0500223 if (!device) {
224 return GRALLOC1_ERROR_BAD_DESCRIPTOR;
225 } else {
226 GrallocImpl const *dev = GRALLOC_IMPL(device);
227 return dev->buf_mgr_->CallBufferDescriptorFunction(descriptor,
228 &BufferDescriptor::SetConsumerUsage, usage);
Prabhanjan Kandula96e92342016-03-24 21:03:35 +0530229 }
Prabhanjan Kandula96e92342016-03-24 21:03:35 +0530230}
231
232gralloc1_error_t GrallocImpl::SetBufferDimensions(gralloc1_device_t *device,
233 gralloc1_buffer_descriptor_t descriptor,
234 uint32_t width, uint32_t height) {
Naseer Ahmede69031e2016-11-22 20:05:16 -0500235 if (!device) {
236 return GRALLOC1_ERROR_BAD_DESCRIPTOR;
237 } else {
238 GrallocImpl const *dev = GRALLOC_IMPL(device);
239 return dev->buf_mgr_->CallBufferDescriptorFunction(descriptor,
240 &BufferDescriptor::SetDimensions,
241 INT(width), INT(height));
Prabhanjan Kandula96e92342016-03-24 21:03:35 +0530242 }
Prabhanjan Kandula96e92342016-03-24 21:03:35 +0530243}
244
245gralloc1_error_t GrallocImpl::SetColorFormat(gralloc1_device_t *device,
246 gralloc1_buffer_descriptor_t descriptor,
247 int32_t format) {
Naseer Ahmede69031e2016-11-22 20:05:16 -0500248 if (!device) {
249 return GRALLOC1_ERROR_BAD_DESCRIPTOR;
250 } else {
251 GrallocImpl const *dev = GRALLOC_IMPL(device);
252 return dev->buf_mgr_->CallBufferDescriptorFunction(descriptor,
253 &BufferDescriptor::SetColorFormat, format);
Prabhanjan Kandula96e92342016-03-24 21:03:35 +0530254 }
Prabhanjan Kandula96e92342016-03-24 21:03:35 +0530255}
256
257gralloc1_error_t GrallocImpl::SetProducerUsage(gralloc1_device_t *device,
258 gralloc1_buffer_descriptor_t descriptor,
259 gralloc1_producer_usage_t usage) {
Naseer Ahmede69031e2016-11-22 20:05:16 -0500260 if (!device) {
261 return GRALLOC1_ERROR_BAD_DESCRIPTOR;
262 } else {
263 GrallocImpl const *dev = GRALLOC_IMPL(device);
264 return dev->buf_mgr_->CallBufferDescriptorFunction(descriptor,
265 &BufferDescriptor::SetProducerUsage, usage);
Prabhanjan Kandula96e92342016-03-24 21:03:35 +0530266 }
Prabhanjan Kandula96e92342016-03-24 21:03:35 +0530267}
268
269gralloc1_error_t GrallocImpl::GetBackingStore(gralloc1_device_t *device, buffer_handle_t buffer,
270 gralloc1_backing_store_t *out_backstore) {
271 if (!device || !buffer) {
272 return GRALLOC1_ERROR_BAD_HANDLE;
273 }
274
275 *out_backstore =
276 static_cast<gralloc1_backing_store_t>(PRIV_HANDLE_CONST(buffer)->GetBackingstore());
277
278 return GRALLOC1_ERROR_NONE;
279}
280
281gralloc1_error_t GrallocImpl::GetConsumerUsage(gralloc1_device_t *device, buffer_handle_t buffer,
282 gralloc1_consumer_usage_t *outUsage) {
283 gralloc1_error_t status = CheckDeviceAndHandle(device, buffer);
284 if (status == GRALLOC1_ERROR_NONE) {
285 *outUsage = PRIV_HANDLE_CONST(buffer)->GetConsumerUsage();
286 }
287
288 return status;
289}
290
291gralloc1_error_t GrallocImpl::GetBufferDimensions(gralloc1_device_t *device, buffer_handle_t buffer,
292 uint32_t *outWidth, uint32_t *outHeight) {
293 gralloc1_error_t status = CheckDeviceAndHandle(device, buffer);
294 if (status == GRALLOC1_ERROR_NONE) {
295 const private_handle_t *hnd = PRIV_HANDLE_CONST(buffer);
Ramkumar Radhakrishnanba55eac2016-08-26 22:33:48 -0700296 *outWidth = UINT(hnd->GetUnalignedWidth());
297 *outHeight = UINT(hnd->GetUnalignedHeight());
Prabhanjan Kandula96e92342016-03-24 21:03:35 +0530298 }
299
300 return status;
301}
302
303gralloc1_error_t GrallocImpl::GetColorFormat(gralloc1_device_t *device, buffer_handle_t buffer,
304 int32_t *outFormat) {
305 gralloc1_error_t status = CheckDeviceAndHandle(device, buffer);
306 if (status == GRALLOC1_ERROR_NONE) {
307 *outFormat = PRIV_HANDLE_CONST(buffer)->GetColorFormat();
308 }
309
310 return status;
311}
312
313gralloc1_error_t GrallocImpl::GetProducerUsage(gralloc1_device_t *device, buffer_handle_t buffer,
314 gralloc1_producer_usage_t *outUsage) {
315 gralloc1_error_t status = CheckDeviceAndHandle(device, buffer);
316 if (status == GRALLOC1_ERROR_NONE) {
317 const private_handle_t *hnd = PRIV_HANDLE_CONST(buffer);
318 *outUsage = hnd->GetProducerUsage();
319 }
320
321 return status;
322}
323
324gralloc1_error_t GrallocImpl::GetBufferStride(gralloc1_device_t *device, buffer_handle_t buffer,
325 uint32_t *outStride) {
326 gralloc1_error_t status = CheckDeviceAndHandle(device, buffer);
327 if (status == GRALLOC1_ERROR_NONE) {
328 *outStride = UINT(PRIV_HANDLE_CONST(buffer)->GetStride());
329 }
330
331 return status;
332}
333
Naseer Ahmede69031e2016-11-22 20:05:16 -0500334gralloc1_error_t GrallocImpl::AllocateBuffers(gralloc1_device_t *device, uint32_t num_descriptors,
335 const gralloc1_buffer_descriptor_t *descriptors,
336 buffer_handle_t *out_buffers) {
337 if (!num_descriptors || !descriptors) {
Prabhanjan Kandula96e92342016-03-24 21:03:35 +0530338 return GRALLOC1_ERROR_BAD_DESCRIPTOR;
339 }
340
341 GrallocImpl const *dev = GRALLOC_IMPL(device);
Naseer Ahmede69031e2016-11-22 20:05:16 -0500342 gralloc1_error_t status = dev->buf_mgr_->AllocateBuffers(num_descriptors, descriptors,
343 out_buffers);
Prabhanjan Kandula96e92342016-03-24 21:03:35 +0530344
345 return status;
346}
347
348gralloc1_error_t GrallocImpl::RetainBuffer(gralloc1_device_t *device, buffer_handle_t buffer) {
349 gralloc1_error_t status = CheckDeviceAndHandle(device, buffer);
350 if (status == GRALLOC1_ERROR_NONE) {
351 const private_handle_t *hnd = PRIV_HANDLE_CONST(buffer);
352 GrallocImpl const *dev = GRALLOC_IMPL(device);
353 status = dev->buf_mgr_->RetainBuffer(hnd);
354 }
355
356 return status;
357}
358
359gralloc1_error_t GrallocImpl::ReleaseBuffer(gralloc1_device_t *device, buffer_handle_t buffer) {
360 gralloc1_error_t status = CheckDeviceAndHandle(device, buffer);
361 if (status == GRALLOC1_ERROR_NONE) {
362 const private_handle_t *hnd = PRIV_HANDLE_CONST(buffer);
363 GrallocImpl const *dev = GRALLOC_IMPL(device);
364 status = dev->buf_mgr_->ReleaseBuffer(hnd);
365 }
366
367 return status;
368}
369
Naseer Ahmede69031e2016-11-22 20:05:16 -0500370gralloc1_error_t GrallocImpl::GetNumFlexPlanes(gralloc1_device_t *device, buffer_handle_t buffer,
371 uint32_t *out_num_planes) {
372 gralloc1_error_t status = CheckDeviceAndHandle(device, buffer);
373 if (status == GRALLOC1_ERROR_NONE) {
374 GrallocImpl const *dev = GRALLOC_IMPL(device);
375 const private_handle_t *hnd = PRIV_HANDLE_CONST(buffer);
376 status = dev->buf_mgr_->GetNumFlexPlanes(hnd, out_num_planes);
377 }
378 return status;
379}
380
Prabhanjan Kandula96e92342016-03-24 21:03:35 +0530381gralloc1_error_t GrallocImpl::LockBuffer(gralloc1_device_t *device, buffer_handle_t buffer,
382 gralloc1_producer_usage_t prod_usage,
383 gralloc1_consumer_usage_t cons_usage,
384 const gralloc1_rect_t *region, void **out_data,
385 int32_t acquire_fence) {
386 gralloc1_error_t status = CheckDeviceAndHandle(device, buffer);
387 if (status == GRALLOC1_ERROR_NONE && (acquire_fence > 0)) {
388 int error = sync_wait(acquire_fence, 1000);
389 if (error < 0) {
390 ALOGE("%s: sync_wait timedout! error = %s", __FUNCTION__, strerror(errno));
391 return GRALLOC1_ERROR_UNDEFINED;
392 }
393 }
394
395 const private_handle_t *hnd = PRIV_HANDLE_CONST(buffer);
396 GrallocImpl const *dev = GRALLOC_IMPL(device);
397
398 // Either producer usage or consumer usage must be *_USAGE_NONE
399 if ((prod_usage != GRALLOC1_PRODUCER_USAGE_NONE) &&
400 (cons_usage != GRALLOC1_CONSUMER_USAGE_NONE)) {
Naseer Ahmede69031e2016-11-22 20:05:16 -0500401 // Current gralloc1 clients do not satisfy this restriction.
402 // See b/33588773 for details
403 // return GRALLOC1_ERROR_BAD_VALUE;
Prabhanjan Kandula96e92342016-03-24 21:03:35 +0530404 }
405
406 // currently we ignore the region/rect client wants to lock
407 if (region == NULL) {
408 return GRALLOC1_ERROR_BAD_VALUE;
409 }
Naseer Ahmede69031e2016-11-22 20:05:16 -0500410 // TODO(user): Need to check if buffer was allocated with the same flags
Prabhanjan Kandula96e92342016-03-24 21:03:35 +0530411 status = dev->buf_mgr_->LockBuffer(hnd, prod_usage, cons_usage);
412
413 *out_data = reinterpret_cast<void *>(hnd->base);
414
415 return status;
416}
417
Naseer Ahmede69031e2016-11-22 20:05:16 -0500418gralloc1_error_t GrallocImpl::LockFlex(gralloc1_device_t *device, buffer_handle_t buffer,
419 gralloc1_producer_usage_t prod_usage,
420 gralloc1_consumer_usage_t cons_usage,
421 const gralloc1_rect_t *region,
422 struct android_flex_layout *out_flex_layout,
423 int32_t acquire_fence) {
424 void *out_data;
425 gralloc1_error_t status = GrallocImpl::LockBuffer(device, buffer, prod_usage, cons_usage, region,
426 &out_data, acquire_fence);
427 if (status != GRALLOC1_ERROR_NONE) {
428 return status;
Prabhanjan Kandula96e92342016-03-24 21:03:35 +0530429 }
430
Naseer Ahmede69031e2016-11-22 20:05:16 -0500431 GrallocImpl const *dev = GRALLOC_IMPL(device);
432 const private_handle_t *hnd = PRIV_HANDLE_CONST(buffer);
433 dev->buf_mgr_->GetFlexLayout(hnd, out_flex_layout);
Prabhanjan Kandula96e92342016-03-24 21:03:35 +0530434 return status;
435}
Prabhanjan Kandula96e92342016-03-24 21:03:35 +0530436
437gralloc1_error_t GrallocImpl::UnlockBuffer(gralloc1_device_t *device, buffer_handle_t buffer,
438 int32_t *release_fence) {
439 gralloc1_error_t status = CheckDeviceAndHandle(device, buffer);
440
441 if (status != GRALLOC1_ERROR_NONE) {
442 return status;
443 }
444
445 const private_handle_t *hnd = PRIV_HANDLE_CONST(buffer);
446 GrallocImpl const *dev = GRALLOC_IMPL(device);
447
448 *release_fence = -1;
449
450 return dev->buf_mgr_->UnlockBuffer(hnd);
451}
452
453gralloc1_error_t GrallocImpl::Gralloc1Perform(gralloc1_device_t *device, int operation, ...) {
454 va_list args;
455 va_start(args, operation);
456 GrallocImpl const *dev = GRALLOC_IMPL(device);
457 gralloc1_error_t err = dev->buf_mgr_->Perform(operation, args);
458 va_end(args);
459
460 return err;
461}
462
463} // namespace gralloc1