diff options
Diffstat (limited to 'src/fb.c')
| -rw-r--r-- | src/fb.c | 18 |
1 files changed, 10 insertions, 8 deletions
@@ -114,24 +114,26 @@ bool pw_fb_coordinates(struct pw_framebuffer *fb, float wx, float wy, return true; } -uint8_t *pw_fb_lock(struct pw_framebuffer *fb) { +uint8_t *pw_fb_lock(struct pw_framebuffer *fb, size_t *pitch) { if (!fb) { SDL_InvalidParamError("fb"); return NULL; } - - void *buffer; - int pitch; - if (!SDL_LockTexture(fb->texture, NULL, &buffer, &pitch)) { + if (!pitch) { + SDL_InvalidParamError("pitch"); return NULL; } - if (pitch != PW_FB_WIDTH * PW_FB_BYTES_PER_PIXEL) { - SDL_UnlockTexture(fb->texture); - SDL_SetError("unexpected framebuffer pitch"); + void *buffer; + int ipitch; + if (!SDL_LockTexture(fb->texture, NULL, &buffer, &ipitch)) { return NULL; } + // This cast is necessarily safe, as it reprensents a memory offset + // from one row to the other, meaning it must fit in a `size_t`. + *pitch = (size_t)ipitch; + return buffer; } |
