exynos4: gralloc: Add support gralloc1-adapter

Change-Id: I6df76e2c0b7d5fad0316ddb2305a7fc8142d6d89
This commit is contained in:
Dominggoes Isakh 2017-10-12 13:16:34 +02:00
parent 9b21248cd4
commit 4ff5df4584
4 changed files with 156 additions and 2 deletions

View file

@ -24,6 +24,7 @@
* limitations under the License.
*/
//#define LOG_NDEBUG 0
#ifndef GRALLOC_PRIV_H_
#define GRALLOC_PRIV_H_
@ -145,6 +146,10 @@ struct private_handle_t {
unsigned int uoffset;
unsigned int voffset;
uint64_t backing_store;
uint64_t producer_usage;
uint64_t consumer_usage;
#ifdef __cplusplus
static const int sNumInts = 21;
static const int sNumFds = 1;
@ -179,6 +184,8 @@ struct private_handle_t {
version = sizeof(native_handle);
numFds = sNumFds;
numInts = sNumInts;
ALOGV("%s: fd:%d magic:%d flags:%d size:%d base:%d", __func__,
fd, magic, flags, size, base);
}
private_handle_t(int flags, int size, int base, int lock_state, int fb_file, int fb_offset):
@ -210,6 +217,8 @@ struct private_handle_t {
version = sizeof(native_handle);
numFds = sNumFds;
numInts = sNumInts;
ALOGV("%s: fd:%d magic:%d flags:%d size:%d base:%d", __func__,
fd, magic, flags, size, base);
}
~private_handle_t()

View file

@ -47,6 +47,9 @@ LOCAL_CFLAGS:= -DLOG_TAG=\"gralloc\" -DGRALLOC_32_BITS
LOCAL_CFLAGS += -DSAMSUNG_EXYNOS
LOCAL_CFLAGS += -DSAMSUNG_EXYNOS_CACHE_UMP
LOCAL_STATIC_LIBRARIES := libgralloc1-adapter
LOCAL_SHARED_LIBRARIES += libsync
ifeq ($(TARGET_SOC),exynos4210)
LOCAL_CFLAGS += -DSAMSUNG_EXYNOS4210
endif
@ -59,4 +62,8 @@ ifeq ($(TARGET_NEEDS_EXYNOS4_ENHANCEMENTS),true)
LOCAL_CFLAGS += -DEXYNOS4_ENHANCEMENTS
endif
ifeq ($(TARGET_USES_GRALLOC1), true)
LOCAL_CFLAGS += -DADVERTISE_GRALLOC1
endif
include $(BUILD_SHARED_LIBRARY)

View file

@ -27,6 +27,7 @@
* limitations under the License.
*/
//#define LOG_NDEBUG 0
#include <string.h>
#include <errno.h>
#include <pthread.h>
@ -95,10 +96,19 @@ extern int release_rect(int secure_id);
#define EXYNOS4_ALIGN( value, base ) (((value) + ((base) - 1)) & ~((base) - 1))
static uint64_t next_backing_store_id()
{
static std::atomic<uint64_t> next_id(1);
return next_id++;
}
static int gralloc_alloc_buffer(alloc_device_t* dev, size_t size, int usage,
buffer_handle_t* pHandle, int w, int h,
int format, int bpp, int stride_raw, int stride)
{
ALOGV("%s: size:%d usage:%d w:%d h:%d format:%d bpp:%d stride_raw:%d stride:%d",
__func__, size, usage, w,h, format, bpp, stride_raw, stride);
ump_handle ump_mem_handle;
void *cpu_ptr;
ump_secure_id ump_id;
@ -141,6 +151,7 @@ static int gralloc_alloc_buffer(alloc_device_t* dev, size_t size, int usage,
private_handle_t::LOCK_STATE_MAPPED, 0, 0);
*pHandle = hnd;
hnd->backing_store = next_backing_store_id();
hnd->format = format;
hnd->usage = usage;
hnd->width = w;
@ -167,6 +178,7 @@ static int gralloc_alloc_buffer(alloc_device_t* dev, size_t size, int usage,
void *mappedAddress = mmap(0, size,
PROT_READ|PROT_WRITE, MAP_SHARED, gMemfd, (hnd->paddr - hnd->offset));
hnd->base = intptr_t(mappedAddress) + hnd->offset;
return 0;
} else {
#endif
@ -243,6 +255,7 @@ static int gralloc_alloc_buffer(alloc_device_t* dev, size_t size, int usage,
psFRect->next = psRect;
}
#endif
hnd->backing_store = next_backing_store_id();
hnd->format = format;
hnd->usage = usage;
hnd->width = w;
@ -283,6 +296,8 @@ static int gralloc_alloc_framebuffer_locked(alloc_device_t* dev, size_t size, in
buffer_handle_t* pHandle, int w, int h,
int format, int bpp)
{
ALOGV("%s: size:%d usage:%d w:%d h:%d format:%d bpp:%d ",
__func__, size, usage, w,h, format, bpp);
private_module_t* m = reinterpret_cast<private_module_t*>(dev->common.module);
/* allocate the framebuffer */
if (m->framebuffer == NULL) {
@ -332,6 +347,7 @@ static int gralloc_alloc_framebuffer_locked(alloc_device_t* dev, size_t size, in
hnd->width = w;
hnd->height = h;
hnd->bpp = bpp;
hnd->backing_store = next_backing_store_id();
*pHandle = hnd;
@ -342,6 +358,8 @@ static int gralloc_alloc_framebuffer(alloc_device_t* dev, size_t size, int usage
buffer_handle_t* pHandle, int w, int h,
int format, int bpp)
{
ALOGV("%s: size:%d usage:%d w:%d h:%d format:%d bpp:%d",
__func__, size, usage, w,h, format, bpp);
private_module_t* m = reinterpret_cast<private_module_t*>(dev->common.module);
pthread_mutex_lock(&m->lock);
int err = gralloc_alloc_framebuffer_locked(dev, size, usage, pHandle, w, h, format, bpp);
@ -352,6 +370,8 @@ static int gralloc_alloc_framebuffer(alloc_device_t* dev, size_t size, int usage
static int alloc_device_alloc(alloc_device_t* dev, int w, int h, int format,
int usage, buffer_handle_t* pHandle, int* pStride)
{
ALOGV("%s: usage:%d w:%d h:%d format:%d ",
__func__, usage, w,h, format);
if (!pHandle || !pStride)
return -EINVAL;

View file

@ -28,6 +28,7 @@
* limitations under the License.
*/
//#define LOG_NDEBUG 0
#include <errno.h>
#include <pthread.h>
@ -38,6 +39,8 @@
#include <hardware/gralloc.h>
#include <fcntl.h>
#include <gralloc1-adapter.h>
#include "gralloc_priv.h"
#include "alloc_device.h"
#include "framebuffer_device.h"
@ -192,6 +195,12 @@ static int gralloc_device_open(const hw_module_t* module, const char* name, hw_d
{
int status = -EINVAL;
#ifdef ADVERTISE_GRALLOC1
if (!strcmp(name, GRALLOC_HARDWARE_MODULE_ID)) {
return gralloc1_adapter_device_open(module, name, device);
}
#endif
if (!strcmp(name, GRALLOC_HARDWARE_GPU0))
status = alloc_device_open(module, name, device);
else if (!strcmp(name, GRALLOC_HARDWARE_FB0))
@ -213,6 +222,10 @@ static int gralloc_register_buffer(gralloc_module_t const* module, buffer_handle
/* if this handle was created in this process, then we keep it as is. */
private_handle_t* hnd = (private_handle_t*)handle;
if (hnd->flags & private_handle_t::PRIV_FLAGS_FRAMEBUFFER) {
return 0;
}
#ifdef USE_PARTIAL_FLUSH
if (hnd->flags & private_handle_t::PRIV_FLAGS_USES_UMP) {
private_handle_rect *psRect;
@ -312,7 +325,6 @@ static int gralloc_unregister_buffer(gralloc_module_t const* module, buffer_hand
}
private_handle_t* hnd = (private_handle_t*)handle;
#ifdef USE_PARTIAL_FLUSH
if (hnd->flags & private_handle_t::PRIV_FLAGS_USES_UMP)
if (!release_rect((int)hnd->ump_id))
@ -436,6 +448,108 @@ static int gralloc_unlock(gralloc_module_t const* module, buffer_handle_t handle
return 0;
}
static int gralloc_perform(struct gralloc_module_t const* module,
int operation, ... )
{
int res = -EINVAL;
va_list args;
if(!module)
return res;
va_start(args, operation);
switch (operation) {
case GRALLOC1_ADAPTER_PERFORM_GET_REAL_MODULE_API_VERSION_MINOR:
{
auto outMinorVersion = va_arg(args, int*);
*outMinorVersion = 0;
ALOGV("%s: GRALLOC1_ADAPTER_PERFORM_GET_REAL_MODULE_API_VERSION_MINOR %d",
__func__, *outMinorVersion);
} break;
case GRALLOC1_ADAPTER_PERFORM_SET_USAGES:
{
auto hnd = va_arg(args, private_handle_t*);
auto producerUsage = va_arg(args, uint64_t);
auto consumerUsage = va_arg(args, uint64_t);
hnd->producer_usage = producerUsage;
hnd->consumer_usage = consumerUsage;
ALOGV("%s: (%p) GRALLOC1_ADAPTER_PERFORM_SET_USAGES p:0x%08x c:0x%08x", __func__,
hnd, producerUsage, consumerUsage);
} break;
case GRALLOC1_ADAPTER_PERFORM_GET_DIMENSIONS:
{
auto hnd = va_arg(args, private_handle_t*);
auto outWidth = va_arg(args, int*);
auto outHeight = va_arg(args, int*);
*outWidth = hnd->width;
*outHeight = hnd->height;
ALOGV("%s: (%p) GRALLOC1_ADAPTER_PERFORM_GET_DIMENSIONS %d x %d", __func__,
hnd, *outWidth, *outHeight);
} break;
case GRALLOC1_ADAPTER_PERFORM_GET_FORMAT:
{
auto hnd = va_arg(args, private_handle_t*);
auto outFormat = va_arg(args, int*);
*outFormat = hnd->format;
ALOGV("%s: (%p) GRALLOC1_ADAPTER_PERFORM_GET_FORMAT %d", __func__,
hnd, *outFormat);
} break;
case GRALLOC1_ADAPTER_PERFORM_GET_PRODUCER_USAGE:
{
auto hnd = va_arg(args, private_handle_t*);
auto outUsage = va_arg(args, uint64_t*);
*outUsage = hnd->producer_usage;
ALOGV("%s: (%p) GRALLOC1_ADAPTER_PERFORM_GET_PRODUCER_USAGE 0x%08x", __func__,
hnd, hnd->producer_usage);
} break;
case GRALLOC1_ADAPTER_PERFORM_GET_CONSUMER_USAGE:
{
auto hnd = va_arg(args, private_handle_t*);
auto outUsage = va_arg(args, uint64_t*);
*outUsage = hnd->consumer_usage;
ALOGV("%s: (%p) GRALLOC1_ADAPTER_PERFORM_GET_CONSUMER_USAGE 0x%08x", __func__,
hnd, hnd->consumer_usage);
} break;
case GRALLOC1_ADAPTER_PERFORM_GET_BACKING_STORE:
{
auto hnd = va_arg(args, private_handle_t*);
auto outBackingStore = va_arg(args, uint64_t*);
*outBackingStore = hnd->backing_store;
ALOGV("%s: (%p) GRALLOC1_ADAPTER_PERFORM_GET_BACKING_STORE %llu", __func__,
hnd, *outBackingStore);
} break;
case GRALLOC1_ADAPTER_PERFORM_GET_NUM_FLEX_PLANES:
{
auto hnd = va_arg(args, private_handle_t*);
auto outNumFlexPlanes = va_arg(args, int*);
(void) hnd;
// for simpilicity
*outNumFlexPlanes = 4;
ALOGV("%s: (%p) GRALLOC1_ADAPTER_PERFORM_GET_NUM_FLEX_PLANES %d", __func__,
hnd, *outNumFlexPlanes);
} break;
case GRALLOC1_ADAPTER_PERFORM_GET_STRIDE:
{
auto hnd = va_arg(args, private_handle_t*);
auto outStride = va_arg(args, int*);
*outStride = hnd->width;
ALOGV("%s: (%p) GRALLOC1_ADAPTER_PERFORM_GET_STRIDE %d", __func__,
hnd, *outStride);
} break;
default:
ALOGE("%s: NOT IMPLEMENTED %d", __func__, operation);
break;
}
va_end(args);
return res;
}
static int gralloc_getphys(gralloc_module_t const* module, buffer_handle_t handle, void** paddr)
{
private_handle_t* hnd = (private_handle_t*)handle;
@ -458,7 +572,11 @@ struct private_module_t HAL_MODULE_INFO_SYM =
common:
{
tag: HARDWARE_MODULE_TAG,
#ifdef ADVERTISE_GRALLOC1
version_major: GRALLOC1_ADAPTER_MODULE_API_VERSION_1_0,
#else
version_major: 1,
#endif
version_minor: 0,
id: GRALLOC_HARDWARE_MODULE_ID,
name: "Graphics Memory Allocator Module",
@ -471,7 +589,7 @@ struct private_module_t HAL_MODULE_INFO_SYM =
lock: gralloc_lock,
unlock: gralloc_unlock,
getphys: gralloc_getphys,
perform: NULL,
perform: gralloc_perform,
},
framebuffer: NULL,
flags: 0,