Browse Source

Properly support strides

K. Lange 5 years ago
parent
commit
f2024aa274
5 changed files with 16 additions and 13 deletions
  1. 0 4
      apps/compositor.c
  2. 4 2
      base/usr/include/toaru/graphics.h
  3. 2 2
      ext/ext_cairo_renderer.c
  4. 8 5
      lib/graphics.c
  5. 2 0
      lib/yutani.c

+ 0 - 4
apps/compositor.c

@@ -880,10 +880,8 @@ static void redraw_windows(yutani_globals_t * yg) {
 
 		if (!yutani_options.nested) {
 			reinit_graphics_fullscreen(yg->backend_ctx);
-			yg->stride = framebuffer_stride();
 		} else {
 			reinit_graphics_yutani(yg->backend_ctx, yg->host_window);
-			yg->stride = yg->backend_ctx->width * 4;
 			yutani_window_resize_done(yg->host_context, yg->host_window);
 		}
 		TRACE("graphics context resized...");
@@ -1961,7 +1959,6 @@ int main(int argc, char * argv[]) {
 		yutani_window_move(yg->host_context, yg->host_window, 50, 50);
 		yutani_window_advertise_icon(yg->host_context, yg->host_window, "Compositor", "compositor");
 		yg->backend_ctx = init_graphics_yutani_double_buffer(yg->host_window);
-		yg->stride = yg->backend_ctx->width * 4;
 	} else {
 		char * d = getenv("DISPLAY");
 		if (d && *d) {
@@ -1971,7 +1968,6 @@ int main(int argc, char * argv[]) {
 		_static_yg = yg;
 		signal(SIGWINEVENT, yutani_display_resize_handle);
 		yg->backend_ctx = init_graphics_fullscreen_double_buffer();
-		yg->stride = framebuffer_stride();
 	}
 
 	if (!yg->backend_ctx) {

+ 4 - 2
base/usr/include/toaru/graphics.h

@@ -8,6 +8,7 @@
 #define GFX_W(ctx)  ((ctx)->width)			/* Display width */
 #define GFX_H(ctx)  ((ctx)->height)			/* Display height */
 #define GFX_B(ctx)  ((ctx)->depth / 8)		/* Display byte depth */
+#define GFX_S(ctx)  ((ctx)->stride)			/* Stride */
 
 #define _RED(color) ((color & 0x00FF0000) / 0x10000)
 #define _GRE(color) ((color & 0x0000FF00) / 0x100)
@@ -17,8 +18,8 @@
 /*
  * Macros make verything easier.
  */
-#define GFX(ctx,x,y) *((uint32_t *)&((ctx)->backbuffer)[(GFX_W(ctx) * (y) + (x)) * GFX_B(ctx)])
-#define GFXR(ctx,x,y) *((uint32_t *)&((ctx)->buffer)[(GFX_W(ctx) * (y) + (x)) * GFX_B(ctx)])
+#define GFX(ctx,x,y) *((uint32_t *)&((ctx)->backbuffer)[(GFX_S(ctx) * (y) + (x) * GFX_B(ctx))])
+#define GFXR(ctx,x,y) *((uint32_t *)&((ctx)->buffer)[(GFX_S(ctx) * (y) + (x) * GFX_B(ctx))])
 #define SPRITE(sprite,x,y) sprite->bitmap[sprite->width * (y) + (x)]
 #define SMASKS(sprite,x,y) sprite->masks[sprite->width * (y) + (x)]
 
@@ -40,6 +41,7 @@ typedef struct context {
 	char *   backbuffer;
 	char *   clips;
 	int32_t  clips_size;
+	uint32_t stride;
 } gfx_context_t;
 
 extern gfx_context_t * init_graphics_fullscreen();

+ 2 - 2
ext/ext_cairo_renderer.c

@@ -30,13 +30,13 @@ int renderer_alloc(yutani_globals_t * yg) {
 int renderer_init(yutani_globals_t * yg) {
 	struct cairo_renderer * c = yg->renderer_ctx;
 
-	int stride = yg->width * 4;
+	int stride = yg->backend_ctx->stride;
 	c->framebuffer_surface = cairo_image_surface_create_for_data(
 			yg->backend_framebuffer, CAIRO_FORMAT_ARGB32, yg->width, yg->height, stride);
 	c->framebuffer_ctx = cairo_create(c->framebuffer_surface);
 
 	c->real_surface = cairo_image_surface_create_for_data(
-			(unsigned char *)yg->backend_ctx->buffer, CAIRO_FORMAT_ARGB32, yg->width, yg->height, yg->stride);
+			(unsigned char *)yg->backend_ctx->buffer, CAIRO_FORMAT_ARGB32, yg->width, yg->height, stride);
 	c->real_ctx = cairo_create(c->real_surface);
 
 	return 0;

+ 8 - 5
lib/graphics.c

@@ -69,7 +69,7 @@ void flip(gfx_context_t * ctx) {
 	if (ctx->clips) {
 		for (size_t i = 0; i < ctx->height; ++i) {
 			if (_is_in_clip(ctx,i)) {
-				memcpy(&ctx->buffer[i*ctx->width*4], &ctx->backbuffer[i*ctx->width*4], 4 * ctx->width);
+				memcpy(&ctx->buffer[i*GFX_S(ctx)], &ctx->backbuffer[i*GFX_S(ctx)], 4 * ctx->width);
 			}
 		}
 	} else {
@@ -99,10 +99,11 @@ gfx_context_t * init_graphics_fullscreen() {
 	ioctl(framebuffer_fd, IO_VID_WIDTH,  &out->width);
 	ioctl(framebuffer_fd, IO_VID_HEIGHT, &out->height);
 	ioctl(framebuffer_fd, IO_VID_DEPTH,  &out->depth);
+	ioctl(framebuffer_fd, IO_VID_STRIDE, &out->stride);
 	ioctl(framebuffer_fd, IO_VID_ADDR,   &out->buffer);
 	ioctl(framebuffer_fd, IO_VID_SIGNAL, NULL);
 
-	out->size   = GFX_H(out) * GFX_W(out) * GFX_B(out);
+	out->size   = GFX_H(out) * GFX_S(out);
 	out->backbuffer = out->buffer;
 	return out;
 }
@@ -116,7 +117,7 @@ uint32_t framebuffer_stride(void) {
 gfx_context_t * init_graphics_fullscreen_double_buffer() {
 	gfx_context_t * out = init_graphics_fullscreen();
 	if (!out) return NULL;
-	out->backbuffer = malloc(sizeof(uint32_t) * GFX_W(out) * GFX_H(out));
+	out->backbuffer = malloc(GFX_S(out) * GFX_H(out));
 	return out;
 }
 
@@ -125,8 +126,9 @@ void reinit_graphics_fullscreen(gfx_context_t * out) {
 	ioctl(framebuffer_fd, IO_VID_WIDTH,  &out->width);
 	ioctl(framebuffer_fd, IO_VID_HEIGHT, &out->height);
 	ioctl(framebuffer_fd, IO_VID_DEPTH,  &out->depth);
+	ioctl(framebuffer_fd, IO_VID_STRIDE, &out->stride);
 
-	out->size = GFX_H(out) * GFX_W(out) * GFX_B(out);
+	out->size   = GFX_H(out) * GFX_S(out);
 
 	if (out->clips && out->clips_size != out->height) {
 		free(out->clips);
@@ -136,7 +138,7 @@ void reinit_graphics_fullscreen(gfx_context_t * out) {
 
 	if (out->buffer != out->backbuffer) {
 		ioctl(framebuffer_fd, IO_VID_ADDR,   &out->buffer);
-		out->backbuffer = realloc(out->backbuffer, sizeof(uint32_t) * GFX_W(out) * GFX_H(out));
+		out->backbuffer = realloc(out->backbuffer, GFX_S(out) * GFX_H(out));
 	} else {
 		ioctl(framebuffer_fd, IO_VID_ADDR,   &out->buffer);
 		out->backbuffer = out->buffer;
@@ -149,6 +151,7 @@ gfx_context_t * init_graphics_sprite(sprite_t * sprite) {
 	out->clips = NULL;
 
 	out->width  = sprite->width;
+	out->stride = sprite->width * sizeof(uint32_t);
 	out->height = sprite->height;
 	out->depth  = 32;
 	out->size   = GFX_H(out) * GFX_W(out) * GFX_B(out);

+ 2 - 0
lib/yutani.c

@@ -1061,6 +1061,7 @@ gfx_context_t * init_graphics_yutani(yutani_window_t * window) {
 	gfx_context_t * out = malloc(sizeof(gfx_context_t));
 	out->width  = window->width;
 	out->height = window->height;
+	out->stride = window->width * sizeof(uint32_t);
 	out->depth  = 32;
 	out->size   = GFX_H(out) * GFX_W(out) * GFX_B(out);
 	out->buffer = window->buffer;
@@ -1090,6 +1091,7 @@ gfx_context_t *  init_graphics_yutani_double_buffer(yutani_window_t * window) {
 void reinit_graphics_yutani(gfx_context_t * out, yutani_window_t * window) {
 	out->width  = window->width;
 	out->height = window->height;
+	out->stride = window->width * 4;
 	out->depth  = 32;
 	out->size   = GFX_H(out) * GFX_W(out) * GFX_B(out);
 	if (out->buffer == out->backbuffer) {