author | Stark Li <stark.li@amlogic.com> | 2017-01-12 11:27:19 (GMT) |
---|---|---|
committer | Stark Li <stark.li@amlogic.com> | 2017-01-12 11:30:03 (GMT) |
commit | 77741039ed0918e4e25d5c36b5792b106e57ebab (patch) | |
tree | f94af446aae5688dd5e6d53295b399d4633769f1 | |
parent | 73807469c941ad4f019b2179848472c3921ba6ae (diff) | |
download | gralloc-77741039ed0918e4e25d5c36b5792b106e57ebab.zip gralloc-77741039ed0918e4e25d5c36b5792b106e57ebab.tar.gz gralloc-77741039ed0918e4e25d5c36b5792b106e57ebab.tar.bz2 |
PD#138457: alloc layer buffer from carvout heap for direct & ge2d composer.
For directbuffer & ge2d composer, the device need continous buffer.
So Gralloc need create app layer from ion carvout heap instead of system heap.
HOW TO ENABLE THIS FEATURE:
1) add "TARGET_APP_LAYER_USE_CONTINUOUS_BUFFER := true" in your product BoardConfig.mk.
2) configure carout heap larger than before.
Change-Id: I75b797ea2a86f7eaa66a145b99c03534b8ce859f
-rw-r--r-- | Android.mk | 4 | ||||
-rw-r--r-- | alloc_ion.cpp | 49 | ||||
-rw-r--r-- | framebuffer.cpp | 104 | ||||
-rw-r--r-- | framebuffer.h | 26 | ||||
-rw-r--r-- | gralloc_priv.h | 1 |
5 files changed, 144 insertions, 40 deletions
@@ -160,6 +160,10 @@ ifdef PLATFORM_CFLAGS LOCAL_CFLAGS += $(PLATFORM_CFLAGS) endif +ifeq ($(TARGET_APP_LAYER_USE_CONTINUOUS_BUFFER),true) +LOCAL_CFLAGS += -DGRALLOC_APP_ALLOC_CONTINUOUS_BUF +endif + LOCAL_MODULE_PATH_32 := $(TARGET_OUT)/lib LOCAL_MODULE_PATH_64 := $(TARGET_OUT)/lib64 LOCAL_MODULE_RELATIVE_PATH := hw diff --git a/alloc_ion.cpp b/alloc_ion.cpp index 3a19a07..4a44fc5 100644 --- a/alloc_ion.cpp +++ b/alloc_ion.cpp @@ -78,17 +78,48 @@ int alloc_backend_alloc(alloc_device_t* dev, size_t size, int usage, buffer_hand ion_flags = ION_FLAG_CACHED | ION_FLAG_CACHED_NEEDS_SYNC; } + bool layerAllocContinousBuf = false; +#ifdef GRALLOC_APP_ALLOC_CONTINUOUS_BUF + char path[256]; + char comm[256]; + sprintf(path, "/proc/%d/comm", getpid()); + FILE *fp = fopen(path, "r"); + if (fp != NULL) + { + fgets(comm, 255, fp); + if (strstr(comm, "surfaceflinger")) + { + layerAllocContinousBuf = true; + } + fclose(fp); + fp = NULL; + } +#endif + + bool allocCodecMem = false; if (usage & GRALLOC_USAGE_AML_DMA_BUFFER) { - ret = ion_alloc(m->ion_client, size, 0, ION_HEAP_CARVEOUT_MASK, - ion_flags, &ion_hnd); - if (ret != 0)/*try alloced from custom:codec_mm*/ - ret = ion_alloc(m->ion_client, size, 0, 1<<ION_HEAP_TYPE_CUSTOM, - ion_flags, &ion_hnd); - } else + allocCodecMem = true; + } + + //alloc from carveout heap. + if (allocCodecMem || layerAllocContinousBuf) + { + ret = ion_alloc(m->ion_client, size, 0, + ION_HEAP_CARVEOUT_MASK, ion_flags, &ion_hnd); + if (ret != 0 && layerAllocContinousBuf) { + layerAllocContinousBuf = false; + } + if (ret != 0 && allocCodecMem) + { + ret = ion_alloc(m->ion_client, size, 0, + 1<<ION_HEAP_TYPE_CUSTOM, ion_flags, &ion_hnd); + } + } + else { ret = ion_alloc(m->ion_client, size, 0, heap_mask, - ion_flags, &ion_hnd ); + ion_flags, &ion_hnd); } if ( ret != 0) @@ -128,6 +159,10 @@ int alloc_backend_alloc(alloc_device_t* dev, size_t size, int usage, buffer_hand hnd->ion_hnd = ion_hnd; /*TODO ion extend hnd->min_pgsz = min_pgsz; */ *pHandle = hnd; + if (layerAllocContinousBuf) + { + hnd->flags |= private_handle_t::PRIV_FLAGS_CONTINUOUS_BUF; + } return 0; } else diff --git a/framebuffer.cpp b/framebuffer.cpp index 08305cc..95fd68f 100644 --- a/framebuffer.cpp +++ b/framebuffer.cpp @@ -22,6 +22,9 @@ #include <hardware/hwcomposer_defs.h> #include <GLES/gl.h> +#include <linux/ion.h> +#include <ion/ion.h> + #ifndef __gl_h_ #error a #endif @@ -498,43 +501,82 @@ int init_frame_buffer_locked(struct framebuffer_info_t* fbinfo) return 0; } -int fb_post_with_fence_locked(struct framebuffer_info_t* fbinfo,buffer_handle_t hnd,int in_fence) + +uint32_t getIonPhyAddr(struct framebuffer_info_t* fbinfo,buffer_handle_t hnd) +{ + private_handle_t const *pHandle = reinterpret_cast<private_handle_t const*> (hnd); + private_module_t *grallocModule = fbinfo->grallocModule; + int result = 0; + struct meson_phys_data phyData = + { + .handle = pHandle->share_fd, + .phys_addr = 0, + .size = 0, + }; + struct ion_custom_data customData = + { + .cmd = ION_IOC_MESON_PHYS_ADDR, + .arg = (unsigned long)&phyData, + }; + + result = ioctl(grallocModule->ion_client, ION_IOC_CUSTOM, (unsigned long)&customData); + + if (result < 0) + { + ALOGE("ion custom ioctl %x failed with code %d: %s\n", + ION_IOC_MESON_PHYS_ADDR, result, strerror(errno)); + } + + return phyData.phys_addr; +} + +int fb_post_with_fence_locked( + struct framebuffer_info_t* fbinfo, + buffer_handle_t hnd, + int in_fence) { #define FBIOPUT_OSD_SYNC_ADD 0x4518 typedef struct{ - unsigned int xoffset; - unsigned int yoffset; - int in_fen_fd; - int out_fen_fd; - }fb_sync_request_t; - private_handle_t const* buffer = reinterpret_cast<private_handle_t const*>(hnd); - - //wait fence sync - //sync_wait(in_fence, 3000); - //close(in_fence); - //in_fence = -1; - //set sync request + unsigned int xoffset; + unsigned int yoffset; + int in_fen_fd; + int out_fen_fd; + int width; + int height; + int format; + unsigned int paddr; + unsigned int op; + unsigned int reserve; + } fb_sync_request_t; + private_handle_t const* buffer = reinterpret_cast<private_handle_t const*>(hnd); fb_sync_request_t sync_req; - memset(&sync_req,0,sizeof(fb_sync_request_t)); - sync_req.xoffset=fbinfo->info.xoffset; - sync_req.yoffset= buffer->offset / fbinfo->finfo.line_length; - sync_req.in_fen_fd=in_fence; - //ALOGD( "req offset:%d\n",sync_req.yoffset); + + memset(&sync_req, 0, sizeof(fb_sync_request_t)); + sync_req.xoffset = fbinfo->info.xoffset; + sync_req.yoffset = buffer->offset / fbinfo->finfo.line_length; + // acquire fence. + sync_req.in_fen_fd = in_fence; + + if (fbinfo->renderMode == 1) { // Direct composer mode. + sync_req.width = buffer->width; + sync_req.height = buffer->height; + sync_req.format = buffer->format; + sync_req.paddr = getIonPhyAddr(fbinfo, hnd); + } else if (fbinfo->renderMode == 2) { // GE2D composer mode. + sync_req.width = fbinfo->info.xres; + sync_req.height = fbinfo->info.yres; + sync_req.format = HAL_PIXEL_FORMAT_RGBA_8888; + unsigned int paddr = getIonPhyAddr(fbinfo, hnd); + if (0 != paddr) + sync_req.paddr = paddr + fbinfo->yOffset * fbinfo->finfo.line_length; + } + sync_req.op = fbinfo->op; + ALOGD( "req offset: %d, width: %d, height: %d, format: %d, addr: 0x%x, op: 0x%x\n", + sync_req.yoffset, sync_req.width, sync_req.height, sync_req.format, sync_req.paddr, sync_req.op); ioctl(fbinfo->fd, FBIOPUT_OSD_SYNC_ADD, &sync_req); - //ALOGD( "post offset:%d\n",buffer->offset/fbinfo->finfo.line_length); - //TODO:: need update with kernel change. - //fb_post_locked(fbinfo,hnd); - - int out_fence = sync_req.out_fen_fd; - /*nsecs_t origin=systemTime(CLOCK_MONOTONIC); - ALOGD( "--sync wait: %d,begin:%lld\n",out_fence,origin); - sync_wait(out_fence, 3000); - close(out_fence); - nsecs_t diff=systemTime(CLOCK_MONOTONIC)-origin; - ALOGD( "++sync wait: %d,wait_delay:%lld\n",out_fence,diff);*/ - - return out_fence; + + return sync_req.out_fen_fd; } int fb_post_locked(struct framebuffer_info_t* fbinfo, buffer_handle_t hnd) diff --git a/framebuffer.h b/framebuffer.h index 7b27cde..0d0d9ed 100644 --- a/framebuffer.h +++ b/framebuffer.h @@ -4,9 +4,14 @@ #include <hardware/hardware.h> struct private_handle_t; - +struct private_module_t; typedef struct framebuffer_info_t{ + // gralloc module. + private_module_t *grallocModule; + + buffer_handle_t currentBuffer; + //set by device. int displayType; int fbIdx; @@ -23,9 +28,26 @@ typedef struct framebuffer_info_t{ float fps; int flipFlags; - buffer_handle_t currentBuffer; + // Composer mode. + int renderMode; + + // GE2D composer mode used only. + int yOffset; + + // osd blank option. + unsigned int op; }framebuffer_info_t; +#define ION_IOC_MESON_PHYS_ADDR 8 + +struct meson_phys_data{ + int handle; + unsigned int phys_addr; + unsigned int size; +}; + +// get ion physical address. +uint32_t getIonPhyAddr(struct framebuffer_info_t* fbinfo, buffer_handle_t hnd); // Initialize the framebuffer (must keep module lock before calling int init_frame_buffer_locked(struct framebuffer_info_t* info); diff --git a/gralloc_priv.h b/gralloc_priv.h index 8e51370..7114beb 100644 --- a/gralloc_priv.h +++ b/gralloc_priv.h @@ -193,6 +193,7 @@ struct private_handle_t PRIV_FLAGS_VIDEO_OMX = 0x00000020, PRIV_FLAGS_CURSOR = 0x00000040, PRIV_FLAGS_OSD_VIDEO_OMX = 0x00000080, + PRIV_FLAGS_CONTINUOUS_BUF = 0x00000100, }; enum |