struct frame_buf * vpu_framebuf_alloc(int strideY, int height) { struct frame_buf *fb; int size; fb = get_framebuf(); if (fb == NULL) return NULL; size = strideY * height; memset(&(fb->desc), 0, sizeof(vpu_mem_desc)); fb->desc.size = (size * 3 / 2); if (IOGetPhyMem(&fb->desc)) { DBG("--- Frame buffer allocation failed ---\n"); memset(&(fb->desc), 0, sizeof(vpu_mem_desc)); return NULL; } fb->addrY = fb->desc.phy_addr; fb->addrCb = fb->addrY + size; fb->addrCr = fb->addrCb + (size>>2); fb->desc.virt_uaddr = IOGetVirtMem(&(fb->desc)); if (fb->desc.virt_uaddr <= 0) { IOFreePhyMem(&fb->desc); memset(&(fb->desc), 0, sizeof(vpu_mem_desc)); return NULL; } return fb; }
struct frame_buf *framebuf_alloc(int stdMode, int format, int strideY, int height) { struct frame_buf *fb; int err; int divX, divY; fb = get_framebuf(); if(fb == NULL) return NULL; divX = (format == MODE420 || format == MODE422) ? 2 : 1; divY = (format == MODE420 || format == MODE224) ? 2 : 1; memset(&(fb->desc), 0, sizeof(vpu_mem_desc)); fb->desc.size = (strideY * height + strideY / divX * height / divY * 2); if(cpu_is_mx37() || cpu_is_mx5x()) fb->desc.size += strideY / divX * height / divY; err = IOGetPhyMem(&fb->desc); if(err) { printf("Frame buffer allocation failure\n"); memset(&(fb->desc), 0, sizeof(vpu_mem_desc)); return NULL; } fb->addrY = fb->desc.phy_addr; fb->addrCb = fb->addrY + strideY * height; fb->addrCr = fb->addrCb + strideY / divX * height / divY; fb->strideY = strideY; fb->strideC = strideY / divX; if(cpu_is_mx37() || cpu_is_mx5x()) { if(stdMode == STD_MJPG) fb->mvColBuf = fb->addrCr; else fb->mvColBuf = fb->addrCr + strideY / divX * height / divY; } fb->desc.virt_uaddr = IOGetVirtMem(&(fb->desc)); if(fb->desc.virt_uaddr <= 0) { IOFreePhyMem(&fb->desc); memset(&(fb->desc), 0, sizeof(vpu_mem_desc)); return NULL; } return fb; }