+static pixman_format_code_t
+_tbm_surface_internal_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;
+}
+
+/**
+ * This function supports only if a buffer has below formats.
+ * - TBM_FORMAT_ARGB8888
+ * - TBM_FORMAT_XRGB8888
+ */
+static tbm_surface_error_e
+_tbm_surface_internal_buffer_scale(void *src_ptr, void *dst_ptr,
+ int format, int src_stride, int src_w, int src_h,
+ int dst_stride, int dst_w, int dst_h)
+{
+ pixman_image_t *src_img = NULL, *dst_img = NULL;
+ pixman_format_code_t pixman_format;
+ pixman_transform_t t;
+ struct pixman_f_transform ft;
+ double scale_x, scale_y;
+
+ TBM_RETURN_VAL_IF_FAIL(src_ptr != NULL, TBM_SURFACE_ERROR_INVALID_OPERATION);
+ TBM_RETURN_VAL_IF_FAIL(dst_ptr != NULL, TBM_SURFACE_ERROR_INVALID_OPERATION);
+
+ pixman_format = _tbm_surface_internal_pixman_format_get(format);
+ TBM_RETURN_VAL_IF_FAIL(pixman_format > 0, TBM_SURFACE_ERROR_INVALID_OPERATION);
+
+ /* src */
+ src_img = pixman_image_create_bits(pixman_format, src_w, src_h,
+ (uint32_t*)src_ptr, src_stride);
+ TBM_GOTO_VAL_IF_FAIL(src_img != NULL, cant_convert);
+
+ /* dst */
+ dst_img = pixman_image_create_bits(pixman_format, dst_w, dst_h,
+ (uint32_t*)dst_ptr, dst_stride);
+ TBM_GOTO_VAL_IF_FAIL(dst_img != NULL, cant_convert);
+
+ pixman_f_transform_init_identity(&ft);
+
+ scale_x = (double)src_w / dst_w;
+ scale_y = (double)src_h / dst_h;
+
+ 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);
+
+ pixman_image_composite(PIXMAN_OP_SRC, src_img, NULL, dst_img,
+ 0, 0, 0, 0, 0, 0, dst_w, dst_h);
+
+ pixman_image_unref(src_img);
+ pixman_image_unref(dst_img);
+
+ return TBM_SURFACE_ERROR_NONE;
+
+cant_convert:
+ if (src_img)
+ pixman_image_unref(src_img);
+
+ return TBM_SURFACE_ERROR_INVALID_OPERATION;
+}
+