intel_sprite_on: coding style fixes

It was driving me nuts...

Signed-off-by: Ben Widawsky <ben@bwidawsk.net>
This commit is contained in:
Ben Widawsky 2012-09-12 17:27:08 -07:00
parent 5b5a7a806f
commit 93e5b4477f

View File

@ -53,8 +53,7 @@
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
struct type_name struct type_name {
{
int type; int type;
const char *name; const char *name;
}; };
@ -76,18 +75,16 @@ struct type_name encoder_type_names[] = {
{ DRM_MODE_ENCODER_LVDS, "LVDS" }, { DRM_MODE_ENCODER_LVDS, "LVDS" },
{ DRM_MODE_ENCODER_TVDAC, "TVDAC" }, { DRM_MODE_ENCODER_TVDAC, "TVDAC" },
}; };
type_name_fn(encoder_type) type_name_fn(encoder_type)
struct type_name connector_status_names[] = { struct type_name connector_status_names[] = {
{ DRM_MODE_CONNECTED, "connected" }, { DRM_MODE_CONNECTED, "connected" },
{ DRM_MODE_DISCONNECTED, "disconnected" }, { DRM_MODE_DISCONNECTED, "disconnected" },
{ DRM_MODE_UNKNOWNCONNECTION, "unknown" }, { DRM_MODE_UNKNOWNCONNECTION, "unknown" },
}; };
type_name_fn(connector_status) type_name_fn(connector_status)
struct type_name connector_type_names[] = { struct type_name connector_type_names[] = {
{ DRM_MODE_CONNECTOR_Unknown, "unknown" }, { DRM_MODE_CONNECTOR_Unknown, "unknown" },
{ DRM_MODE_CONNECTOR_VGA, "VGA" }, { DRM_MODE_CONNECTOR_VGA, "VGA" },
{ DRM_MODE_CONNECTOR_DVII, "DVI-I" }, { DRM_MODE_CONNECTOR_DVII, "DVI-I" },
@ -103,19 +100,17 @@ type_name_fn(connector_status)
{ DRM_MODE_CONNECTOR_HDMIB, "HDMI-B" }, { DRM_MODE_CONNECTOR_HDMIB, "HDMI-B" },
{ DRM_MODE_CONNECTOR_TV, "TV" }, { DRM_MODE_CONNECTOR_TV, "TV" },
{ DRM_MODE_CONNECTOR_eDP, "Embedded DisplayPort" }, { DRM_MODE_CONNECTOR_eDP, "Embedded DisplayPort" },
}; };
type_name_fn(connector_type) type_name_fn(connector_type)
/* /*
* Mode setting with the kernel interfaces is a bit of a chore. * Mode setting with the kernel interfaces is a bit of a chore.
* First you have to find the connector in question and make sure the * First you have to find the connector in question and make sure the
* requested mode is available. * requested mode is available.
* Then you need to find the encoder attached to that connector so you * Then you need to find the encoder attached to that connector so you
* can bind it with a free crtc. * can bind it with a free crtc.
*/ */
struct connector struct connector {
{
uint32_t id; uint32_t id;
int mode_valid; int mode_valid;
drmModeModeInfo mode; drmModeModeInfo mode;
@ -125,8 +120,7 @@ type_name_fn(connector_type)
int pipe; int pipe;
}; };
static void dump_mode( static void dump_mode(drmModeModeInfo *mode)
drmModeModeInfo *mode)
{ {
printf(" %s %d %d %d %d %d %d %d %d %d 0x%x 0x%x %d\n", printf(" %s %d %d %d %d %d %d %d %d %d 0x%x 0x%x %d\n",
mode->name, mode->name,
@ -144,9 +138,7 @@ static void dump_mode(
mode->clock); mode->clock);
} }
static void dump_connectors( static void dump_connectors(int gfx_fd, drmModeRes *resources)
int gfx_fd,
drmModeRes *resources)
{ {
int i, j; int i, j;
@ -174,8 +166,7 @@ static void dump_connectors(
continue; continue;
printf(" modes:\n"); printf(" modes:\n");
printf(" name refresh (Hz) hdisp hss hse htot vdisp " printf(" name refresh (Hz) hdisp hss hse htot vdisp vss vse vtot flags type clock\n");
"vss vse vtot flags type clock\n");
for (j = 0; j < connector->count_modes; j++) for (j = 0; j < connector->count_modes; j++)
dump_mode(&connector->modes[j]); dump_mode(&connector->modes[j]);
@ -184,9 +175,7 @@ static void dump_connectors(
printf("\n"); printf("\n");
} }
static void dump_crtcs( static void dump_crtcs(int gfx_fd, drmModeRes *resources)
int gfx_fd,
drmModeRes *resources)
{ {
int i; int i;
@ -214,9 +203,7 @@ static void dump_crtcs(
printf("\n"); printf("\n");
} }
static void dump_planes( static void dump_planes(int gfx_fd, drmModeRes *resources)
int gfx_fd,
drmModeRes *resources)
{ {
drmModePlaneRes *plane_resources; drmModePlaneRes *plane_resources;
drmModePlane *ovr; drmModePlane *ovr;
@ -251,8 +238,7 @@ static void dump_planes(
return; return;
} }
static void connector_find_preferred_mode( static void connector_find_preferred_mode(int gfx_fd,
int gfx_fd,
drmModeRes *gfx_resources, drmModeRes *gfx_resources,
struct connector *c) struct connector *c)
{ {
@ -380,14 +366,9 @@ static int connector_find_plane(int gfx_fd, struct connector *c)
return id; return id;
} }
static int prepare_primary_surface( static int prepare_primary_surface(int fd, int prim_width, int prim_height,
int fd, uint32_t *prim_handle, uint32_t *prim_stride,
int prim_width, uint32_t *prim_size, int tiled)
int prim_height,
uint32_t *prim_handle,
uint32_t *prim_stride,
uint32_t *prim_size,
int tiled)
{ {
uint32_t bytes_per_pixel = sizeof(uint32_t); uint32_t bytes_per_pixel = sizeof(uint32_t);
uint32_t *prim_fb_ptr; uint32_t *prim_fb_ptr;
@ -436,9 +417,7 @@ static int prepare_primary_surface(
} }
} }
prim_fb_ptr = gem_mmap(fd, prim_fb_ptr = gem_mmap(fd, *prim_handle, *prim_size, PROT_READ | PROT_WRITE);
*prim_handle, *prim_size,
PROT_READ | PROT_WRITE);
if (prim_fb_ptr != NULL) { if (prim_fb_ptr != NULL) {
// Write primary surface with gray background // Write primary surface with gray background
@ -449,12 +428,8 @@ static int prepare_primary_surface(
return 0; return 0;
} }
static void fill_sprite( static void fill_sprite(int sprite_width, int sprite_height, int sprite_stride,
int sprite_width, int sprite_index, void *sprite_fb_ptr)
int sprite_height,
int sprite_stride,
int sprite_index,
void *sprite_fb_ptr)
{ {
__u32 *pLinePat0, __u32 *pLinePat0,
*pLinePat1, *pLinePat1,
@ -491,14 +466,9 @@ static void fill_sprite(
return; return;
} }
static int prepare_sprite_surfaces( static int prepare_sprite_surfaces(int fd, int sprite_width, int sprite_height,
int fd, uint32_t num_surfaces, uint32_t *sprite_handles,
int sprite_width, uint32_t *sprite_stride, uint32_t *sprite_size,
int sprite_height,
uint32_t num_surfaces,
uint32_t *sprite_handles,
uint32_t *sprite_stride,
uint32_t *sprite_size,
int tiled) int tiled)
{ {
uint32_t bytes_per_pixel = sizeof(uint32_t); uint32_t bytes_per_pixel = sizeof(uint32_t);
@ -557,11 +527,7 @@ static int prepare_sprite_surfaces(
if (sprite_fb_ptr != NULL) { if (sprite_fb_ptr != NULL) {
// Fill with checkerboard pattern // Fill with checkerboard pattern
fill_sprite( fill_sprite(sprite_width, sprite_height, *sprite_stride, i, sprite_fb_ptr);
sprite_width,
sprite_height,
*sprite_stride,
i, sprite_fb_ptr);
munmap(sprite_fb_ptr, *sprite_size); munmap(sprite_fb_ptr, *sprite_size);
} else { } else {
@ -576,13 +542,8 @@ static int prepare_sprite_surfaces(
return 0; return 0;
} }
static void ricochet( static void ricochet(int tiled, int sprite_w, int sprite_h,
int tiled, int out_w, int out_h, int dump_info)
int sprite_w,
int sprite_h,
int out_w,
int out_h,
int dump_info)
{ {
int ret; int ret;
int gfx_fd; int gfx_fd;
@ -657,8 +618,7 @@ static void ricochet(
curr_term.c_cc[VTIME] = 0 ; // Return immediately, even if curr_term.c_cc[VTIME] = 0 ; // Return immediately, even if
// nothing has been entered. // nothing has been entered.
if (tcsetattr( 0, TCSANOW, &curr_term) != 0) { if (tcsetattr( 0, TCSANOW, &curr_term) != 0) {
printf("tcgetattr failure: %s\n", printf("tcgetattr failure: %s\n", strerror(errno));
strerror(errno));
return; return;
} }
@ -702,14 +662,8 @@ static void ricochet(
} }
// Add the primary surface framebuffer // Add the primary surface framebuffer
ret = drmModeAddFB( ret = drmModeAddFB(gfx_fd, prim_width, prim_height, 24, 32,
gfx_fd, prim_stride, prim_handle, &prim_fb_id);
prim_width,
prim_height,
24, 32,
prim_stride,
prim_handle,
&prim_fb_id);
gem_close(gfx_fd, prim_handle); gem_close(gfx_fd, prim_handle);
if (ret != 0) { if (ret != 0) {
@ -719,14 +673,9 @@ static void ricochet(
} }
// Allocate and fill sprite surfaces // Allocate and fill sprite surfaces
ret = prepare_sprite_surfaces( ret = prepare_sprite_surfaces(gfx_fd, sprite_w, sprite_h, num_surfaces,
gfx_fd,
sprite_w,
sprite_h,
num_surfaces,
&sprite_handles[0], &sprite_handles[0],
&sprite_stride, &sprite_stride, &sprite_size,
&sprite_size,
tiled); tiled);
if (ret != 0) { if (ret != 0) {
printf("Preparation of sprite surfaces failed %dx%d\n", printf("Preparation of sprite surfaces failed %dx%d\n",
@ -746,11 +695,10 @@ static void ricochet(
pitches[3] = sprite_stride; pitches[3] = sprite_stride;
memset(offsets, 0, sizeof(offsets)); memset(offsets, 0, sizeof(offsets));
ret = drmModeAddFB2( ret = drmModeAddFB2(gfx_fd, sprite_w, sprite_h,
gfx_fd, DRM_FORMAT_XRGB8888,
sprite_w, sprite_h, DRM_FORMAT_XRGB8888, handles, pitches, offsets,
handles, pitches, offsets, &sprite_fb_id[sprite_index], &sprite_fb_id[sprite_index], plane_flags);
plane_flags);
gem_close(gfx_fd, sprite_handles[sprite_index]); gem_close(gfx_fd, sprite_handles[sprite_index]);
if (ret) { if (ret) {
@ -809,10 +757,7 @@ static void ricochet(
printf("Sprite surface dimensions = %dx%d\n" printf("Sprite surface dimensions = %dx%d\n"
"Sprite output dimensions = %dx%d\n" "Sprite output dimensions = %dx%d\n"
"Press any key to continue >\n", "Press any key to continue >\n",
sprite_w, sprite_w, sprite_h, out_w, out_h);
sprite_h,
out_w,
out_h);
// Wait for a key-press // Wait for a key-press
while( read(0, &key, 1) == 0); while( read(0, &key, 1) == 0);
@ -821,16 +766,9 @@ static void ricochet(
} }
// Set up the primary display mode // Set up the primary display mode
ret = drmModeSetCrtc( ret = drmModeSetCrtc(gfx_fd, curr_connector.crtc, prim_fb_id,
gfx_fd, 0, 0, &curr_connector.id, 1, &curr_connector.mode);
curr_connector.crtc, if (ret != 0) {
prim_fb_id,
0, 0,
&curr_connector.id,
1,
&curr_connector.mode);
if (ret != 0)
{
printf("Failed to set mode (%dx%d@%dHz): %s\n", printf("Failed to set mode (%dx%d@%dHz): %s\n",
prim_width, prim_height, curr_connector.mode.vrefresh, prim_width, prim_height, curr_connector.mode.vrefresh,
strerror(errno)); strerror(errno));
@ -842,8 +780,7 @@ static void ricochet(
set.min_value = 0; set.min_value = 0;
set.max_value = 0; set.max_value = 0;
set.flags = I915_SET_COLORKEY_NONE; set.flags = I915_SET_COLORKEY_NONE;
ret = drmCommandWrite(gfx_fd, DRM_I915_SET_SPRITE_COLORKEY, &set, ret = drmCommandWrite(gfx_fd, DRM_I915_SET_SPRITE_COLORKEY, &set, sizeof(set));
sizeof(set));
assert(ret == 0); assert(ret == 0);
// Set up sprite output dimensions, initial position, etc. // Set up sprite output dimensions, initial position, etc.
@ -868,12 +805,10 @@ static void ricochet(
// Bounce sprite off the walls // Bounce sprite off the walls
while (keep_moving) { while (keep_moving) {
// Obtain system time in usec. // Obtain system time in usec.
if (gettimeofday( &stTimeVal, NULL ) != 0) { if (gettimeofday( &stTimeVal, NULL ) != 0)
printf("gettimeofday error: %s\n", printf("gettimeofday error: %s\n", strerror(errno));
strerror(errno)); else
} else {
currTime = ((long long)stTimeVal.tv_sec * 1000000) + stTimeVal.tv_usec; currTime = ((long long)stTimeVal.tv_sec * 1000000) + stTimeVal.tv_usec;
}
// Check if it's time to flip the sprite surface // Check if it's time to flip the sprite surface
if (currTime - prevFlipTime > deltaFlipTime) { if (currTime - prevFlipTime > deltaFlipTime) {
@ -884,19 +819,12 @@ static void ricochet(
// Move the sprite on the screen and flip // Move the sprite on the screen and flip
// the surface if the index has changed // the surface if the index has changed
if (drmModeSetPlane( if (drmModeSetPlane(gfx_fd, sprite_plane_id, curr_connector.crtc,
gfx_fd, sprite_fb_id[sprite_index], plane_flags,
sprite_plane_id,
curr_connector.crtc,
sprite_fb_id[sprite_index],
plane_flags,
sprite_x, sprite_y, sprite_x, sprite_y,
out_w, out_h, out_w, out_h,
0, 0, 0, 0, sprite_w, sprite_h))
sprite_w, sprite_h)) { printf("Failed to enable sprite plane: %s\n", strerror(errno));
printf("Failed to enable sprite plane: %s\n",
strerror(errno));
}
// Check if it's time to move the sprite surface // Check if it's time to move the sprite surface
if (currTime - prevMoveTime > deltaMoveTime) { if (currTime - prevMoveTime > deltaMoveTime) {
@ -946,15 +874,13 @@ static void ricochet(
break; break;
case 'f': // Slow down sprite flipping; case 'f': // Slow down sprite flipping;
deltaFlipTime = (deltaFlipTime * 100) / 90; deltaFlipTime = (deltaFlipTime * 100) / 90;
if (deltaFlipTime > 1000000) { if (deltaFlipTime > 1000000)
deltaFlipTime = 1000000; deltaFlipTime = 1000000;
}
break; break;
case 'F': // Speed up sprite flipping; case 'F': // Speed up sprite flipping;
deltaFlipTime = (deltaFlipTime * 100) / 110; deltaFlipTime = (deltaFlipTime * 100) / 110;
if (deltaFlipTime < 20000) { if (deltaFlipTime < 20000)
deltaFlipTime = 20000; deltaFlipTime = 20000;
}
break; break;
case 'n': // Next connector case 'n': // Next connector
case 'N': case 'N':
@ -980,8 +906,7 @@ out:
tcflush(0, TCIFLUSH); tcflush(0, TCIFLUSH);
// Restore previous terminal settings // Restore previous terminal settings
if (tcsetattr( 0, TCSANOW, &orig_term) != 0) { if (tcsetattr( 0, TCSANOW, &orig_term) != 0) {
printf("tcgetattr failure: %s\n", printf("tcgetattr failure: %s\n", strerror(errno));
strerror(errno));
return; return;
} }
@ -1027,14 +952,12 @@ int main(int argc, char **argv)
enable_tiling = 1; enable_tiling = 1;
break; break;
case 's': // Surface dimensions case 's': // Surface dimensions
if (sscanf(optarg, "%dx%d", if (sscanf(optarg, "%dx%d", &plane_width, &plane_height) != 2)
&plane_width, &plane_height) != 2)
usage(argv[0]); usage(argv[0]);
test_overlay = 1; test_overlay = 1;
break; break;
case 'o': // Output dimensions case 'o': // Output dimensions
if (sscanf(optarg, "%dx%d", if (sscanf(optarg, "%dx%d", &out_width, &out_height) != 2)
&out_width, &out_height) != 2)
usage(argv[0]); usage(argv[0]);
break; break;
default: default:
@ -1047,20 +970,13 @@ int main(int argc, char **argv)
} }
if (test_overlay) { if (test_overlay) {
if (out_width < (plane_width / 2)) { if (out_width < (plane_width / 2))
out_width = plane_width; out_width = plane_width;
}
if (out_height < (plane_height / 2)) { if (out_height < (plane_height / 2))
out_height = plane_height; out_height = plane_height;
}
ricochet(enable_tiling, ricochet(enable_tiling, plane_width, plane_height, out_width, out_height, dump_info);
plane_width,
plane_height,
out_width,
out_height,
dump_info);
} else { } else {
printf("Sprite dimensions are required:\n"); printf("Sprite dimensions are required:\n");
usage(argv[0]); usage(argv[0]);