/** * \brief Convert `HGraphicBufferProducer::FrameEventHistoryDelta` to * `::android::FrameEventHistoryDelta`. * * \param[out] l The destination `::android::FrameEventHistoryDelta`. * \param[in] t The source `HGraphicBufferProducer::FrameEventHistoryDelta`. * * This function will duplicate all file descriptors contained in \p t. */ inline bool convertTo( ::android::FrameEventHistoryDelta* l, HGraphicBufferProducer::FrameEventHistoryDelta const& t) { size_t const baseSize = getFlattenedSize(t); std::unique_ptr<uint8_t[]> baseBuffer( new (std::nothrow) uint8_t[baseSize]); if (!baseBuffer) { return false; } size_t const baseNumFds = getFdCount(t); std::unique_ptr<int[]> baseFds( new (std::nothrow) int[baseNumFds]); if (!baseFds) { return false; } void* buffer = static_cast<void*>(baseBuffer.get()); size_t size = baseSize; int* fds = static_cast<int*>(baseFds.get()); size_t numFds = baseNumFds; std::vector<std::vector<native_handle_t*> > nhAA; if (flatten(t, &nhAA, buffer, size, fds, numFds) != NO_ERROR) { return false; } void const* constBuffer = static_cast<void const*>(baseBuffer.get()); size = baseSize; int const* constFds = static_cast<int const*>(baseFds.get()); numFds = baseNumFds; if (l->unflatten(constBuffer, size, constFds, numFds) != NO_ERROR) { for (auto nhA : nhAA) { for (auto nh : nhA) { if (nh != nullptr) { native_handle_close(nh); native_handle_delete(nh); } } } return false; } for (auto nhA : nhAA) { for (auto nh : nhA) { if (nh != nullptr) { native_handle_delete(nh); } } } return true; }
void recordingFrameHandleCallbackTimestamp(nsecs_t timestamp, native_handle_t* handle) { ALOGV("recordingFrameHandleCallbackTimestamp"); Parcel data, reply; data.writeInterfaceToken(ICameraRecordingProxyListener::getInterfaceDescriptor()); data.writeInt64(timestamp); data.writeNativeHandle(handle); remote()->transact(RECORDING_FRAME_HANDLE_CALLBACK_TIMESTAMP, data, &reply, IBinder::FLAG_ONEWAY); // The native handle is dupped in ICameraClient so we need to free it here. native_handle_close(handle); native_handle_delete(handle); }
int hybris_gralloc_release(buffer_handle_t handle, int was_allocated) { int ret = -ENOSYS; if GRALLOC1( ret = gralloc1_release(gralloc1_device, handle); // this needs to happen if the last reference is gone, this function is // only called in such cases. if (!gralloc1_release_implies_delete) { native_handle_close((native_handle_t*)handle); native_handle_delete((native_handle_t*)handle); } ) else if GRALLOC0(
static int sensors_open(struct sensors_data_device_t *dev, native_handle_t* hd) { event_fd = open(SYSFS_PATH "coord", O_RDONLY | O_NONBLOCK); if (event_fd < 0) { LOGE("coord open failed in %s: %s", __FUNCTION__, strerror(errno)); return -1; } sensors.vector.status = SENSOR_STATUS_ACCURACY_HIGH; LOGD("%s\n", __func__); write_int("ths", DEFAULT_THRESHOLD); native_handle_close(hd); native_handle_delete(hd); return 0; }
static int data__data_open(struct sensors_poll_device_t *dev, native_handle_t* handle) { SensorPoll* data = (void*)dev; int i; D("%s: dev=%p fd=%d", __FUNCTION__, dev, handle->data[0]); memset(&data->sensors, 0, sizeof(data->sensors)); data->pendingSensors = 0; data->timeStart = 0; data->timeOffset = 0; data->events_fd = dup(handle->data[0]); D("%s: dev=%p fd=%d (was %d)", __FUNCTION__, dev, data->events_fd, handle->data[0]); native_handle_close(handle); native_handle_delete(handle); return 0; }
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; }
static void server_wlegl_create_buffer(struct wl_client *client, struct wl_resource *resource, uint32_t id, int32_t width, int32_t height, int32_t stride, int32_t format, int32_t usage, struct wl_resource *hnd) { server_wlegl *wlegl = server_wlegl_from(resource); server_wlegl_handle *handle = server_wlegl_handle_from(hnd); server_wlegl_buffer *buffer; buffer_handle_t native; if (width < 1 || height < 1) { wl_resource_post_error(resource, ANDROID_WLEGL_ERROR_BAD_VALUE, "bad width (%d) or height (%d)", width, height); return; } native = server_wlegl_handle_to_native(handle); if (!native) { wl_resource_post_error(resource, ANDROID_WLEGL_ERROR_BAD_HANDLE, "fd count mismatch"); return; } buffer = server_wlegl_buffer_create(client, id, width, height, stride, format, usage, native, wlegl); if (!buffer) { native_handle_close((native_handle_t *)native); native_handle_delete((native_handle_t *)native); wl_resource_post_error(resource, ANDROID_WLEGL_ERROR_BAD_HANDLE, "invalid native handle"); return; } }
void GraphicBuffer::free_handle() { if (mOwner == ownHandle) { #ifndef MTK_DEFAULT_AOSP ALOGD("close handle(%p) (w:%d h:%d f:%d)", handle, stride, height, format); #endif mBufferMapper.unregisterBuffer(handle); native_handle_close(handle); native_handle_delete(const_cast<native_handle*>(handle)); } else if (mOwner == ownData) { #ifndef MTK_DEFAULT_AOSP ALOGI("free buffer (w:%d h:%d f:%d) handle(%p)", stride, height, format, handle); #endif GraphicBufferAllocator& allocator(GraphicBufferAllocator::get()); allocator.free(handle); } mWrappedBuffer = 0; }
arxstatus_t ImageBuffer::free() { if (mRemote) { if (mImage.memType == DVP_MTYPE_GRALLOC_2DTILED || mImage.memType == DVP_MTYPE_DISPLAY_2DTILED) { native_handle_t *handle = reinterpret_cast<native_handle_t *>(mImage.reserved); if (!mUsingTexture) { GraphicBufferMapper &mapper = GraphicBufferMapper::get(); mapper.unlock(handle); mapper.unregisterBuffer(handle); } native_handle_close(handle); native_handle_delete(handle); } else { DVP_Image_Free_Import(mDvp, &mImage, mImportHdls); if (mImage.memType != DVP_MTYPE_MPUCACHED_VIRTUAL_SHARED) { for (uint32_t i = 0; i < mImage.planes; i++) { close(mSharedFds[i]); } } } return NOERROR; } if (mAnw) { anativewindow_release(mAnw, &(mImage.reserved)); } else { DVP_Image_Free(mDvp, &mImage); if (mImage.memType != DVP_MTYPE_MPUCACHED_VIRTUAL_SHARED) { for (uint32_t i = 0; i < mImage.planes; i++) { close(mSharedFds[i]); } } } return NOERROR; }
RemoteWindowBuffer::~RemoteWindowBuffer() { this->m_gralloc->unregisterBuffer(this->m_gralloc, this->handle); native_handle_close(this->handle); native_handle_delete(const_cast<native_handle_t*>(this->handle)); }