mirror of
https://github.com/tiagovignatti/intel-gpu-tools.git
synced 2026-08-23 22:32:57 +00:00
overlay: Rudiments of config files and option parsing
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
This commit is contained in:
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
* Copyright © 2013 Intel Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "position.h"
|
||||
#include "../overlay.h"
|
||||
|
||||
static enum position get_position(struct config *config)
|
||||
{
|
||||
const char *v = config_get_value(config, "window", "position");
|
||||
if (v == NULL)
|
||||
return POS_UNSET;
|
||||
|
||||
if (strcmp(v, "top-left") == 0)
|
||||
return POS_TOP_LEFT;
|
||||
|
||||
if (strcmp(v, "top-centre") == 0)
|
||||
return POS_TOP_CENTRE;
|
||||
|
||||
if (strcmp(v, "top-right") == 0)
|
||||
return POS_TOP_RIGHT;
|
||||
|
||||
if (strcmp(v, "middle-left") == 0)
|
||||
return POS_MIDDLE_LEFT;
|
||||
|
||||
if (strcmp(v, "middle-centre") == 0)
|
||||
return POS_MIDDLE_CENTRE;
|
||||
|
||||
if (strcmp(v, "middle-right") == 0)
|
||||
return POS_MIDDLE_RIGHT;
|
||||
|
||||
if (strcmp(v, "bottom-left") == 0)
|
||||
return POS_BOTTOM_LEFT;
|
||||
|
||||
if (strcmp(v, "bottom-centre") == 0)
|
||||
return POS_BOTTOM_CENTRE;
|
||||
|
||||
if (strcmp(v, "bottom-right") == 0)
|
||||
return POS_BOTTOM_RIGHT;
|
||||
|
||||
return POS_UNSET;
|
||||
}
|
||||
|
||||
enum position
|
||||
x11_position(Screen *scr, int width, int height,
|
||||
struct config *config,
|
||||
int *x, int *y, int *w, int *h)
|
||||
{
|
||||
enum position position = POS_UNSET;
|
||||
const char *geometry;
|
||||
|
||||
*x = *y = 0;
|
||||
*w = width;
|
||||
*h = height;
|
||||
|
||||
geometry = config_get_value(config, "window", "geometry");
|
||||
if (geometry) {
|
||||
sscanf(geometry, "%dx%d+%d+%d", w, h, x, y);
|
||||
if (*w < width)
|
||||
*w = width;
|
||||
if (*h < height)
|
||||
*h = height;
|
||||
} else {
|
||||
position = get_position(config);
|
||||
if (position != POS_UNSET) {
|
||||
if (width == -1) {
|
||||
*w = scr->width;
|
||||
switch (position & 7) {
|
||||
default:
|
||||
case 0:
|
||||
case 2: *w >>= 1; break;
|
||||
}
|
||||
} else if (width > scr->width) {
|
||||
*w = scr->width;
|
||||
} else
|
||||
*w = width;
|
||||
|
||||
if (height == -1) {
|
||||
*h = scr->height;
|
||||
switch ((position >> 4) & 7) {
|
||||
default:
|
||||
case 0:
|
||||
case 2: *h >>= 1; break;
|
||||
}
|
||||
} else if (height > scr->height)
|
||||
*h = scr->height;
|
||||
else
|
||||
*h = height;
|
||||
|
||||
switch (position & 7) {
|
||||
default:
|
||||
case 0: *x = 0; break;
|
||||
case 1: *x = (scr->width - *w)/2; break;
|
||||
case 2: *x = scr->width - *w; break;
|
||||
}
|
||||
|
||||
switch ((position >> 4) & 7) {
|
||||
default:
|
||||
case 0: *y = 0; break;
|
||||
case 1: *y = (scr->height - *h)/2; break;
|
||||
case 2: *y = scr->height - *h; break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return position;
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright © 2013 Intel Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef X11_POSITION_H
|
||||
#define X11_POSITION_H
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
|
||||
struct config;
|
||||
enum position;
|
||||
|
||||
enum position
|
||||
x11_position(Screen *scr, int width, int height,
|
||||
struct config *config,
|
||||
int *x, int *y, int *w, int *h);
|
||||
|
||||
#endif /* X11_POSITION_H */
|
||||
+20
-36
@@ -38,6 +38,7 @@
|
||||
#include <i915_drm.h>
|
||||
#include "../overlay.h"
|
||||
#include "dri2.h"
|
||||
#include "position.h"
|
||||
#include "rgb2yuv.h"
|
||||
|
||||
#ifndef ALIGN
|
||||
@@ -142,7 +143,7 @@ static void x11_overlay_destroy(void *data)
|
||||
}
|
||||
|
||||
cairo_surface_t *
|
||||
x11_overlay_create(enum position position, int *width, int *height)
|
||||
x11_overlay_create(struct config *config, int *width, int *height)
|
||||
{
|
||||
Display *dpy;
|
||||
Screen *scr;
|
||||
@@ -152,11 +153,12 @@ x11_overlay_create(enum position position, int *width, int *height)
|
||||
struct drm_i915_gem_mmap_gtt map;
|
||||
struct x11_overlay *priv;
|
||||
unsigned int count, i, j;
|
||||
int fd, w, h;
|
||||
int fd, x, y, w, h;
|
||||
XvAdaptorInfo *info;
|
||||
XvImage *image;
|
||||
XvPortID port = -1;
|
||||
void *ptr, *mem;
|
||||
enum position position;
|
||||
|
||||
dpy = XOpenDisplay(NULL);
|
||||
if (dpy == NULL)
|
||||
@@ -195,29 +197,7 @@ x11_overlay_create(enum position position, int *width, int *height)
|
||||
|
||||
XSetErrorHandler(noop);
|
||||
|
||||
if (*width == -1) {
|
||||
w = scr->width;
|
||||
switch (position & 7) {
|
||||
default:
|
||||
case 0:
|
||||
case 2: w >>= 1; break;
|
||||
}
|
||||
} else if (*width > scr->width) {
|
||||
w = scr->width;
|
||||
} else
|
||||
w = *width;
|
||||
|
||||
if (*height == -1) {
|
||||
h = scr->height;
|
||||
switch ((position >> 4) & 7) {
|
||||
default:
|
||||
case 0:
|
||||
case 2: h >>= 1; break;
|
||||
}
|
||||
} else if (*height > scr->height)
|
||||
h = scr->height;
|
||||
else
|
||||
h = *height;
|
||||
position = x11_position(scr, *width, *height, config, &x, &y, &w, &h);
|
||||
|
||||
image = XvCreateImage(dpy, port, FOURCC_RGB565, NULL, w, h);
|
||||
if (image == NULL)
|
||||
@@ -308,18 +288,22 @@ x11_overlay_create(enum position position, int *width, int *height)
|
||||
priv->name = flink.name;
|
||||
priv->visible = false;
|
||||
|
||||
switch (position & 7) {
|
||||
default:
|
||||
case 0: priv->x = 0; break;
|
||||
case 1: priv->x = (scr->width - image->width)/2; break;
|
||||
case 2: priv->x = scr->width - image->width; break;
|
||||
}
|
||||
priv->x = x;
|
||||
priv->y = y;
|
||||
if (position != POS_UNSET) {
|
||||
switch (position & 7) {
|
||||
default:
|
||||
case 0: priv->x = 0; break;
|
||||
case 1: priv->x = (scr->width - image->width)/2; break;
|
||||
case 2: priv->x = scr->width - image->width; break;
|
||||
}
|
||||
|
||||
switch ((position >> 4) & 7) {
|
||||
default:
|
||||
case 0: priv->y = 0; break;
|
||||
case 1: priv->y = (scr->height - image->height)/2; break;
|
||||
case 2: priv->y = scr->height - image->height; break;
|
||||
switch ((position >> 4) & 7) {
|
||||
default:
|
||||
case 0: priv->y = 0; break;
|
||||
case 1: priv->y = (scr->height - image->height)/2; break;
|
||||
case 2: priv->y = scr->height - image->height; break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include "../overlay.h"
|
||||
#include "position.h"
|
||||
|
||||
struct x11_window {
|
||||
struct overlay base;
|
||||
@@ -109,7 +110,7 @@ static void x11_window_destroy(void *data)
|
||||
}
|
||||
|
||||
cairo_surface_t *
|
||||
x11_window_create(enum position position, int *width, int *height)
|
||||
x11_window_create(struct config *config, int *width, int *height)
|
||||
{
|
||||
Display *dpy;
|
||||
Screen *scr;
|
||||
@@ -129,43 +130,7 @@ x11_window_create(enum position position, int *width, int *height)
|
||||
|
||||
XSetErrorHandler(noop);
|
||||
|
||||
if (*width == -1) {
|
||||
w = scr->width;
|
||||
switch (position & 7) {
|
||||
default:
|
||||
case 0:
|
||||
case 2: w >>= 1; break;
|
||||
}
|
||||
} else if (*width > scr->width) {
|
||||
w = scr->width;
|
||||
} else
|
||||
w = *width;
|
||||
|
||||
if (*height == -1) {
|
||||
h = scr->height;
|
||||
switch ((position >> 4) & 7) {
|
||||
default:
|
||||
case 0:
|
||||
case 2: h >>= 1; break;
|
||||
}
|
||||
} else if (*height > scr->height)
|
||||
h = scr->height;
|
||||
else
|
||||
h = *height;
|
||||
|
||||
switch (position & 7) {
|
||||
default:
|
||||
case 0: x = 0; break;
|
||||
case 1: x = (scr->width - w)/2; break;
|
||||
case 2: x = scr->width - w; break;
|
||||
}
|
||||
|
||||
switch ((position >> 4) & 7) {
|
||||
default:
|
||||
case 0: y = 0; break;
|
||||
case 1: y = (scr->height - h)/2; break;
|
||||
case 2: y = scr->height - h; break;
|
||||
}
|
||||
x11_position(scr, *width, *height, config, &x, &y, &w, &h);
|
||||
|
||||
attr.override_redirect = True;
|
||||
win = XCreateWindow(dpy, DefaultRootWindow(dpy),
|
||||
|
||||
Reference in New Issue
Block a user