2017-12-06 11:28:13 -07:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2010-2011 Chia-I Wu <olvaffe@gmail.com>
|
|
|
|
* Copyright (C) 2010-2011 LunarG Inc.
|
|
|
|
* Copyright (C) 2016 Linaro, Ltd., Rob Herring <robh@kernel.org>
|
|
|
|
* Copyright (C) 2018 Collabora, Robert Foss <robert.foss@collabora.com>
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included
|
|
|
|
* in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __ANDROID_GRALLOC_HANDLE_H__
|
|
|
|
#define __ANDROID_GRALLOC_HANDLE_H__
|
|
|
|
|
|
|
|
#include <cutils/native_handle.h>
|
2018-01-16 06:36:13 -07:00
|
|
|
#include <stdint.h>
|
2017-12-06 11:28:13 -07:00
|
|
|
|
|
|
|
/* support users of drm_gralloc/gbm_gralloc */
|
|
|
|
#define gralloc_gbm_handle_t gralloc_handle_t
|
|
|
|
#define gralloc_drm_handle_t gralloc_handle_t
|
|
|
|
|
|
|
|
struct gralloc_handle_t {
|
|
|
|
native_handle_t base;
|
|
|
|
|
|
|
|
/* dma-buf file descriptor
|
|
|
|
* Must be located first since, native_handle_t is allocated
|
|
|
|
* using native_handle_create(), which allocates space for
|
|
|
|
* sizeof(native_handle_t) + sizeof(int) * (numFds + numInts)
|
|
|
|
* numFds = GRALLOC_HANDLE_NUM_FDS
|
|
|
|
* numInts = GRALLOC_HANDLE_NUM_INTS
|
|
|
|
* Where numFds represents the number of FDs and
|
|
|
|
* numInts represents the space needed for the
|
|
|
|
* remainder of this struct.
|
|
|
|
* And the FDs are expected to be found first following
|
|
|
|
* native_handle_t.
|
|
|
|
*/
|
|
|
|
int prime_fd;
|
|
|
|
|
2018-01-16 06:36:13 -07:00
|
|
|
/* api variables */
|
2018-02-14 16:10:25 -07:00
|
|
|
uint32_t magic; /* differentiate between allocator impls */
|
|
|
|
uint32_t version; /* api version */
|
2017-12-06 11:28:13 -07:00
|
|
|
|
2018-01-16 10:07:15 -07:00
|
|
|
uint32_t width; /* width of buffer in pixels */
|
|
|
|
uint32_t height; /* height of buffer in pixels */
|
|
|
|
uint32_t format; /* pixel format (Android) */
|
|
|
|
uint32_t usage; /* android libhardware usage flags */
|
2017-12-06 11:28:13 -07:00
|
|
|
|
2018-01-16 10:07:15 -07:00
|
|
|
uint32_t stride; /* the stride in bytes */
|
2017-12-06 11:28:13 -07:00
|
|
|
uint64_t modifier; /* buffer modifiers */
|
|
|
|
|
|
|
|
int data_owner; /* owner of data (for validation) */
|
|
|
|
union {
|
|
|
|
void *data; /* pointer to struct gralloc_gbm_bo_t */
|
|
|
|
uint64_t reserved;
|
|
|
|
} __attribute__((aligned(8)));
|
|
|
|
};
|
|
|
|
|
2018-01-16 10:07:15 -07:00
|
|
|
#define GRALLOC_HANDLE_VERSION 3
|
2017-12-06 11:28:13 -07:00
|
|
|
#define GRALLOC_HANDLE_MAGIC 0x60585350
|
|
|
|
#define GRALLOC_HANDLE_NUM_FDS 1
|
|
|
|
#define GRALLOC_HANDLE_NUM_INTS ( \
|
2018-02-14 16:06:46 -07:00
|
|
|
((sizeof(struct gralloc_handle_t) - sizeof(native_handle_t))/sizeof(int)) \
|
2017-12-06 11:28:13 -07:00
|
|
|
- GRALLOC_HANDLE_NUM_FDS)
|
|
|
|
|
2018-02-14 16:05:42 -07:00
|
|
|
static inline struct gralloc_handle_t *gralloc_handle(buffer_handle_t handle)
|
|
|
|
{
|
|
|
|
return (struct gralloc_handle_t *)handle;
|
|
|
|
}
|
|
|
|
|
2017-12-06 11:28:13 -07:00
|
|
|
/**
|
|
|
|
* Create a buffer handle.
|
|
|
|
*/
|
2018-01-16 10:07:15 -07:00
|
|
|
static struct gralloc_handle_t gralloc_handle_create(int32_t width,
|
|
|
|
int32_t height,
|
|
|
|
int32_t format,
|
|
|
|
int32_t usage)
|
2017-12-06 11:28:13 -07:00
|
|
|
{
|
2018-01-16 06:36:13 -07:00
|
|
|
struct alloc_handle_t handle = {
|
|
|
|
.magic = GRALLOC_HANDLE_MAGIC,
|
|
|
|
.version = GRALLOC_HANDLE_VERSION };
|
2017-12-06 11:28:13 -07:00
|
|
|
|
|
|
|
native_handle_t *nhandle = native_handle_create(GRALLOC_HANDLE_NUM_FDS,
|
|
|
|
GRALLOC_HANDLE_NUM_INTS);
|
|
|
|
handle.base = *nhandle;
|
|
|
|
native_handle_delete(nhandle);
|
|
|
|
|
|
|
|
handle.width = width;
|
|
|
|
handle.height = height;
|
|
|
|
handle.format = format;
|
|
|
|
handle.usage = usage;
|
|
|
|
handle.prime_fd = -1;
|
|
|
|
|
|
|
|
handle->data_owner = getpid();
|
|
|
|
handle->data = bo;
|
|
|
|
|
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|