blob: cea8ac9afe8b5d600aabdc3e86b6157cd14a3b6b [file] [log] [blame]
Prabhanjan Kandula96e92342016-03-24 21:03:35 +05301/*
Saurabh Shahc5b2b702016-10-24 17:16:01 -07002 * Copyright (c) 2011-2017 The Linux Foundation. All rights reserved.
Prabhanjan Kandula96e92342016-03-24 21:03:35 +05303 * Not a Contribution
4 *
5 * Copyright (C) 2010 The Android Open Source Project
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19
20#include <utility>
21
22#include "qd_utils.h"
23#include "gr_priv_handle.h"
24#include "gr_buf_descriptor.h"
25#include "gr_utils.h"
26#include "gr_buf_mgr.h"
27#include "qdMetaData.h"
28
29namespace gralloc1 {
30
31BufferManager::BufferManager() {
32 char property[PROPERTY_VALUE_MAX];
33
34 // Map framebuffer memory
35 if ((property_get("debug.gralloc.map_fb_memory", property, NULL) > 0) &&
36 (!strncmp(property, "1", PROPERTY_VALUE_MAX) ||
37 (!strncasecmp(property, "true", PROPERTY_VALUE_MAX)))) {
38 map_fb_mem_ = true;
39 }
40
41 // Enable UBWC for framebuffer
42 if ((property_get("debug.gralloc.enable_fb_ubwc", property, NULL) > 0) &&
43 (!strncmp(property, "1", PROPERTY_VALUE_MAX) ||
44 (!strncasecmp(property, "true", PROPERTY_VALUE_MAX)))) {
45 ubwc_for_fb_ = true;
46 }
47
48 handles_map_.clear();
49}
50
51BufferManager::~BufferManager() {
52 if (allocator_) {
53 delete allocator_;
54 }
55}
56
57bool BufferManager::Init() {
58 allocator_ = new Allocator();
59
60 return allocator_->Init();
61}
62
63gralloc1_error_t BufferManager::AllocateBuffers(uint32_t num_descriptors,
64 const BufferDescriptor *descriptors,
65 buffer_handle_t *out_buffers) {
66 bool shared = true;
67 gralloc1_error_t status = GRALLOC1_ERROR_NONE;
68
69 // since GRALLOC1_CAPABILITY_TEST_ALLOCATE capability is supported
70 // client can ask to test the allocation by passing NULL out_buffers
71 bool test_allocate = !out_buffers;
72
73 // Check if input descriptors can be supported AND
74 // Find out if a single buffer can be shared for all the given input descriptors
75 uint32_t i = 0;
76 int max_buf_index = -1;
77 shared = allocator_->CheckForBufferSharing(num_descriptors, descriptors, &max_buf_index);
78
79 if (test_allocate) {
80 status = shared ? GRALLOC1_ERROR_NOT_SHARED : status;
81 return status;
82 }
83
84 if (shared && (max_buf_index >= 0)) {
85 // Allocate one and duplicate/copy the handles for each descriptor
86 if (AllocateBuffer(descriptors[max_buf_index], &out_buffers[max_buf_index])) {
87 return GRALLOC1_ERROR_NO_RESOURCES;
88 }
89
90 for (i = 0; i < num_descriptors; i++) {
91 // Create new handle for a given descriptor.
92 // Current assumption is even MetaData memory would be same
93 // Need to revisit if there is a need for own metadata memory
94 if (i != UINT(max_buf_index)) {
95 CreateSharedHandle(out_buffers[max_buf_index], descriptors[i], &out_buffers[i]);
96
97 // since we just created handle out of existing handle add it to map
98 locker_.lock();
99 handles_map_.insert(std::pair<private_handle_t const *, int>(
100 reinterpret_cast<private_handle_t const *>(out_buffers[i]), 1));
101 locker_.unlock();
102 }
103 }
104 } else {
105 // Buffer sharing is not feasible.
106 // Allocate seperate buffer for each descriptor
107 for (i = 0; i < num_descriptors; i++) {
108 if (AllocateBuffer(descriptors[i], &out_buffers[i])) {
109 return GRALLOC1_ERROR_NO_RESOURCES;
110 }
111 }
112 }
113
114 // Allocation is successful. If backstore is not shared inform the client.
115 if (!shared) {
116 return GRALLOC1_ERROR_NOT_SHARED;
117 }
118
119 return status;
120}
121
122void BufferManager::CreateSharedHandle(buffer_handle_t inbuffer, const BufferDescriptor &descriptor,
123 buffer_handle_t *outbuffer) {
124 private_handle_t const *input = reinterpret_cast<private_handle_t const *>(inbuffer);
125
126 // Get Buffer attributes or dimension
127 unsigned int alignedw = 0, alignedh = 0;
128 allocator_->GetAlignedWidthAndHeight(descriptor, &alignedw, &alignedh);
129
130 // create new handle from input reference handle and given descriptor
131 int flags = GetHandleFlags(descriptor.GetFormat(), descriptor.GetProducerUsage(),
132 descriptor.GetConsumerUsage());
133 int buffer_type = GetBufferType(descriptor.GetFormat());
134
135 // Duplicate the fds
136 private_handle_t *out_hnd = new private_handle_t(
137 dup(input->fd), input->size, flags, buffer_type, descriptor.GetFormat(), INT(alignedw),
138 INT(alignedh), dup(input->fd_metadata), input->offset_metadata, input->base_metadata,
139 descriptor.GetWidth(), descriptor.GetHeight(), descriptor.GetProducerUsage(),
140 descriptor.GetConsumerUsage());
141
142 *outbuffer = out_hnd;
143}
144
145gralloc1_error_t BufferManager::FreeBuffer(private_handle_t const *hnd) {
146 if (allocator_->FreeBuffer(reinterpret_cast<void *>(hnd->base), hnd->size, hnd->offset,
147 hnd->fd) != 0) {
148 return GRALLOC1_ERROR_BAD_HANDLE;
149 }
150
151 unsigned int meta_size = ALIGN((unsigned int)sizeof(MetaData_t), PAGE_SIZE);
152 if (allocator_->FreeBuffer(reinterpret_cast<void *>(hnd->base_metadata), meta_size,
153 hnd->offset_metadata, hnd->fd_metadata) != 0) {
154 return GRALLOC1_ERROR_BAD_HANDLE;
155 }
156
157 // delete handle also
158 private_handle_t *handle = const_cast<private_handle_t *>(hnd);
159 delete handle;
160
161 return GRALLOC1_ERROR_NONE;
162}
163
164gralloc1_error_t BufferManager::MapBuffer(private_handle_t const *handle) {
165 private_handle_t *hnd = const_cast<private_handle_t *>(handle);
166
167 hnd->base = 0;
168 hnd->base_metadata = 0;
169 if (allocator_->MapBuffer(reinterpret_cast<void **>(&hnd->base), hnd->size, hnd->offset,
170 hnd->fd) != 0) {
171 return GRALLOC1_ERROR_BAD_HANDLE;
172 }
173
174 unsigned int size = ALIGN((unsigned int)sizeof(MetaData_t), PAGE_SIZE);
175 if (allocator_->MapBuffer(reinterpret_cast<void **>(&hnd->base_metadata), size,
176 hnd->offset_metadata, hnd->fd_metadata) != 0) {
177 return GRALLOC1_ERROR_BAD_HANDLE;
178 }
179
180 return GRALLOC1_ERROR_NONE;
181}
182
183gralloc1_error_t BufferManager::RetainBuffer(private_handle_t const *hnd) {
184 locker_.lock();
185
186 // find if this handle is already in map
187 auto it = handles_map_.find(hnd);
188 if (it != handles_map_.end()) {
189 // It's already in map, Just increment refcnt
190 // No need to mmap the memory.
191 it->second = it->second + 1;
192 } else {
193 // not present in the map. mmap and then add entry to map
194 if (MapBuffer(hnd) == GRALLOC1_ERROR_NONE) {
195 handles_map_.insert(std::pair<private_handle_t const *, int>(hnd, 1));
196 }
197 }
198
199 locker_.unlock();
200 return GRALLOC1_ERROR_NONE;
201}
202
203gralloc1_error_t BufferManager::ReleaseBuffer(private_handle_t const *hnd) {
204 locker_.lock();
205
206 // find if this handle is already in map
207 auto it = handles_map_.find(hnd);
208 if (it == handles_map_.end()) {
209 // Corrupt handle or map.
210 locker_.unlock();
211 return GRALLOC1_ERROR_BAD_HANDLE;
212 } else {
213 it->second = it->second - 1;
214 }
215
216 if (!it->second) {
217 handles_map_.erase(it);
218 FreeBuffer(hnd);
219 }
220
221 locker_.unlock();
222 return GRALLOC1_ERROR_NONE;
223}
224
225gralloc1_error_t BufferManager::LockBuffer(const private_handle_t *hnd,
226 gralloc1_producer_usage_t prod_usage,
227 gralloc1_consumer_usage_t cons_usage) {
228 gralloc1_error_t err = GRALLOC1_ERROR_NONE;
229
230 // If buffer is not meant for CPU return err
231 if (!CpuCanAccess(prod_usage, cons_usage)) {
232 return GRALLOC1_ERROR_BAD_VALUE;
233 }
234
235 if (hnd->base == 0) {
236 // we need to map for real
237 locker_.lock();
238 err = MapBuffer(hnd);
239 locker_.unlock();
240 }
241
242 // Invalidate if CPU reads in software and there are non-CPU
243 // writers. No need to do this for the metadata buffer as it is
244 // only read/written in software.
245 if (!err && (hnd->flags & private_handle_t::PRIV_FLAGS_USES_ION) &&
246 (hnd->flags & private_handle_t::PRIV_FLAGS_CACHED)) {
247 if (allocator_->CleanBuffer(reinterpret_cast<void *>(hnd->base), hnd->size, hnd->offset,
248 hnd->fd, CACHE_INVALIDATE)) {
249 return GRALLOC1_ERROR_BAD_HANDLE;
250 }
251 }
252
253 // Mark the buffer to be flushed after CPU write.
254 if (!err && CpuCanWrite(prod_usage)) {
255 private_handle_t *handle = const_cast<private_handle_t *>(hnd);
256 handle->flags |= private_handle_t::PRIV_FLAGS_NEEDS_FLUSH;
257 }
258
259 return err;
260}
261
262gralloc1_error_t BufferManager::UnlockBuffer(const private_handle_t *handle) {
263 gralloc1_error_t status = GRALLOC1_ERROR_NONE;
264
265 locker_.lock();
266 private_handle_t *hnd = const_cast<private_handle_t *>(handle);
267
268 if (hnd->flags & private_handle_t::PRIV_FLAGS_NEEDS_FLUSH) {
269 if (allocator_->CleanBuffer(reinterpret_cast<void *>(hnd->base), hnd->size, hnd->offset,
270 hnd->fd, CACHE_CLEAN) != 0) {
271 status = GRALLOC1_ERROR_BAD_HANDLE;
272 }
273 hnd->flags &= ~private_handle_t::PRIV_FLAGS_NEEDS_FLUSH;
274 }
275
276 locker_.unlock();
277 return status;
278}
279
280int BufferManager::GetDataAlignment(int format, gralloc1_producer_usage_t prod_usage,
281 gralloc1_consumer_usage_t cons_usage) {
282 int align = getpagesize();
283 if (format == HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED) {
284 align = 8192;
285 }
286
287 if (prod_usage & GRALLOC1_PRODUCER_USAGE_PROTECTED) {
Sushil Chauhandfe55a22016-09-12 15:48:29 -0700288 if ((prod_usage & GRALLOC1_PRODUCER_USAGE_CAMERA) ||
289 (cons_usage & GRALLOC1_CONSUMER_USAGE_PRIVATE_SECURE_DISPLAY)) {
Prabhanjan Kandula96e92342016-03-24 21:03:35 +0530290 // The alignment here reflects qsee mmu V7L/V8L requirement
291 align = SZ_2M;
292 } else {
293 align = SECURE_ALIGN;
294 }
295 }
296
297 return align;
298}
299
300int BufferManager::GetHandleFlags(int format, gralloc1_producer_usage_t prod_usage,
301 gralloc1_consumer_usage_t cons_usage) {
302 int flags = 0;
303 if (cons_usage & GRALLOC1_CONSUMER_USAGE_PRIVATE_EXTERNAL_ONLY) {
304 flags |= private_handle_t::PRIV_FLAGS_EXTERNAL_ONLY;
305 }
306
307 if (cons_usage & GRALLOC1_CONSUMER_USAGE_PRIVATE_INTERNAL_ONLY) {
308 flags |= private_handle_t::PRIV_FLAGS_INTERNAL_ONLY;
309 }
310
311 if (cons_usage & GRALLOC1_CONSUMER_USAGE_VIDEO_ENCODER) {
312 flags |= private_handle_t::PRIV_FLAGS_VIDEO_ENCODER;
313 }
314
315 if (prod_usage & GRALLOC1_PRODUCER_USAGE_CAMERA) {
316 flags |= private_handle_t::PRIV_FLAGS_CAMERA_WRITE;
317 }
318
319 if (prod_usage & GRALLOC1_CONSUMER_USAGE_CAMERA) {
320 flags |= private_handle_t::PRIV_FLAGS_CAMERA_READ;
321 }
322
323 if (cons_usage & GRALLOC1_CONSUMER_USAGE_HWCOMPOSER) {
324 flags |= private_handle_t::PRIV_FLAGS_HW_COMPOSER;
325 }
326
327 if (prod_usage & GRALLOC1_CONSUMER_USAGE_GPU_TEXTURE) {
328 flags |= private_handle_t::PRIV_FLAGS_HW_TEXTURE;
329 }
330
331 if (prod_usage & GRALLOC1_CONSUMER_USAGE_PRIVATE_SECURE_DISPLAY) {
332 flags |= private_handle_t::PRIV_FLAGS_SECURE_DISPLAY;
333 }
334
Prabhanjan Kandula96e92342016-03-24 21:03:35 +0530335 if (allocator_->IsUBwcEnabled(format, prod_usage, cons_usage)) {
336 flags |= private_handle_t::PRIV_FLAGS_UBWC_ALIGNED;
337 }
338
339 if (prod_usage & (GRALLOC1_PRODUCER_USAGE_CPU_READ | GRALLOC1_PRODUCER_USAGE_CPU_WRITE)) {
340 flags |= private_handle_t::PRIV_FLAGS_CPU_RENDERED;
341 }
342
343 // TODO(user): is this correct???
344 if ((cons_usage &
345 (GRALLOC1_CONSUMER_USAGE_VIDEO_ENCODER | GRALLOC1_CONSUMER_USAGE_CLIENT_TARGET)) ||
346 (prod_usage & (GRALLOC1_PRODUCER_USAGE_CAMERA | GRALLOC1_PRODUCER_USAGE_GPU_RENDER_TARGET))) {
347 flags |= private_handle_t::PRIV_FLAGS_NON_CPU_WRITER;
348 }
349
350 if (cons_usage & GRALLOC1_CONSUMER_USAGE_HWCOMPOSER) {
351 flags |= private_handle_t::PRIV_FLAGS_DISP_CONSUMER;
352 }
353
354 if (!allocator_->UseUncached(prod_usage)) {
355 flags |= private_handle_t::PRIV_FLAGS_CACHED;
356 }
357
358 return flags;
359}
360
Ramkumar Radhakrishnanba55eac2016-08-26 22:33:48 -0700361int BufferManager::AllocateBuffer(unsigned int size, int aligned_w, int aligned_h, int unaligned_w,
362 int unaligned_h, int format, int bufferType,
Prabhanjan Kandula96e92342016-03-24 21:03:35 +0530363 gralloc1_producer_usage_t prod_usage,
364 gralloc1_consumer_usage_t cons_usage, buffer_handle_t *handle) {
365 int err = 0;
366 int flags = 0;
367 size = ALIGN(size, PAGE_SIZE);
368 AllocData data;
369 data.align = (unsigned int)GetDataAlignment(format, prod_usage, cons_usage);
370 size = ALIGN(size, data.align);
371 data.size = size;
372 data.handle = (uintptr_t)handle;
373
374 // Allocate memory
375 data.uncached = allocator_->UseUncached(prod_usage);
376 err = allocator_->AllocateMem(&data, prod_usage, cons_usage);
377 if (err) {
378 ALOGE("gralloc failed to allocate err=%s", strerror(-err));
379 *handle = 0;
380 return err;
381 }
382
383 // allocate memory for MetaData
384 AllocData e_data;
385 e_data.size = ALIGN((unsigned int)sizeof(MetaData_t), PAGE_SIZE);
386 e_data.handle = data.handle;
387 e_data.align = (unsigned int)getpagesize();
388
389 ColorSpace_t colorSpace = ITU_R_601;
390 if (prod_usage & GRALLOC1_PRODUCER_USAGE_CAMERA) {
391 colorSpace = ITU_R_601_FR;
392 }
393
394 err =
395 allocator_->AllocateMem(&e_data, GRALLOC1_PRODUCER_USAGE_NONE, GRALLOC1_CONSUMER_USAGE_NONE);
396 ALOGE_IF(err, "gralloc failed for e_daata error=%s", strerror(-err));
397
398 flags = GetHandleFlags(format, prod_usage, cons_usage);
399 flags |= data.alloc_type;
400
401 // Create handle
402 uint64_t eBaseAddr = (uint64_t)(e_data.base) + e_data.offset;
403 private_handle_t *hnd = new private_handle_t(data.fd, size, flags, bufferType, format, aligned_w,
404 aligned_h, e_data.fd, e_data.offset, eBaseAddr,
Ramkumar Radhakrishnanba55eac2016-08-26 22:33:48 -0700405 unaligned_w, unaligned_h, prod_usage, cons_usage);
Prabhanjan Kandula96e92342016-03-24 21:03:35 +0530406
407 hnd->offset = data.offset;
408 hnd->base = (uint64_t)(data.base) + data.offset;
409 hnd->gpuaddr = 0;
410
411 setMetaData(hnd, UPDATE_COLOR_SPACE, reinterpret_cast<void *>(&colorSpace));
412
413 *handle = hnd;
414
415 // we have just allocated the buffer & mmapped. Add to map
416 locker_.lock();
417 handles_map_.insert(std::pair<private_handle_t const *, int>(hnd, 1));
418 locker_.unlock();
419
420 return err;
421}
422
423int BufferManager::GetBufferType(int inputFormat) {
424 int buffer_type = BUFFER_TYPE_VIDEO;
425 if (IsUncompressedRGBFormat(inputFormat)) {
426 // RGB formats
427 buffer_type = BUFFER_TYPE_UI;
428 }
429
430 return buffer_type;
431}
432
433int BufferManager::AllocateBuffer(const BufferDescriptor &descriptor, buffer_handle_t *handle,
434 unsigned int bufferSize) {
435 if (!handle)
436 return -EINVAL;
437
438 int format = descriptor.GetFormat();
439 gralloc1_producer_usage_t prod_usage = descriptor.GetProducerUsage();
440 gralloc1_consumer_usage_t cons_usage = descriptor.GetConsumerUsage();
441
442 // Get implementation defined format
443 int gralloc_format = allocator_->GetImplDefinedFormat(prod_usage, cons_usage, format);
444
445 bool use_fb_mem = false;
446 if ((cons_usage & GRALLOC1_CONSUMER_USAGE_CLIENT_TARGET) && map_fb_mem_) {
447 use_fb_mem = true;
448 }
449
450 if ((cons_usage & GRALLOC1_CONSUMER_USAGE_CLIENT_TARGET) && ubwc_for_fb_) {
451 prod_usage =
452 (gralloc1_producer_usage_t)(prod_usage | GRALLOC1_PRODUCER_USAGE_PRIVATE_ALLOC_UBWC);
453 }
454
455 unsigned int size;
456 unsigned int alignedw, alignedh;
457 int buffer_type = GetBufferType(gralloc_format);
458 allocator_->GetBufferSizeAndDimensions(descriptor, &size, &alignedw, &alignedh);
459
460 size = (bufferSize >= size) ? bufferSize : size;
461
462 int err = 0;
463 if (use_fb_mem) {
464 // TODO(user): TBD Framebuffer specific implementation in a seperate file/class
465 } else {
466 err = AllocateBuffer(size, INT(alignedw), INT(alignedh), descriptor.GetWidth(),
467 descriptor.GetHeight(), format, buffer_type, descriptor.GetProducerUsage(),
468 descriptor.GetConsumerUsage(), handle);
469 }
470
471 if (err < 0) {
472 return err;
473 }
474
475 return 0;
476}
477
478gralloc1_error_t BufferManager::Perform(int operation, va_list args) {
479 switch (operation) {
480 case GRALLOC_MODULE_PERFORM_CREATE_HANDLE_FROM_BUFFER: {
481 int fd = va_arg(args, int);
482 unsigned int size = va_arg(args, unsigned int);
483 unsigned int offset = va_arg(args, unsigned int);
484 void *base = va_arg(args, void *);
485 int width = va_arg(args, int);
486 int height = va_arg(args, int);
487 int format = va_arg(args, int);
488
489 native_handle_t **handle = va_arg(args, native_handle_t **);
490 private_handle_t *hnd = reinterpret_cast<private_handle_t *>(
491 native_handle_create(private_handle_t::kNumFds, private_handle_t::NumInts()));
492 if (hnd) {
Ramkumar Radhakrishnanba55eac2016-08-26 22:33:48 -0700493 unsigned int alignedw = 0, alignedh = 0;
Prabhanjan Kandula96e92342016-03-24 21:03:35 +0530494 hnd->magic = private_handle_t::kMagic;
495 hnd->fd = fd;
496 hnd->flags = private_handle_t::PRIV_FLAGS_USES_ION;
497 hnd->size = size;
498 hnd->offset = offset;
499 hnd->base = uint64_t(base) + offset;
500 hnd->gpuaddr = 0;
Ramkumar Radhakrishnanba55eac2016-08-26 22:33:48 -0700501 BufferDescriptor descriptor(width, height, format);
502 allocator_->GetAlignedWidthAndHeight(descriptor, &alignedw, &alignedh);
503 hnd->unaligned_width = width;
504 hnd->unaligned_height = height;
505 hnd->width = alignedw;
506 hnd->height = alignedh;
Prabhanjan Kandula96e92342016-03-24 21:03:35 +0530507 hnd->format = format;
508 *handle = reinterpret_cast<native_handle_t *>(hnd);
509 }
510 } break;
511
512 case GRALLOC_MODULE_PERFORM_GET_STRIDE: {
513 int width = va_arg(args, int);
514 int format = va_arg(args, int);
515 int *stride = va_arg(args, int *);
516 unsigned int alignedw = 0, alignedh = 0;
517 BufferDescriptor descriptor(width, width, format);
518 allocator_->GetAlignedWidthAndHeight(descriptor, &alignedw, &alignedh);
519 *stride = INT(alignedw);
520 } break;
521
522 case GRALLOC_MODULE_PERFORM_GET_CUSTOM_STRIDE_FROM_HANDLE: {
523 private_handle_t *hnd = va_arg(args, private_handle_t *);
524 int *stride = va_arg(args, int *);
525 if (private_handle_t::validate(hnd) != 0) {
526 return GRALLOC1_ERROR_BAD_HANDLE;
527 }
528
529 MetaData_t *metadata = reinterpret_cast<MetaData_t *>(hnd->base_metadata);
530 if (metadata && metadata->operation & UPDATE_BUFFER_GEOMETRY) {
531 *stride = metadata->bufferDim.sliceWidth;
532 } else {
533 *stride = hnd->width;
534 }
535 } break;
536
537 // TODO(user) : this alone should be sufficient, ask gfx to get rid of above
538 case GRALLOC_MODULE_PERFORM_GET_CUSTOM_STRIDE_AND_HEIGHT_FROM_HANDLE: {
539 private_handle_t *hnd = va_arg(args, private_handle_t *);
540 int *stride = va_arg(args, int *);
541 int *height = va_arg(args, int *);
542 if (private_handle_t::validate(hnd) != 0) {
543 return GRALLOC1_ERROR_BAD_HANDLE;
544 }
545
546 MetaData_t *metadata = reinterpret_cast<MetaData_t *>(hnd->base_metadata);
547 if (metadata && metadata->operation & UPDATE_BUFFER_GEOMETRY) {
548 *stride = metadata->bufferDim.sliceWidth;
549 *height = metadata->bufferDim.sliceHeight;
550 } else {
551 *stride = hnd->width;
552 *height = hnd->height;
553 }
554 } break;
555
556 case GRALLOC_MODULE_PERFORM_GET_ATTRIBUTES: {
557 // TODO(user): Usage is split now. take care of it from Gfx client.
558 // see if we can directly expect descriptor from gfx client.
559 int width = va_arg(args, int);
560 int height = va_arg(args, int);
561 int format = va_arg(args, int);
562 uint64_t producer_usage = va_arg(args, uint64_t);
563 uint64_t consumer_usage = va_arg(args, uint64_t);
564 gralloc1_producer_usage_t prod_usage = static_cast<gralloc1_producer_usage_t>(producer_usage);
565 gralloc1_consumer_usage_t cons_usage = static_cast<gralloc1_consumer_usage_t>(consumer_usage);
566
567 int *aligned_width = va_arg(args, int *);
568 int *aligned_height = va_arg(args, int *);
569 int *tile_enabled = va_arg(args, int *);
570 unsigned int alignedw, alignedh;
571 BufferDescriptor descriptor(width, height, format, prod_usage, cons_usage);
Saurabh Shahc5b2b702016-10-24 17:16:01 -0700572 *tile_enabled = allocator_->IsUBwcEnabled(format, prod_usage, cons_usage);
Prabhanjan Kandula96e92342016-03-24 21:03:35 +0530573
574 allocator_->GetAlignedWidthAndHeight(descriptor, &alignedw, &alignedh);
575 *aligned_width = INT(alignedw);
576 *aligned_height = INT(alignedh);
577 } break;
578
579 case GRALLOC_MODULE_PERFORM_GET_COLOR_SPACE_FROM_HANDLE: {
580 private_handle_t *hnd = va_arg(args, private_handle_t *);
581 int *color_space = va_arg(args, int *);
582 if (private_handle_t::validate(hnd) != 0) {
583 return GRALLOC1_ERROR_BAD_HANDLE;
584 }
585 MetaData_t *metadata = reinterpret_cast<MetaData_t *>(hnd->base_metadata);
Arun Kumar K.Rb2771bf2016-10-03 21:38:23 -0700586 if (!metadata) {
587 return GRALLOC1_ERROR_BAD_HANDLE;
588#ifdef USE_COLOR_METADATA
589 } else if (metadata->operation & COLOR_METADATA) {
590 ColorMetaData *colorMetadata = &metadata->color;
591 switch (colorMetadata->colorPrimaries) {
592 case ColorPrimaries_BT709_5:
593 *color_space = HAL_CSC_ITU_R_709;
594 break;
595 case ColorPrimaries_BT601_6_525:
596 *color_space = ((colorMetadata->range) ? HAL_CSC_ITU_R_601_FR : HAL_CSC_ITU_R_601);
597 break;
598 case ColorPrimaries_BT2020:
599 *color_space = (colorMetadata->range) ? HAL_CSC_ITU_R_2020_FR : HAL_CSC_ITU_R_2020;
600 break;
601 default:
602 ALOGE("Unknown Color Space = %d", colorMetadata->colorPrimaries);
603 break;
604 }
605#endif
606 } else if (metadata->operation & UPDATE_COLOR_SPACE) {
Prabhanjan Kandula96e92342016-03-24 21:03:35 +0530607 *color_space = metadata->colorSpace;
608 }
609 } break;
610 case GRALLOC_MODULE_PERFORM_GET_YUV_PLANE_INFO: {
611 private_handle_t *hnd = va_arg(args, private_handle_t *);
612 android_ycbcr *ycbcr = va_arg(args, struct android_ycbcr *);
613 if (private_handle_t::validate(hnd) != 0) {
614 return GRALLOC1_ERROR_BAD_HANDLE;
615 }
616 if (allocator_->GetYUVPlaneInfo(hnd, ycbcr)) {
617 return GRALLOC1_ERROR_UNDEFINED;
618 }
619 } break;
620
621 case GRALLOC_MODULE_PERFORM_GET_MAP_SECURE_BUFFER_INFO: {
622 private_handle_t *hnd = va_arg(args, private_handle_t *);
623 int *map_secure_buffer = va_arg(args, int *);
624 if (private_handle_t::validate(hnd) != 0) {
625 return GRALLOC1_ERROR_BAD_HANDLE;
626 }
627 MetaData_t *metadata = reinterpret_cast<MetaData_t *>(hnd->base_metadata);
628 if (metadata && metadata->operation & MAP_SECURE_BUFFER) {
629 *map_secure_buffer = metadata->mapSecureBuffer;
630 } else {
631 *map_secure_buffer = 0;
632 }
633 } break;
634
635 case GRALLOC_MODULE_PERFORM_GET_UBWC_FLAG: {
636 private_handle_t *hnd = va_arg(args, private_handle_t *);
637 int *flag = va_arg(args, int *);
638 if (private_handle_t::validate(hnd) != 0) {
639 return GRALLOC1_ERROR_BAD_HANDLE;
640 }
641 *flag = hnd->flags &private_handle_t::PRIV_FLAGS_UBWC_ALIGNED;
642 } break;
643
644 case GRALLOC_MODULE_PERFORM_GET_RGB_DATA_ADDRESS: {
645 private_handle_t *hnd = va_arg(args, private_handle_t *);
646 void **rgb_data = va_arg(args, void **);
647 if (private_handle_t::validate(hnd) != 0) {
648 return GRALLOC1_ERROR_BAD_HANDLE;
649 }
650 if (allocator_->GetRgbDataAddress(hnd, rgb_data)) {
651 return GRALLOC1_ERROR_UNDEFINED;
652 }
653 } break;
654
655 default:
656 break;
657 }
658
659 return GRALLOC1_ERROR_NONE;
660}
661
662} // namespace gralloc1