Skip to content

Commit 1ebb102

Browse files
committed
Start removing the old ram-buffer system
1 parent f4a2ac1 commit 1ebb102

File tree

18 files changed

+138
-2355
lines changed

18 files changed

+138
-2355
lines changed

kos/include/libvideo/gfx/buffer.h

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -917,54 +917,6 @@ old_video_buffer_fromgfx(struct video_gfx const *__restrict __self);
917917
#endif /* LIBVIDEO_GFX_WANT_PROTOTYPES */
918918

919919

920-
/* Create a wrapper video buffer for `__self' that can only ever be used to access
921-
* the intersection of pixels from `__rect' and `__self' (trying a GFX context will
922-
* always start out with the I/O rect set to "__rect", but the clip rect still set
923-
* to the buffer's base dimensions, and trying to lock OOB regions always fails)
924-
*
925-
* NOTE: Starting coords in `__rect' are allowed to be negative, and its dimensions
926-
* are allowed to be greater than those of `__self', too!
927-
*
928-
* `old_video_buffer_region_revocable()' does the same, but the returned video buffer
929-
* is also "revocable" (s.a. `old_video_buffer_region_revoke()'), meaning it can be
930-
* detached from the original buffer (and turned into a no-op) at any point in time
931-
* (blocking if a video lock is held in `old_video_buffer_region_revoke()').
932-
*
933-
* @return: * : The wrapper video buffer
934-
* @return: NULL: Failed to create video buffer (s.a. `errno') */
935-
typedef __ATTR_WUNUSED_T __ATTR_INOUT_T(1) __ATTR_IN_T(2) __REF struct video_buffer *
936-
(LIBVIDEO_GFX_CC *POLD_VIDEO_BUFFER_REGION)(struct video_buffer *__restrict __self,
937-
struct video_rect const *__restrict __rect);
938-
typedef __ATTR_WUNUSED_T __ATTR_INOUT_T(1) __ATTR_IN_T(2) __REF struct video_buffer *
939-
(LIBVIDEO_GFX_CC *POLD_VIDEO_BUFFER_REGION_REVOCABLE)(struct video_buffer *__restrict __self,
940-
struct video_rect const *__restrict __rect);
941-
#ifdef LIBVIDEO_GFX_WANT_PROTOTYPES
942-
LIBVIDEO_GFX_DECL __ATTR_WUNUSED __ATTR_INOUT(1) __ATTR_IN(2) __REF struct video_buffer *LIBVIDEO_GFX_CC
943-
old_video_buffer_region(struct video_buffer *__restrict __self,
944-
struct video_rect const *__restrict __rect);
945-
LIBVIDEO_GFX_DECL __ATTR_WUNUSED __ATTR_INOUT(1) __ATTR_IN(2) __REF struct video_buffer *LIBVIDEO_GFX_CC
946-
old_video_buffer_region_revocable(struct video_buffer *__restrict __self,
947-
struct video_rect const *__restrict __rect);
948-
#endif /* LIBVIDEO_GFX_WANT_PROTOTYPES */
949-
950-
951-
/* Revoke access to the underlying video buffer, given a video
952-
* buffer that was returned by `old_video_buffer_region_revocable()'.
953-
* If the buffer had already been revoked, this is a no-op.
954-
*
955-
* >> DO NOT CALL THIS FUNCTION FOR BUFFERS OBTAINED FROM SOMETHING
956-
* >> OTHER THAN `old_video_buffer_region_revocable()' !!!
957-
*
958-
* @return: * : Always re-returns `__self' */
959-
typedef __ATTR_INOUT_T(1) struct video_buffer *
960-
(LIBVIDEO_GFX_CC *POLD_VIDEO_BUFFER_REGION_REVOKE)(struct video_buffer *__restrict __self);
961-
#ifdef LIBVIDEO_GFX_WANT_PROTOTYPES
962-
LIBVIDEO_GFX_DECL __ATTR_INOUT(1) struct video_buffer *LIBVIDEO_GFX_CC
963-
old_video_buffer_region_revoke(struct video_buffer *__restrict __self);
964-
#endif /* LIBVIDEO_GFX_WANT_PROTOTYPES */
965-
966-
967-
968920
/* Various functions for opening a file/stream/blob as an image file.
969921
* The actual file format is auto-detected, and supported formats depend
970922
* on installed 3rd party libraries. By default, BMP and PNG is supported. */

kos/src/apps/showpic/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -566,10 +566,10 @@ int main(int argc, char *argv[]) {
566566
rect.vr_ymin = 100;
567567
rect.vr_xdim = screen_buffer_asvideo(screen)->vb_xdim - 200;
568568
rect.vr_ydim = screen_buffer_asvideo(screen)->vb_ydim - 200;
569-
bscreen = old_video_buffer_region_revocable(screen_buffer_asvideo(screen), &rect);
569+
bscreen = video_buffer_region(screen_buffer_asvideo(screen), &rect, 0);
570570
if (!bscreen)
571571
err(EXIT_FAILURE, "Failed to load screen buffer");
572-
// old_video_buffer_region_revoke(bscreen);
572+
// video_buffer_revoke(bscreen);
573573
}
574574
#else
575575
bscreen = screen_buffer_asvideo(screen);

kos/src/libvideo/compositor/compositor.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ try_convert_window_to_passthru(struct local_window *__restrict self) {
233233
* become viewable, even if the window is moved to be fully on-screen) */
234234

235235
/* Allocate passthru buffer */
236-
new_content = old_video_buffer_region_revocable(comp->lc_buffer, &self->lw_attr.vwa_rect);
236+
new_content = video_buffer_region(comp->lc_buffer, &self->lw_attr.vwa_rect, 0);
237237
if unlikely(!new_content)
238238
return; /* Failed to allocate passthru buffer */
239239

@@ -540,7 +540,7 @@ local_window_destroy(struct video_display *__restrict self) {
540540
local_window_assert(me);
541541
if (!(me->lw_attr.vwa_flags & VIDEO_WINDOW_F_HIDDEN)) {
542542
if (LIST_ISBOUND(me, lw_passthru)) {
543-
old_video_buffer_region_revoke(me->lw_content);
543+
video_buffer_revoke(me->lw_content);
544544
LIST_UNBIND(me, lw_passthru);
545545
}
546546
local_window_hide_impl(me);
@@ -1713,7 +1713,7 @@ _local_window_ensure_not_passthru_impl(struct local_window *__restrict self) {
17131713
self->lw_content = newbuf; /* Inherit reference (x2) */
17141714

17151715
/* Revoke video access and drop old buffer */
1716-
oldbuf = old_video_buffer_region_revoke(oldbuf);
1716+
oldbuf = video_buffer_revoke(oldbuf);
17171717
LIST_UNBIND(self, lw_passthru);
17181718
video_buffer_decref(oldbuf);
17191719
return 0;
@@ -2026,7 +2026,7 @@ local_compositor_newwindow(struct video_compositor *__restrict self,
20262026
(result->lw_overlay_mask_allcount == 0)) {
20272027
/* Use a passthru buffer */
20282028
REF struct video_buffer *content;
2029-
content = old_video_buffer_region_revocable(comp->lc_buffer, &result->lw_attr.vwa_rect);
2029+
content = video_buffer_region(comp->lc_buffer, &result->lw_attr.vwa_rect, 0);
20302030
if unlikely(!content)
20312031
goto err_unlock_r_overlay;
20322032
result->lw_content = content;
@@ -2272,7 +2272,7 @@ local_compositor_setbuffer_locked(struct local_compositor *__restrict me,
22722272
REF struct video_buffer *new_passthru;
22732273
assert(LIST_ISBOUND(pt_window, lw_passthru));
22742274
local_window_assert(pt_window);
2275-
new_passthru = old_video_buffer_region_revocable(new_buffer, &pt_window->lw_attr.vwa_rect);
2275+
new_passthru = video_buffer_region(new_buffer, &pt_window->lw_attr.vwa_rect, 0);
22762276
if unlikely(!new_passthru) {
22772277
struct local_window *rollback;
22782278
/* Rollback already-allocated (new) passthru buffers */
@@ -2505,7 +2505,7 @@ local_compositor_setfeatures(struct video_compositor *__restrict self,
25052505
video_gfx_bitblit(&ngfx, 0, 0, &ogfx, 0, 0,
25062506
video_gfx_getclipw(&ngfx),
25072507
video_gfx_getcliph(&ngfx));
2508-
obuffer = old_video_buffer_region_revoke(obuffer);
2508+
obuffer = video_buffer_revoke(obuffer);
25092509
video_buffer_decref(obuffer);
25102510
LIST_UNBIND(pt_window, lw_passthru);
25112511
}

kos/src/libvideo/compositor/compositor.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ struct local_window: video_window {
9696
struct video_window_attr lw_attr; /* [lock(local_window_comp(this)->lc_lock)] Window attributes (empty windows aren't allowed!) */
9797
REF struct video_buffer *lw_content; /* [1..1][lock(local_window_comp(this)->lc_lock)]
9898
* - RGB/RGBA Content buffer (returned by `video_window_getbuffer()')
99-
* - Alternatively, when `lw_passthru' is bound, this is a revocable region in
100-
* `local_window_comp(this)->lc_buffer' (s.a. `old_video_buffer_region_revoke()'). */
99+
* - Alternatively, when `lw_passthru' is bound, this is a revocable region in
100+
* `local_window_comp(this)->lc_buffer' (s.a. `video_buffer_revoke()'). */
101101
LIST_ENTRY(local_window) lw_passthru; /* [0..1][lock(local_window_comp(this)->lc_lock)] Entry in the list of windows with passthru buffers */
102102
TAILQ_ENTRY(local_window) lw_zorder; /* [1..1][lock(local_window_comp(this)->lc_lock)] Entry in the list of all windows */
103103
TAILQ_ENTRY(local_window) lw_zorder_visi; /* [0..1][lock(local_window_comp(this)->lc_lock)] Entry in the list of all visible windows */

kos/src/libvideo/gfx/buffer/lockable.c

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,8 @@
4444

4545
#include "../buffer.h"
4646
#include "../ramdomain.h"
47-
#include "old-gfx.h"
4847
#include "lockable.h"
49-
#include "old-ram.h"
48+
#include "region.h"
5049

5150
DECL_BEGIN
5251

@@ -56,24 +55,19 @@ DECL_BEGIN
5655
#define DBG_memset(p, c, n) (void)0
5756
#endif /* NDEBUG || NDEBUG_FINI */
5857

59-
#undef LOCKABLE_BUFFER_PALREF
60-
#if 0
61-
#define LOCKABLE_BUFFER_PALREF
62-
#endif
63-
6458
/* Indices into `struct video_lock::_vl_driver' */
6559
#define LOCKABLE_BUFFER_VLOCK_ISWRITE 0
6660
static_assert(_VIDEO_LOCK__N_DRIVER >= 1);
6761

6862
/* Initialize a mock ram-buffer using the video lock of "self" */
6963
PRIVATE ATTR_OUT(1) ATTR_IN(2) void FCC
70-
lockable_asram(struct old_video_rambuffer *__restrict rb,
64+
lockable_asram(struct video_rambuffer_base *__restrict rb,
7165
struct lockable_buffer const *__restrict self) {
72-
rb->vb_ops = _old_rambuffer_ops();
73-
rb->vb_format.vf_codec = self->vb_format.vf_codec;
74-
rb->vb_format.vf_pal = self->vb_format.vf_pal;
75-
rb->vb_xdim = self->vb_xdim;
76-
rb->vb_ydim = self->vb_ydim;
66+
DBG_memset(&rb->vb_domain, 0xcc, sizeof(rb->vb_domain));
67+
rb->vb_ops = _rambuffer_ops();
68+
rb->vb_format = self->vb_format;
69+
rb->vb_xdim = self->vb_xdim;
70+
rb->vb_ydim = self->vb_ydim;
7771
#ifndef NDEBUG
7872
rb->vb_refcnt = 0; /* So someone incref'ing will fault */
7973
#endif /* !NDEBUG */
@@ -86,7 +80,7 @@ PRIVATE NONNULL((1)) void FCC
8680
lockable_readpixels(struct lockable_buffer const *__restrict self) {
8781
struct video_gfx srcgfx, *p_srcgfx;
8882
struct video_gfx dstgfx, *p_dstgfx;
89-
struct old_video_rambuffer dst;
83+
struct video_rambuffer_base dst;
9084
lockable_asram(&dst, self);
9185
p_srcgfx = video_buffer_getgfx(self->lb_base, &srcgfx, GFX_BLENDMODE_OVERRIDE, VIDEO_GFX_F_NORMAL, 0);
9286
p_dstgfx = video_buffer_getgfx(&dst, &dstgfx, GFX_BLENDMODE_OVERRIDE, VIDEO_GFX_F_NORMAL, 0);
@@ -103,7 +97,7 @@ PRIVATE NONNULL((1)) void FCC
10397
lockable_writepixels(struct lockable_buffer const *__restrict self) {
10498
struct video_gfx srcgfx, *p_srcgfx;
10599
struct video_gfx dstgfx, *p_dstgfx;
106-
struct old_video_rambuffer src;
100+
struct video_rambuffer_base src;
107101
lockable_asram(&src, self);
108102
p_srcgfx = video_buffer_getgfx(&src, &srcgfx, GFX_BLENDMODE_OVERRIDE, VIDEO_GFX_F_NORMAL, 0);
109103
p_dstgfx = video_buffer_getgfx(self->lb_base, &dstgfx, GFX_BLENDMODE_OVERRIDE, VIDEO_GFX_F_NORMAL, 0);
@@ -121,7 +115,7 @@ lockable_readpixels_region(struct lockable_buffer const *__restrict self,
121115
struct video_regionlock const *__restrict region) {
122116
struct video_gfx srcgfx, *p_srcgfx;
123117
struct video_gfx dstgfx, *p_dstgfx;
124-
struct old_video_rambuffer dst;
118+
struct video_rambuffer_base dst;
125119
lockable_asram(&dst, self);
126120
p_srcgfx = video_buffer_getgfx(self->lb_base, &srcgfx, GFX_BLENDMODE_OVERRIDE, VIDEO_GFX_F_NORMAL, 0);
127121
p_dstgfx = video_buffer_getgfx(&dst, &dstgfx, GFX_BLENDMODE_OVERRIDE, VIDEO_GFX_F_NORMAL, 0);
@@ -139,7 +133,7 @@ lockable_writepixels_region(struct lockable_buffer const *__restrict self,
139133
struct video_regionlock const *__restrict region) {
140134
struct video_gfx srcgfx, *p_srcgfx;
141135
struct video_gfx dstgfx, *p_dstgfx;
142-
struct old_video_rambuffer src;
136+
struct video_rambuffer_base src;
143137
lockable_asram(&src, self);
144138
p_srcgfx = video_buffer_getgfx(&src, &srcgfx, GFX_BLENDMODE_OVERRIDE, VIDEO_GFX_F_NORMAL, 0);
145139
p_dstgfx = video_buffer_getgfx(self->lb_base, &dstgfx, GFX_BLENDMODE_OVERRIDE, VIDEO_GFX_F_NORMAL, 0);
@@ -155,10 +149,8 @@ lockable_writepixels_region(struct lockable_buffer const *__restrict self,
155149
PRIVATE NONNULL((1)) void FCC
156150
lockable_destroy(struct video_buffer *__restrict self) {
157151
struct lockable_buffer *me = (struct lockable_buffer *)self;
158-
#ifdef LOCKABLE_BUFFER_PALREF
159152
if (me->vb_format.vf_pal)
160153
video_palette_decref(me->vb_format.vf_pal);
161-
#endif /* LOCKABLE_BUFFER_PALREF */
162154
video_buffer_decref(me->lb_base);
163155
free(me->lb_data);
164156
free(me);
@@ -352,19 +344,28 @@ PRIVATE ATTR_PURE WUNUSED ATTR_IN(1) bool CC
352344
video_buffer_islockable(struct video_buffer const *__restrict self) {
353345
if (self->vb_ops == &lockable_ops)
354346
goto yes;
355-
if (self->vb_ops == &old_rambuffer_ops)
347+
if (self->vb_ops == &rambuffer_ops)
348+
goto yes;
349+
if (self->vb_ops == &rambuffer_xcodec_ops)
350+
goto yes;
351+
if (self->vb_ops == &rambuffer_subregion_ops)
352+
goto yes;
353+
if (self->vb_ops == &rambuffer_subsubregion_ops)
356354
goto yes;
357-
if (self->vb_ops == &old_rambuffer_ops__for_codec)
355+
if (self->vb_ops == &rambuffer_formem_ops)
358356
goto yes;
359-
if (self->vb_ops == &old_membuffer_ops)
357+
if (self->vb_ops == &rambuffer_formem_xcodec_ops)
360358
goto yes;
361-
if (self->vb_ops == &old_membuffer_ops__for_codec)
359+
if (self->vb_ops == &rambuffer_formem_subregion_ops)
362360
goto yes;
363-
if (self->vb_ops == &old_subregion_buffer_ops_norem) {
364-
/* Subregion buffers are locked iff the underlying buffer is */
365-
struct old_subregion_buffer const *me;
366-
me = (struct old_subregion_buffer const *)self;
367-
return video_buffer_islockable(me->srb_base);
361+
if (self->vb_ops == &region_buffer_subregion_alias_ops) {
362+
/* Region alias buffers are locked iff the underlying buffer is.
363+
* Note that other region buffers are never lockable, since they
364+
* always contain at least 1 pixel that is out-of-bounds of some
365+
* base buffer (meaning not **all** pixels are lockable) */
366+
struct region_buffer_subregion_alias const *me;
367+
me = (struct region_buffer_subregion_alias const *)self;
368+
return video_buffer_islockable(me->rbf_base);
368369
}
369370
return false;
370371
yes:
@@ -379,7 +380,6 @@ video_buffer_islockable(struct video_buffer const *__restrict self) {
379380
INTERN WUNUSED ATTR_OUT(1) NONNULL((2)) struct video_buffer *CC
380381
libvideo_buffer_lockable_init(struct lockable_buffer *self,
381382
struct video_buffer *__restrict buffer) {
382-
self->lb_data = NULL;
383383
if (video_buffer_islockable(buffer))
384384
return buffer;
385385
self->vb_ops = _lockable_ops();
@@ -389,8 +389,9 @@ libvideo_buffer_lockable_init(struct lockable_buffer *self,
389389
#ifndef NDEBUG
390390
self->vb_refcnt = 0;
391391
#endif /* !NDEBUG */
392-
self->lb_base = buffer;
393-
self->lb_data = NULL;
392+
self->lb_base = buffer;
393+
self->lb_data = NULL;
394+
self->lb_edata = NULL;
394395
DBG_memset(&self->lb_stride, 0xcc, sizeof(self->lb_stride));
395396
return self;
396397
}
@@ -439,15 +440,14 @@ libvideo_buffer_lockable(struct video_buffer *__restrict self) {
439440
result->vb_format = self->vb_format;
440441
result->vb_xdim = self->vb_xdim;
441442
result->vb_ydim = self->vb_ydim;
442-
result->vb_domain = video_buffer_domain_for_wrapper(self);
443+
result->vb_domain = _libvideo_ramdomain();
443444
result->vb_refcnt = 1;
444445
video_buffer_incref(self);
445-
result->lb_base = self;
446-
result->lb_data = NULL;
447-
#ifdef LOCKABLE_BUFFER_PALREF
446+
result->lb_base = self;
447+
result->lb_data = NULL;
448+
result->lb_edata = NULL;
448449
if (result->vb_format.vf_pal)
449450
video_palette_incref(result->vb_format.vf_pal);
450-
#endif /* LOCKABLE_BUFFER_PALREF */
451451
DBG_memset(&result->lb_stride, 0xcc, sizeof(result->lb_stride));
452452
return result;
453453
err:

kos/src/libvideo/gfx/buffer/old-gfx.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ old_libvideo_buffer_fromgfx(struct video_gfx const *__restrict self) {
427427
sr_result->vb_format = src->vb_format;
428428
sr_result->vb_xdim = self->vx_hdr.vxh_cxsiz;
429429
sr_result->vb_ydim = self->vx_hdr.vxh_cysiz;
430-
sr_result->vb_domain = video_buffer_domain_for_wrapper(src);
430+
sr_result->vb_domain = src->vb_domain;
431431
sr_result->vb_refcnt = 1;
432432
sr_result->srb_base = src;
433433
video_buffer_incref(src);
@@ -455,7 +455,7 @@ old_libvideo_buffer_fromgfx(struct video_gfx const *__restrict self) {
455455
gx_result->vb_format = src->vb_format;
456456
gx_result->vb_xdim = self->vx_hdr.vxh_cxsiz;
457457
gx_result->vb_ydim = self->vx_hdr.vxh_cysiz;
458-
gx_result->vb_domain = video_buffer_domain_for_wrapper(src);
458+
gx_result->vb_domain = src->vb_domain;
459459
gx_result->vb_refcnt = 1;
460460
gx_result->gxb_base = src;
461461
video_buffer_incref(src);

0 commit comments

Comments
 (0)