+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;
+ tdm_backend_module *module_data;
+ tdm_func_output *func_output;
+ tdm_func_layer *func_layer;
+ tdm_private_output *private_output = NULL;
+ tdm_private_layer *private_layer = NULL;
+ tdm_private_pp *private_pp = NULL;
+ tdm_private_capture *private_capture = NULL;
+ tdm_error ret;
+ int i;
+
+ TDM_DBG_RETURN_IF_FAIL(dpy != NULL);
+
+ private_display = dpy;
+ func_output = &private_display->func_output;
+ func_layer = &private_display->func_layer;
+
+ /* module information */
+ module_data = private_display->module_data;
+ TDM_SNPRINTF(reply, len, "[TDM backend information]\n");
+ TDM_SNPRINTF(reply, len, "name: %s\n", module_data->name);
+ TDM_SNPRINTF(reply, len, "vendor: %s\n", module_data->vendor);
+ TDM_SNPRINTF(reply, len, "version: %d.%d\n\n",
+ (int)TDM_BACKEND_GET_ABI_MAJOR(module_data->abi_version),
+ (int)TDM_BACKEND_GET_ABI_MINOR(module_data->abi_version));
+
+ /* output information */
+ TDM_SNPRINTF(reply, len, "[Output information]\n");
+ TDM_SNPRINTF(reply, len, "--------------------------------------------------------------------------------------------\n");
+ TDM_SNPRINTF(reply, len, "idx maker model name type status dpms subpixel align_w min max phy(mm)\n");
+ TDM_SNPRINTF(reply, len, "--------------------------------------------------------------------------------------------\n");
+ LIST_FOR_EACH_ENTRY(private_output, &private_display->output_list, link) {
+ TDM_SNPRINTF(reply, len, "%d %s %s %s %s %s %s %u %d %dx%d %dx%d %ux%u\n",
+ private_output->index, private_output->caps.maker,
+ private_output->caps.model, private_output->caps.name,
+ tdm_conn_str(private_output->caps.type),
+ tdm_status_str(private_output->caps.status),
+ tdm_dpms_str(private_output->current_dpms_value),
+ private_output->caps.subpixel,
+ TDM_FRONT_VALUE(private_output->caps.preferred_align),
+ TDM_FRONT_VALUE(private_output->caps.min_w),
+ TDM_FRONT_VALUE(private_output->caps.min_h),
+ TDM_FRONT_VALUE(private_output->caps.max_w),
+ TDM_FRONT_VALUE(private_output->caps.max_h),
+ private_output->caps.mmWidth, private_output->caps.mmHeight);
+
+ TDM_SNPRINTF(reply, len, "\t%u modes:\n", private_output->caps.mode_count);
+
+ if (private_output->caps.mode_count > 0) {
+ const tdm_output_mode *current_mode = NULL;
+
+ TDM_DBG_RETURN_IF_FAIL(func_output->output_get_mode);
+ ret = func_output->output_get_mode(private_output->output_backend, ¤t_mode);
+ TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
+
+ TDM_SNPRINTF(reply, len, "\t\t name refresh (Hz) clk hdisp hss hse htot vdisp vss vse vtot vscan\n");
+ for (i = 0; i < private_output->caps.mode_count; i++) {
+ char *current = (current_mode == private_output->caps.modes + i) ? "*" : " ";
+ TDM_SNPRINTF(reply, len, "\t\t%s%s %u %u %u %u %u %u %u %u %u %u %u ",
+ current,
+ private_output->caps.modes[i].name,
+ private_output->caps.modes[i].vrefresh,
+ private_output->caps.modes[i].clock,
+ private_output->caps.modes[i].hdisplay,
+ private_output->caps.modes[i].hsync_start,
+ private_output->caps.modes[i].hsync_end,
+ private_output->caps.modes[i].htotal,
+ private_output->caps.modes[i].vdisplay,
+ private_output->caps.modes[i].vsync_start,
+ private_output->caps.modes[i].vsync_end,
+ private_output->caps.modes[i].vtotal,
+ private_output->caps.modes[i].vscan);
+ tdm_mode_flag_str(private_output->caps.modes[i].flags, &reply, len);
+ TDM_SNPRINTF(reply, len, " ");
+ tdm_mode_type_str(private_output->caps.modes[i].type, &reply, len);
+ TDM_SNPRINTF(reply, len, "\n");
+ }
+ }
+
+ TDM_SNPRINTF(reply, len, "\t%d properties:\n", private_output->caps.prop_count);
+ if (private_output->caps.prop_count > 0) {
+ TDM_SNPRINTF(reply, len, "\t\tname\ttype\tidx\tvalue\n");
+ for (i = 0; i < private_output->caps.prop_count; i++) {
+ tdm_value value;
+ TDM_DBG_RETURN_IF_FAIL(func_output->output_get_property);
+ ret = func_output->output_get_property(private_output->output_backend,
+ private_output->caps.props[i].id,
+ &value);
+ TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
+ TDM_SNPRINTF(reply, len, "\t\t%s\t%s\t%u\t",
+ private_output->caps.props[i].name,
+ tdm_value_type_str(private_output->caps.props[i].type),
+ private_output->caps.props[i].id);
+ switch (private_output->caps.props[i].type) {
+ case TDM_VALUE_TYPE_PTR:
+ TDM_SNPRINTF(reply, len, "%p\n", value.ptr);
+ break;
+ case TDM_VALUE_TYPE_INT32:
+ TDM_SNPRINTF(reply, len, "%d\n", value.s32);
+ break;
+ case TDM_VALUE_TYPE_INT64:
+ TDM_SNPRINTF(reply, len, "%"PRId64"\n", value.s64);
+ break;
+ case TDM_VALUE_TYPE_UINT64:
+ TDM_SNPRINTF(reply, len, "%"PRIu64"\n", value.u64);
+ break;
+ case TDM_VALUE_TYPE_UINT32:
+ default:
+ TDM_SNPRINTF(reply, len, "%u\n", value.u32);
+ break;
+ }
+ }
+ }
+ }
+ TDM_SNPRINTF(reply, len, "\n");
+
+ /* layer information */
+ TDM_SNPRINTF(reply, len, "[Layer information]\n");
+ TDM_SNPRINTF(reply, len, "-----------------------------------------------------------------------\n");
+ TDM_SNPRINTF(reply, len, "idx output zpos buf format size crop geometry transform\n");
+ TDM_SNPRINTF(reply, len, "-----------------------------------------------------------------------\n");
+ LIST_FOR_EACH_ENTRY(private_output, &private_display->output_list, link) {
+ LIST_FOR_EACH_ENTRY(private_layer, &private_output->layer_list, link) {
+ if (!private_layer->usable) {
+ tdm_info_layer info;
+ unsigned int format;
+ tdm_size size;
+ tbm_surface_info_s buf_info;
+
+ TDM_DBG_RETURN_IF_FAIL(func_layer->layer_get_info);
+ memset(&info, 0, sizeof info);
+ ret = func_layer->layer_get_info(private_layer->layer_backend, &info);
+ TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
+
+ if (!private_layer->showing_buffer)
+ continue;
+
+ format = tbm_surface_get_format(private_layer->showing_buffer->buffer);
+ tbm_surface_get_info(private_layer->showing_buffer->buffer, &buf_info);
+
+ if (IS_RGB(format))
+ size.h = buf_info.planes[0].stride >> 2;
+ else
+ size.h = buf_info.planes[0].stride;
+ size.v = tbm_surface_get_height(private_layer->showing_buffer->buffer);
+
+ if (info.src_config.format)
+ format = (info.src_config.format) ? : format;
+
+ TDM_SNPRINTF(reply, len, "%d %d %d %p %c%c%c%c %ux%u %ux%u+%u+%u %ux%u+%u+%u %s\n",
+ private_layer->index,
+ private_output->index,
+ private_layer->caps.zpos,
+ private_layer->showing_buffer->buffer, FOURCC_STR(format), size.h, size.v,
+ info.src_config.pos.w, info.src_config.pos.h, info.src_config.pos.x, info.src_config.pos.y,
+ info.dst_pos.w, info.dst_pos.h, info.dst_pos.x, info.dst_pos.y,
+ tdm_transform_str(info.transform));
+ } else {
+ TDM_SNPRINTF(reply, len, "%d %d %d -\n",
+ private_layer->index,
+ private_output->index,
+ private_layer->caps.zpos);
+ }
+
+ TDM_SNPRINTF(reply, len, "\tcaps\t: ");
+ tdm_layer_caps_str(private_layer->caps.capabilities, &reply, len);
+ TDM_SNPRINTF(reply, len, "\n");
+
+ TDM_SNPRINTF(reply, len, "\tformats\t: ");
+ if (private_layer->caps.format_count > 0) {
+ const char *sep = "";
+ for (i = 0; i < private_layer->caps.format_count; i++) {
+ if (private_layer->caps.formats[i] == 0)
+ continue;
+ TDM_SNPRINTF(reply, len, "%s%c%c%c%c", sep, FOURCC_STR(private_layer->caps.formats[i]));
+ sep = ",";
+ }
+ TDM_SNPRINTF(reply, len, "\n");
+ }
+
+ TDM_SNPRINTF(reply, len, "\t%u properties:\n", private_layer->caps.prop_count);
+ if (private_layer->caps.prop_count > 0) {
+ TDM_SNPRINTF(reply, len, "\t\tname\ttype\tidx\tvalue\n");
+ for (i = 0; i < private_layer->caps.prop_count; i++) {
+ tdm_value value;
+ TDM_DBG_RETURN_IF_FAIL(func_layer->layer_get_property);
+ ret = func_layer->layer_get_property(private_layer->layer_backend,
+ private_layer->caps.props[i].id,
+ &value);
+ TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
+ TDM_SNPRINTF(reply, len, "\t\t%s\t%s\t%u\t",
+ private_layer->caps.props[i].name,
+ tdm_value_type_str(private_output->caps.props[i].type),
+ private_layer->caps.props[i].id);
+ switch (private_layer->caps.props[i].type) {
+ case TDM_VALUE_TYPE_PTR:
+ TDM_SNPRINTF(reply, len, "%p\n", value.ptr);
+ break;
+ case TDM_VALUE_TYPE_INT32:
+ TDM_SNPRINTF(reply, len, "%d\n", value.s32);
+ break;
+ case TDM_VALUE_TYPE_INT64:
+ TDM_SNPRINTF(reply, len, "%"PRId64"\n", value.s64);
+ break;
+ case TDM_VALUE_TYPE_UINT64:
+ TDM_SNPRINTF(reply, len, "%"PRIu64"\n", value.u64);
+ break;
+ case TDM_VALUE_TYPE_UINT32:
+ default:
+ TDM_SNPRINTF(reply, len, "%u\n", value.u32);
+ break;
+ }
+ }
+ }
+ }
+ }
+ TDM_SNPRINTF(reply, len, "\n");
+
+ if (private_display->capabilities & TDM_DISPLAY_CAPABILITY_PP) {
+ const char *sep = "";
+ TDM_SNPRINTF(reply, len, "[PP information]\n");
+ TDM_SNPRINTF(reply, len, "caps\t: ");
+ tdm_pp_caps_str(private_display->caps_pp.capabilities, &reply, len);
+ TDM_SNPRINTF(reply, len, "\n");
+ TDM_SNPRINTF(reply, len, "formats\t: ");
+ for (i = 0; i < private_display->caps_pp.format_count; i++) {
+ if (private_display->caps_pp.formats[i] == 0)
+ continue;
+ TDM_SNPRINTF(reply, len, "%s%c%c%c%c", sep, FOURCC_STR(private_display->caps_pp.formats[i]));
+ sep = ",";
+ }
+ TDM_SNPRINTF(reply, len, "\n");
+ TDM_SNPRINTF(reply, len, "size\t: min(%dx%d) max(%dx%d) align_w(%d)\n",
+ TDM_FRONT_VALUE(private_display->caps_pp.min_w),
+ TDM_FRONT_VALUE(private_display->caps_pp.min_h),
+ TDM_FRONT_VALUE(private_display->caps_pp.max_w),
+ TDM_FRONT_VALUE(private_display->caps_pp.max_h),
+ TDM_FRONT_VALUE(private_display->caps_pp.preferred_align));
+ if (!LIST_IS_EMPTY(&private_display->pp_list)) {
+ TDM_SNPRINTF(reply, len, "-------------------------------------------------------------\n");
+ TDM_SNPRINTF(reply, len, "src(format size crop) | dst(format size crop) | transform\n");
+ TDM_SNPRINTF(reply, len, "-------------------------------------------------------------\n");
+ LIST_FOR_EACH_ENTRY(private_pp, &private_display->pp_list, link) {
+ TDM_SNPRINTF(reply, len, "%c%c%c%c %ux%u %ux%u+%u+%u | %c%c%c%c %ux%u %ux%u+%u+%u | %s\n",
+ FOURCC_STR(private_pp->info.src_config.format),
+ private_pp->info.src_config.size.h,
+ private_pp->info.src_config.size.v,
+ private_pp->info.src_config.pos.x, private_pp->info.src_config.pos.y,
+ private_pp->info.src_config.pos.w, private_pp->info.src_config.pos.h,
+ FOURCC_STR(private_pp->info.dst_config.format),
+ private_pp->info.dst_config.size.h,
+ private_pp->info.dst_config.size.v,
+ private_pp->info.dst_config.pos.x, private_pp->info.dst_config.pos.y,
+ private_pp->info.dst_config.pos.w, private_pp->info.dst_config.pos.h,
+ tdm_transform_str(private_pp->info.transform));
+ }
+ }
+ } else {
+ TDM_SNPRINTF(reply, len, "[No PP capability]\n");
+ }
+ TDM_SNPRINTF(reply, len, "\n");
+
+ if (private_display->capabilities & TDM_DISPLAY_CAPABILITY_CAPTURE) {
+ const char *sep = "";
+ TDM_SNPRINTF(reply, len, "[Capture information]\n");
+ TDM_SNPRINTF(reply, len, "caps\t: ");
+ tdm_capture_caps_str(private_display->caps_capture.capabilities, &reply, len);
+ TDM_SNPRINTF(reply, len, "\n");
+ TDM_SNPRINTF(reply, len, "formats\t: ");
+ for (i = 0; i < private_display->caps_capture.format_count; i++) {
+ if (private_display->caps_capture.formats[i] == 0)
+ continue;
+ TDM_SNPRINTF(reply, len, "%s%c%c%c%c", sep, FOURCC_STR(private_display->caps_capture.formats[i]));
+ sep = ",";
+ }
+ TDM_SNPRINTF(reply, len, "\n");
+ TDM_SNPRINTF(reply, len, "size\t: min(%dx%d) max(%dx%d) align_w(%d)\n",
+ TDM_FRONT_VALUE(private_display->caps_capture.min_w),
+ TDM_FRONT_VALUE(private_display->caps_capture.min_h),
+ TDM_FRONT_VALUE(private_display->caps_capture.max_w),
+ TDM_FRONT_VALUE(private_display->caps_capture.max_h),
+ TDM_FRONT_VALUE(private_display->caps_capture.preferred_align));
+ if (!LIST_IS_EMPTY(&private_display->capture_list)) {
+ TDM_SNPRINTF(reply, len, "-----------------------------------\n");
+ TDM_SNPRINTF(reply, len, "dst(format size crop) | transform\n");
+ TDM_SNPRINTF(reply, len, "-----------------------------------\n");
+ LIST_FOR_EACH_ENTRY(private_capture, &private_display->capture_list, link) {
+ TDM_SNPRINTF(reply, len, "%c%c%c%c %ux%u %ux%u+%u+%u | %s\n",
+ FOURCC_STR(private_capture->info.dst_config.format),
+ private_capture->info.dst_config.size.h,
+ private_capture->info.dst_config.size.v,
+ private_capture->info.dst_config.pos.x, private_capture->info.dst_config.pos.y,
+ private_capture->info.dst_config.pos.w, private_capture->info.dst_config.pos.h,
+ tdm_transform_str(private_capture->info.transform));
+ }
+ }
+ } else {
+ TDM_SNPRINTF(reply, len, "[No Capture capability]\n");
+ }
+ TDM_SNPRINTF(reply, len, "\n");
+}
+
+EXTERN int
+tdm_helper_commit_per_vblank_enabled(tdm_display *dpy)
+{
+ TDM_ERR("the deprecated function, use 'tdm_helper_output_commit_per_vblank_enabled' instead.");
+
+ return 0;
+}
+
+EXTERN int
+tdm_helper_output_commit_per_vblank_enabled(tdm_output *output)
+{
+ tdm_private_output *private_output = output;
+
+ TDM_RETURN_VAL_IF_FAIL(private_output != NULL, -1);
+
+ return !!private_output->commit_per_vblank;
+}
+