river: fix viewporter protocol implementation
It turns out that wlroots requires us to do a bit more than just create the wlr_viewporter. Docs are being added to the wlroots header in https://github.com/swaywm/wlroots/pull/3171
This commit is contained in:
		| @ -76,7 +76,9 @@ const State = struct { | |||||||
|  |  | ||||||
| const SavedBuffer = struct { | const SavedBuffer = struct { | ||||||
|     client_buffer: *wlr.ClientBuffer, |     client_buffer: *wlr.ClientBuffer, | ||||||
|     box: Box, |     /// x/y relative to the root surface in the surface tree. | ||||||
|  |     surface_box: Box, | ||||||
|  |     source_box: wlr.FBox, | ||||||
|     transform: wl.Output.Transform, |     transform: wl.Output.Transform, | ||||||
| }; | }; | ||||||
|  |  | ||||||
| @ -258,14 +260,17 @@ fn saveBuffersIterator( | |||||||
|     saved_buffers: *std.ArrayList(SavedBuffer), |     saved_buffers: *std.ArrayList(SavedBuffer), | ||||||
| ) callconv(.C) void { | ) callconv(.C) void { | ||||||
|     if (surface.buffer) |buffer| { |     if (surface.buffer) |buffer| { | ||||||
|  |         var source_box: wlr.FBox = undefined; | ||||||
|  |         surface.getBufferSourceBox(&source_box); | ||||||
|         saved_buffers.append(.{ |         saved_buffers.append(.{ | ||||||
|             .client_buffer = buffer, |             .client_buffer = buffer, | ||||||
|             .box = Box{ |             .surface_box = .{ | ||||||
|                 .x = surface_x, |                 .x = surface_x, | ||||||
|                 .y = surface_y, |                 .y = surface_y, | ||||||
|                 .width = @intCast(u32, surface.current.width), |                 .width = @intCast(u32, surface.current.width), | ||||||
|                 .height = @intCast(u32, surface.current.height), |                 .height = @intCast(u32, surface.current.height), | ||||||
|             }, |             }, | ||||||
|  |             .source_box = source_box, | ||||||
|             .transform = surface.current.transform, |             .transform = surface.current.transform, | ||||||
|         }) catch return; |         }) catch return; | ||||||
|         _ = buffer.base.lock(); |         _ = buffer.base.lock(); | ||||||
|  | |||||||
| @ -197,18 +197,21 @@ fn renderView(output: *const Output, view: *View, now: *os.timespec) void { | |||||||
|     // If we have saved buffers, we are in the middle of a transaction |     // If we have saved buffers, we are in the middle of a transaction | ||||||
|     // and need to render those buffers until the transaction is complete. |     // and need to render those buffers until the transaction is complete. | ||||||
|     if (view.saved_buffers.items.len != 0) { |     if (view.saved_buffers.items.len != 0) { | ||||||
|         for (view.saved_buffers.items) |saved_buffer| |         for (view.saved_buffers.items) |saved_buffer| { | ||||||
|  |             const texture = saved_buffer.client_buffer.texture orelse continue; | ||||||
|             renderTexture( |             renderTexture( | ||||||
|                 output, |                 output, | ||||||
|                 saved_buffer.client_buffer.texture orelse continue, |                 texture, | ||||||
|                 .{ |                 .{ | ||||||
|                     .x = saved_buffer.box.x + view.current.box.x - view.saved_surface_box.x, |                     .x = saved_buffer.surface_box.x + view.current.box.x - view.saved_surface_box.x, | ||||||
|                     .y = saved_buffer.box.y + view.current.box.y - view.saved_surface_box.y, |                     .y = saved_buffer.surface_box.y + view.current.box.y - view.saved_surface_box.y, | ||||||
|                     .width = @intCast(c_int, saved_buffer.box.width), |                     .width = @intCast(c_int, saved_buffer.surface_box.width), | ||||||
|                     .height = @intCast(c_int, saved_buffer.box.height), |                     .height = @intCast(c_int, saved_buffer.surface_box.height), | ||||||
|                 }, |                 }, | ||||||
|  |                 &saved_buffer.source_box, | ||||||
|                 saved_buffer.transform, |                 saved_buffer.transform, | ||||||
|             ); |             ); | ||||||
|  |         } | ||||||
|     } else { |     } else { | ||||||
|         // Since there are no stashed buffers, we are not in the middle of |         // Since there are no stashed buffers, we are not in the middle of | ||||||
|         // a transaction and may simply render the most recent buffers provided |         // a transaction and may simply render the most recent buffers provided | ||||||
| @ -267,15 +270,21 @@ fn renderSurfaceIterator( | |||||||
|     surface_y: c_int, |     surface_y: c_int, | ||||||
|     rdata: *SurfaceRenderData, |     rdata: *SurfaceRenderData, | ||||||
| ) callconv(.C) void { | ) callconv(.C) void { | ||||||
|  |     const texture = surface.getTexture() orelse return; | ||||||
|  |  | ||||||
|  |     var source_box: wlr.FBox = undefined; | ||||||
|  |     surface.getBufferSourceBox(&source_box); | ||||||
|  |  | ||||||
|     renderTexture( |     renderTexture( | ||||||
|         rdata.output, |         rdata.output, | ||||||
|         surface.getTexture() orelse return, |         texture, | ||||||
|         .{ |         .{ | ||||||
|             .x = rdata.output_x + surface_x, |             .x = rdata.output_x + surface_x, | ||||||
|             .y = rdata.output_y + surface_y, |             .y = rdata.output_y + surface_y, | ||||||
|             .width = surface.current.width, |             .width = surface.current.width, | ||||||
|             .height = surface.current.height, |             .height = surface.current.height, | ||||||
|         }, |         }, | ||||||
|  |         &source_box, | ||||||
|         surface.current.transform, |         surface.current.transform, | ||||||
|     ); |     ); | ||||||
|  |  | ||||||
| @ -287,10 +296,11 @@ fn renderSurfaceIterator( | |||||||
| fn renderTexture( | fn renderTexture( | ||||||
|     output: *const Output, |     output: *const Output, | ||||||
|     texture: *wlr.Texture, |     texture: *wlr.Texture, | ||||||
|     wlr_box: wlr.Box, |     dest_box: wlr.Box, | ||||||
|  |     source_box: *const wlr.FBox, | ||||||
|     transform: wl.Output.Transform, |     transform: wl.Output.Transform, | ||||||
| ) void { | ) void { | ||||||
|     var box = wlr_box; |     var box = dest_box; | ||||||
|  |  | ||||||
|     // Scale the box to the output's current scaling factor |     // Scale the box to the output's current scaling factor | ||||||
|     scaleBox(&box, output.wlr_output.scale); |     scaleBox(&box, output.wlr_output.scale); | ||||||
| @ -306,7 +316,7 @@ fn renderTexture( | |||||||
|     // This takes our matrix, the texture, and an alpha, and performs the actual |     // This takes our matrix, the texture, and an alpha, and performs the actual | ||||||
|     // rendering on the GPU. |     // rendering on the GPU. | ||||||
|     const renderer = output.wlr_output.backend.getRenderer().?; |     const renderer = output.wlr_output.backend.getRenderer().?; | ||||||
|     renderer.renderTextureWithMatrix(texture, &matrix, 1.0) catch return; |     renderer.renderSubtextureWithMatrix(texture, source_box, &matrix, 1.0) catch return; | ||||||
| } | } | ||||||
|  |  | ||||||
| fn renderBorders(output: *const Output, view: *View, now: *os.timespec) void { | fn renderBorders(output: *const Output, view: *View, now: *os.timespec) void { | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user