19bd392adSmrg/* 29bd392adSmrg * Copyright (C) 2010-2011 Chia-I Wu <olvaffe@gmail.com> 39bd392adSmrg * Copyright (C) 2010-2011 LunarG Inc. 49bd392adSmrg * Copyright (C) 2016 Linaro, Ltd., Rob Herring <robh@kernel.org> 59bd392adSmrg * Copyright (C) 2018 Collabora, Robert Foss <robert.foss@collabora.com> 69bd392adSmrg * 79bd392adSmrg * Permission is hereby granted, free of charge, to any person obtaining a 89bd392adSmrg * copy of this software and associated documentation files (the "Software"), 99bd392adSmrg * to deal in the Software without restriction, including without limitation 109bd392adSmrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 119bd392adSmrg * and/or sell copies of the Software, and to permit persons to whom the 129bd392adSmrg * Software is furnished to do so, subject to the following conditions: 139bd392adSmrg * 149bd392adSmrg * The above copyright notice and this permission notice shall be included 159bd392adSmrg * in all copies or substantial portions of the Software. 169bd392adSmrg * 179bd392adSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 189bd392adSmrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 199bd392adSmrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 209bd392adSmrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 219bd392adSmrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 229bd392adSmrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 239bd392adSmrg * DEALINGS IN THE SOFTWARE. 249bd392adSmrg */ 259bd392adSmrg 269bd392adSmrg#ifndef __ANDROID_GRALLOC_HANDLE_H__ 279bd392adSmrg#define __ANDROID_GRALLOC_HANDLE_H__ 289bd392adSmrg 299bd392adSmrg#include <cutils/native_handle.h> 309bd392adSmrg#include <stdint.h> 319bd392adSmrg 329bd392adSmrg/* support users of drm_gralloc/gbm_gralloc */ 339bd392adSmrg#define gralloc_gbm_handle_t gralloc_handle_t 349bd392adSmrg#define gralloc_drm_handle_t gralloc_handle_t 359bd392adSmrg 369bd392adSmrgstruct gralloc_handle_t { 379bd392adSmrg native_handle_t base; 389bd392adSmrg 399bd392adSmrg /* dma-buf file descriptor 409bd392adSmrg * Must be located first since, native_handle_t is allocated 419bd392adSmrg * using native_handle_create(), which allocates space for 429bd392adSmrg * sizeof(native_handle_t) + sizeof(int) * (numFds + numInts) 439bd392adSmrg * numFds = GRALLOC_HANDLE_NUM_FDS 449bd392adSmrg * numInts = GRALLOC_HANDLE_NUM_INTS 459bd392adSmrg * Where numFds represents the number of FDs and 469bd392adSmrg * numInts represents the space needed for the 479bd392adSmrg * remainder of this struct. 489bd392adSmrg * And the FDs are expected to be found first following 499bd392adSmrg * native_handle_t. 509bd392adSmrg */ 519bd392adSmrg int prime_fd; 529bd392adSmrg 539bd392adSmrg /* api variables */ 549bd392adSmrg uint32_t magic; /* differentiate between allocator impls */ 559bd392adSmrg uint32_t version; /* api version */ 569bd392adSmrg 579bd392adSmrg uint32_t width; /* width of buffer in pixels */ 589bd392adSmrg uint32_t height; /* height of buffer in pixels */ 599bd392adSmrg uint32_t format; /* pixel format (Android) */ 609bd392adSmrg uint32_t usage; /* android libhardware usage flags */ 619bd392adSmrg 629bd392adSmrg uint32_t stride; /* the stride in bytes */ 639bd392adSmrg int data_owner; /* owner of data (for validation) */ 649bd392adSmrg uint64_t modifier __attribute__((aligned(8))); /* buffer modifiers */ 659bd392adSmrg 669bd392adSmrg union { 679bd392adSmrg void *data; /* pointer to struct gralloc_gbm_bo_t */ 689bd392adSmrg uint64_t reserved; 699bd392adSmrg } __attribute__((aligned(8))); 709bd392adSmrg}; 719bd392adSmrg 729bd392adSmrg#define GRALLOC_HANDLE_VERSION 4 739bd392adSmrg#define GRALLOC_HANDLE_MAGIC 0x60585350 749bd392adSmrg#define GRALLOC_HANDLE_NUM_FDS 1 759bd392adSmrg#define GRALLOC_HANDLE_NUM_INTS ( \ 769bd392adSmrg ((sizeof(struct gralloc_handle_t) - sizeof(native_handle_t))/sizeof(int)) \ 779bd392adSmrg - GRALLOC_HANDLE_NUM_FDS) 789bd392adSmrg 799bd392adSmrgstatic inline struct gralloc_handle_t *gralloc_handle(buffer_handle_t handle) 809bd392adSmrg{ 819bd392adSmrg return (struct gralloc_handle_t *)handle; 829bd392adSmrg} 839bd392adSmrg 849bd392adSmrg/** 859bd392adSmrg * Create a buffer handle. 869bd392adSmrg */ 879bd392adSmrgstatic inline native_handle_t *gralloc_handle_create(int32_t width, 889bd392adSmrg int32_t height, 899bd392adSmrg int32_t hal_format, 909bd392adSmrg int32_t usage) 919bd392adSmrg{ 929bd392adSmrg struct gralloc_handle_t *handle; 939bd392adSmrg native_handle_t *nhandle = native_handle_create(GRALLOC_HANDLE_NUM_FDS, 949bd392adSmrg GRALLOC_HANDLE_NUM_INTS); 959bd392adSmrg 969bd392adSmrg if (!nhandle) 979bd392adSmrg return NULL; 989bd392adSmrg 999bd392adSmrg handle = gralloc_handle(nhandle); 1009bd392adSmrg handle->magic = GRALLOC_HANDLE_MAGIC; 1019bd392adSmrg handle->version = GRALLOC_HANDLE_VERSION; 1029bd392adSmrg handle->width = width; 1039bd392adSmrg handle->height = height; 1049bd392adSmrg handle->format = hal_format; 1059bd392adSmrg handle->usage = usage; 1069bd392adSmrg handle->prime_fd = -1; 1079bd392adSmrg 1089bd392adSmrg return nhandle; 1099bd392adSmrg} 1109bd392adSmrg 1119bd392adSmrg#endif 112