Skip to content

Commit af72c42

Browse files
committed
Re-implement video_buffer_fromgfx()
1 parent 3392e0d commit af72c42

File tree

14 files changed

+436
-648
lines changed

14 files changed

+436
-648
lines changed

kos/cpp.hint

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2905,3 +2905,4 @@
29052905
void libvideo_swgfx_preblend__fillstretchmask_l__##n(struct video_gfx const*__restrict self,video_coord_t dst_x,video_coord_t dst_y,video_dim_t dst_size_x,video_dim_t dst_size_y,video_color_t const bg_fg_colors[2],video_dim_t src_size_x,video_dim_t src_size_y,struct video_bitmask const*__restrict bm){}\
29062906
void libvideo_swgfx_preblend__fillstretchmask_n__##n(struct video_gfx const*__restrict self,video_coord_t dst_x,video_coord_t dst_y,video_dim_t dst_size_x,video_dim_t dst_size_y,video_color_t const bg_fg_colors[2],video_dim_t src_size_x,video_dim_t src_size_y,struct video_bitmask const*__restrict bm){}
29072907
#define GFX_FOREACH_DEDICATED_PREBLENDMODE(cb)cb(alpha,0,alpha_premultiplied,gfx_preblend_alpha)cb(alpha_factor,0,alpha_premultiplied,gfx_preblend_alpha_factor)cb(alpha_override,0,alpha_premultiplied,gfx_preblend_alpha_override)cb(add,0,add_premultiplied,gfx_preblend_add)
2908+
#define DEFINE_VIDEO_BUFFER_TYPE(name,...) struct video_buffer_ops name={};struct video_buffer_ops const*_##name(void){}

kos/include/libvideo/gfx/buffer.h

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -706,17 +706,6 @@ video_buffer_forbitmask(video_dim_t __size_x, video_dim_t __size_y,
706706
video_color_t const __bg_fg_colors[2]);
707707
#endif /* LIBVIDEO_GFX_WANT_PROTOTYPES */
708708

709-
/* Return the preferred video format.
710-
* If possible, this format will match the format used by the host's graphics card.
711-
* If no graphics card exists, or the card isn't clear on its preferred format, some
712-
* other, common format will be returned instead. */
713-
typedef __ATTR_RETNONNULL_T __ATTR_WUNUSED_T struct video_format const *
714-
(LIBVIDEO_GFX_CC *PVIDEO_PREFERRED_FORMAT)(void);
715-
#ifdef LIBVIDEO_GFX_WANT_PROTOTYPES
716-
LIBVIDEO_GFX_DECL __ATTR_RETNONNULL __ATTR_WUNUSED struct video_format const *
717-
LIBVIDEO_GFX_CC video_preferred_format(void);
718-
#endif /* LIBVIDEO_GFX_WANT_PROTOTYPES */
719-
720709
#endif /* TODO: END DEPRECATED */
721710

722711

@@ -885,29 +874,46 @@ video_buffer_region(struct video_buffer *__restrict __self,
885874
#endif /* LIBVIDEO_GFX_WANT_PROTOTYPES */
886875

887876

888-
889-
890-
/* Return a video buffer that will always (forcefully) re-return `__self'
891-
* whenever a GFX context is requested. Additionally, video locks will fail
892-
* when pixels represented by `__self' cannot represented as a video lock
893-
* (e.g. the Clip- and I/O-Rects don't match, or the Clip Rect's bounds
894-
* don't end up at some whole-byte boundary, or don't end up aligned to a
895-
* degree that is sufficient for the codec of `__self', or `__self' is
896-
* making using of some rotation/mirror GFX flags).
877+
/* Return a video buffer that simulates the clipping/rotation behavior
878+
* of the given GFX context `__self'. Other GFX pixel modification flags
879+
* that are unrelated to rotation/mirroring are also retained by the
880+
* returned buffer (e.g. VIDEO_GFX_F_BLUR is retained).
881+
*
882+
* Note that the returned buffer only retains:
883+
* - Clip Rect
884+
* - I/O Rect
885+
* - GFX Flags
897886
*
898-
* If you want to guaranty that the returned buffer is still lockable, you
899-
* should wrap it again using `video_buffer_lockable()'.
887+
* It does not retain:
888+
* - Blend Mode
889+
* - Color Key
900890
*
901-
* @return: * : A video buffer representing the Clip Rect of `__self'
891+
* Note that unlike `video_buffer_region()', which still allows for use
892+
* of video locks being applied to the returned buffer when rotation is
893+
* being used (with those locks then used to access un-rotated pixels),
894+
* the buffer returned by this function REJECTS video locks when pixel
895+
* data is transformed in any way that cannot be represented using only
896+
* I/O rects. As such, you may need to use `video_buffer_lockable()' on
897+
* the returned buffer in order to make it lockable (if you wish to use
898+
* pixel data in a rotated/mirrored form).
899+
*
900+
* NOTE: Revoking pixel access on the returned buffer, or other types
901+
* of buffers derived from it may also revoke pixel access from
902+
* `__self', so use with care.
903+
*
904+
* @return: * : A video buffer representing the given `__self'
902905
* @return: NULL: [errno=ENOMEM] Insufficient memory. */
903906
typedef __ATTR_WUNUSED_T __ATTR_IN_T(1) __REF struct video_buffer *
904-
(LIBVIDEO_GFX_CC *POLD_VIDEO_BUFFER_FROMGFX)(struct video_gfx const *__restrict __self);
907+
(LIBVIDEO_GFX_CC *PVIDEO_BUFFER_FROMGFX)(struct video_gfx const *__restrict __self);
905908
#ifdef LIBVIDEO_GFX_WANT_PROTOTYPES
906909
LIBVIDEO_GFX_DECL __ATTR_WUNUSED __ATTR_IN(1) __REF struct video_buffer *LIBVIDEO_GFX_CC
907-
old_video_buffer_fromgfx(struct video_gfx const *__restrict __self);
910+
video_buffer_fromgfx(struct video_gfx const *__restrict __self);
908911
#endif /* LIBVIDEO_GFX_WANT_PROTOTYPES */
909912

910913

914+
915+
916+
911917
/* Various functions for opening a file/stream/blob as an image file.
912918
* The actual file format is auto-detected, and supported formats depend
913919
* on installed 3rd party libraries. By default, BMP and PNG is supported. */

kos/include/libvideo/gfx/gfx.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#endif /* __cplusplus */
4141

4242
#ifndef __INTELLISENSE__
43+
#include "../rect.h"
4344
#include <libc/string.h>
4445
#endif /* !__INTELLISENSE__ */
4546

@@ -95,7 +96,7 @@ typedef __UINT32_TYPE__ video_gfx_flag_t;
9596

9697
/* Combine pre-existing GFX flags `__old_flags' with `__more_flags' */
9798
__LOCAL __ATTR_CONST __ATTR_WUNUSED video_gfx_flag_t
98-
gfx_flag_combine(video_gfx_flag_t __old_flags, video_gfx_flag_t __more_flags) {
99+
video_gfx_flag_combine(video_gfx_flag_t __old_flags, video_gfx_flag_t __more_flags) {
99100
if (__old_flags & VIDEO_GFX_F_XYSWAP) {
100101
__more_flags = (__more_flags & ~(_VIDEO_GFX_XFLAGS | _VIDEO_GFX_YFLAGS)) |
101102
((__more_flags & _VIDEO_GFX_XFLAGS) << _VIDEO_GFX_FLAGS_X_TO_Y_LSHIFT) |
@@ -584,6 +585,9 @@ extern __ATTR_RETNONNULL __ATTR_INOUT(1) struct video_gfx *
584585
video_gfx_clip(struct video_gfx *__restrict __self,
585586
video_offset_t __clip_x, video_offset_t __clip_y,
586587
video_dim_t __size_x, video_dim_t __size_y);
588+
extern __ATTR_RETNONNULL __ATTR_INOUT(1) __ATTR_IN(2) struct video_gfx *
589+
video_gfx_cliprect(struct video_gfx *__restrict __self,
590+
struct video_rect const *__restrict __rect);
587591

588592

589593
/* Translate virtual (offset) pixel coords to physical (coord) coords.
@@ -755,6 +759,8 @@ video_gfx_stretch3(struct video_gfx const *__wrdst, video_offset_t __wrdst_x, vi
755759
#define video_gfx_getflags(self) ((self)->vx_flags)
756760
#define video_gfx_clip(self, clip_x, clip_y, size_x, size_y) \
757761
(*(self)->vx_hdr.vxh_ops->vgfo_clip)(self, clip_x, clip_y, size_x, size_y)
762+
#define video_gfx_cliprect(self, rect) \
763+
video_gfx_clip(self, (rect)->vr_xmin, (rect)->vr_ymin, (rect)->vr_xdim, (rect)->vr_ydim)
758764
#define video_gfx_offset2coord(self, x, y, coords) \
759765
(*(self)->vx_hdr.vxh_ops->vgfo_offset2coord)(self, x, y, coords)
760766
#define video_gfx_coord2offset(self, x, y, offsets) \

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ custom_buffer_subregion__subregion(struct video_buffer *__restrict self,
240240
video_gfx_flag_t gfx_flags) {
241241
struct custom_buffer_subregion *me = (struct custom_buffer_subregion *)self;
242242
return custom_buffer__subregion_impl(me, rect,
243-
gfx_flag_combine(me->cbsr_gfx, gfx_flags),
243+
video_gfx_flag_combine(me->cbsr_gfx, gfx_flags),
244244
me->cbsr_xoff,
245245
me->cbsr_yoff);
246246
}
@@ -508,7 +508,7 @@ INTERN ATTR_RETNONNULL ATTR_INOUT(1) struct video_gfx *FCC
508508
custom_buffer_subregion__initgfx(struct video_gfx *__restrict self) {
509509
struct custom_buffer_subregion *me = (struct custom_buffer_subregion *)self->vx_buffer;
510510
struct gfx_swdrv *drv = video_swgfx_getdrv(self);
511-
self->vx_flags = gfx_flag_combine(me->cbsr_gfx, self->vx_flags);
511+
self->vx_flags = video_gfx_flag_combine(me->cbsr_gfx, self->vx_flags);
512512
libvideo_gfx_init_fullclip(self);
513513

514514
/* Default pixel accessors */
@@ -523,7 +523,7 @@ custom_buffer_subregion__initgfx(struct video_gfx *__restrict self) {
523523
INTERN ATTR_RETNONNULL ATTR_INOUT(1) struct video_gfx *FCC
524524
custom_buffer_subregion_nooff__initgfx(struct video_gfx *__restrict self) {
525525
struct custom_buffer_subregion *me = (struct custom_buffer_subregion *)self->vx_buffer;
526-
self->vx_flags = gfx_flag_combine(me->cbsr_gfx, self->vx_flags);
526+
self->vx_flags = video_gfx_flag_combine(me->cbsr_gfx, self->vx_flags);
527527
return custom_buffer__initgfx(self);
528528
}
529529

0 commit comments

Comments
 (0)