Lines Matching refs:bo
213 struct bo *drv_bo_new(struct driver *drv, uint32_t width, uint32_t height, uint32_t format, in drv_bo_new()
217 struct bo *bo; in drv_bo_new() local
218 bo = (struct bo *)calloc(1, sizeof(*bo)); in drv_bo_new()
220 if (!bo) in drv_bo_new()
223 bo->drv = drv; in drv_bo_new()
224 bo->meta.width = width; in drv_bo_new()
225 bo->meta.height = height; in drv_bo_new()
226 bo->meta.format = format; in drv_bo_new()
227 bo->meta.use_flags = use_flags; in drv_bo_new()
228 bo->meta.num_planes = drv_num_planes_from_format(format); in drv_bo_new()
229 bo->is_test_buffer = is_test_buffer; in drv_bo_new()
231 if (!bo->meta.num_planes) { in drv_bo_new()
232 free(bo); in drv_bo_new()
236 return bo; in drv_bo_new()
239 struct bo *drv_bo_create(struct driver *drv, uint32_t width, uint32_t height, uint32_t format, in drv_bo_create()
244 struct bo *bo; in drv_bo_create() local
250 bo = drv_bo_new(drv, width, height, format, use_flags, is_test_alloc); in drv_bo_create()
252 if (!bo) in drv_bo_create()
257 ret = drv->backend->bo_compute_metadata(bo, width, height, format, use_flags, NULL, in drv_bo_create()
260 ret = drv->backend->bo_create_from_metadata(bo); in drv_bo_create()
262 ret = drv->backend->bo_create(bo, width, height, format, use_flags); in drv_bo_create()
266 free(bo); in drv_bo_create()
272 for (plane = 0; plane < bo->meta.num_planes; plane++) { in drv_bo_create()
274 assert(bo->meta.offsets[plane] >= bo->meta.offsets[plane - 1]); in drv_bo_create()
276 drv_increment_reference_count(drv, bo, plane); in drv_bo_create()
281 return bo; in drv_bo_create()
284 struct bo *drv_bo_create_with_modifiers(struct driver *drv, uint32_t width, uint32_t height, in drv_bo_create_with_modifiers()
289 struct bo *bo; in drv_bo_create_with_modifiers() local
296 bo = drv_bo_new(drv, width, height, format, BO_USE_NONE, false); in drv_bo_create_with_modifiers()
298 if (!bo) in drv_bo_create_with_modifiers()
303 ret = drv->backend->bo_compute_metadata(bo, width, height, format, BO_USE_NONE, in drv_bo_create_with_modifiers()
306 ret = drv->backend->bo_create_from_metadata(bo); in drv_bo_create_with_modifiers()
308 ret = drv->backend->bo_create_with_modifiers(bo, width, height, format, modifiers, in drv_bo_create_with_modifiers()
313 free(bo); in drv_bo_create_with_modifiers()
319 for (plane = 0; plane < bo->meta.num_planes; plane++) { in drv_bo_create_with_modifiers()
321 assert(bo->meta.offsets[plane] >= bo->meta.offsets[plane - 1]); in drv_bo_create_with_modifiers()
323 drv_increment_reference_count(drv, bo, plane); in drv_bo_create_with_modifiers()
328 return bo; in drv_bo_create_with_modifiers()
331 void drv_bo_destroy(struct bo *bo) in drv_bo_destroy() argument
336 struct driver *drv = bo->drv; in drv_bo_destroy()
338 if (!bo->is_test_buffer) { in drv_bo_destroy()
341 for (plane = 0; plane < bo->meta.num_planes; plane++) in drv_bo_destroy()
342 drv_decrement_reference_count(drv, bo, plane); in drv_bo_destroy()
344 for (plane = 0; plane < bo->meta.num_planes; plane++) in drv_bo_destroy()
345 total += drv_get_reference_count(drv, bo, plane); in drv_bo_destroy()
350 ret = drv_mapping_destroy(bo); in drv_bo_destroy()
352 bo->drv->backend->bo_destroy(bo); in drv_bo_destroy()
356 free(bo); in drv_bo_destroy()
359 struct bo *drv_bo_import(struct driver *drv, struct drv_import_fd_data *data) in drv_bo_import()
363 struct bo *bo; in drv_bo_import() local
366 bo = drv_bo_new(drv, data->width, data->height, data->format, data->use_flags, false); in drv_bo_import()
368 if (!bo) in drv_bo_import()
371 ret = drv->backend->bo_import(bo, data); in drv_bo_import()
373 free(bo); in drv_bo_import()
377 for (plane = 0; plane < bo->meta.num_planes; plane++) { in drv_bo_import()
378 pthread_mutex_lock(&bo->drv->driver_lock); in drv_bo_import()
379 drv_increment_reference_count(bo->drv, bo, plane); in drv_bo_import()
380 pthread_mutex_unlock(&bo->drv->driver_lock); in drv_bo_import()
383 bo->meta.format_modifier = data->format_modifier; in drv_bo_import()
384 for (plane = 0; plane < bo->meta.num_planes; plane++) { in drv_bo_import()
385 bo->meta.strides[plane] = data->strides[plane]; in drv_bo_import()
386 bo->meta.offsets[plane] = data->offsets[plane]; in drv_bo_import()
395 if (plane == bo->meta.num_planes - 1 || data->offsets[plane + 1] == 0) in drv_bo_import()
396 bo->meta.sizes[plane] = seek_end - data->offsets[plane]; in drv_bo_import()
398 bo->meta.sizes[plane] = data->offsets[plane + 1] - data->offsets[plane]; in drv_bo_import()
400 if ((int64_t)bo->meta.offsets[plane] + bo->meta.sizes[plane] > seek_end) { in drv_bo_import()
405 bo->meta.total_size += bo->meta.sizes[plane]; in drv_bo_import()
408 return bo; in drv_bo_import()
411 drv_bo_destroy(bo); in drv_bo_import()
415 void *drv_bo_map(struct bo *bo, const struct rectangle *rect, uint32_t map_flags, in drv_bo_map() argument
424 assert(rect->x + rect->width <= drv_bo_get_width(bo)); in drv_bo_map()
425 assert(rect->y + rect->height <= drv_bo_get_height(bo)); in drv_bo_map()
428 assert(!(bo->meta.use_flags & BO_USE_PROTECTED)); in drv_bo_map()
430 if (bo->is_test_buffer) in drv_bo_map()
436 pthread_mutex_lock(&bo->drv->driver_lock); in drv_bo_map()
438 for (i = 0; i < drv_array_size(bo->drv->mappings); i++) { in drv_bo_map()
439 struct mapping *prior = (struct mapping *)drv_array_at_idx(bo->drv->mappings, i); in drv_bo_map()
440 if (prior->vma->handle != bo->handles[plane].u32 || in drv_bo_map()
453 for (i = 0; i < drv_array_size(bo->drv->mappings); i++) { in drv_bo_map()
454 struct mapping *prior = (struct mapping *)drv_array_at_idx(bo->drv->mappings, i); in drv_bo_map()
455 if (prior->vma->handle != bo->handles[plane].u32 || in drv_bo_map()
465 memcpy(mapping.vma->map_strides, bo->meta.strides, sizeof(mapping.vma->map_strides)); in drv_bo_map()
466 addr = bo->drv->backend->bo_map(bo, mapping.vma, plane, map_flags); in drv_bo_map()
470 pthread_mutex_unlock(&bo->drv->driver_lock); in drv_bo_map()
476 mapping.vma->handle = bo->handles[plane].u32; in drv_bo_map()
480 *map_data = drv_array_append(bo->drv->mappings, &mapping); in drv_bo_map()
482 drv_bo_invalidate(bo, *map_data); in drv_bo_map()
484 addr += drv_bo_get_plane_offset(bo, plane); in drv_bo_map()
485 pthread_mutex_unlock(&bo->drv->driver_lock); in drv_bo_map()
489 int drv_bo_unmap(struct bo *bo, struct mapping *mapping) in drv_bo_unmap() argument
494 pthread_mutex_lock(&bo->drv->driver_lock); in drv_bo_unmap()
500 ret = bo->drv->backend->bo_unmap(bo, mapping->vma); in drv_bo_unmap()
504 for (i = 0; i < drv_array_size(bo->drv->mappings); i++) { in drv_bo_unmap()
505 if (mapping == (struct mapping *)drv_array_at_idx(bo->drv->mappings, i)) { in drv_bo_unmap()
506 drv_array_remove(bo->drv->mappings, i); in drv_bo_unmap()
512 pthread_mutex_unlock(&bo->drv->driver_lock); in drv_bo_unmap()
516 int drv_bo_invalidate(struct bo *bo, struct mapping *mapping) in drv_bo_invalidate() argument
525 if (bo->drv->backend->bo_invalidate) in drv_bo_invalidate()
526 ret = bo->drv->backend->bo_invalidate(bo, mapping); in drv_bo_invalidate()
531 int drv_bo_flush(struct bo *bo, struct mapping *mapping) in drv_bo_flush() argument
540 if (bo->drv->backend->bo_flush) in drv_bo_flush()
541 ret = bo->drv->backend->bo_flush(bo, mapping); in drv_bo_flush()
546 int drv_bo_flush_or_unmap(struct bo *bo, struct mapping *mapping) in drv_bo_flush_or_unmap() argument
554 assert(!(bo->meta.use_flags & BO_USE_PROTECTED)); in drv_bo_flush_or_unmap()
556 if (bo->drv->backend->bo_flush) in drv_bo_flush_or_unmap()
557 ret = bo->drv->backend->bo_flush(bo, mapping); in drv_bo_flush_or_unmap()
559 ret = drv_bo_unmap(bo, mapping); in drv_bo_flush_or_unmap()
564 uint32_t drv_bo_get_width(struct bo *bo) in drv_bo_get_width() argument
566 return bo->meta.width; in drv_bo_get_width()
569 uint32_t drv_bo_get_height(struct bo *bo) in drv_bo_get_height() argument
571 return bo->meta.height; in drv_bo_get_height()
574 size_t drv_bo_get_num_planes(struct bo *bo) in drv_bo_get_num_planes() argument
576 return bo->meta.num_planes; in drv_bo_get_num_planes()
579 union bo_handle drv_bo_get_plane_handle(struct bo *bo, size_t plane) in drv_bo_get_plane_handle() argument
581 return bo->handles[plane]; in drv_bo_get_plane_handle()
588 int drv_bo_get_plane_fd(struct bo *bo, size_t plane) in drv_bo_get_plane_fd() argument
592 assert(plane < bo->meta.num_planes); in drv_bo_get_plane_fd()
594 if (bo->is_test_buffer) in drv_bo_get_plane_fd()
597 ret = drmPrimeHandleToFD(bo->drv->fd, bo->handles[plane].u32, DRM_CLOEXEC | DRM_RDWR, &fd); in drv_bo_get_plane_fd()
601 ret = drmPrimeHandleToFD(bo->drv->fd, bo->handles[plane].u32, DRM_CLOEXEC, &fd); in drv_bo_get_plane_fd()
609 uint32_t drv_bo_get_plane_offset(struct bo *bo, size_t plane) in drv_bo_get_plane_offset() argument
611 assert(plane < bo->meta.num_planes); in drv_bo_get_plane_offset()
612 return bo->meta.offsets[plane]; in drv_bo_get_plane_offset()
615 uint32_t drv_bo_get_plane_size(struct bo *bo, size_t plane) in drv_bo_get_plane_size() argument
617 assert(plane < bo->meta.num_planes); in drv_bo_get_plane_size()
618 return bo->meta.sizes[plane]; in drv_bo_get_plane_size()
621 uint32_t drv_bo_get_plane_stride(struct bo *bo, size_t plane) in drv_bo_get_plane_stride() argument
623 assert(plane < bo->meta.num_planes); in drv_bo_get_plane_stride()
624 return bo->meta.strides[plane]; in drv_bo_get_plane_stride()
627 uint64_t drv_bo_get_format_modifier(struct bo *bo) in drv_bo_get_format_modifier() argument
629 return bo->meta.format_modifier; in drv_bo_get_format_modifier()
632 uint32_t drv_bo_get_format(struct bo *bo) in drv_bo_get_format() argument
634 return bo->meta.format; in drv_bo_get_format()
637 size_t drv_bo_get_total_size(struct bo *bo) in drv_bo_get_total_size() argument
639 return bo->meta.total_size; in drv_bo_get_total_size()
650 uint32_t drv_num_buffers_per_bo(struct bo *bo) in drv_num_buffers_per_bo() argument
655 if (bo->is_test_buffer) in drv_num_buffers_per_bo()
658 for (plane = 0; plane < bo->meta.num_planes; plane++) { in drv_num_buffers_per_bo()
660 if (bo->handles[p].u32 == bo->handles[plane].u32) in drv_num_buffers_per_bo()
685 int drv_resource_info(struct bo *bo, uint32_t strides[DRV_MAX_PLANES], in drv_resource_info() argument
688 for (uint32_t plane = 0; plane < bo->meta.num_planes; plane++) { in drv_resource_info()
689 strides[plane] = bo->meta.strides[plane]; in drv_resource_info()
690 offsets[plane] = bo->meta.offsets[plane]; in drv_resource_info()
692 *format_modifier = bo->meta.format_modifier; in drv_resource_info()
694 if (bo->drv->backend->resource_info) in drv_resource_info()
695 return bo->drv->backend->resource_info(bo, strides, offsets, format_modifier); in drv_resource_info()