const int pixel_size = 4; // RGBA
png_bytep *row_pointers =
png_malloc(pPngStruct, height * sizeof(png_byte *));
+ if (!row_pointers) {
+ png_destroy_write_struct(&pPngStruct, &pPngInfo);
+ fclose(fp);
+ return;
+ }
unsigned int *blocks = (unsigned int *)data;
int y = 0;
for (; y < height; ++y) {
png_bytep row =
png_malloc(pPngStruct, sizeof(png_byte) * width * pixel_size);
+ if (!row) {
+ for (x = 0; x < y; x++)
+ png_free(pPngStruct, row_pointers[x]);
+ png_free(pPngStruct, row_pointers);
+ png_destroy_write_struct(&pPngStruct, &pPngInfo);
+ fclose(fp);
+ return;
+ }
+
row_pointers[y] = (png_bytep)row;
for (x = 0; x < width; ++x) {
unsigned int curBlock = blocks[y * width + x];
TDM_INFO("dump %s", file);
}
-EXTERN void
-tdm_helper_clear_buffer(tbm_surface_h buffer)
+void
+tdm_helper_clear_buffer_pos(tbm_surface_h buffer, tdm_pos *pos)
{
tbm_surface_info_s info;
int ret;
switch (info.format) {
case TBM_FORMAT_ARGB8888:
case TBM_FORMAT_XRGB8888:
- memset(info.planes[0].ptr, 0, info.planes[0].stride * info.height);
+ if (!pos) {
+ memset(info.planes[0].ptr, 0, info.planes[0].stride * info.height);
+ } else {
+ unsigned char *p;
+ int x, y;
+ for (y = pos->y; y <= (pos->y + pos->h); y++) {
+ p = info.planes[0].ptr + info.planes[0].stride * y;
+ for (x = pos->x; x <= (pos->x + pos->w); x++) {
+ int *ibuf = (int*)p;
+ ibuf[x] = 0x00000000;
+ }
+ }
+ }
break;
case TBM_FORMAT_YVU420:
case TBM_FORMAT_YUV420:
tbm_surface_unmap(buffer);
}
+EXTERN void
+tdm_helper_clear_buffer(tbm_surface_h buffer)
+{
+ TDM_RETURN_IF_FAIL(buffer != NULL);
+
+ tdm_helper_clear_buffer_pos(buffer, NULL);
+}
+
+static pixman_format_code_t
+_tdm_helper_pixman_format_get(tbm_format format)
+{
+ switch (format) {
+ case TBM_FORMAT_ARGB8888:
+ return PIXMAN_a8r8g8b8;
+ case TBM_FORMAT_XRGB8888:
+ return PIXMAN_x8r8g8b8;
+ default:
+ return 0;
+ }
+
+ return 0;
+}
+
+EXTERN tdm_error
+tdm_helper_convert_buffer(tbm_surface_h srcbuf, tbm_surface_h dstbuf,
+ tdm_pos *srcpos, tdm_pos *dstpos,
+ tdm_transform transform, int over)
+{
+ tbm_surface_info_s src_info, dst_info;
+ pixman_image_t *src_img = NULL, *dst_img = NULL;
+ pixman_format_code_t src_format, dst_format;
+ double scale_x, scale_y;
+ int rotate_step, bos;
+ pixman_transform_t t;
+ struct pixman_f_transform ft;
+ pixman_op_t op;
+ int src_stride, dst_stride;
+ int buf_width, err;
+ tdm_error ret = TDM_ERROR_OPERATION_FAILED;
+
+ TDM_RETURN_VAL_IF_FAIL(srcbuf != NULL, TDM_ERROR_INVALID_PARAMETER);
+ TDM_RETURN_VAL_IF_FAIL(dstbuf != NULL, TDM_ERROR_INVALID_PARAMETER);
+
+ bos = tbm_surface_internal_get_num_bos(srcbuf);
+ TDM_RETURN_VAL_IF_FAIL(bos == 1, TDM_ERROR_OPERATION_FAILED);
+
+ bos = tbm_surface_internal_get_num_bos(dstbuf);
+ TDM_RETURN_VAL_IF_FAIL(bos == 1, TDM_ERROR_OPERATION_FAILED);
+
+ err = tbm_surface_map(srcbuf, TBM_OPTION_READ, &src_info);
+ TDM_RETURN_VAL_IF_FAIL(err == TBM_SURFACE_ERROR_NONE, TDM_ERROR_OPERATION_FAILED);
+
+ err = tbm_surface_map(dstbuf, TBM_OPTION_WRITE, &dst_info);
+ TDM_GOTO_IF_FAIL(err == TBM_SURFACE_ERROR_NONE, unmap_srcbuf);
+
+ /* not handle buffers which have 2 more gem handles */
+ TDM_GOTO_IF_FAIL(src_info.planes[0].ptr != NULL, unmap_dstbuf);
+ TDM_GOTO_IF_FAIL(dst_info.planes[0].ptr != NULL, unmap_dstbuf);
+
+ src_format = _tdm_helper_pixman_format_get(src_info.format);
+ TDM_GOTO_IF_FAIL(src_format > 0, unmap_dstbuf);
+ dst_format = _tdm_helper_pixman_format_get(dst_info.format);
+ TDM_GOTO_IF_FAIL(dst_format > 0, unmap_dstbuf);
+
+ buf_width = src_info.planes[0].stride >> 2;
+ src_stride = src_info.planes[0].stride;
+ src_img = pixman_image_create_bits(src_format, buf_width, src_info.height,
+ (uint32_t*)src_info.planes[0].ptr, src_stride);
+ TDM_GOTO_IF_FAIL(src_img, unref_img);
+
+ buf_width = dst_info.planes[0].stride >> 2;
+ dst_stride = dst_info.planes[0].stride;
+ dst_img = pixman_image_create_bits(dst_format, buf_width, dst_info.height,
+ (uint32_t*)dst_info.planes[0].ptr, dst_stride);
+ TDM_GOTO_IF_FAIL(dst_img, unref_img);
+
+ pixman_f_transform_init_identity(&ft);
+
+ if (transform & TDM_TRANSFORM_FLIPPED) {
+ pixman_f_transform_scale(&ft, NULL, -1, 1);
+ pixman_f_transform_translate(&ft, NULL, dstpos->w, 0);
+ }
+
+ rotate_step = transform & 0x3;
+ if (rotate_step > 0) {
+ int c, s, tx = 0, ty = 0;
+ switch (rotate_step) {
+ case 1:
+ c = 0, s = -1, tx = -dstpos->w;
+ break;
+ case 2:
+ c = -1, s = 0, tx = -dstpos->w, ty = -dstpos->h;
+ break;
+ case 3:
+ c = 0, s = 1, ty = -dstpos->h;
+ break;
+ default:
+ break;
+ }
+ pixman_f_transform_translate(&ft, NULL, tx, ty);
+ pixman_f_transform_rotate(&ft, NULL, c, s);
+ }
+
+ if (rotate_step % 2 == 0) {
+ scale_x = (double)srcpos->w / dstpos->w;
+ scale_y = (double)srcpos->h / dstpos->h;
+ } else {
+ scale_x = (double)srcpos->w / dstpos->h;
+ scale_y = (double)srcpos->h / dstpos->w;
+ }
+
+ pixman_f_transform_scale(&ft, NULL, scale_x, scale_y);
+ pixman_f_transform_translate(&ft, NULL, srcpos->x, srcpos->y);
+ pixman_transform_from_pixman_f_transform(&t, &ft);
+ pixman_image_set_transform(src_img, &t);
+
+ op = (!over) ? PIXMAN_OP_SRC : PIXMAN_OP_OVER;
+
+ pixman_image_composite(op, src_img, NULL, dst_img, 0, 0, 0, 0,
+ dstpos->x, dstpos->y, dstpos->w, dstpos->h);
+
+ ret = TDM_ERROR_NONE;
+
+unref_img:
+ if (src_img)
+ pixman_image_unref(src_img);
+ if (dst_img)
+ pixman_image_unref(dst_img);
+unmap_dstbuf:
+ tbm_surface_unmap(dstbuf);
+unmap_srcbuf:
+ tbm_surface_unmap(srcbuf);
+
+ return ret;
+}
+
EXTERN int
tdm_helper_get_fd(const char *env)
{
}
EXTERN void
+tdm_helper_dump_start(char *dumppath, int *count)
+{
+ if (dumppath == NULL || count == NULL) {
+ TDM_DBG("tdm_helper_dump dumppath or count is null.");
+ return;
+ }
+
+ tdm_dump_enable = 1;
+
+ TDM_DBG("tdm_helper_dump start.(path : %s)", dumppath);
+}
+
+EXTERN void
+tdm_helper_dump_stop(void)
+{
+ tdm_dump_enable = 0;
+
+ TDM_DBG("tdm_helper_dump stop.");
+}
+
+static tdm_error
+_tdm_helper_buffer_convert(tbm_surface_h srcbuf, tbm_surface_h dstbuf,
+ int dx, int dy, int dw, int dh, int count)
+{
+ pixman_image_t *src_img = NULL, *dst_img = NULL;
+ pixman_format_code_t src_format, dst_format;
+ pixman_transform_t t;
+ struct pixman_f_transform ft;
+ pixman_op_t op;
+ tbm_surface_info_s src_info = {0, };
+ tbm_surface_info_s dst_info = {0, };
+ int stride, width;
+ double scale_x, scale_y;
+
+ TDM_RETURN_VAL_IF_FAIL(srcbuf != NULL, TDM_ERROR_INVALID_PARAMETER);
+ TDM_RETURN_VAL_IF_FAIL(dstbuf != NULL, TDM_ERROR_INVALID_PARAMETER);
+
+ if (tbm_surface_map(srcbuf, TBM_SURF_OPTION_READ, &src_info)
+ != TBM_SURFACE_ERROR_NONE) {
+ TDM_ERR("cannot mmap srcbuf\n");
+ return TDM_ERROR_OPERATION_FAILED;
+ }
+
+ if (tbm_surface_map(dstbuf, TBM_SURF_OPTION_WRITE, &dst_info)
+ != TBM_SURFACE_ERROR_NONE) {
+ TDM_ERR("cannot mmap dstbuf\n");
+ tbm_surface_unmap(srcbuf);
+ return TDM_ERROR_OPERATION_FAILED;
+ }
+ TDM_GOTO_IF_FAIL(src_info.num_planes == 1, cant_convert);
+ TDM_GOTO_IF_FAIL(dst_info.num_planes == 1, cant_convert);
+
+ /* src */
+ src_format = _tdm_helper_pixman_format_get(src_info.format);
+ TDM_GOTO_IF_FAIL(src_format > 0, cant_convert);
+
+ width = src_info.planes[0].stride / 4;
+ stride = src_info.planes[0].stride;
+ src_img = pixman_image_create_bits(src_format, width, src_info.height,
+ (uint32_t*)src_info.planes[0].ptr, stride);
+ TDM_GOTO_IF_FAIL(src_img != NULL, cant_convert);
+
+ /* dst */
+ dst_format = _tdm_helper_pixman_format_get(dst_info.format);
+ TDM_GOTO_IF_FAIL(dst_format > 0, cant_convert);
+
+ width = dst_info.planes[0].stride / 4;
+ stride = dst_info.planes[0].stride;
+ dst_img = pixman_image_create_bits(dst_format, width, dst_info.height,
+ (uint32_t*)dst_info.planes[0].ptr, stride);
+ TDM_GOTO_IF_FAIL(dst_img != NULL, cant_convert);
+
+ pixman_f_transform_init_identity(&ft);
+
+ scale_x = (double)src_info.width / dw;
+ scale_y = (double)src_info.height / dh;
+
+ pixman_f_transform_scale(&ft, NULL, scale_x, scale_y);
+ pixman_f_transform_translate(&ft, NULL, 0, 0);
+ pixman_transform_from_pixman_f_transform(&t, &ft);
+ pixman_image_set_transform(src_img, &t);
+
+ if (count == 0)
+ op = PIXMAN_OP_SRC;
+ else
+ op = PIXMAN_OP_OVER;
+
+ pixman_image_composite(op, src_img, NULL, dst_img,
+ 0, 0, 0, 0, dx, dy, dw, dh);
+
+ if (src_img)
+ pixman_image_unref(src_img);
+ if (dst_img)
+ pixman_image_unref(dst_img);
+
+ tbm_surface_unmap(srcbuf);
+ tbm_surface_unmap(dstbuf);
+
+ return TDM_ERROR_NONE;
+
+cant_convert:
+ if (src_img)
+ pixman_image_unref(src_img);
+
+ tbm_surface_unmap(srcbuf);
+ tbm_surface_unmap(dstbuf);
+
+ return TDM_ERROR_OPERATION_FAILED;
+}
+
+EXTERN tdm_error
+tdm_helper_capture_output(tdm_output *output, tbm_surface_h dst_buffer,
+ int x, int y, int w, int h,
+ tdm_helper_capture_handler func, void *data)
+{
+ tbm_surface_h surface;
+ tdm_error err;
+ int i, count, first = 0;
+
+ TDM_RETURN_VAL_IF_FAIL(output != NULL, TDM_ERROR_INVALID_PARAMETER);
+ TDM_RETURN_VAL_IF_FAIL(dst_buffer != NULL, TDM_ERROR_INVALID_PARAMETER);
+ TDM_RETURN_VAL_IF_FAIL(x >= 0, TDM_ERROR_INVALID_PARAMETER);
+ TDM_RETURN_VAL_IF_FAIL(y >= 0, TDM_ERROR_INVALID_PARAMETER);
+ TDM_RETURN_VAL_IF_FAIL(w >= 0, TDM_ERROR_INVALID_PARAMETER);
+ TDM_RETURN_VAL_IF_FAIL(h >= 0, TDM_ERROR_INVALID_PARAMETER);
+ TDM_RETURN_VAL_IF_FAIL(func != NULL, TDM_ERROR_INVALID_PARAMETER);
+ TDM_RETURN_VAL_IF_FAIL(data != NULL, TDM_ERROR_INVALID_PARAMETER);
+
+ err = tdm_output_get_layer_count(output, &count);
+ if (err != TDM_ERROR_NONE) {
+ TDM_ERR("tdm_output_get_layer_count fail(%d)\n", err);
+ return TDM_ERROR_OPERATION_FAILED;
+ }
+ if (count <= 0) {
+ TDM_ERR("tdm_output_get_layer_count err(%d, %d)\n", err, count);
+ return TDM_ERROR_BAD_MODULE;
+ }
+
+ for (i = count - 1; i >= 0; i--) {
+ tdm_layer *layer = tdm_output_get_layer(output, i, NULL);
+
+ surface = tdm_layer_get_displaying_buffer(layer, &err);
+ if (err != TDM_ERROR_NONE)
+ continue;
+
+ err = _tdm_helper_buffer_convert(surface, dst_buffer, x, y, w, h, first++);
+ if (err != TDM_ERROR_NONE)
+ TDM_DBG("convert fail %d-layer buffer\n", i);
+ else
+ TDM_DBG("convert success %d-layer buffer\n", i);
+ }
+
+ func(dst_buffer, data);
+
+ return TDM_ERROR_NONE;
+}
+
+EXTERN void
tdm_helper_get_display_information(tdm_display *dpy, char *reply, int *len)
{
tdm_private_display *private_display;