static int gralloc_lock_ycbcr(struct gralloc_module_t const* module,
            buffer_handle_t handle, int usage,
            int l, int t, int w, int h,
            struct android_ycbcr *ycbcr)
{
	if (private_handle_t::validate(handle) < 0)
	{
		AERR("Locking invalid buffer 0x%p, returning error", handle );
		return -EINVAL;
	}
	private_handle_t* hnd = (private_handle_t*)handle;
	int ystride;
	int err=0;

	switch (hnd->format) {
		case HAL_PIXEL_FORMAT_YCrCb_420_SP:
			ystride = GRALLOC_ALIGN(hnd->width, 16);
			ycbcr->y  = (void*)hnd->base;
			ycbcr->cr = (void*)((uintptr_t)hnd->base + ystride * hnd->height);
			ycbcr->cb = (void*)((uintptr_t)hnd->base + ystride * hnd->height + 1);
			ycbcr->ystride = ystride;
			ycbcr->cstride = ystride;
			ycbcr->chroma_step = 2;
			memset(ycbcr->reserved, 0, sizeof(ycbcr->reserved));
			break;
		case HAL_PIXEL_FORMAT_YCbCr_420_SP:
			ystride = GRALLOC_ALIGN(hnd->width, 16);
			ycbcr->y  = (void*)hnd->base;
			ycbcr->cb = (void*)((uintptr_t)hnd->base + ystride * hnd->height);
			ycbcr->cr = (void*)((uintptr_t)hnd->base + ystride * hnd->height + 1);
			ycbcr->ystride = ystride;
			ycbcr->cstride = ystride;
			ycbcr->chroma_step = 2;
			memset(ycbcr->reserved, 0, sizeof(ycbcr->reserved));
			break;
		default:
			ALOGD("%s: Invalid format passed: 0x%x", __FUNCTION__,
			       hnd->format);
			err = -EINVAL;
	}

	MALI_IGNORE(module);
	MALI_IGNORE(usage);
	MALI_IGNORE(l);
	MALI_IGNORE(t);
	MALI_IGNORE(w);
	MALI_IGNORE(h);
	return err;
}
Пример #2
0
static int alloc_device_alloc(alloc_device_t *dev, int w, int h, int format, int usage, buffer_handle_t *pHandle, int *pStride)
{
	if (!pHandle || !pStride)
	{
		return -EINVAL;
	}

	size_t size;
	size_t stride;

	if (format == HAL_PIXEL_FORMAT_YCrCb_420_SP || format == HAL_PIXEL_FORMAT_YV12)
	{
		switch (format)
		{
			case HAL_PIXEL_FORMAT_YCrCb_420_SP:
				stride = GRALLOC_ALIGN(w, 16);
			if (usage & GRALLOC_USAGE_PRIVATE_1){

                                /************************************************************
                                 *
                                 * height is 16bytes aligned for encode canvas read
                                 *
                                 * with 16bytes align. width is 32bytes aligned for
                                 *
                                 * ge2d working with 256bit once that is 32bytes
                                 *
                                 ************************************************************/
				size = GRALLOC_ALIGN(h, 16) * (GRALLOC_ALIGN(w, 32) + GRALLOC_ALIGN(stride/2,16));
			}else {
				size = h * (stride + GRALLOC_ALIGN(stride/2,16));
			}
				break;
			case HAL_PIXEL_FORMAT_YV12:
                                stride = GRALLOC_ALIGN(w, 16);
                                if (usage & GRALLOC_USAGE_PRIVATE_1){

                                        /************************************************************
                                         *
                                         * height is 16bytes aligned for encode canvas read
                                         *
                                         * with 16bytes align. width is 32bytes aligned for
                                         *
                                         * ge2d working with 256bit once that is 32bytes
                                         *
                                         ************************************************************/
                                        size = GRALLOC_ALIGN(h, 16) * (GRALLOC_ALIGN(w, 64) + GRALLOC_ALIGN(stride/2,32));
                                }else {
                                        size = h * (stride + GRALLOC_ALIGN(stride/2,16));
                                }
				break;
			default:
				return -EINVAL;
		}
	}
	else
	{
		int bpp = 0;

		switch (format)
		{
			case HAL_PIXEL_FORMAT_RGBA_8888:
			case HAL_PIXEL_FORMAT_RGBX_8888:
			case HAL_PIXEL_FORMAT_BGRA_8888:
				bpp = 4;
				break;

			case HAL_PIXEL_FORMAT_RGB_888:
				bpp = 3;
				break;

			case HAL_PIXEL_FORMAT_RGB_565:
				bpp = 2;
				break;

			default:
				return -EINVAL;
		}

		size_t bpr = GRALLOC_ALIGN(w * bpp, 64);
		size = bpr * h;
		stride = bpr / bpp;
	}

	int err;

#ifndef MALI_600

	if (usage & GRALLOC_USAGE_HW_FB)
	{
		err = gralloc_alloc_framebuffer(dev, size, usage, pHandle);
	}
	else
#endif

	{
		err = gralloc_alloc_buffer(dev, size, usage, pHandle);

		if (err < 0)
		{
		return err;
		}
		private_handle_t* hnd = (private_handle_t*)(*pHandle);
		hnd->format = format;
    }

	*pStride = stride;
	return 0;
}
static int alloc_device_alloc(alloc_device_t* dev, int w, int h, int format, int usage, buffer_handle_t* pHandle, int* pStride)
{
	if (!pHandle || !pStride)
	{
		return -EINVAL;
	}

	size_t size;
	size_t stride;
	if (format == HAL_PIXEL_FORMAT_YCrCb_420_SP || format == HAL_PIXEL_FORMAT_YV12 ) 
	{
		switch (format)
		{
			case HAL_PIXEL_FORMAT_YCrCb_420_SP:
			case HAL_PIXEL_FORMAT_YV12:
				stride = GRALLOC_ALIGN(w, 16);
				size = h * (stride + GRALLOC_ALIGN(stride/2,16));

				break;
			default:
				return -EINVAL;
		}
	}
	else
	{
		int bpp = 0;
		switch (format)
		{
		case HAL_PIXEL_FORMAT_RGBA_8888:
		case HAL_PIXEL_FORMAT_RGBX_8888:
		case HAL_PIXEL_FORMAT_BGRA_8888:
			bpp = 4;
			break;
		case HAL_PIXEL_FORMAT_RGB_888:
			bpp = 3;
			break;
		case HAL_PIXEL_FORMAT_RGB_565:
		case HAL_PIXEL_FORMAT_RGBA_5551:
		case HAL_PIXEL_FORMAT_RGBA_4444:
			bpp = 2;
			break;
		default:
			return -EINVAL;
		}
		size_t bpr = GRALLOC_ALIGN(w * bpp, 64);
		size = bpr * h;
		stride = bpr / bpp;
	}

	int err;

	#ifndef MALI_600
	if (usage & GRALLOC_USAGE_HW_FB)
	{
		err = gralloc_alloc_framebuffer(dev, size, usage, pHandle);
	}
	else
	#endif

	{
		err = gralloc_alloc_buffer(dev, size, usage, pHandle);
	}

	if (err < 0)
	{
		return err;
	}

	*pStride = stride;
	return 0;
}
static unsigned int memsizealloc = 0;
static int alloc_device_alloc(alloc_device_t *dev, int w, int h, int format, int usage, buffer_handle_t *pHandle, int *pStride)
{
	if (!pHandle || !pStride)
	{
		return -EINVAL;
	}

	size_t size;
	size_t stride;
	size_t bpr = 0;
	int reserve = true;
	int fmt_bak = format;
	bool fmt_chg = false;

    #ifdef USE_X86	

	if(format == HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED  )
	{
	    if(usage & GRALLOC_USAGE_HW_VIDEO_ENCODER )
	    {
	        //ALOGD("(usage & GRALLOC_USAGE_HW_VIDEO_ENCODER treat as NV12");
	        format = HAL_PIXEL_FORMAT_YCrCb_NV12;
	    }
	    else
	    {
	        //ALOGD("treat as NV12 888");
	        format = HAL_PIXEL_FORMAT_RGBX_8888;
	        fmt_chg = true;	        
	    }
	}
	#endif
	if (format == HAL_PIXEL_FORMAT_YCrCb_420_SP
                        || format == HAL_PIXEL_FORMAT_YV12
						|| format == HAL_PIXEL_FORMAT_YCrCb_NV12
						|| format == HAL_PIXEL_FORMAT_YCrCb_NV12_VIDEO
						|| format == HAL_PIXEL_FORMAT_YCbCr_420_888) 	
	{
        int align = 8;
        int bpp = 0;
        char property[PROPERTY_VALUE_MAX];
		int gpuformat = HAL_PIXEL_FORMAT_RGB_565;
		switch (format)
		{
			case HAL_PIXEL_FORMAT_YCrCb_420_SP:
			case HAL_PIXEL_FORMAT_YV12:
			case HAL_PIXEL_FORMAT_YCbCr_420_888:
				stride = GRALLOC_ALIGN(w, 16);
				size = h * (stride + GRALLOC_ALIGN(stride / 2, 16));
				break;
			case HAL_PIXEL_FORMAT_YCrCb_NV12:
				//stride = GRALLOC_ALIGN(w, 16);
				//size = h * (stride + GRALLOC_ALIGN(stride/2,16));
				bpp = 2;
	            bpr = (w*bpp + (align-1)) & ~(align-1);
				size = bpr * h;
				stride = bpr / bpp;				

				break;
			case HAL_PIXEL_FORMAT_YCrCb_NV12_VIDEO:
                property_set("sys.gmali.performance","video");
				bpp = 2;

				if (property_get("sys.yuv.rgb.format", property, NULL) > 0) {
					gpuformat = atoi(property);
				}
				if(gpuformat == HAL_PIXEL_FORMAT_RGBA_8888 || gpuformat == HAL_PIXEL_FORMAT_RGBX_8888)
					bpp = 4;
				else if(gpuformat == HAL_PIXEL_FORMAT_RGB_565)
					bpp = 2;
				
				bpr = (w*bpp + (align-1)) & ~(align-1);
#if GET_VPU_INTO_FROM_HEAD
				size = bpr * h;
#else
                //zxl:add tVPU_FRAME at the end of allocated buffer
                size = bpr * h + sizeof(tVPU_FRAME);
#endif
				stride = bpr / bpp;

				break;
			default:
				return -EINVAL;
		}
	}
	else
	{
		int align = 8;
		int bpp = 0;

		switch (format)
		{
			case HAL_PIXEL_FORMAT_RGBA_8888:
			case HAL_PIXEL_FORMAT_RGBX_8888:
			case HAL_PIXEL_FORMAT_BGRA_8888:
			case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED:
				bpp = 4;
				break;

			case HAL_PIXEL_FORMAT_RGB_888:
				bpp = 3;
				break;

			case HAL_PIXEL_FORMAT_RGB_565:
			case HAL_PIXEL_FORMAT_YCbCr_422_I:
			case HAL_PIXEL_FORMAT_YCbCr_422_SP:
			case HAL_PIXEL_FORMAT_RAW_SENSOR:
#if PLATFORM_SDK_VERSION < 18
			case HAL_PIXEL_FORMAT_RGBA_5551:
			case HAL_PIXEL_FORMAT_RGBA_4444:
#endif
				bpp = 2;
				break;
			case HAL_PIXEL_FORMAT_BLOB:
				bpp = 1;
				break;
			default:
				return -EINVAL;
		}

	int w_e = w, h_e = h;

#ifdef USE_LCDC_COMPOSER

        if (!(usage & GRALLOC_USAGE_HW_FB)) {
        #ifndef LCDC_COMPOSER_LANDSCAPE_ONLY
            private_module_t* m = reinterpret_cast<private_module_t*>(dev->common.module);
            uint32_t rot = (usage & GRALLOC_USAGE_ROT_MASK) >> 24;
            int bar = 0;    
           
            if(rot & 0x08) {
                rot &= ~0x08;
                switch(rot) {
                case 0:
                case HAL_TRANSFORM_ROT_180:
                    bar = m->info.yres - h;            
                    //ALOGD("bar=%d",bar);
           
                    if((w == m->info.xres) && (bar > 0) && (bar < 100)) {
                        if(0 == rot)
                            h_e += bar;
                        else
                            reserve = true;
                    }

                    //ALOGI("rot=%d [0/180]bar=%d,w=%d,h=%d,w_e=%d,h_e=%d",rot,bar,w,h,w_e,h_e);
                    break;
                case HAL_TRANSFORM_ROT_90:
                case HAL_TRANSFORM_ROT_270:
                    bar = m->info.xres - w;
                    if((h == m->info.yres) && (bar > 0) && (bar < 100)) {
                        w_e += bar;
                    }
                    if (rot == HAL_TRANSFORM_ROT_270)
                    {
						 reserve = true;
                    }

                   // ALOGI("rot=%d  [90/270]bar=%d,w=%d,h=%d,w_e=%d,h_e=%d",rot,bar,w,h,w_e,h_e);

                    break;
                default:
                    break;
                }
            }
            else
            {
                int bar_h;
                int bar_w;
                bar_h = m->info.yres - h;   
                bar_w = m->info.xres - w;
                    //ALOGD("bar=%d",bar);           
                if((w == m->info.xres) && (bar_h > 0) && (bar_h < 100)) 
                {
                     h_e += bar_h;
                }
                else if((h == m->info.yres) && (bar_w > 0) && (bar_w < 100))
                {
                     w_e += bar_w;
                }
                reserve = true;

               // ALOGI("[other rot=%x]bar_w=%d,bar_h=%d,w=%d,h=%d,w_e=%d,h_e=%d",rot,bar_w,bar_h,w,h,w_e,h_e);                            
            }
            //ALOGD("rot[%d]: %d x %d => %d x %d, reserve=%d", rot, w, h, w_e, h_e, (int)reserve);
        #else
            h_e += 100;
        #endif
        }
        if(w_e % 16) {
            //ALOGD("alloc_device_alloc, w[%d] not align, aligned to %d", w_e, (w + 31) & (~31));
            w_e = (w + 15) & (~15);
        }
#endif
		if (!(usage & GRALLOC_USAGE_HW_FB))
		{
			//zxl:fix failed of cts DecodeEditEncodeTest
			if(usage == 0x10702)
			{
				if(w_e % 32) {
					w_e=GRALLOC_ALIGN(w_e,32);
				}
			}
			else
			{
				if(w_e % 16) {
					w_e=GRALLOC_ALIGN(w_e,16);
				}
			}
		}
		else
		{
		    if(w_e % 32) 
		    {
				w_e=GRALLOC_ALIGN(w_e,32);
			}
		}

	//	bpr = (w_e*bpp + (align-1)) & ~(align-1);
	 	bpr = GRALLOC_ALIGN(w_e * bpp, 64);
		size = bpr * h_e;
		stride = bpr / bpp;

		if (format == HAL_PIXEL_FORMAT_BLOB) {
			bpp = 1;
			size = w*h;
			stride = w;
			if (GRALLOC_USAGE_HW_CAMERA_WRITE & usage) {
				/* take count from private usage flags */
				int count = (usage & GRALLOC_USAGE_PRIVATE_MASK ) >> 28;
				size += count * GRALLOC_EXTRA_ALLOCATION_UNIT_SIZE;