gralloc: Fix GraphicBuffer screenshot issues in Pie

Buffer allocation for GraphicBuffer fails because it is released
to early. Use ION buffer and add an ump-reference to stall.
Change-Id: I077bd7176fff4aa08a46362d80e64ad9b740773a
This commit is contained in:
Dominggoes Isakh 2018-12-13 21:41:09 +01:00 committed by Shilin Victor
parent 3c86d5e6eb
commit 41bfeb9370
3 changed files with 30 additions and 16 deletions

View File

@ -97,13 +97,14 @@ struct private_handle_t {
struct native_handle nativeHandle;
#endif
enum {
PRIV_FLAGS_FRAMEBUFFER = 0x00000001,
PRIV_FLAGS_USES_UMP = 0x00000002,
PRIV_FLAGS_USES_PMEM = 0x00000004,
PRIV_FLAGS_USES_IOCTL = 0x00000008,
PRIV_FLAGS_USES_HDMI = 0x00000010,
PRIV_FLAGS_USES_ION = 0x00000020,
PRIV_FLAGS_NONE_CACHED = 0x00000040,
PRIV_FLAGS_FRAMEBUFFER = 0x00000001,
PRIV_FLAGS_USES_UMP = 0x00000002,
PRIV_FLAGS_USES_PMEM = 0x00000004,
PRIV_FLAGS_USES_IOCTL = 0x00000008,
PRIV_FLAGS_USES_HDMI = 0x00000010,
PRIV_FLAGS_USES_ION = 0x00000020,
PRIV_FLAGS_NONE_CACHED = 0x00000040,
PRIV_FLAGS_GRAPHICBUFFER = 0x00000080
};
enum {

View File

@ -99,12 +99,6 @@ extern int get_bpp(int format);
#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++;
}
int gralloc_alloc_fimc1(size_t size, int usage,
buffer_handle_t* pHandle, int w, int h,
int format, int bpp, int stride_raw, int stride) {
@ -299,10 +293,16 @@ static int gralloc_alloc_buffer(alloc_device_t* dev, size_t size, int usage,
ret = -1;
if (usage & (GRALLOC_USAGE_HW_COMPOSER | GRALLOC_USAGE_HW_ION)) {
ALOGV("%s: Allocating for HWC via ION...", __func__);
// the handle is guaranteed to have this usage flag set
// if it is going to be used as an HWC layer (see hwcomposer.h in hardware/libhardware)
ret = gralloc_alloc_ion(dev, size, usage, format, &ion_fd, &ion_paddr, &priv_alloc_flag, &ump_mem_handle);
} else if (usage & (GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE)) {
ALOGV("%s: Allocating graphicbuffer via ION...", __func__);
priv_alloc_flag = priv_alloc_flag | private_handle_t::PRIV_FLAGS_GRAPHICBUFFER;
ret = gralloc_alloc_ion(dev, size, usage, format, &ion_fd, &ion_paddr, &priv_alloc_flag, &ump_mem_handle);
}
if (ret < 0) {
// may happen if ion carveout is out of memory, or if the
// handle is not needed for HWC
@ -347,7 +347,7 @@ static int gralloc_alloc_buffer(alloc_device_t* dev, size_t size, int usage,
}
#endif
hnd->backing_store = next_backing_store_id();
hnd->backing_store = ump_id;
hnd->format = format;
hnd->usage = usage;
hnd->width = w;
@ -361,6 +361,11 @@ static int gralloc_alloc_buffer(alloc_device_t* dev, size_t size, int usage,
hnd->ion_memory = ion_map(ion_fd, size, 0);
ALOGD_IF(debug_level > 0, "%s hnd->format=0x%x hnd->uoffset=%d hnd->voffset=%d hnd->paddr=%x hnd->bpp=%d", __func__, hnd->format, hnd->uoffset, hnd->voffset, hnd->paddr, hnd->bpp);
if (hnd->flags & private_handle_t::PRIV_FLAGS_GRAPHICBUFFER) {
ALOGD_IF(debug_level > 0, "%s: GraphicBuffer (ump_id:%d): ump_reference_add ump_mem_handle:%08x", __func__, ump_id, ump_mem_handle);
ump_reference_add(ump_mem_handle);
}
return 0;
} else {
ALOGE("%s failed to allocate handle", __func__);
@ -454,7 +459,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();
hnd->backing_store = 0;
hnd->paddr = l_paddr;
hnd->stride = stride;
@ -649,6 +654,9 @@ static int alloc_device_free(alloc_device_t* dev, buffer_handle_t handle)
private_module_t* m = reinterpret_cast<private_module_t*>(dev->common.module);
pthread_mutex_lock(&l_surface);
if (hnd->flags & private_handle_t::PRIV_FLAGS_GRAPHICBUFFER) {
ALOGD_IF(debug_level > 0, "%s: GraphicBuffer (ump_id:%d): Freeing ump_mem_handle:%08x", __func__, hnd->ump_id, hnd->ump_mem_handle);
}
if (hnd->flags & private_handle_t::PRIV_FLAGS_FRAMEBUFFER) {
/* free this buffer */
@ -659,7 +667,7 @@ static int alloc_device_free(alloc_device_t* dev, buffer_handle_t handle)
close(hnd->fd);
} else if (hnd->flags & private_handle_t::PRIV_FLAGS_USES_UMP) {
ALOGD_IF(debug_level > 0, "%s hnd->ump_mem_handle=%d hnd->ump_id=%d", __func__, hnd->ump_mem_handle, hnd->ump_id);
ALOGD_IF(debug_level > 0, "%s hnd->ump_mem_handle:%08x hnd->ump_id=%d", __func__, hnd->ump_mem_handle, hnd->ump_id);
#ifdef USE_PARTIAL_FLUSH
if (!release_rect((int)hnd->ump_id))

View File

@ -398,6 +398,11 @@ sd
ALOGE("%s registering non-UMP buffer not supported", __func__);
}
if (hnd->flags & private_handle_t::PRIV_FLAGS_GRAPHICBUFFER) {
ALOGD_IF(debug_level > 0, "ump_id:%d %s: GraphicBuffer (ump_id:%d): ump_mem_handle:%08x (ump_reference_release)", hnd->ump_id, __func__, hnd->ump_id, hnd->ump_mem_handle);
ump_reference_release((ump_handle)hnd->ump_mem_handle);
}
pthread_mutex_unlock(&s_map_lock);
return retval;
}