Skip to content

Commit 67a2af1

Browse files
committed
Improve video_surface dimension calculation
1 parent f958ef1 commit 67a2af1

File tree

4 files changed

+30
-12
lines changed

4 files changed

+30
-12
lines changed

kos/include/libvideo/gfx/buffer.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -670,8 +670,8 @@ __NOTHROW(video_buffer_revoke)(struct video_buffer *__restrict __self);
670670
#define video_buffer_getflags(self) (self)->vb_surf.vs_flags
671671
#define video_buffer_getcolorkey(self) (self)->vb_surf.vs_colorkey
672672
#define video_buffer_hascolorkey(self) ((video_buffer_getflags(self) & VIDEO_GFX_F_COLORKEY) != 0)
673-
#define video_buffer_getxdim(self) (self)->vb_xdim
674-
#define video_buffer_getydim(self) (self)->vb_ydim
673+
#define video_buffer_getxdim(self) (self)->vb_dim[0]
674+
#define video_buffer_getydim(self) (self)->vb_dim[1]
675675
#define video_buffer_setcolorkey(self, colorkey) \
676676
__hybrid_atomic_store((video_pixel_t *)&(self)->vb_surf.vs_colorkey, colorkey, __ATOMIC_RELEASE)
677677
#define video_buffer_enablecolorkey(self, colorkey) \
@@ -746,9 +746,7 @@ struct video_buffer {
746746
struct video_domain const *__VIDEO_BUFFER_const vb_domain; /* [1..1][const] Buffer domain (generic wrappers use `video_ramdomain()',
747747
* meaning a different value here implies that the buffer was created by
748748
* that domain's `video_domain_newbuffer()' or `video_domain_formem()') */
749-
/* TODO: Replace the following with "video_dim_t __VIDEO_BUFFER_const vb_dim[2]" (where 0: x, 1: y) */
750-
video_dim_t __VIDEO_BUFFER_const vb_xdim; /* Buffer physical dimension in X (in pixels) */
751-
video_dim_t __VIDEO_BUFFER_const vb_ydim; /* Buffer physical dimension in Y (in pixels) */
749+
video_dim_t __VIDEO_BUFFER_const vb_dim[2]; /* Buffer physical dimension in X and Y (in pixels) */
752750
__uintptr_t vb_refcnt; /* Reference counter. */
753751
/* Buffer-specific fields go here */
754752
};
@@ -769,7 +767,7 @@ struct video_buffer {
769767
(void)((self)->vb_domain = (domain))
770768
/* Initialize dimensions of a buffer */
771769
#define __video_buffer_init_dim(self, xdim, ydim) \
772-
(void)((self)->vb_xdim = (xdim), (self)->vb_ydim = (ydim))
770+
(void)((self)->vb_dim[0] = (xdim), (self)->vb_dim[1] = (ydim))
773771
/* Initialize format+domain+dim for a subregion buffer */
774772
#define __video_buffer_init_subregion(self, parent_surface, parent_buffer, rect) \
775773
(void)((self)->vb_surf.vs_pal = (parent_surface)->vs_pal, \

kos/include/libvideo/gfx/surface.h

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -357,9 +357,30 @@ video_buffer_convert_distinct(struct video_buffer *__restrict __self,
357357
#define video_surface_getbuffer(self) (self)->vs_buffer
358358
#define video_surface_getbufferxdim(self) video_buffer_getxdim(video_surface_getbuffer(self))
359359
#define video_surface_getbufferydim(self) video_buffer_getydim(video_surface_getbuffer(self))
360-
/* TODO: Change vb_xdim / vb_ydim into vb_dim[2] and use ((flags & VIDEO_GFX_F_XYSWAP) [^ 1]) as index */
361-
#define video_surface_getxdim(self) (__unlikely(video_surface_getflags(self) & VIDEO_GFX_F_XYSWAP) ? video_surface_getbufferydim(self) : video_surface_getbufferxdim(self))
362-
#define video_surface_getydim(self) (__unlikely(video_surface_getflags(self) & VIDEO_GFX_F_XYSWAP) ? video_surface_getbufferxdim(self) : video_surface_getbufferydim(self))
360+
#if VIDEO_GFX_F_XYSWAP == 1
361+
#define __video_surface_getxbit(self) (video_surface_getflags(self) & VIDEO_GFX_F_XYSWAP)
362+
#elif VIDEO_GFX_F_XYSWAP == 2
363+
#define __video_surface_getxbit(self) ((video_surface_getflags(self) & VIDEO_GFX_F_XYSWAP) >> 1)
364+
#elif VIDEO_GFX_F_XYSWAP == 4
365+
#define __video_surface_getxbit(self) ((video_surface_getflags(self) & VIDEO_GFX_F_XYSWAP) >> 2)
366+
#elif VIDEO_GFX_F_XYSWAP == 8
367+
#define __video_surface_getxbit(self) ((video_surface_getflags(self) & VIDEO_GFX_F_XYSWAP) >> 3)
368+
#elif VIDEO_GFX_F_XYSWAP == 16
369+
#define __video_surface_getxbit(self) ((video_surface_getflags(self) & VIDEO_GFX_F_XYSWAP) >> 4)
370+
#elif VIDEO_GFX_F_XYSWAP == 32
371+
#define __video_surface_getxbit(self) ((video_surface_getflags(self) & VIDEO_GFX_F_XYSWAP) >> 5)
372+
#elif VIDEO_GFX_F_XYSWAP == 64
373+
#define __video_surface_getxbit(self) ((video_surface_getflags(self) & VIDEO_GFX_F_XYSWAP) >> 6)
374+
#elif VIDEO_GFX_F_XYSWAP == 128
375+
#define __video_surface_getxbit(self) ((video_surface_getflags(self) & VIDEO_GFX_F_XYSWAP) >> 7)
376+
#elif VIDEO_GFX_F_XYSWAP == 256
377+
#define __video_surface_getxbit(self) ((video_surface_getflags(self) & VIDEO_GFX_F_XYSWAP) >> 8)
378+
#else /* VIDEO_GFX_F_XYSWAP == ... */
379+
#define __video_surface_getxbit(self) ((video_surface_getflags(self) & VIDEO_GFX_F_XYSWAP) ? 1 : 0)
380+
#endif /* VIDEO_GFX_F_XYSWAP != ... */
381+
#define __video_surface_getybit(self) (__video_surface_getxbit(self) ^ 1)
382+
#define video_surface_getxdim(self) video_surface_getbuffer(self)->vb_dim[__video_surface_getxbit(self)]
383+
#define video_surface_getydim(self) video_surface_getbuffer(self)->vb_dim[__video_surface_getybit(self)]
363384
#define video_surface_hasobjpalette(self) (((self)->vs_flags & VIDEO_GFX_F_PALOBJ) != 0)
364385
#define video_surface_getpalette(self) (self)->vs_pal
365386
#define video_surface_setpalette(self, palette, isobj) (void)((self)->vs_pal = (palette), (self)->vs_flags = ((self)->vs_flags & ~VIDEO_GFX_F_PALOBJ) | ((isobj) ? VIDEO_GFX_F_PALOBJ : 0))

kos/src/libvideo/gfx/gfx-empty.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,7 @@ PRIVATE struct video_buffer libvideo_emptybuffer = {
338338
.vb_codec = NULL, /* Initialized lazily */
339339
.vb_ops = NULL, /* Initialized lazily */
340340
.vb_domain = NULL, /* Initialized lazily */
341-
.vb_xdim = 0,
342-
.vb_ydim = 0,
341+
.vb_dim = { 0, 0 },
343342
.vb_refcnt = 0x7fff,
344343
};
345344

kos/src/libvideo/gfx/screen.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,9 +496,9 @@ svga_newscreen(struct screen_buffer_hint *hint) {
496496
/* Fill in remaining fields of "result" */
497497
result->vb_surf.vs_buffer = result;
498498
result->vb_surf.vs_colorkey = 0;
499-
result->vb_refcnt = 1;
500499
__video_buffer_init_ops(result, &result->ss_ops.sbo_video);
501500
__video_buffer_init_dim(result, mode->smi_resx, mode->smi_resy);
501+
result->vb_refcnt = 1;
502502
result->ss_vdlck = vdlck.of_hint;
503503
result->ss_libsvgadrv = libsvgadrv;
504504
result->ss_drv = driver;

0 commit comments

Comments
 (0)