/*=========================================================================== * FUNCTION : allocate * * DESCRIPTION: allocate requested number of buffers of certain size * * PARAMETERS : * @count : number of buffers to be allocated * @size : lenght of the buffer to be allocated * * RETURN : int32_t type of status * NO_ERROR -- success * none-zero failure code *==========================================================================*/ int QCameraVideoMemory::allocate(int count, int size) { int rc = QCameraStreamMemory::allocate(count, size); if (rc < 0) return rc; for (int i = 0; i < count; i ++) { mMetadata[i] = mGetMemory(-1, sizeof(struct encoder_media_buffer_type), 1, this); if (!mMetadata[i]) { ALOGE("allocation of video metadata failed."); for (int j = 0; j < i-1; j ++) mMetadata[j]->release(mMetadata[j]); QCameraStreamMemory::deallocate(); return NO_MEMORY; } struct encoder_media_buffer_type * packet = (struct encoder_media_buffer_type *)mMetadata[i]->data; packet->meta_handle = native_handle_create(1, 2); //1 fd, 1 offset and 1 size packet->buffer_type = kMetadataBufferTypeCameraSource; native_handle_t * nh = const_cast<native_handle_t *>(packet->meta_handle); nh->data[0] = mMemInfo[i].fd; nh->data[1] = 0; nh->data[2] = mMemInfo[i].size; } mBufferCount = count; return NO_ERROR; }
static void ssb_buffer(void *data, android_wlegl_server_buffer_handle *, wl_buffer *buffer, int32_t format, int32_t stride) { ServerWaylandBuffer *wsb = static_cast<ServerWaylandBuffer *>(data); native_handle_t *native; int numFds = wsb->fds.size / sizeof(int); int numInts = wsb->ints.size / sizeof(int32_t); native = native_handle_create(numFds, numInts); memcpy(&native->data[0], wsb->fds.data, wsb->fds.size); memcpy(&native->data[numFds], wsb->ints.data, wsb->ints.size); /* ownership of fds passed to native_handle_t */ wsb->fds.size = 0; wsb->handle = (buffer_handle_t) native; wsb->format = format; wsb->stride = stride; int ret = wsb->m_gralloc->registerBuffer(wsb->m_gralloc, wsb->handle); if (ret) { fprintf(stderr,"failed to register buffer\n"); return; } wsb->common.incRef(&wsb->common); wsb->m_buf = buffer; }
status_t GraphicBuffer::unflatten( void const*& buffer, size_t& size, int const*& fds, size_t& count) { if (size < 8*sizeof(int)) return NO_MEMORY; int const* buf = static_cast<int const*>(buffer); if (buf[0] != 'GBFR') return BAD_TYPE; const size_t numFds = buf[6]; const size_t numInts = buf[7]; const size_t sizeNeeded = (8 + numInts) * sizeof(int); if (size < sizeNeeded) return NO_MEMORY; size_t fdCountNeeded = 0; if (count < fdCountNeeded) return NO_MEMORY; if (handle) { // free previous handle if any free_handle(); } if (numFds || numInts) { width = buf[1]; height = buf[2]; stride = buf[3]; format = buf[4]; usage = buf[5]; native_handle* h = native_handle_create(numFds, numInts); memcpy(h->data, fds, numFds*sizeof(int)); memcpy(h->data + numFds, &buf[8], numInts*sizeof(int)); handle = h; #ifndef MTK_DEFAULT_AOSP ALOGD("create handle(%p) (w:%d, h:%d, f:%d)", handle, stride, height, format); #endif } else { width = height = stride = format = usage = 0; handle = NULL; } mOwner = ownHandle; if (handle != 0) { status_t err = mBufferMapper.registerBuffer(handle); if (err != NO_ERROR) { width = height = stride = format = usage = 0; handle = NULL; ALOGE("unflatten: registerBuffer failed: %s (%d)", strerror(-err), err); return err; } } buffer = reinterpret_cast<void const*>(static_cast<int const*>(buffer) + sizeNeeded); size -= sizeNeeded; fds += numFds; count -= numFds; return NO_ERROR; }
bool ParamTraits<GonkNativeHandle>::Read(const Message* aMsg, void** aIter, paramType* aResult) { size_t nbytes; const char* data; if (!aMsg->ReadSize(aIter, &nbytes) || !aMsg->ReadBytes(aIter, &data, nbytes)) { return false; } if (nbytes % sizeof(int) != 0) { return false; } size_t numInts = nbytes / sizeof(int); size_t numFds = aMsg->num_fds(); native_handle* nativeHandle = native_handle_create(numFds, numInts); if (!nativeHandle) { return false; } memcpy(nativeHandle->data + nativeHandle->numFds, data, nbytes); for (size_t i = 0; i < static_cast<size_t>(nativeHandle->numFds); ++i) { base::FileDescriptor fd; if (!aMsg->ReadFileDescriptor(aIter, &fd)) { return false; } nativeHandle->data[i] = fd.fd; } return true; }
native_handle_t *JNativeHandle::MakeCppNativeHandle( JNIEnv *env, jobject jHandle, EphemeralStorage *storage) { if (jHandle == nullptr) { return nullptr; } if (!env->IsInstanceOf(jHandle, gNativeHandleFields.clazz)) { jniThrowException(env, "java/lang/ClassCastException", "jHandle must be an instance of NativeHandle."); return nullptr; } ScopedLocalRef<jintArray> fds(env, (jintArray) env->CallObjectMethod( jHandle, gNativeHandleFields.getFdsID)); ScopedLocalRef<jintArray> ints(env, (jintArray) env->CallObjectMethod( jHandle, gNativeHandleFields.getIntsID)); const int numFds = (int) env->GetArrayLength(fds.get()); const int numInts = (int) env->GetArrayLength(ints.get()); native_handle_t *handle = (storage == nullptr) ? native_handle_create(numFds, numInts) : storage->allocTemporaryNativeHandle(numFds, numInts); if (handle != nullptr) { env->GetIntArrayRegion(fds.get(), 0, numFds, &(handle->data[0])); env->GetIntArrayRegion(ints.get(), 0, numInts, &(handle->data[numFds])); } else { jniThrowException(env, "java/lang/OutOfMemoryError", "Failed to allocate memory for native_handle_t."); } return handle; }
int gralloc_create_handle_from_buffer_pmem(int fd, size_t size, size_t offset, void* base, native_handle_t** handle) { struct hwmem_gralloc_buf_handle_t* hwmem_gralloc_buf_handle; int is_pmem_fd_var; if (!is_pmem_fd(fd, &is_pmem_fd_var)) return -errno; if (!is_pmem_fd_var) return -EINVAL; hwmem_gralloc_buf_handle = (struct hwmem_gralloc_buf_handle_t*)native_handle_create( num_fds_in_hwmem_gralloc_buf_handle, num_ints_in_hwmem_gralloc_buf_handle); if (NULL == hwmem_gralloc_buf_handle) { return -ENOMEM; } hwmem_gralloc_buf_handle->fd = fd; hwmem_gralloc_buf_handle->flags = PRIV_FLAGS_USES_PMEM; hwmem_gralloc_buf_handle->type_identifier = hwmem_gralloc_buf_handle_type_identifier; hwmem_gralloc_buf_handle->type = GRALLOC_BUF_TYPE_PMEM; hwmem_gralloc_buf_handle->size = size; hwmem_gralloc_buf_handle->offset = offset; hwmem_gralloc_buf_handle->base_addr = (int)base + offset; hwmem_gralloc_buf_handle->lockState = LOCK_STATE_MAPPED; *handle = (native_handle_t*)hwmem_gralloc_buf_handle; return 0; }
int gralloc_perform(struct gralloc_module_t const* module, int operation, ... ) { int res = -EINVAL; va_list args; va_start(args, operation); switch (operation) { case GRALLOC_MODULE_PERFORM_CREATE_HANDLE_FROM_BUFFER: { int fd = va_arg(args, int); size_t size = va_arg(args, size_t); size_t offset = va_arg(args, size_t); void* base = va_arg(args, void*); native_handle_t** handle = va_arg(args, native_handle_t**); private_handle_t* hnd = (private_handle_t*)native_handle_create( private_handle_t::sNumFds, private_handle_t::sNumInts); hnd->magic = private_handle_t::sMagic; hnd->fd = fd; hnd->flags = private_handle_t::PRIV_FLAGS_USES_PMEM; hnd->size = size; hnd->offset = offset; hnd->base = intptr_t(base) + offset; hnd->lockState = private_handle_t::LOCK_STATE_MAPPED; *handle = (native_handle_t *)hnd; res = 0; break; } } va_end(args); return res; }
static native_handle_t *control_open_data_source(struct sensors_control_device_t *dev) { native_handle_t *hd; #if 0 if (event_fd != -1) { LOGE("Sensor open and not yet closed\n"); return NULL; } #endif if (control_fd[0] == -1 && control_fd[1] == -1) { if (socketpair(AF_LOCAL, SOCK_STREAM, 0, control_fd) < 0 ) { LOGE("could not create thread control socket pair: %s", strerror(errno)); return NULL; } } LOGD("%s sensor_fd=%d\n", __func__, sensor_fd); hd = native_handle_create(1, 0); hd->data[0] = control_fd[0]; return hd; }
status_t StreamHalHidl::dump(int fd) { if (!mStream) return NO_INIT; native_handle_t* hidlHandle = native_handle_create(1, 0); hidlHandle->data[0] = fd; Return<void> ret = mStream->debugDump(hidlHandle); native_handle_delete(hidlHandle); return processReturn("dump", ret); }
static native_handle_t* sensors_control_open_data_source(struct sensors_control_device_t *dev) { LOGI("sensors_control_open_data_source"); native_handle * nh = native_handle_create(1, 0); nh->data[0] = open_input(); return nh; }
native_handle_t *open_data_source(struct sensors_control_device_t *dev) { native_handle_t *hdl=native_handle_create(1,0); hdl->data[0]=sFD; #ifdef DEBUG LOGE("called open_data_source"); #endif return hdl; }
status_t GraphicBuffer::unflatten(void const* buffer, size_t size, int fds[], size_t count) { if (size < 8*sizeof(int)) return NO_MEMORY; int const* buf = static_cast<int const*>(buffer); if (buf[0] != 'GBFR') return BAD_TYPE; const size_t numFds = buf[6]; const size_t numInts = buf[7]; const size_t sizeNeeded = (8 + numInts) * sizeof(int); if (size < sizeNeeded) return NO_MEMORY; size_t fdCountNeeded = 0; if (count < fdCountNeeded) return NO_MEMORY; if (handle) { // free previous handle if any free_handle(); } if (numFds || numInts) { width = buf[1]; height = buf[2]; stride = buf[3]; format = buf[4]; usage = buf[5]; native_handle* h = native_handle_create(numFds, numInts); memcpy(h->data, fds, numFds*sizeof(int)); memcpy(h->data + numFds, &buf[8], numInts*sizeof(int)); handle = h; } else { width = height = stride = format = usage = 0; handle = NULL; } mOwner = ownHandle; if (handle != 0) { status_t err = mBufferMapper.registerBuffer(handle); if (err != NO_ERROR) { width = height = stride = format = usage = 0; handle = NULL; ALOGE("unflatten: registerBuffer failed: %s (%d)", strerror(-err), err); return err; } } return NO_ERROR; }
/* this must return a file descriptor that will be used to read * the sensors data (it is passed to data__data_open() below */ static native_handle_t* control__open_data_source(struct sensors_poll_device_t *dev) { SensorPoll* ctl = (void*)dev; native_handle_t* handle; if (ctl->fd < 0) { ctl->fd = qemud_channel_open(SENSORS_SERVICE_NAME); } D("%s: fd=%d", __FUNCTION__, ctl->fd); handle = native_handle_create(1, 0); handle->data[0] = dup(ctl->fd); return handle; }
buffer_handle_t wlegl_handle_create_native(struct wlegl_handle *handle) { native_handle_t *native; native = native_handle_create(handle->num_fds, handle->num_ints); if (!native) return NULL; memcpy(&native->data[0], handle->fds.data, handle->fds.size); memcpy(&native->data[handle->num_fds], handle->ints.data, handle->ints.size); handle->fds.size = 0; return native; }
//#define UNIX_DOMAIN "unix.domain" static native_handle_t* control__open_data_source(struct sensors_control_device_t *dev) { native_handle_t* handle; int acc_event_fd, mag_event_fd; D("%s", __FUNCTION__); if (open_inputs(&acc_event_fd, &mag_event_fd) < 0) return NULL; handle = native_handle_create(2, 0); handle->data[0] = acc_event_fd; handle->data[1] = mag_event_fd; return handle; }
static native_handle_t* control__open_data_source(struct sensors_control_context_t *dev) { native_handle_t* handle; int akm_fd, p_fd, l_fd; if (open_inputs(O_RDONLY, &akm_fd, &p_fd, &l_fd) < 0 || akm_fd < 0 || p_fd < 0 || l_fd < 0) { return NULL; } handle = native_handle_create(3, 0); handle->data[0] = akm_fd; handle->data[1] = p_fd; handle->data[2] = l_fd; return handle; }
static native_handle_t* control__open_data_source(struct sensors_control_context_t *dev) { native_handle_t* handle; int acc_fd, ori_fd; if (open_inputs(O_RDONLY, &acc_fd, &ori_fd) < 0 || acc_fd < 0 || ori_fd < 0) { LOGE("open_inputs return failed." ); return NULL; } handle = native_handle_create(2, 0); handle->data[0] = acc_fd; handle->data[1] = ori_fd; //handle->data[2] = l_fd; return handle; }
native_handle_t* sensors_proxy_open_all_dev(SensorsProxy* proxy) { int i=0; native_handle_t* handle = native_handle_create(2, 0);; for(i=0;i<numSensorDrivers;i++) { handle->data[i]= sensor_open_dev(proxy->mSensors[i]); if(handle->data[i]<0) { native_handle_close(handle); native_handle_delete(handle); handle = NULL; break; } } return handle; }
native_handle_t* native_handle_clone(const native_handle_t* handle) { native_handle_t* clone = native_handle_create(handle->numFds, handle->numInts); if (clone == NULL) return NULL; for (int i = 0; i < handle->numFds; i++) { clone->data[i] = dup(handle->data[i]); if (clone->data[i] == -1) { clone->numFds = i; native_handle_close(clone); native_handle_delete(clone); return NULL; } } memcpy(&clone->data[handle->numFds], &handle->data[handle->numFds], sizeof(int) * handle->numInts); return clone; }
status_t GraphicBuffer::unflatten(void const* buffer, size_t size, int fds[], size_t count) { if (size < kFlattenFdsOffset*sizeof(int)) return NO_MEMORY; int const* buf = static_cast<int const*>(buffer); if (buf[0] != 'GBFR') return BAD_TYPE; const size_t numFds = buf[6]; const size_t numInts = buf[7]; const size_t sizeNeeded = (kFlattenFdsOffset + numInts) * sizeof(int); if (size < sizeNeeded) return NO_MEMORY; size_t fdCountNeeded = 0; if (count < fdCountNeeded) return NO_MEMORY; if (handle) { // free previous handle if any free_handle(); } if (numFds || numInts) { width = buf[1]; height = buf[2]; stride = buf[3]; format = buf[4]; usage = buf[5]; transform = buf[8]; native_handle* h = native_handle_create(numFds, numInts); memcpy(h->data, fds, numFds*sizeof(int)); memcpy(h->data + numFds, &buf[kFlattenFdsOffset], numInts*sizeof(int)); handle = h; } else { width = height = stride = format = usage = 0; handle = NULL; } mOwner = ownHandle; return NO_ERROR; }
OMX_U8* OMXVideoDecoderAVCSecure::MemAllocDataBuffer(OMX_U32 nSizeBytes) { ALOGW_IF(nSizeBytes != INPORT_BUFFER_SIZE, "%s: size of memory to allocate is %" PRIu32 ", but will allocate %zu", __FUNCTION__, nSizeBytes, sizeof(ProtectedDataBuffer)); if (mNumInportBuffers >= INPORT_ACTUAL_BUFFER_COUNT) { ALOGE("%s: cannot allocate buffer: number of inport buffers is %u, which is already at maximum", __FUNCTION__, mNumInportBuffers); return NULL; } int fd = ashmem_create_region("protectd-content-buffer", sizeof(ProtectedDataBuffer)); if(fd < 0) { ALOGE("Unable to create ashmem region"); return NULL; } native_handle_t *native = native_handle_create(1, 2); native->data[0] = fd; ProtectedDataBuffer *pBuffer =(ProtectedDataBuffer *) mmap(NULL, sizeof(ProtectedDataBuffer), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (pBuffer == MAP_FAILED) { ALOGE("%s: mmap failed", __FUNCTION__); return NULL; } native->data[1] = (int) pBuffer; // Use a random value as the buffer id native->data[2] = rand(); ++mNumInportBuffers; Init_ProtectedDataBuffer(pBuffer); pBuffer->size = INPORT_BUFFER_SIZE; ALOGV("Allocating native=[%p] buffer = %#x, data = %#x data_end= %#x size=%d",(OMX_U8 *)native,(uint32_t)pBuffer, (uint32_t)pBuffer->data, (uint32_t)pBuffer->data + sizeof(ProtectedDataBuffer) ,sizeof(ProtectedDataBuffer)); return (OMX_U8 *) native; }
int gralloc_perform(struct gralloc_module_t const* module, int operation, ... ) { int res = -EINVAL; va_list args; va_start(args, operation); switch (operation) { case GRALLOC_MODULE_PERFORM_CREATE_HANDLE_FROM_BUFFER: { int fd = va_arg(args, int); size_t size = va_arg(args, size_t); size_t offset = va_arg(args, size_t); void* base = va_arg(args, void*); // validate that it's indeed a pmem buffer pmem_region region; if (ioctl(fd, PMEM_GET_SIZE, ®ion) < 0) { break; } native_handle_t** handle = va_arg(args, native_handle_t**); private_handle_t* hnd = (private_handle_t*)native_handle_create( private_handle_t::sNumFds, private_handle_t::sNumInts); hnd->magic = private_handle_t::sMagic; hnd->fd = fd; hnd->flags = private_handle_t::PRIV_FLAGS_USES_PMEM | private_handle_t::PRIV_FLAGS_DO_NOT_FLUSH; hnd->size = size; hnd->offset = offset; hnd->base = intptr_t(base) + offset; *handle = (native_handle_t *)hnd; res = 0; break; } } va_end(args); return res; }
//Record Related Functions status_t QCameraStream_record::initEncodeBuffers() { ALOGE("%s : BEGIN",__func__); status_t ret = NO_ERROR; for (int cnt = 0; cnt < mHalCamCtrl->mPreviewMemory.buffer_count; cnt++) { if (mHalCamCtrl->mStoreMetaDataInFrame) { mHalCamCtrl->mRecordingMemory.metadata_memory[cnt] = mHalCamCtrl->mGetMemory(-1, sizeof(struct encoder_media_buffer_type), 1, (void *)this); struct encoder_media_buffer_type * packet = (struct encoder_media_buffer_type *) mHalCamCtrl->mRecordingMemory.metadata_memory[cnt]->data; packet->meta_handle = native_handle_create(1, 3); //1 fd, 1 offset,1 size and 1 data packet->buffer_type = kMetadataBufferTypeCameraSource; native_handle_t * nh = const_cast<native_handle_t *>(packet->meta_handle); nh->data[0] = mHalCamCtrl->mPreviewMemory.private_buffer_handle[cnt]->fd; nh->data[1] = 0; nh->data[2] = mHalCamCtrl->mPreviewMemory.private_buffer_handle[cnt]->size; nh->data[3] = (uint32_t)mHalCamCtrl->mPreviewMemory.camera_memory[cnt]->data; } } ALOGE("%s : END",__func__); return NO_ERROR; }
gralloc1_error_t BufferManager::Perform(int operation, va_list args) { switch (operation) { case GRALLOC_MODULE_PERFORM_CREATE_HANDLE_FROM_BUFFER: { int fd = va_arg(args, int); unsigned int size = va_arg(args, unsigned int); unsigned int offset = va_arg(args, unsigned int); void *base = va_arg(args, void *); int width = va_arg(args, int); int height = va_arg(args, int); int format = va_arg(args, int); native_handle_t **handle = va_arg(args, native_handle_t **); private_handle_t *hnd = reinterpret_cast<private_handle_t *>( native_handle_create(private_handle_t::kNumFds, private_handle_t::NumInts())); if (hnd) { unsigned int alignedw = 0, alignedh = 0; hnd->magic = private_handle_t::kMagic; hnd->fd = fd; hnd->flags = private_handle_t::PRIV_FLAGS_USES_ION; hnd->size = size; hnd->offset = offset; hnd->base = uint64_t(base) + offset; hnd->gpuaddr = 0; BufferDescriptor descriptor(width, height, format); allocator_->GetAlignedWidthAndHeight(descriptor, &alignedw, &alignedh); hnd->unaligned_width = width; hnd->unaligned_height = height; hnd->width = INT(alignedw); hnd->height = INT(alignedh); hnd->format = format; *handle = reinterpret_cast<native_handle_t *>(hnd); } } break; case GRALLOC_MODULE_PERFORM_GET_STRIDE: { int width = va_arg(args, int); int format = va_arg(args, int); int *stride = va_arg(args, int *); unsigned int alignedw = 0, alignedh = 0; BufferDescriptor descriptor(width, width, format); allocator_->GetAlignedWidthAndHeight(descriptor, &alignedw, &alignedh); *stride = INT(alignedw); } break; case GRALLOC_MODULE_PERFORM_GET_CUSTOM_STRIDE_FROM_HANDLE: { private_handle_t *hnd = va_arg(args, private_handle_t *); int *stride = va_arg(args, int *); if (private_handle_t::validate(hnd) != 0) { return GRALLOC1_ERROR_BAD_HANDLE; } BufferDim_t buffer_dim; if (getMetaData(hnd, GET_BUFFER_GEOMETRY, &buffer_dim) == 0) { *stride = buffer_dim.sliceWidth; } else { *stride = hnd->width; } } break; // TODO(user) : this alone should be sufficient, ask gfx to get rid of above case GRALLOC_MODULE_PERFORM_GET_CUSTOM_STRIDE_AND_HEIGHT_FROM_HANDLE: { private_handle_t *hnd = va_arg(args, private_handle_t *); int *stride = va_arg(args, int *); int *height = va_arg(args, int *); if (private_handle_t::validate(hnd) != 0) { return GRALLOC1_ERROR_BAD_HANDLE; } BufferDim_t buffer_dim; if (getMetaData(hnd, GET_BUFFER_GEOMETRY, &buffer_dim) == 0) { *stride = buffer_dim.sliceWidth; *height = buffer_dim.sliceHeight; } else { *stride = hnd->width; *height = hnd->height; } } break; case GRALLOC_MODULE_PERFORM_GET_ATTRIBUTES: { // TODO(user): Usage is split now. take care of it from Gfx client. // see if we can directly expect descriptor from gfx client. int width = va_arg(args, int); int height = va_arg(args, int); int format = va_arg(args, int); uint64_t producer_usage = va_arg(args, uint64_t); uint64_t consumer_usage = va_arg(args, uint64_t); gralloc1_producer_usage_t prod_usage = static_cast<gralloc1_producer_usage_t>(producer_usage); gralloc1_consumer_usage_t cons_usage = static_cast<gralloc1_consumer_usage_t>(consumer_usage); int *aligned_width = va_arg(args, int *); int *aligned_height = va_arg(args, int *); int *tile_enabled = va_arg(args, int *); unsigned int alignedw, alignedh; BufferDescriptor descriptor(width, height, format, prod_usage, cons_usage); *tile_enabled = allocator_->IsUBwcEnabled(format, prod_usage, cons_usage); allocator_->GetAlignedWidthAndHeight(descriptor, &alignedw, &alignedh); *aligned_width = INT(alignedw); *aligned_height = INT(alignedh); } break; case GRALLOC_MODULE_PERFORM_GET_COLOR_SPACE_FROM_HANDLE: { private_handle_t *hnd = va_arg(args, private_handle_t *); int *color_space = va_arg(args, int *); if (private_handle_t::validate(hnd) != 0) { return GRALLOC1_ERROR_BAD_HANDLE; } #ifdef USE_COLOR_METADATA ColorMetaData color_metadata; if (getMetaData(hnd, GET_COLOR_METADATA, &color_metadata) == 0) { switch (color_metadata.colorPrimaries) { case ColorPrimaries_BT709_5: *color_space = HAL_CSC_ITU_R_709; break; case ColorPrimaries_BT601_6_525: *color_space = ((color_metadata.range) ? HAL_CSC_ITU_R_601_FR : HAL_CSC_ITU_R_601); break; case ColorPrimaries_BT2020: *color_space = (color_metadata.range) ? HAL_CSC_ITU_R_2020_FR : HAL_CSC_ITU_R_2020; break; default: ALOGE("Unknown Color Space = %d", color_metadata.colorPrimaries); break; } break; } if (getMetaData(hnd, GET_COLOR_SPACE, &color_metadata) != 0) { *color_space = 0; } #else *color_space = 0; #endif } break; case GRALLOC_MODULE_PERFORM_GET_YUV_PLANE_INFO: { private_handle_t *hnd = va_arg(args, private_handle_t *); android_ycbcr *ycbcr = va_arg(args, struct android_ycbcr *); if (private_handle_t::validate(hnd) != 0) { return GRALLOC1_ERROR_BAD_HANDLE; } if (allocator_->GetYUVPlaneInfo(hnd, ycbcr)) { return GRALLOC1_ERROR_UNDEFINED; } } break; case GRALLOC_MODULE_PERFORM_GET_MAP_SECURE_BUFFER_INFO: { private_handle_t *hnd = va_arg(args, private_handle_t *); int *map_secure_buffer = va_arg(args, int *); if (private_handle_t::validate(hnd) != 0) { return GRALLOC1_ERROR_BAD_HANDLE; } if (getMetaData(hnd, GET_MAP_SECURE_BUFFER, map_secure_buffer) == 0) { *map_secure_buffer = 0; } } break; case GRALLOC_MODULE_PERFORM_GET_UBWC_FLAG: { private_handle_t *hnd = va_arg(args, private_handle_t *); int *flag = va_arg(args, int *); if (private_handle_t::validate(hnd) != 0) { return GRALLOC1_ERROR_BAD_HANDLE; } *flag = hnd->flags &private_handle_t::PRIV_FLAGS_UBWC_ALIGNED; } break; case GRALLOC_MODULE_PERFORM_GET_RGB_DATA_ADDRESS: { private_handle_t *hnd = va_arg(args, private_handle_t *); void **rgb_data = va_arg(args, void **); if (private_handle_t::validate(hnd) != 0) { return GRALLOC1_ERROR_BAD_HANDLE; } if (allocator_->GetRgbDataAddress(hnd, rgb_data)) { return GRALLOC1_ERROR_UNDEFINED; } } break; case GRALLOC1_MODULE_PERFORM_GET_BUFFER_SIZE_AND_DIMENSIONS: { int width = va_arg(args, int); int height = va_arg(args, int); int format = va_arg(args, int); uint64_t p_usage = va_arg(args, uint64_t); uint64_t c_usage = va_arg(args, uint64_t); gralloc1_producer_usage_t producer_usage = static_cast<gralloc1_producer_usage_t>(p_usage); gralloc1_consumer_usage_t consumer_usage = static_cast<gralloc1_consumer_usage_t>(c_usage); uint32_t *aligned_width = va_arg(args, uint32_t *); uint32_t *aligned_height = va_arg(args, uint32_t *); uint32_t *size = va_arg(args, uint32_t *); auto descriptor = BufferDescriptor(width, height, format, producer_usage, consumer_usage); allocator_->GetBufferSizeAndDimensions(descriptor, size, aligned_width, aligned_height); // Align size auto align = GetDataAlignment(format, producer_usage, consumer_usage); *size = ALIGN(*size, align); } break; // TODO(user): Break out similar functionality, preferably moving to a common lib. case GRALLOC1_MODULE_PERFORM_ALLOCATE_BUFFER: { int width = va_arg(args, int); int height = va_arg(args, int); int format = va_arg(args, int); uint64_t p_usage = va_arg(args, uint64_t); uint64_t c_usage = va_arg(args, uint64_t); buffer_handle_t *hnd = va_arg(args, buffer_handle_t*); gralloc1_producer_usage_t producer_usage = static_cast<gralloc1_producer_usage_t>(p_usage); gralloc1_consumer_usage_t consumer_usage = static_cast<gralloc1_consumer_usage_t>(c_usage); BufferDescriptor descriptor(width, height, format, producer_usage, consumer_usage); unsigned int size; unsigned int alignedw, alignedh; allocator_->GetBufferSizeAndDimensions(descriptor, &size, &alignedw, &alignedh); AllocateBuffer(descriptor, hnd, size); } break; default: break; } return GRALLOC1_ERROR_NONE; }