Skip to content

Commit f958ef1

Browse files
committed
Cleanup & minor fixes/improvements
1 parent 65ae9b0 commit f958ef1

File tree

21 files changed

+325
-421
lines changed

21 files changed

+325
-421
lines changed

kos/cpp.hint

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2733,8 +2733,11 @@
27332733
#define MPFR_DEPRECATED
27342734
#define MPFR_RETURNS_NONNULL
27352735
#define __MPC_DECLSPEC
2736-
#define PARAMS(x) x
2736+
#define PARAMS(p)p
27372737
#define INLINE
2738+
#define EXTERN(x)extern x
2739+
#define JPP(p)p
2740+
#define JMETHOD(T,n,p)T(*n)p
27382741

27392742

27402743

kos/include/libvideo/gfx/buffer.h

Lines changed: 41 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -454,8 +454,8 @@ struct video_buffer_ops {
454454
* @assume(__lock->_vrl_rect.vcr_ydim > 0);
455455
* @assume((__lock->_vrl_rect.vcr_xmin + __lock->_vrl_rect.vcr_xdim) > __lock->_vrl_rect.vcr_xmin);
456456
* @assume((__lock->_vrl_rect.vcr_ymin + __lock->_vrl_rect.vcr_ydim) > __lock->_vrl_rect.vcr_ymin);
457-
* @assume((__lock->_vrl_rect.vcr_xmin + __lock->_vrl_rect.vcr_xdim) <= __self->vb_xdim);
458-
* @assume((__lock->_vrl_rect.vcr_ymin + __lock->_vrl_rect.vcr_ydim) <= __self->vb_ydim);
457+
* @assume((__lock->_vrl_rect.vcr_xmin + __lock->_vrl_rect.vcr_xdim) <= video_buffer_getxdim(__self));
458+
* @assume((__lock->_vrl_rect.vcr_ymin + __lock->_vrl_rect.vcr_ydim) <= video_buffer_getydim(__self));
459459
*
460460
* @return: 0: Success
461461
* @return: -1: Error (s.a. `errno') */
@@ -472,8 +472,8 @@ struct video_buffer_ops {
472472
* @assume(__lock->_vrl_rect.vcr_ydim > 0);
473473
* @assume((__lock->_vrl_rect.vcr_xmin + __lock->_vrl_rect.vcr_xdim) > __lock->_vrl_rect.vcr_xmin);
474474
* @assume((__lock->_vrl_rect.vcr_ymin + __lock->_vrl_rect.vcr_ydim) > __lock->_vrl_rect.vcr_ymin);
475-
* @assume((__lock->_vrl_rect.vcr_xmin + __lock->_vrl_rect.vcr_xdim) <= __self->vb_xdim);
476-
* @assume((__lock->_vrl_rect.vcr_ymin + __lock->_vrl_rect.vcr_ydim) <= __self->vb_ydim);
475+
* @assume((__lock->_vrl_rect.vcr_xmin + __lock->_vrl_rect.vcr_xdim) <= video_buffer_getxdim(__self));
476+
* @assume((__lock->_vrl_rect.vcr_ymin + __lock->_vrl_rect.vcr_ydim) <= video_buffer_getydim(__self));
477477
*
478478
* @return: 0: Success
479479
* @return: -1: Error (s.a. `errno') */
@@ -486,11 +486,11 @@ struct video_buffer_ops {
486486
__NOTHROW_T(LIBVIDEO_GFX_FCC *vi_unlockregion)(struct video_buffer *__restrict __self,
487487
struct video_regionlock *__restrict __lock);
488488

489-
/* Create a new hard subregion-proxy of `__self'. The caller is responsible to ensure
490-
* that the given `__rect' does not exceed `__self->vb_xdim' / `__self->vb_ydim'. Note
491-
* that this function behaves slightly different from `video_surface_region()', in that
492-
* the later accepts a signed rect, while also allowing said rect to be greater than
493-
* the dimensions of the original buffer.
489+
/* Create a new hard subregion-proxy of `__self'. The caller is responsible to ensure
490+
* that the given `__rect' does not exceed `video_buffer_get[xy]dim(__self)'. Note
491+
* that this function behaves slightly different from `video_surface_region()', in
492+
* that the later accepts a signed rect, while also allowing said rect to be greater
493+
* than the dimensions of the original buffer.
494494
*
495495
* On the other hand, this function only works for creating **true** sub-rects, but
496496
* since this one is implemented by individual buffers, it is probably faster, too.
@@ -613,8 +613,8 @@ video_buffer_unlock(struct video_buffer *__self, struct video_lock *__lock);
613613
* @assume(__ydim > 0);
614614
* @assume((__xmin + __xdim) > __xmin);
615615
* @assume((__ymin + __ydim) > __ymin);
616-
* @assume((__xmin + __xdim) <= __self->vb_xdim);
617-
* @assume((__ymin + __ydim) <= __self->vb_ydim);
616+
* @assume((__xmin + __xdim) <= video_buffer_getxdim(__self));
617+
* @assume((__ymin + __ydim) <= video_buffer_getydim(__self));
618618
*
619619
* @return: 0: Success
620620
* @return: -1: Error (s.a. `errno') */
@@ -632,8 +632,8 @@ video_buffer_rlockregion(struct video_buffer *__self, struct video_regionlock *_
632632
* @assume(__ydim > 0);
633633
* @assume((__xmin + __xdim) > __xmin);
634634
* @assume((__ymin + __ydim) > __ymin);
635-
* @assume((__xmin + __xdim) <= __self->vb_xdim);
636-
* @assume((__ymin + __ydim) <= __self->vb_ydim);
635+
* @assume((__xmin + __xdim) <= video_buffer_getxdim(__self));
636+
* @assume((__ymin + __ydim) <= video_buffer_getydim(__self));
637637
*
638638
* @return: 0: Success
639639
* @return: -1: Error (s.a. `errno') */
@@ -755,24 +755,41 @@ struct video_buffer {
755755

756756
/* Acquire/release references to sub-objects that any (initialized) buffer must hold */
757757
#ifdef LIBVIDEO_GFX_EXPOSE_INTERNALS
758-
#define __video_buffer_setsubregion(self, parent_surface, parent_buffer) \
759-
(void)((self)->vb_surf.vs_pal = (parent_surface)->vs_pal, \
760-
(self)->vb_surf.vs_flags = (parent_surface)->vs_flags, \
761-
(self)->vb_surf.vs_colorkey = (parent_surface)->vs_colorkey, \
762-
(self)->vb_codec = (parent_buffer)->vb_codec)
763-
#define __video_buffer_setformat(self, format) \
764-
(void)((self)->vb_surf.vs_pal = (format)->vbf_pal, \
765-
(self)->vb_surf.vs_flags = (format)->vbf_flags, \
766-
(self)->vb_surf.vs_colorkey = (format)->vbf_colorkey, \
767-
(self)->vb_codec = (format)->vbf_codec)
758+
/* Initialize format of `self' from `format'
759+
* @return: true: Success
760+
* @return: false: Error: missing palette */
761+
#define __video_buffer_init_format(self, format) \
762+
((self)->vb_surf.vs_pal = (format)->vbf_pal, \
763+
(self)->vb_surf.vs_flags = (format)->vbf_flags, \
764+
(self)->vb_surf.vs_colorkey = (format)->vbf_colorkey, \
765+
(((self)->vb_codec = (format)->vbf_codec)->vc_specs.vcs_flags & VIDEO_CODEC_FLAG_PAL) \
766+
? ((self)->vb_surf.vs_pal != __NULLPTR) \
767+
: ((self)->vb_surf.vs_pal = __NULLPTR, (self)->vb_surf.vs_flags &= ~VIDEO_GFX_F_PALOBJ, 1))
768+
#define __video_buffer_init_domain(self, domain) \
769+
(void)((self)->vb_domain = (domain))
770+
/* Initialize dimensions of a buffer */
771+
#define __video_buffer_init_dim(self, xdim, ydim) \
772+
(void)((self)->vb_xdim = (xdim), (self)->vb_ydim = (ydim))
773+
/* Initialize format+domain+dim for a subregion buffer */
774+
#define __video_buffer_init_subregion(self, parent_surface, parent_buffer, rect) \
775+
(void)((self)->vb_surf.vs_pal = (parent_surface)->vs_pal, \
776+
(self)->vb_surf.vs_flags = (parent_surface)->vs_flags, \
777+
(self)->vb_surf.vs_colorkey = (parent_surface)->vs_colorkey, \
778+
(self)->vb_codec = (parent_buffer)->vb_codec, \
779+
(self)->vb_domain = (parent_buffer)->vb_domain, \
780+
__video_buffer_init_dim(self, (rect)->vcr_xdim, (rect)->vcr_ydim))
781+
/* Initialize operators of a buffer */
782+
#define __video_buffer_init_ops(self, ops) \
783+
(void)((self)->vb_ops = (ops))
768784
#ifdef __INTELLISENSE__
769785
#define __video_buffer_init_common(self) ((self)->vb_surf.vs_buffer = (self))
770786
#define __video_buffer_fini_common(self) (void)((self)->vb_surf.vs_buffer = (self))
771787
#else /* __INTELLISENSE__ */
772788
#define __video_buffer_init_common(self) \
773789
(!((self)->vb_surf.vs_flags & VIDEO_GFX_F_PALOBJ) || \
774790
(video_palette_incref((self)->vb_surf.vs_pal), 0), \
775-
video_codec_incref((self)->vb_codec), (self)->vb_surf.vs_buffer = (self))
791+
video_codec_incref((self)->vb_codec), \
792+
(self)->vb_refcnt = 1, (self)->vb_surf.vs_buffer = (self))
776793
#define __video_buffer_fini_common(self) \
777794
(void)(__hybrid_assert((self)->vb_surf.vs_buffer == (self)), \
778795
video_codec_decref((self)->vb_codec), \

kos/include/libvideo/gfx/gfx.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,7 +1198,7 @@ struct video_gfxhdr {
11981198
* - VIDEO_GFX_F_XMIRROR/*Y mirror the "I/O Rect"
11991199
*
12001200
* Coords of these rects are (in absolute "video_coord_t" coords):
1201-
* - Buffer: {xy: {0,0}, wh: {vx_surf.vs_buffer->vb_xdim,vx_surf.vs_buffer->vb_ydim}}
1201+
* - Buffer: {xy: {0,0}, wh: video_buffer_getXYdim(vx_surf.vs_buffer)}
12021202
* - Clip Rect: {xy: {vxh_cxoff,vxh_cyoff}, wh: {vxh_cxdim,vxh_cydim}}
12031203
* - I/O Rect: {xy: {vxh_bxmin,vxh_bymin}, wh: {vxh_bxsiz,vxh_bysiz}}
12041204
*
@@ -1253,8 +1253,8 @@ struct video_gfxhdr {
12531253
* NOTE: The I/O Rect is already pre-adjusted for VIDEO_GFX_F_XMIRROR/VIDEO_GFX_F_YMIRROR */
12541254
video_coord_t vxh_bxmin; /* [<= vxh_bxend][>= vxh_cxoff] Absolute buffer start coord in X (start of acc) */
12551255
video_coord_t vxh_bymin; /* [<= vxh_byend][>= vxh_cyoff] Absolute buffer start coord in Y */
1256-
video_coord_t vxh_bxend; /* [<= vx_surf.vs_buffer->vb_xdim] Absolute buffer end coord in X (<= `vx_surf.vs_buffer->vb_xdim') */
1257-
video_coord_t vxh_byend; /* [<= vx_surf.vs_buffer->vb_ydim] Absolute buffer end coord in Y (<= `vx_surf.vs_buffer->vb_ydim') */
1256+
video_coord_t vxh_bxend; /* [<= video_buffer_getxdim(:vx_surf.vs_buffer)] Absolute buffer end coord in X */
1257+
video_coord_t vxh_byend; /* [<= video_buffer_getydim(:vx_surf.vs_buffer)] Absolute buffer end coord in Y */
12581258
// video_dim_t vxh_bxdim; /* [== vxh_bxend - vxh_bxmin][<= vxh_cxdim] I/O Rect width */
12591259
// video_dim_t vxh_bydim; /* [== vxh_byend - vxh_bymin][<= vxh_cydim] I/O Rect height */
12601260
};

kos/include/libvideo/gfx/surface.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,11 @@ video_surface_getgfx(struct video_surface const *__self,
210210
struct video_gfx *__result,
211211
gfx_blendmode_t __blendmode);
212212

213-
/* Create a new hard subregion-proxy of `__self'. The caller is responsible to ensure
214-
* that the given `__rect' does not exceed `__self->vb_xdim' / `__self->vb_ydim'. Note
215-
* that this function behaves slightly different from `video_surface_region()', in that
216-
* the later accepts a signed rect, while also allowing said rect to be greater than
217-
* the dimensions of the original buffer.
213+
/* Create a new hard subregion-proxy of `__self'. The caller is responsible to ensure
214+
* that the given `__rect' does not exceed `video_surface_get[xy]dim(__self)'. Note
215+
* that this function behaves slightly different from `video_surface_region()', in
216+
* that the later accepts a signed rect, while also allowing said rect to be greater
217+
* than the dimensions of the original buffer.
218218
*
219219
* On the other hand, this function only works for creating **true** sub-rects, but
220220
* since this one is implemented by individual buffers, it is probably faster, too.

kos/src/apps/showpic/main.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -562,8 +562,8 @@ int main(int argc, char *argv[]) {
562562
struct video_rect rect;
563563
rect.vr_xmin = 100;
564564
rect.vr_ymin = 100;
565-
rect.vr_xdim = screen_buffer_asvideo(screen)->vb_xdim - 200;
566-
rect.vr_ydim = screen_buffer_asvideo(screen)->vb_ydim - 200;
565+
rect.vr_xdim = video_buffer_getxdim(screen_buffer_asvideo(screen)) - 200;
566+
rect.vr_ydim = video_buffer_getydim(screen_buffer_asvideo(screen)) - 200;
567567
bscreen = video_buffer_region(screen_buffer_asvideo(screen), &rect);
568568
if (!bscreen)
569569
err(EXIT_FAILURE, "Failed to load screen buffer");
@@ -643,7 +643,7 @@ int main(int argc, char *argv[]) {
643643
#endif
644644

645645
/* Load the named file as a video buffer. */
646-
anim = video_anim_open(bscreen->vb_domain, argv[1]);
646+
anim = video_anim_open(video_buffer_getdomain(bscreen), argv[1]);
647647
if unlikely(!anim)
648648
err(EXIT_FAILURE, "Failed to open image");
649649

@@ -657,7 +657,7 @@ int main(int argc, char *argv[]) {
657657
{
658658
struct video_buffer_format format;
659659
video_buffer_getformat(bscreen, &format);
660-
anim = video_anim_cached(anim, bscreen->vb_domain, &format);
660+
anim = video_anim_cached(anim, video_buffer_getdomain(bscreen), &format);
661661
}
662662
#endif
663663

kos/src/libvideo/compositor/compositor.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2229,14 +2229,10 @@ add_alpha(struct video_codec *__restrict codec) {
22292229
PRIVATE ATTR_INOUT(1) void CC
22302230
local_compositor_updatebuffercaches(struct local_compositor *__restrict me) {
22312231
struct video_buffer *buffer = me->lc_buffer;
2232-
2233-
me->lc_domain = buffer->vb_domain;
2234-
me->lc_nalpha_format.vbf_codec = video_buffer_getcodec(buffer);
2235-
me->lc_nalpha_format.vbf_pal = buffer->vb_surf.vs_pal;
2236-
me->lc_nalpha_format.vbf_flags = video_buffer_getflags(buffer) & ~VIDEO_GFX_F_COLORKEY;
2237-
me->lc_yalpha_format.vbf_codec = add_alpha(video_buffer_getcodec(buffer));
2238-
me->lc_yalpha_format.vbf_pal = buffer->vb_surf.vs_pal;
2239-
me->lc_yalpha_format.vbf_flags = me->lc_nalpha_format.vbf_flags;
2232+
me->lc_domain = video_buffer_getdomain(buffer);
2233+
video_buffer_getformat(buffer, &me->lc_nalpha_format);
2234+
me->lc_yalpha_format = me->lc_nalpha_format;
2235+
me->lc_yalpha_format.vbf_codec = add_alpha(me->lc_yalpha_format.vbf_codec);
22402236

22412237
/* Generate new (pre-cached) GFX contexts */
22422238
DBG_memset(&me->lc_buffer_gfx_write, 0xcc, sizeof(me->lc_buffer_gfx_write));

kos/src/libvideo/gfx/anim.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ libvideo_anim_fromframe(struct video_buffer *__restrict frame) {
115115
if unlikely(!result)
116116
goto err;
117117
result->va_ops = _oneframe_anim_ops();
118-
result->va_domain = frame->vb_domain;
119-
result->va_xdim = frame->vb_xdim;
120-
result->va_ydim = frame->vb_ydim;
118+
result->va_domain = video_buffer_getdomain(frame);
119+
result->va_xdim = video_buffer_getxdim(frame);
120+
result->va_ydim = video_buffer_getydim(frame);
121121
result->va_refcnt = 1;
122122
result->ofa_frame = frame;
123123
video_buffer_incref(frame);
@@ -430,7 +430,7 @@ libvideo_anim_cached(struct video_anim *__restrict self,
430430
REF struct video_buffer *converted;
431431
struct oneframe_anim *me = (struct oneframe_anim *)self;
432432
struct video_buffer *frame = me->ofa_frame;
433-
if (frame->vb_domain == domain &&
433+
if (video_buffer_getdomain(frame) == domain &&
434434
(!format || video_buffer_hasformat(frame, format))) {
435435
video_anim_incref(me);
436436
return me;

kos/src/libvideo/gfx/buffer.h

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,27 @@
3535

3636
DECL_BEGIN
3737

38-
#define video_regionlock_assert(self, lock) \
39-
(__assertf(((lock)->_vrl_rect.vcr_xmin + (lock)->_vrl_rect.vcr_xdim) > (lock)->_vrl_rect.vcr_xmin, \
40-
"video_regionlock: X+SX overflows, or SX=0 [X=%" PRIuCRD ",SX=%" PRIuDIM "]", \
41-
(lock)->_vrl_rect.vcr_xmin, (lock)->_vrl_rect.vcr_xdim), \
42-
__assertf(((lock)->_vrl_rect.vcr_ymin + (lock)->_vrl_rect.vcr_ydim) > (lock)->_vrl_rect.vcr_ymin, \
43-
"video_regionlock: Y+SY overflows, or SY=0 [Y=%" PRIuCRD ",SY=%" PRIuDIM "]", \
44-
(lock)->_vrl_rect.vcr_ymin, (lock)->_vrl_rect.vcr_ydim), \
45-
__assertf(((lock)->_vrl_rect.vcr_xmin + (lock)->_vrl_rect.vcr_xdim) <= (self)->vb_xdim, \
46-
"video_regionlock: X+SX overflows exceeds buffer dimension " \
47-
"[X=%" PRIuCRD ",SX=%" PRIuDIM ",X+SX=%" PRIuDIM ",DIM=%" PRIuDIM "]", \
48-
(lock)->_vrl_rect.vcr_xmin, (lock)->_vrl_rect.vcr_xdim, \
49-
(lock)->_vrl_rect.vcr_xmin + (lock)->_vrl_rect.vcr_xdim, (self)->vb_xdim), \
50-
__assertf(((lock)->_vrl_rect.vcr_ymin + (lock)->_vrl_rect.vcr_ydim) <= (self)->vb_ydim, \
51-
"video_regionlock: Y+SY overflows exceeds buffer dimension " \
52-
"[Y=%" PRIuCRD ",SY=%" PRIuDIM ",Y+SY=%" PRIuDIM ",DIM=%" PRIuDIM "]", \
53-
(lock)->_vrl_rect.vcr_ymin, (lock)->_vrl_rect.vcr_ydim, \
54-
(lock)->_vrl_rect.vcr_ymin + (lock)->_vrl_rect.vcr_ydim, (self)->vb_ydim))
38+
#define _video_buffer_assert_rect(context, self, rect) \
39+
(__assertf(((rect)->vcr_xmin + (rect)->vcr_xdim) > (rect)->vcr_xmin, \
40+
context ": X+SX overflows, or SX=0 [X=%" PRIuCRD ",SX=%" PRIuDIM "]", \
41+
(rect)->vcr_xmin, (rect)->vcr_xdim), \
42+
__assertf(((rect)->vcr_ymin + (rect)->vcr_ydim) > (rect)->vcr_ymin, \
43+
context ": Y+SY overflows, or SY=0 [Y=%" PRIuCRD ",SY=%" PRIuDIM "]", \
44+
(rect)->vcr_ymin, (rect)->vcr_ydim), \
45+
__assertf(((rect)->vcr_xmin + (rect)->vcr_xdim) <= video_buffer_getxdim(self), \
46+
context ": X+SX overflows exceeds buffer dimension " \
47+
"[X=%" PRIuCRD ",SX=%" PRIuDIM ",X+SX=%" PRIuDIM ",DIM=%" PRIuDIM "]", \
48+
(rect)->vcr_xmin, (rect)->vcr_xdim, \
49+
(rect)->vcr_xmin + (rect)->vcr_xdim, video_buffer_getxdim(self)), \
50+
__assertf(((rect)->vcr_ymin + (rect)->vcr_ydim) <= video_buffer_getydim(self), \
51+
context ": Y+SY overflows exceeds buffer dimension " \
52+
"[Y=%" PRIuCRD ",SY=%" PRIuDIM ",Y+SY=%" PRIuDIM ",DIM=%" PRIuDIM "]", \
53+
(rect)->vcr_ymin, (rect)->vcr_ydim, \
54+
(rect)->vcr_ymin + (rect)->vcr_ydim, video_buffer_getydim(self)))
55+
#define video_buffer_assert_rect(self, rect) \
56+
_video_buffer_assert_rect("assert_rect", self, rect)
57+
#define video_regionlock_assert(self, lock) \
58+
_video_buffer_assert_rect("video_regionlock", self, &(lock)->_vrl_rect)
5559

5660
/* Generic implementations for video buffer operators. */
5761
INTDEF ATTR_RETNONNULL ATTR_INOUT(1) struct video_gfx *FCC

0 commit comments

Comments
 (0)