hnd->format = drv_bo_get_format(bo);
hnd->magic = cros_gralloc_magic();
- hnd->registrations = 0;
hnd->pixel_stride = hnd->strides[0];
hnd->pixel_stride /= drv_stride_from_format(hnd->format, 1, 0);
hnd->droid_format = static_cast<int32_t>(format);
hnd->usage = static_cast<int32_t>(usage);
- hnd->bo = reinterpret_cast<uint64_t>(bo);
+ mod->handles[hnd].registrations = 0;
+ mod->handles[hnd].bo = bo;
bo->hnd = hnd;
- mod->handles.insert(reinterpret_cast<uint64_t>(&hnd->base));
mod->buffers[drv_bo_get_plane_handle(bo->bo, 0).u32] = bo;
*stride = static_cast<int>(hnd->pixel_stride);
return CROS_GRALLOC_ERROR_BAD_HANDLE;
}
- if (hnd->registrations > 0) {
+ if (mod->handles[hnd].registrations > 0) {
cros_gralloc_error("Deallocating before unregistering.");
return CROS_GRALLOC_ERROR_BAD_HANDLE;
}
struct cros_gralloc_handle *hnd,
struct cros_gralloc_bo **bo)
{
- uint64_t key = reinterpret_cast<uint64_t>(&hnd->base);
-
- if (!mod->handles.count(key))
+ if (!mod->handles.count(hnd))
return CROS_GRALLOC_ERROR_BAD_HANDLE;
- *bo = reinterpret_cast<cros_gralloc_bo*>(hnd->bo);
+ *bo = mod->handles[hnd].bo;
return CROS_GRALLOC_ERROR_NONE;
}
drv_bo_destroy(bo->bo);
if (bo->hnd) {
+ mod->handles.erase(bo->hnd);
native_handle_close(&bo->hnd->base);
delete bo->hnd;
}
if (!cros_gralloc_validate_reference(mod, hnd, &bo)) {
bo->refcount++;
- hnd->registrations++;
+ mod->handles[hnd].registrations++;
return CROS_GRALLOC_ERROR_NONE;
}
if (mod->buffers.count(id)) {
bo = mod->buffers[id];
bo->refcount++;
- hnd->bo = reinterpret_cast<uint64_t>(bo);
} else {
struct drv_import_fd_data data;
size_t num_planes = drv_num_planes_from_format(hnd->format);
mod->buffers[id] = bo;
bo->refcount = 1;
- hnd->bo = reinterpret_cast<uint64_t>(bo);
}
- hnd->registrations = 1;
- mod->handles.insert(reinterpret_cast<uint64_t>(&hnd->base));
+ mod->handles[hnd].bo = bo;
+ mod->handles[hnd].registrations = 1;
return CROS_GRALLOC_ERROR_NONE;
}
return CROS_GRALLOC_ERROR_BAD_HANDLE;
}
- if (hnd->registrations <= 0) {
+ if (mod->handles[hnd].registrations <= 0) {
cros_gralloc_error("Handle not registered.");
return CROS_GRALLOC_ERROR_BAD_HANDLE;
}
- hnd->registrations--;
+ mod->handles[hnd].registrations--;
- if (!hnd->registrations)
- mod->handles.erase(reinterpret_cast<uint64_t>(&hnd->base));
+ if (!mod->handles[hnd].registrations)
+ mod->handles.erase(hnd);
return cros_gralloc_decrement_reference_count(mod, bo);
}