Merge branch 'wip/otte/vulkan-for-main' into 'main'

tools: No need for --force when specifying filename

See merge request GNOME/gtk!6205
This commit is contained in:
Benjamin Otte 2023-07-22 21:48:29 +00:00
commit 0b1bcf8bee
7 changed files with 52 additions and 82 deletions

View File

@ -50,7 +50,6 @@ struct _GskVulkanRender
GskRenderer *renderer;
GdkVulkanContext *vulkan;
double scale;
graphene_rect_t viewport;
cairo_region_t *clip;
@ -175,22 +174,9 @@ gsk_vulkan_render_setup (GskVulkanRender *self,
const graphene_rect_t *rect,
const cairo_region_t *clip)
{
GdkSurface *surface = gsk_renderer_get_surface (self->renderer);
self->target = g_object_ref (target);
self->viewport = *rect;
if (rect)
{
self->viewport = *rect;
self->scale = 1.0;
}
else
{
self->scale = gdk_surface_get_scale (surface);
self->viewport = GRAPHENE_RECT_INIT (0, 0,
(int) ceil (gdk_surface_get_width (surface) * self->scale),
(int) ceil (gdk_surface_get_height (surface) * self->scale));
}
if (clip)
{
self->clip = cairo_region_reference ((cairo_region_t *) clip);
@ -492,27 +478,24 @@ gsk_vulkan_render_add_node (GskVulkanRender *self,
gpointer download_data)
{
GskVulkanRenderPass *render_pass;
graphene_vec2_t scale;
cairo_rectangle_int_t extents;
graphene_vec2_init (&scale, self->scale, self->scale);
cairo_region_get_extents (self->clip, &extents);
gsk_vulkan_render_pass_begin_op (self,
g_object_ref (self->target),
&extents,
&self->viewport.size,
VK_IMAGE_LAYOUT_UNDEFINED,
VK_IMAGE_LAYOUT_PRESENT_SRC_KHR);
render_pass = gsk_vulkan_render_pass_new ();
gsk_vulkan_render_pass_add (render_pass,
self,
&scale,
&self->viewport,
gsk_vulkan_image_get_width (self->target),
gsk_vulkan_image_get_height (self->target),
&extents,
node);
node,
&self->viewport);
gsk_vulkan_render_pass_free (render_pass);
gsk_vulkan_render_pass_end_op (self,

View File

@ -353,6 +353,7 @@ gsk_vulkan_renderer_render (GskRenderer *renderer,
{
GskVulkanRenderer *self = GSK_VULKAN_RENDERER (renderer);
GskVulkanRender *render;
GdkSurface *surface;
cairo_region_t *render_region;
#ifdef G_ENABLE_DEBUG
GskProfiler *profiler;
@ -372,13 +373,18 @@ gsk_vulkan_renderer_render (GskRenderer *renderer,
gsk_render_node_get_preferred_depth (root),
region);
render = gsk_vulkan_renderer_get_render (self);
surface = gdk_draw_context_get_surface (GDK_DRAW_CONTEXT (self->vulkan));
render_region = get_render_region (self);
draw_index = gdk_vulkan_context_get_draw_index (self->vulkan);
gsk_vulkan_render_render (render,
self->targets[draw_index],
NULL,
&GRAPHENE_RECT_INIT(
0, 0,
gdk_surface_get_width (surface),
gdk_surface_get_height (surface)
),
render_region,
root,
NULL, NULL);

View File

@ -164,7 +164,6 @@ gsk_vulkan_render_pass_upload_texture (GskVulkanRender *render,
gsk_vulkan_render_pass_begin_op (render,
g_object_ref (better_image),
&(cairo_rectangle_int_t) { 0, 0, width, height },
&GRAPHENE_SIZE_INIT(width, height),
VK_IMAGE_LAYOUT_UNDEFINED,
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
gsk_vulkan_scissor_op (render, &(cairo_rectangle_int_t) { 0, 0, width, height });
@ -184,6 +183,8 @@ gsk_vulkan_render_pass_upload_texture (GskVulkanRender *render,
gsk_vulkan_render_pass_end_op (render,
better_image,
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
g_object_unref (better_image);
return better_image;
}
@ -1302,31 +1303,27 @@ gsk_vulkan_render_pass_add_node (GskVulkanRenderPass *self,
void
gsk_vulkan_render_pass_add (GskVulkanRenderPass *self,
GskVulkanRender *render,
const graphene_vec2_t *scale,
const graphene_rect_t *viewport,
int width,
int height,
cairo_rectangle_int_t *clip,
GskRenderNode *node)
GskRenderNode *node,
const graphene_rect_t *viewport)
{
GskVulkanParseState state;
graphene_rect_t scaled_clip;
float scale_x, scale_y;
scale_x = 1 / graphene_vec2_get_x (scale);
scale_y = 1 / graphene_vec2_get_y (scale);
state.scissor = *clip;
scaled_clip = GRAPHENE_RECT_INIT(clip->x, clip->y, clip->width, clip->height);
graphene_rect_scale (&scaled_clip, scale_x, scale_y, &scaled_clip);
gsk_vulkan_clip_init_empty (&state.clip, &scaled_clip);
gsk_vulkan_clip_init_empty (&state.clip, &GRAPHENE_RECT_INIT (0, 0, viewport->size.width, viewport->size.height));
state.modelview = NULL;
graphene_matrix_init_ortho (&state.projection,
0, viewport->size.width,
0, viewport->size.height,
0, width,
0, height,
2 * ORTHO_NEAR_PLANE - ORTHO_FAR_PLANE,
ORTHO_FAR_PLANE);
graphene_vec2_init_from_vec2 (&state.scale, scale);
state.offset = GRAPHENE_POINT_INIT (-viewport->origin.x * scale_x,
-viewport->origin.y * scale_y);
graphene_vec2_init (&state.scale, width / viewport->size.width,
height / viewport->size.height);
state.offset = GRAPHENE_POINT_INIT (-viewport->origin.x,
-viewport->origin.y);
gsk_vulkan_render_pass_append_scissor (render, node, &state);
gsk_vulkan_render_pass_append_push_constants (render, node, &state);

View File

@ -16,7 +16,6 @@ struct _GskVulkanRenderPassOp
GskVulkanImage *image;
cairo_rectangle_int_t area;
graphene_size_t viewport_size;
VkImageLayout initial_layout;
VkImageLayout final_layout;
@ -117,8 +116,8 @@ gsk_vulkan_render_pass_op_command (GskVulkanOp *op,
&(VkViewport) {
.x = 0,
.y = 0,
.width = self->viewport_size.width,
.height = self->viewport_size.height,
.width = gsk_vulkan_image_get_width (self->image),
.height = gsk_vulkan_image_get_height (self->image),
.minDepth = 0,
.maxDepth = 1
});
@ -244,7 +243,6 @@ void
gsk_vulkan_render_pass_begin_op (GskVulkanRender *render,
GskVulkanImage *image,
const cairo_rectangle_int_t *area,
const graphene_size_t *viewport_size,
VkImageLayout initial_layout,
VkImageLayout final_layout)
{
@ -256,7 +254,6 @@ gsk_vulkan_render_pass_begin_op (GskVulkanRender *render,
self->initial_layout = initial_layout;
self->final_layout = final_layout;
self->area = *area;
self->viewport_size = *viewport_size;
}
void
@ -280,50 +277,38 @@ gsk_vulkan_render_pass_op_offscreen (GskVulkanRender *render,
{
GskVulkanRenderPass *render_pass;
GdkVulkanContext *context;
graphene_rect_t view;
GskVulkanImage *image;
float scale_x, scale_y;
int width, height;
scale_x = graphene_vec2_get_x (scale);
scale_y = graphene_vec2_get_y (scale);
view = GRAPHENE_RECT_INIT (scale_x * viewport->origin.x,
scale_y * viewport->origin.y,
ceil (scale_x * viewport->size.width),
ceil (scale_y * viewport->size.height));
width = ceil (graphene_vec2_get_x (scale) * viewport->size.width);
height = ceil (graphene_vec2_get_y (scale) * viewport->size.height);
context = gsk_vulkan_render_get_context (render);
image = gsk_vulkan_image_new_for_offscreen (context,
gdk_vulkan_context_get_offscreen_format (context,
gsk_render_node_get_preferred_depth (node)),
view.size.width, view.size.height);
width, height);
gsk_vulkan_render_pass_begin_op (render,
image,
&(cairo_rectangle_int_t) {
0, 0,
gsk_vulkan_image_get_width (image),
gsk_vulkan_image_get_height (image)
},
&viewport->size,
&(cairo_rectangle_int_t) { 0, 0, width, height },
VK_IMAGE_LAYOUT_UNDEFINED,
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
render_pass = gsk_vulkan_render_pass_new ();
gsk_vulkan_render_pass_add (render_pass,
render,
scale,
viewport,
&(cairo_rectangle_int_t) {
0, 0,
gsk_vulkan_image_get_width (image),
gsk_vulkan_image_get_height (image)
},
node);
width, height,
&(cairo_rectangle_int_t) { 0, 0, width, height },
node,
viewport);
gsk_vulkan_render_pass_free (render_pass);
gsk_vulkan_render_pass_end_op (render,
image,
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
g_object_unref (image);
return image;
}

View File

@ -8,7 +8,6 @@ G_BEGIN_DECLS
void gsk_vulkan_render_pass_begin_op (GskVulkanRender *render,
GskVulkanImage *image,
const cairo_rectangle_int_t *area,
const graphene_size_t *viewport_size,
VkImageLayout initial_layout,
VkImageLayout final_layout);
void gsk_vulkan_render_pass_end_op (GskVulkanRender *render,

View File

@ -16,10 +16,11 @@ void gsk_vulkan_render_pass_free (GskVulk
void gsk_vulkan_render_pass_add (GskVulkanRenderPass *self,
GskVulkanRender *render,
const graphene_vec2_t *scale,
const graphene_rect_t *viewport,
int width,
int height,
cairo_rectangle_int_t *clip,
GskRenderNode *node);
GskRenderNode *node,
const graphene_rect_t *viewport);
G_END_DECLS

View File

@ -51,8 +51,7 @@ get_save_filename (const char *filename)
static void
render_file (const char *filename,
const char *renderer_name,
const char *save_file,
gboolean force)
const char *save_file)
{
GskRenderNode *node;
GBytes *bytes;
@ -76,15 +75,17 @@ render_file (const char *filename,
save_to = (char *)save_file;
if (save_to == NULL)
save_to = get_save_filename (filename);
if (g_file_test (save_to, G_FILE_TEST_EXISTS) && !force)
{
g_printerr (_("File %s exists.\n"
"Use --force to overwrite.\n"), save_to);
exit (1);
save_to = get_save_filename (filename);
if (g_file_test (save_to, G_FILE_TEST_EXISTS))
{
g_printerr (_("File %s exists.\n"
"If you want to overwrite, specify the filename.\n"), save_to);
exit (1);
}
}
bytes = gdk_texture_save_to_png_bytes (texture);
if (g_file_set_contents (save_to,
@ -116,11 +117,9 @@ do_render (int *argc,
{
GOptionContext *context;
char **filenames = NULL;
gboolean force = FALSE;
char *renderer = NULL;
const GOptionEntry entries[] = {
{ "renderer", 0, 0, G_OPTION_ARG_STRING, &renderer, N_("Renderer to use"), N_("RENDERER") },
{ "force", 0, 0, G_OPTION_ARG_NONE, &force, N_("Overwrite existing file"), NULL },
{ G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &filenames, NULL, N_("FILE…") },
{ NULL, }
};
@ -159,7 +158,7 @@ do_render (int *argc,
exit (1);
}
render_file (filenames[0], renderer, filenames[1], force);
render_file (filenames[0], renderer, filenames[1]);
g_strfreev (filenames);
}