#include <string.h>
#include <tbm_surface.h>
#include <tbm_surface_internal.h>
+#include <tbm_drm_helper.h>
#include <string.h>
#include <time.h>
#include <pixman.h>
return 0;
}
+static int
+_tdm_helper_check_file_is_valid(const char* path, int del_link)
+{
+ char *real_path;
+
+ if (!path)
+ return 0;
+
+ real_path = realpath(path, NULL);
+ if (real_path && strncmp(path, real_path, strlen(path))) {
+ if (del_link)
+ unlink(path);
+ free(real_path);
+
+ return 0;
+ }
+
+ if (real_path)
+ free(real_path);
+
+ return 1;
+}
+
static void
_tdm_helper_dump_raw(const char *file, void *data1, int size1, void *data2,
int size2, void *data3, int size3)
{
unsigned int *blocks;
- FILE *fp = fopen(file, "w+");
+ FILE *fp;
+
+ if (!_tdm_helper_check_file_is_valid(file, 1))
+ TDM_WRN("'%s' may be symbolic link\n", file);
+
+ fp = fopen(file, "w+");
TDM_RETURN_IF_FAIL(fp != NULL);
blocks = (unsigned int *)data1;
_tdm_helper_dump_png(const char *file, const void *data, int width,
int height)
{
- FILE *fp = fopen(file, "wb");
+ FILE *fp;
+
+ if (!_tdm_helper_check_file_is_valid(file, 1))
+ TDM_WRN("'%s' may be symbolic link\n", file);
+
+ fp = fopen(file, "wb");
TDM_RETURN_IF_FAIL(fp != NULL);
png_structp pPngStruct =
TDM_INFO("dump %s", file);
}
-void
-tdm_helper_clear_buffer_pos(tbm_surface_h buffer, tdm_pos *pos)
+EXTERN void
+tdm_helper_clear_buffer_color(tbm_surface_h buffer, tdm_pos *pos, unsigned int color)
{
tbm_surface_info_s info;
int ret;
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;
+ unsigned int *ibuf = (unsigned int*)p;
+ ibuf[x] = color;
}
}
}
}
EXTERN void
+tdm_helper_clear_buffer_pos(tbm_surface_h buffer, tdm_pos *pos)
+{
+ TDM_RETURN_IF_FAIL(buffer != NULL);
+
+ tdm_helper_clear_buffer_color(buffer, pos, 0);
+}
+
+EXTERN void
tdm_helper_clear_buffer(tbm_surface_h buffer)
{
TDM_RETURN_IF_FAIL(buffer != NULL);
EXTERN int
tdm_helper_get_fd(const char *env)
{
- const char *value;
- int fd, newfd, flags, ret;
- char *end;
- errno = 0;
-
- value = (const char*)getenv(env);
- if (!value)
- return -1;
-
- const long sl = strtol(value, &end, 10);
- if (end == value) {
- TDM_ERR("%s: not a decimal number\n", value);
- return -1;
- } else if (*end != '\0') {
- TDM_ERR("%s: extra characters at end of input: %s\n", value, end);
- return -1;
- } else if ((sl == LONG_MIN || sl == LONG_MAX) && errno == ERANGE) {
- TDM_ERR("%s out of range of type long\n", value);
- return -1;
- } else if (sl > INT_MAX) {
- TDM_ERR("%ld greater than INT_MAX\n", sl);
- return -1;
- } else if (sl < INT_MIN) {
- TDM_ERR("%ld less than INT_MIN\n", sl);
- return -1;
- } else {
- fd = (int)sl;
- if (fd < 0) {
- TDM_ERR("%d out of fd range\n", fd);
- return -1;
- }
- }
-
- flags = fcntl(fd, F_GETFD);
- if (flags == -1) {
- TDM_ERR("fcntl failed: %m");
+ if (strncmp(env, "TBM_DRM_MASTER_FD", 17) && strncmp(env, "TDM_DRM_MASTER_FD", 17)) {
+ TDM_INFO("DEPRECATED! '%s'", env);
return -1;
}
- newfd = dup(fd);
- if (newfd < 0) {
- TDM_ERR("dup failed: %m");
- return -1;
- }
-
- TDM_INFO("%s: fd(%d) newfd(%d)", env, fd, newfd);
-
- ret = fcntl(newfd, F_SETFD, flags | FD_CLOEXEC);
- if (ret == -1) {
- TDM_ERR("fcntl failed: %m");
- close(newfd);
- return -1;
- }
-
- return newfd;
+ return tbm_drm_helper_get_master_fd();
}
EXTERN void
tdm_helper_set_fd(const char *env, int fd)
{
- char buf[32];
- int ret;
-
- snprintf(buf, sizeof(buf), "%d", fd);
-
- ret = setenv(env, (const char*)buf, 1);
- if (ret) {
- TDM_ERR("setenv failed: %m");
+ if (strncmp(env, "TBM_DRM_MASTER_FD", 17) && strncmp(env, "TDM_DRM_MASTER_FD", 17)) {
+ TDM_INFO("DEPRECATED! '%s'", env);
return;
}
- if (fd >= 0)
- TDM_INFO("%s: fd(%d)", env, fd);
+ tbm_drm_helper_set_tbm_master_fd(fd);
}
EXTERN void
private_display = dpy;
func_output = &private_display->func_output;
func_layer = &private_display->func_layer;
- _pthread_mutex_lock(&private_display->lock);
/* module information */
module_data = private_display->module_data;
if (private_output->caps.mode_count > 0) {
const tdm_output_mode *current_mode = NULL;
- TDM_DBG_GOTO_IF_FAIL(func_output->output_get_mode, unlock);
+ TDM_DBG_RETURN_IF_FAIL(func_output->output_get_mode);
ret = func_output->output_get_mode(private_output->output_backend, ¤t_mode);
- TDM_DBG_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, unlock);
+ 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++) {
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_GOTO_IF_FAIL(func_output->output_get_property, unlock);
+ 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_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, unlock);
+ 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),
tdm_size size;
tbm_surface_info_s buf_info;
- TDM_DBG_GOTO_IF_FAIL(func_layer->layer_get_info, unlock);
+ 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_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, unlock);
+ TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
if (!private_layer->showing_buffer)
continue;
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_GOTO_IF_FAIL(func_layer->layer_get_property, unlock);
+ 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_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, unlock);
+ 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),
TDM_SNPRINTF(reply, len, "[No Capture capability]\n");
}
TDM_SNPRINTF(reply, len, "\n");
-
-unlock:
- _pthread_mutex_unlock(&private_display->lock);
}
EXTERN int
tdm_helper_commit_per_vblank_enabled(tdm_display *dpy)
{
- tdm_private_display *private_display;
+ TDM_ERR("the deprecated function, use 'tdm_helper_output_commit_per_vblank_enabled' instead.");
- TDM_RETURN_VAL_IF_FAIL(dpy != NULL, 0);
+ return 0;
+}
- private_display = dpy;
+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_display->commit_per_vblank;
+ return !!private_output->commit_per_vblank;
}