cogl/scanout: Add API for source/destination rectangles

These will get passed on to KMS later.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3177>
This commit is contained in:
Robert Mader 2023-08-26 15:01:48 +02:00 committed by Marge Bot
parent 52c4b85161
commit 912cd80f10
3 changed files with 116 additions and 0 deletions

View File

@ -45,6 +45,11 @@ struct _CoglScanout
GObject parent;
CoglScanoutBuffer *scanout_buffer;
gboolean has_src_rect;
graphene_rect_t src_rect;
gboolean has_dst_rect;
MtkRectangle dst_rect;
};
G_DEFINE_FINAL_TYPE (CoglScanout, cogl_scanout, G_TYPE_OBJECT);
@ -67,6 +72,24 @@ cogl_scanout_blit_to_framebuffer (CoglScanout *scanout,
return iface->blit_to_framebuffer (scanout, framebuffer, x, y, error);
}
int
cogl_scanout_buffer_get_width (CoglScanoutBuffer *scanout_buffer)
{
CoglScanoutBufferInterface *iface =
COGL_SCANOUT_BUFFER_GET_IFACE (scanout_buffer);
return iface->get_width (scanout_buffer);
}
int
cogl_scanout_buffer_get_height (CoglScanoutBuffer *scanout_buffer)
{
CoglScanoutBufferInterface *iface =
COGL_SCANOUT_BUFFER_GET_IFACE (scanout_buffer);
return iface->get_height (scanout_buffer);
}
CoglScanoutBuffer *
cogl_scanout_get_buffer (CoglScanout *scanout)
{
@ -90,6 +113,58 @@ cogl_scanout_new (CoglScanoutBuffer *scanout_buffer)
return scanout;
}
void
cogl_scanout_get_src_rect (CoglScanout *scanout,
graphene_rect_t *rect)
{
if (scanout->has_src_rect)
{
*rect = scanout->src_rect;
return;
}
rect->origin.x = 0;
rect->origin.y = 0;
rect->size.width = cogl_scanout_buffer_get_width (scanout->scanout_buffer);
rect->size.height = cogl_scanout_buffer_get_height (scanout->scanout_buffer);
}
void
cogl_scanout_set_src_rect (CoglScanout *scanout,
const graphene_rect_t *rect)
{
if (rect != NULL)
scanout->src_rect = *rect;
scanout->has_src_rect = rect != NULL;
}
void
cogl_scanout_get_dst_rect (CoglScanout *scanout,
MtkRectangle *rect)
{
if (scanout->has_dst_rect)
{
*rect = scanout->dst_rect;
return;
}
rect->x = 0;
rect->y = 0;
rect->width = cogl_scanout_buffer_get_width (scanout->scanout_buffer);
rect->height = cogl_scanout_buffer_get_height (scanout->scanout_buffer);
}
void
cogl_scanout_set_dst_rect (CoglScanout *scanout,
const MtkRectangle *rect)
{
if (rect != NULL)
scanout->dst_rect = *rect;
scanout->has_dst_rect = rect != NULL;
}
static void
cogl_scanout_finalize (GObject *object)
{

View File

@ -30,6 +30,7 @@
#include "cogl/cogl-types.h"
#include "cogl/cogl-framebuffer.h"
#include "cogl/cogl-onscreen.h"
#include "mtk/mtk.h"
#include <glib-object.h>
@ -52,6 +53,9 @@ struct _CoglScanoutBufferInterface
int x,
int y,
GError **error);
int (*get_width) (CoglScanoutBuffer *scanout_buffer);
int (*get_height) (CoglScanoutBuffer *scanout_buffer);
};
COGL_EXPORT
@ -61,6 +65,9 @@ gboolean cogl_scanout_blit_to_framebuffer (CoglScanout *scanout,
int y,
GError **error);
int cogl_scanout_buffer_get_width (CoglScanoutBuffer *scanout_buffer);
int cogl_scanout_buffer_get_height (CoglScanoutBuffer *scanout_buffer);
COGL_EXPORT
CoglScanoutBuffer * cogl_scanout_get_buffer (CoglScanout *scanout);
@ -70,3 +77,19 @@ void cogl_scanout_notify_failed (CoglScanout *scanout,
COGL_EXPORT
CoglScanout * cogl_scanout_new (CoglScanoutBuffer *scanout_buffer);
COGL_EXPORT
void cogl_scanout_get_src_rect (CoglScanout *scanout,
graphene_rect_t *rect);
COGL_EXPORT
void cogl_scanout_set_src_rect (CoglScanout *scanout,
const graphene_rect_t *rect);
COGL_EXPORT
void cogl_scanout_get_dst_rect (CoglScanout *scanout,
MtkRectangle *rect);
COGL_EXPORT
void cogl_scanout_set_dst_rect (CoglScanout *scanout,
const MtkRectangle *rect);

View File

@ -357,10 +357,28 @@ out:
return result;
}
static int
meta_drm_buffer_gbm_scanout_get_width (CoglScanoutBuffer *scanout_buffer)
{
MetaDrmBuffer *buffer = META_DRM_BUFFER (scanout_buffer);
return meta_drm_buffer_get_width (buffer);
}
static int
meta_drm_buffer_gbm_scanout_get_height (CoglScanoutBuffer *scanout_buffer)
{
MetaDrmBuffer *buffer = META_DRM_BUFFER (scanout_buffer);
return meta_drm_buffer_get_height (buffer);
}
static void
cogl_scanout_buffer_iface_init (CoglScanoutBufferInterface *iface)
{
iface->blit_to_framebuffer = meta_drm_buffer_gbm_blit_to_framebuffer;
iface->get_width = meta_drm_buffer_gbm_scanout_get_width;
iface->get_height = meta_drm_buffer_gbm_scanout_get_height;
}
static void