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