Skip to content

Commit 50f2fb6

Browse files
committed
Add domain override to video_anim_cached()
1 parent 3cf7c0c commit 50f2fb6

File tree

4 files changed

+32
-17
lines changed

4 files changed

+32
-17
lines changed

kos/include/libvideo/gfx/anim.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,15 +179,19 @@ video_anim_fromframe(struct video_buffer *__restrict __frame);
179179

180180
/* Return a wrapper for `__self' that caches animation frames during
181181
* the first loop, and simply replays them during any subsequent loop.
182+
* @param: __domain: When non-null, animation frames are cached in this
183+
* domain, rather than being kept in `__self->va_domain'
182184
* @param: __format: When non-null, animation frames are converted into
183-
* this pixel format, rather than being copied verbatim.
184-
* @param: __type: The type of video buffer to use for cached images. */
185-
typedef __ATTR_WUNUSED_T __ATTR_INOUT_T(1) __ATTR_IN_OPT_T(2) __REF struct video_anim *
185+
* this pixel format, rather than being copied verbatim. */
186+
typedef __ATTR_WUNUSED_T __ATTR_INOUT_T(1) __ATTR_IN_OPT_T(2) __ATTR_IN_OPT_T(3) __REF struct video_anim *
186187
(LIBVIDEO_GFX_CC *PVIDEO_ANIM_CACHED)(struct video_anim *__restrict __self,
188+
struct video_domain const *__domain,
187189
struct video_format const *__format);
188190
#ifdef LIBVIDEO_GFX_WANT_PROTOTYPES
189-
LIBVIDEO_GFX_DECL __ATTR_WUNUSED __ATTR_INOUT(1) __ATTR_IN_OPT(2) __REF struct video_anim *LIBVIDEO_GFX_CC
190-
video_anim_cached(struct video_anim *__restrict __self, struct video_format const *__format);
191+
LIBVIDEO_GFX_DECL __ATTR_WUNUSED __ATTR_INOUT(1) __ATTR_IN_OPT(2) __ATTR_IN_OPT(3) __REF struct video_anim *LIBVIDEO_GFX_CC
192+
video_anim_cached(struct video_anim *__restrict __self,
193+
struct video_domain const *__domain,
194+
struct video_format const *__format);
191195
#endif /* LIBVIDEO_GFX_WANT_PROTOTYPES */
192196

193197

kos/src/apps/showpic/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -651,9 +651,9 @@ int main(int argc, char *argv[]) {
651651
* - src format caching: ~95% spent sleeping (=> x20 pixel output possible)
652652
* - dst format caching: ~97% spent sleeping (=> x30 pixel output possible) */
653653
#if 0
654-
anim = video_anim_cached(anim, NULL);
654+
anim = video_anim_cached(anim, NULL, NULL);
655655
#elif 1
656-
anim = video_anim_cached(anim, &bscreen->vb_format);
656+
anim = video_anim_cached(anim, bscreen->vb_domain, &bscreen->vb_format);
657657
#endif
658658
if unlikely(!anim)
659659
err(EXIT_FAILURE, "Failed to cache animation");

kos/src/libvideo/gfx/anim.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -404,18 +404,26 @@ PRIVATE ATTR_RETNONNULL WUNUSED struct video_anim_ops *CC _cached_anim_ops(void)
404404

405405
/* Return a wrapper for `self' that caches animation frames during
406406
* the first loop, and simply replays them during any subsequent loop.
407+
* @param: domain: When non-null, animation frames are cached in this
408+
* domain, rather than being kept in `self->va_domain'
407409
* @param: format: When non-null, animation frames are converted into
408-
* this pixel format, rather than being copied verbatim.
409-
* @param: type: The type of video buffer to use for cached images. */
410+
* this pixel format, rather than being copied verbatim. */
410411
DEFINE_PUBLIC_ALIAS(video_anim_cached, libvideo_anim_cached);
411-
INTERN WUNUSED ATTR_INOUT(1) ATTR_IN_OPT(2) REF struct video_anim *CC
412+
INTERN WUNUSED ATTR_INOUT(1) ATTR_IN_OPT(2) ATTR_IN_OPT(3) REF struct video_anim *CC
412413
libvideo_anim_cached(struct video_anim *__restrict self,
414+
struct video_domain const *domain,
413415
struct video_format const *format) {
414416
REF struct cached_anim *result;
417+
if (domain == NULL)
418+
domain = self->va_domain;
415419
if (self->va_ops == &cached_anim_ops) {
416420
/* Check for special case: `self' is already cached and uses a compatible format */
417421
struct cached_anim *me = (struct cached_anim *)self;
418-
if (!format) {
422+
if (format == NULL)
423+
format = &me->ca_fmt;
424+
if (format->vf_codec == me->ca_fmt.vf_codec &&
425+
format->vf_pal == me->ca_fmt.vf_pal &&
426+
me->va_domain == domain) {
419427
video_anim_incref(me);
420428
return me;
421429
}
@@ -428,11 +436,12 @@ libvideo_anim_cached(struct video_anim *__restrict self,
428436
if (format == NULL)
429437
format = &frame->vb_format;
430438
if (frame->vb_format.vf_codec == format->vf_codec &&
431-
frame->vb_format.vf_pal == format->vf_pal) {
439+
frame->vb_format.vf_pal == format->vf_pal &&
440+
frame->vb_domain == domain) {
432441
video_anim_incref(me);
433442
return me;
434443
}
435-
converted = libvideo_buffer_convert(frame, me->va_domain, format);
444+
converted = libvideo_buffer_convert(frame, domain, format);
436445
if unlikely(!converted)
437446
goto err;
438447
oneframe_result = libvideo_anim_fromframe(converted);
@@ -443,7 +452,7 @@ libvideo_anim_cached(struct video_anim *__restrict self,
443452
result = (REF struct cached_anim *)malloc(sizeof(struct cached_anim));
444453
if unlikely(!result)
445454
goto err;
446-
result->va_domain = self->va_domain;
455+
result->va_domain = domain ? domain : self->va_domain;
447456
result->va_ops = _cached_anim_ops();
448457
result->va_xdim = self->va_xdim;
449458
result->va_ydim = self->va_ydim;

kos/src/libvideo/gfx/anim.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,13 @@ libvideo_anim_fromframe(struct video_buffer *__restrict frame);
4343

4444
/* Return a wrapper for `self' that caches animation frames during
4545
* the first loop, and simply replays them during any subsequent loop.
46+
* @param: domain: When non-null, animation frames are cached in this
47+
* domain, rather than being kept in `self->va_domain'
4648
* @param: format: When non-null, animation frames are converted into
47-
* this pixel format, rather than being copied verbatim.
48-
* @param: type: The type of video buffer to use for cached images. */
49-
INTDEF WUNUSED ATTR_INOUT(1) ATTR_IN_OPT(2) REF struct video_anim *CC
49+
* this pixel format, rather than being copied verbatim. */
50+
INTDEF WUNUSED ATTR_INOUT(1) ATTR_IN_OPT(2) ATTR_IN_OPT(3) REF struct video_anim *CC
5051
libvideo_anim_cached(struct video_anim *__restrict self,
52+
struct video_domain const *domain,
5153
struct video_format const *format);
5254

5355
DECL_END

0 commit comments

Comments
 (0)