free(data);
return NULL;
}
+
+#define QUALCOMPADDING 16
+static int check_padding(uint32_t *img, int width, int height)
+{
+ int padding;
+ int x, y, tmp;
+
+ /* check that potential padding is all black */
+ padding = 1;
+ for (y = 0; y < height; y += height / 16) {
+ tmp = y * (width + QUALCOMPADDING) + width;
+ if (img[tmp] &&
+ img[tmp + 4] &&
+ img[tmp + 8]) {
+ padding = 0;
+ break;
+ }
+ }
+
+ if (!padding) {
+ return 0;
+ }
+ /* check for black screen*/
+ for (y = 0; y < height; y++) {
+ for (x = 0; x < width; x++) {
+ if (img[y * width + x] != 0) {
+ return -EAGAIN;
+ }
+ }
+ }
+ return -ECANCELED;
+}
+
static int __capture_screnshot_wayland(const char *path)
{
struct screenshooter_output *output;
int plane_idx = 0;
int ret = -1;
int err;
+ static int checked4padding;
+ static int padding;
+ int width, height;
data = __wayland_init();
if (!data) {
return -1;
}
- t_surface = tbm_surface_create(data->width, data->height, TBM_FORMAT_XRGB8888);
+ width = data->width + padding;
+ height = data->height;
+
+ t_surface = tbm_surface_create(width, data->height, TBM_FORMAT_XRGB8888);
if (!t_surface) {
PRINTERR("failed to create tbm_surface\n");
goto fail_tbm_client;
goto fail_map_surface;
}
+ if (!checked4padding) {
+ ret = check_padding((uint32_t *)tsuri.planes[plane_idx].ptr,
+ data->width, data->height);
+ if (ret == -EAGAIN) {
+ padding = QUALCOMPADDING; /* HW specific 16 pixels
+ padding on right side */
+ checked4padding = true;
+ goto wrong_padding;
+ } else if (ret == -ECANCELED) {
+ PRINTERR("Checking for padding failed because of screen is black. Let's check next time.\n");
+ } else {
+ checked4padding = true;
+ }
+ }
+
ret = __save_to_png(path, tsuri.planes[plane_idx].ptr,
- data->width, data->height);
+ width, height);
+wrong_padding:
tbm_surface_unmap(t_surface);
fail_map_surface:
getCurrentEventIndex());
ret = __capture_screnshot_wayland(dstpath);
+ if (ret == -EAGAIN)
+ ret = __capture_screnshot_wayland(dstpath);
if (!ret) {
if (chmod(dstpath, 0777) == -1)
PRINTWRN("cannot chmod -R777 <%s>", dstpath);