Exemple #1
0
static int _dpu_format_get_plane_sizes_ubwc(
		const struct dpu_format *fmt,
		const uint32_t width,
		const uint32_t height,
		struct dpu_hw_fmt_layout *layout)
{
	int i;
	int color;
	bool meta = DPU_FORMAT_IS_UBWC(fmt);

	memset(layout, 0, sizeof(struct dpu_hw_fmt_layout));
	layout->format = fmt;
	layout->width = width;
	layout->height = height;
	layout->num_planes = fmt->num_planes;

	color = _dpu_format_get_media_color_ubwc(fmt);
	if (color < 0) {
		DRM_ERROR("UBWC format not supported for fmt: %4.4s\n",
			(char *)&fmt->base.pixel_format);
		return -EINVAL;
	}

	if (DPU_FORMAT_IS_YUV(layout->format)) {
		uint32_t y_sclines, uv_sclines;
		uint32_t y_meta_scanlines = 0;
		uint32_t uv_meta_scanlines = 0;

		layout->num_planes = 2;
		layout->plane_pitch[0] = VENUS_Y_STRIDE(color, width);
		y_sclines = VENUS_Y_SCANLINES(color, height);
		layout->plane_size[0] = MSM_MEDIA_ALIGN(layout->plane_pitch[0] *
			y_sclines, DPU_UBWC_PLANE_SIZE_ALIGNMENT);

		layout->plane_pitch[1] = VENUS_UV_STRIDE(color, width);
		uv_sclines = VENUS_UV_SCANLINES(color, height);
		layout->plane_size[1] = MSM_MEDIA_ALIGN(layout->plane_pitch[1] *
			uv_sclines, DPU_UBWC_PLANE_SIZE_ALIGNMENT);

		if (!meta)
			goto done;

		layout->num_planes += 2;
		layout->plane_pitch[2] = VENUS_Y_META_STRIDE(color, width);
		y_meta_scanlines = VENUS_Y_META_SCANLINES(color, height);
		layout->plane_size[2] = MSM_MEDIA_ALIGN(layout->plane_pitch[2] *
			y_meta_scanlines, DPU_UBWC_PLANE_SIZE_ALIGNMENT);

		layout->plane_pitch[3] = VENUS_UV_META_STRIDE(color, width);
		uv_meta_scanlines = VENUS_UV_META_SCANLINES(color, height);
		layout->plane_size[3] = MSM_MEDIA_ALIGN(layout->plane_pitch[3] *
			uv_meta_scanlines, DPU_UBWC_PLANE_SIZE_ALIGNMENT);

	} else {
		uint32_t rgb_scanlines, rgb_meta_scanlines;

		layout->num_planes = 1;

		layout->plane_pitch[0] = VENUS_RGB_STRIDE(color, width);
		rgb_scanlines = VENUS_RGB_SCANLINES(color, height);
		layout->plane_size[0] = MSM_MEDIA_ALIGN(layout->plane_pitch[0] *
			rgb_scanlines, DPU_UBWC_PLANE_SIZE_ALIGNMENT);

		if (!meta)
			goto done;
		layout->num_planes += 2;
		layout->plane_pitch[2] = VENUS_RGB_META_STRIDE(color, width);
		rgb_meta_scanlines = VENUS_RGB_META_SCANLINES(color, height);
		layout->plane_size[2] = MSM_MEDIA_ALIGN(layout->plane_pitch[2] *
			rgb_meta_scanlines, DPU_UBWC_PLANE_SIZE_ALIGNMENT);
	}

done:
	for (i = 0; i < DPU_MAX_PLANES; i++)
		layout->total_size += layout->plane_size[i];

	return 0;
}
Exemple #2
0
int jpegenc_encode(void* addr, int in_fd, void** out, int* size) {

    mm_jpeg_encode_params_t* p      = &jpeg.params;
    mm_jpeg_encode_job_t* job       = &jpeg.job.encode_job;
    unsigned long t0 = get_ms();
    unsigned long t1 = 0;
    unsigned long t2 = 0;
    //memcpy(jpeg.in.addr, addr, jpeg.size.w * jpeg.size.h * 3 / 2);
    t1 = get_ms();
    n1 = t1;

    int stride;
    int scanline;

    p->src_main_buf[0].buf_size     = jpeg.size.w * jpeg.size.h * 3 / 2;
    p->src_main_buf[0].buf_vaddr    = (uint8_t*)jpeg.in.addr;
    p->src_main_buf[0].fd           = jpeg.in.p_pmem_fd;
    p->src_main_buf[0].buf_vaddr    = (uint8_t*)addr;
    p->src_main_buf[0].fd           = in_fd;
    p->src_main_buf[0].index        = 0;
    p->src_main_buf[0].format       = MM_JPEG_FMT_YUV;
    p->src_main_buf[0].offset.num_planes = 2;
    stride = VENUS_Y_STRIDE(COLOR_FMT_NV21, jpeg.size.w);
    scanline = VENUS_Y_SCANLINES(COLOR_FMT_NV21, jpeg.size.h);
    p->src_main_buf[0].offset.mp[0].len         = stride * scanline;
    p->src_main_buf[0].offset.mp[0].stride      = stride;
    p->src_main_buf[0].offset.mp[0].scanline    = scanline;
    p->src_main_buf[0].offset.mp[0].width       = jpeg.size.w;
    p->src_main_buf[0].offset.mp[0].height      = jpeg.size.h;
    p->src_main_buf[0].offset.mp[0].offset      = 0;
    p->src_main_buf[0].offset.mp[0].offset_x    = 0;
    p->src_main_buf[0].offset.mp[0].offset_y    = 0;
    stride = VENUS_UV_STRIDE(COLOR_FMT_NV21, jpeg.size.w);
    scanline = VENUS_UV_SCANLINES(COLOR_FMT_NV21, jpeg.size.h);
    p->src_main_buf[0].offset.mp[1].len         = stride * scanline;
    p->src_main_buf[0].offset.mp[1].stride      = stride;
    p->src_main_buf[0].offset.mp[1].scanline    = scanline;
    p->src_main_buf[0].offset.mp[1].width       = jpeg.size.w;
    p->src_main_buf[0].offset.mp[1].height      = jpeg.size.h/2;
    p->src_main_buf[0].offset.mp[1].offset      = 0;
    p->src_main_buf[0].offset.mp[1].offset_x    = 0;
    p->src_main_buf[0].offset.mp[1].offset_y    = 0;

    //p->src_thumb_buf[0].buf_size     = jpeg.size.w * jpeg.size.h * 3 / 2;
    //p->src_thumb_buf[0].buf_vaddr    = (uint8_t*)addr;
    //p->src_thumb_buf[0].fd           = in_fd;
    //p->src_thumb_buf[0].index        = 0;
    //p->src_thumb_buf[0].format       = MM_JPEG_FMT_YUV;
    //p->src_thumb_buf[0].offset.mp[0].len         = jpeg.size.w * jpeg.size.h;
    //p->src_thumb_buf[0].offset.mp[0].stride      = jpeg.size.w;
    //p->src_thumb_buf[0].offset.mp[0].scanline    = jpeg.size.h;
    //p->src_thumb_buf[0].offset.mp[1].len         = jpeg.size.w * jpeg.size.h / 2;
    p->num_src_bufs = 1;
    
    p->dest_buf[0].buf_size = jpeg.out.size;
    p->dest_buf[0].buf_vaddr = jpeg.out.addr;
    p->dest_buf[0].fd = jpeg.out.p_pmem_fd;
    p->dest_buf[0].index = 0;
    p->num_dst_bufs = 1;

    p->jpeg_cb  = jpegenc_callback;
    p->userdata = &jpeg;
    p->color_format = MM_JPEG_COLOR_FORMAT_YCRCBLP_H2V2;  //FIXME
    p->thumb_color_format = MM_JPEG_COLOR_FORMAT_YCRCBLP_H2V2;  //FIXME
    p->encode_thumbnail = 0;
    p->quality = 80;     //FIXME;
    p->thumb_quality = 80;     //FIXME;

    job->dst_index = 0;
    job->src_index = 0;
    job->rotation = 0;

    /* main dimension */
    job->main_dim.src_dim.width = jpeg.size.w;
    job->main_dim.src_dim.height = jpeg.size.h;
    job->main_dim.dst_dim.width = jpeg.size.w;
    job->main_dim.dst_dim.height = jpeg.size.h;
    job->main_dim.crop.top = 0;
    job->main_dim.crop.left = 0;
    job->main_dim.crop.width = jpeg.size.w;
    job->main_dim.crop.height = jpeg.size.h;
    p->main_dim  = job->main_dim;

    job->thumb_dim.src_dim.width = jpeg.size.w;
    job->thumb_dim.src_dim.height = jpeg.size.h;
    job->thumb_dim.dst_dim.width = 320;
    job->thumb_dim.dst_dim.height = 240;
    job->thumb_dim.crop.top = 0;
    job->thumb_dim.crop.left = 0;
    job->thumb_dim.crop.width = 0;
    job->thumb_dim.crop.height = 0;
    p->thumb_dim = job->thumb_dim;

    job->exif_info.numOfEntries = 0;
    p->burst_mode = 0;

    /* Qtable */
    job->qtable[0].eQuantizationTable =
        OMX_IMAGE_QuantizationTableLuma;
    job->qtable[1].eQuantizationTable =
        OMX_IMAGE_QuantizationTableChroma;

    for (int i = 0; i < QUANT_SIZE; i++) {
        job->qtable[0].nQuantizationMatrix[i] = DEFAULT_QTABLE_0[i];
        job->qtable[1].nQuantizationMatrix[i] = DEFAULT_QTABLE_1[i];
    }

    job->qtable_set[0] = 1;
    job->qtable_set[1] = 1;

    int ret = jpeg.ops.create_session(jpeg.handle, &jpeg.params, &jpeg.session_id);
    if (0 == jpeg.session_id) {
        loge("failed to create session: %d", ret);
        ret = -EINVAL;
        goto OUT;
    }

    jpeg.job.job_type = JPEG_JOB_TYPE_ENCODE;
    jpeg.job.encode_job.src_index = 0;
    jpeg.job.encode_job.dst_index = 0;
    ret = jpeg.ops.start_job(&jpeg.job, &jpeg.job_id);
    if (ret != 0) {
        loge("fail to start jpeg job");
        ret = -EINVAL;
        goto OUT;
    }

    pthread_mutex_lock(&jpeg.lock);
    pthread_cond_wait(&jpeg.cond, &jpeg.lock);
    pthread_mutex_unlock(&jpeg.lock);
    t2 = get_ms();
    logd("====jpeg: %lu %lu", t2-t1, t1-t0);


    if (jpeg.status == JPEG_JOB_STATUS_ERROR) {
        loge("encode error");
        ret = -EINVAL;
        goto OUT;
    }

    *out = jpeg.out.addr;
    *size = jpeg.out_size;

OUT:
    if (jpeg.ops.destroy_session && 0 != jpeg.session_id) {
        jpeg.ops.destroy_session(jpeg.session_id);
        jpeg.session_id = 0;
    }

    return ret;
}
int mdss_mdp_get_plane_sizes(u32 format, u32 w, u32 h,
			     struct mdss_mdp_plane_sizes *ps, u32 bwc_mode)
{
	struct mdss_mdp_format_params *fmt;
	int i, rc;
	u32 bpp, ystride0_off, ystride1_off;
	if (ps == NULL)
		return -EINVAL;

	if ((w > MAX_IMG_WIDTH) || (h > MAX_IMG_HEIGHT))
		return -ERANGE;

	fmt = mdss_mdp_get_format_params(format);
	if (!fmt)
		return -EINVAL;

	bpp = fmt->bpp;
	memset(ps, 0, sizeof(struct mdss_mdp_plane_sizes));

	if (bwc_mode) {
		rc = mdss_mdp_get_rau_strides(w, h, fmt, ps);
		if (rc)
			return rc;
		ystride0_off = DIV_ROUND_UP(h, ps->rau_h[0]);
		ystride1_off = DIV_ROUND_UP(h, ps->rau_h[1]);
		ps->plane_size[0] = (ps->ystride[0] * ystride0_off) +
				    (ps->ystride[1] * ystride1_off);
		ps->ystride[0] += ps->ystride[1];
		ps->ystride[1] = 2;
		ps->plane_size[1] = ps->rau_cnt * ps->ystride[1] *
				   (ystride0_off + ystride1_off);
	} else {
		if (fmt->fetch_planes == MDSS_MDP_PLANE_INTERLEAVED) {
			ps->num_planes = 1;
			ps->plane_size[0] = w * h * bpp;
			ps->ystride[0] = w * bpp;
		} else if (format == MDP_Y_CBCR_H2V2_VENUS) {
			int cf = COLOR_FMT_NV12;
			ps->num_planes = 2;
			ps->ystride[0] = VENUS_Y_STRIDE(cf, w);
			ps->ystride[1] = VENUS_UV_STRIDE(cf, w);
			ps->plane_size[0] = VENUS_Y_SCANLINES(cf, h) *
				ps->ystride[0];
			ps->plane_size[1] = VENUS_UV_SCANLINES(cf, h) *
				ps->ystride[1];
		} else {
			u8 hmap[] = { 1, 2, 1, 2 };
			u8 vmap[] = { 1, 1, 2, 2 };
			u8 horiz, vert, stride_align, height_align;

			horiz = hmap[fmt->chroma_sample];
			vert = vmap[fmt->chroma_sample];

			switch (format) {
			case MDP_Y_CR_CB_GH2V2:
				stride_align = 16;
				height_align = 1;
				break;
			default:
				stride_align = 1;
				height_align = 1;
				break;
			}

			ps->ystride[0] = ALIGN(w, stride_align);
			ps->ystride[1] = ALIGN(w / horiz, stride_align);
			ps->plane_size[0] = ps->ystride[0] *
				ALIGN(h, height_align);
			ps->plane_size[1] = ps->ystride[1] * (h / vert);

			if (fmt->fetch_planes == MDSS_MDP_PLANE_PSEUDO_PLANAR) {
				ps->num_planes = 2;
				ps->plane_size[1] *= 2;
				ps->ystride[1] *= 2;
			} else { /* planar */
				ps->num_planes = 3;
				ps->plane_size[2] = ps->plane_size[1];
				ps->ystride[2] = ps->ystride[1];
			}
		}
	}
	for (i = 0; i < ps->num_planes; i++)
		ps->total_size += ps->plane_size[i];

	return 0;
}