mirror of
https://github.com/brl/mutter.git
synced 2024-11-25 09:30:45 -05:00
clutter/stage: Cleanup the capture_view code
Reuse capture's rect parameter instead of passing a new one, and support the case where there are no returned areas. https://gitlab.gnome.org/GNOME/mutter/merge_requests/3
This commit is contained in:
parent
c695471475
commit
4be4d85f84
@ -4757,7 +4757,6 @@ static void
|
|||||||
capture_view (ClutterStage *stage,
|
capture_view (ClutterStage *stage,
|
||||||
gboolean paint,
|
gboolean paint,
|
||||||
ClutterStageView *view,
|
ClutterStageView *view,
|
||||||
cairo_rectangle_int_t *rect,
|
|
||||||
ClutterCapture *capture)
|
ClutterCapture *capture)
|
||||||
{
|
{
|
||||||
CoglFramebuffer *framebuffer;
|
CoglFramebuffer *framebuffer;
|
||||||
@ -4768,10 +4767,12 @@ capture_view (ClutterStage *stage,
|
|||||||
int stride;
|
int stride;
|
||||||
CoglBitmap *bitmap;
|
CoglBitmap *bitmap;
|
||||||
cairo_rectangle_int_t view_layout;
|
cairo_rectangle_int_t view_layout;
|
||||||
|
cairo_rectangle_int_t *rect;
|
||||||
float view_scale;
|
float view_scale;
|
||||||
float texture_width;
|
float texture_width;
|
||||||
float texture_height;
|
float texture_height;
|
||||||
|
|
||||||
|
rect = &capture->rect;
|
||||||
framebuffer = clutter_stage_view_get_framebuffer (view);
|
framebuffer = clutter_stage_view_get_framebuffer (view);
|
||||||
|
|
||||||
if (paint)
|
if (paint)
|
||||||
@ -4809,7 +4810,6 @@ capture_view (ClutterStage *stage,
|
|||||||
if (paint)
|
if (paint)
|
||||||
cogl_pop_framebuffer ();
|
cogl_pop_framebuffer ();
|
||||||
|
|
||||||
capture->rect = *rect;
|
|
||||||
capture->image = image;
|
capture->image = image;
|
||||||
|
|
||||||
cairo_surface_mark_dirty (capture->image);
|
cairo_surface_mark_dirty (capture->image);
|
||||||
@ -4829,34 +4829,91 @@ clutter_stage_capture (ClutterStage *stage,
|
|||||||
ClutterCapture *captures;
|
ClutterCapture *captures;
|
||||||
int n_captures;
|
int n_captures;
|
||||||
|
|
||||||
|
g_return_val_if_fail (CLUTTER_IS_STAGE (stage), FALSE);
|
||||||
|
|
||||||
captures = g_new0 (ClutterCapture, g_list_length (views));
|
captures = g_new0 (ClutterCapture, g_list_length (views));
|
||||||
n_captures = 0;
|
n_captures = 0;
|
||||||
|
|
||||||
for (l = views; l; l = l->next)
|
for (l = views; l; l = l->next)
|
||||||
{
|
{
|
||||||
ClutterStageView *view = l->data;
|
ClutterStageView *view = l->data;
|
||||||
|
ClutterCapture *capture;
|
||||||
cairo_rectangle_int_t view_layout;
|
cairo_rectangle_int_t view_layout;
|
||||||
cairo_region_t *region;
|
cairo_region_t *region;
|
||||||
cairo_rectangle_int_t view_capture_rect;
|
|
||||||
|
|
||||||
clutter_stage_view_get_layout (view, &view_layout);
|
clutter_stage_view_get_layout (view, &view_layout);
|
||||||
region = cairo_region_create_rectangle (&view_layout);
|
region = cairo_region_create_rectangle (&view_layout);
|
||||||
cairo_region_intersect_rectangle (region, rect);
|
cairo_region_intersect_rectangle (region, rect);
|
||||||
cairo_region_get_extents (region, &view_capture_rect);
|
|
||||||
|
capture = &captures[n_captures];
|
||||||
|
cairo_region_get_extents (region, &capture->rect);
|
||||||
cairo_region_destroy (region);
|
cairo_region_destroy (region);
|
||||||
|
|
||||||
if (view_capture_rect.width == 0 || view_capture_rect.height == 0)
|
if (capture->rect.width == 0 || capture->rect.height == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
capture_view (stage, paint, view, &view_capture_rect,
|
capture_view (stage, paint, view, capture);
|
||||||
&captures[n_captures]);
|
|
||||||
|
|
||||||
n_captures++;
|
n_captures++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (n_captures == 0)
|
||||||
|
g_clear_pointer (&captures, g_free);
|
||||||
|
|
||||||
*out_captures = captures;
|
*out_captures = captures;
|
||||||
*out_n_captures = n_captures;
|
*out_n_captures = n_captures;
|
||||||
|
|
||||||
|
return n_captures > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
clutter_stage_get_capture_final_size (ClutterStage *stage,
|
||||||
|
cairo_rectangle_int_t *rect,
|
||||||
|
int *out_width,
|
||||||
|
int *out_height,
|
||||||
|
float *out_scale)
|
||||||
|
{
|
||||||
|
float max_scale;
|
||||||
|
|
||||||
|
g_return_val_if_fail (CLUTTER_IS_STAGE (stage), FALSE);
|
||||||
|
|
||||||
|
if (rect)
|
||||||
|
{
|
||||||
|
ClutterRect capture_rect;
|
||||||
|
|
||||||
|
_clutter_util_rect_from_rectangle (rect, &capture_rect);
|
||||||
|
if (!_clutter_stage_get_max_view_scale_factor_for_rect (stage,
|
||||||
|
&capture_rect,
|
||||||
|
&max_scale))
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
if (out_width)
|
||||||
|
*out_width = (gint) roundf (rect->width * max_scale);
|
||||||
|
|
||||||
|
if (out_height)
|
||||||
|
*out_height = (gint) roundf (rect->height * max_scale);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ClutterActorBox alloc;
|
||||||
|
float stage_width, stage_height;
|
||||||
|
|
||||||
|
clutter_actor_get_allocation_box (CLUTTER_ACTOR (stage), &alloc);
|
||||||
|
clutter_actor_box_get_size (&alloc, &stage_width, &stage_height);
|
||||||
|
if (!_clutter_actor_get_real_resource_scale (CLUTTER_ACTOR (stage),
|
||||||
|
&max_scale))
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
if (out_width)
|
||||||
|
*out_width = (gint) roundf (stage_width * max_scale);
|
||||||
|
|
||||||
|
if (out_height)
|
||||||
|
*out_height = (gint) roundf (stage_height * max_scale);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (out_scale)
|
||||||
|
*out_scale = max_scale;
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4874,6 +4931,8 @@ capture_view_into (ClutterStage *stage,
|
|||||||
CoglBitmap *bitmap;
|
CoglBitmap *bitmap;
|
||||||
cairo_rectangle_int_t view_layout;
|
cairo_rectangle_int_t view_layout;
|
||||||
|
|
||||||
|
g_return_if_fail (CLUTTER_IS_STAGE (stage));
|
||||||
|
|
||||||
framebuffer = clutter_stage_view_get_framebuffer (view);
|
framebuffer = clutter_stage_view_get_framebuffer (view);
|
||||||
|
|
||||||
if (paint)
|
if (paint)
|
||||||
|
@ -261,6 +261,13 @@ CLUTTER_EXPORT
|
|||||||
void clutter_stage_skip_sync_delay (ClutterStage *stage);
|
void clutter_stage_skip_sync_delay (ClutterStage *stage);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
CLUTTER_EXPORT
|
||||||
|
gboolean clutter_stage_get_capture_final_size (ClutterStage *stage,
|
||||||
|
cairo_rectangle_int_t *rect,
|
||||||
|
int *width,
|
||||||
|
int *height,
|
||||||
|
float *scale);
|
||||||
|
|
||||||
CLUTTER_EXPORT
|
CLUTTER_EXPORT
|
||||||
gboolean clutter_stage_capture (ClutterStage *stage,
|
gboolean clutter_stage_capture (ClutterStage *stage,
|
||||||
gboolean paint,
|
gboolean paint,
|
||||||
|
Loading…
Reference in New Issue
Block a user