aboutsummaryrefslogtreecommitdiffstats
path: root/sway/desktop/transaction.c
diff options
context:
space:
mode:
authorLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-08-01 16:23:11 +1000
committerLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-08-01 16:24:15 +1000
commitd10ccc1eb144e4de2477398f6b11753f6b7df70b (patch)
treea4792f1ca754ed427a5b472d1bcf3e75fcf1f2ef /sway/desktop/transaction.c
parentMerge pull request #2395 from RedSoxFan/create-mouse-binding-list (diff)
downloadsway-d10ccc1eb144e4de2477398f6b11753f6b7df70b.tar.gz
sway-d10ccc1eb144e4de2477398f6b11753f6b7df70b.tar.zst
sway-d10ccc1eb144e4de2477398f6b11753f6b7df70b.zip
Correctly track saved surfaces during multiple transactions
Fixes #2364. Suppose a view is 600px wide, and we tell it to resize to 601px during a resize operation. We create a transaction, save the 600px buffer and send the configure. This buffer is saved into the associated instruction, and is rendered while we wait for the view to commit a 601px buffer. Before the view commits the 601px buffer, suppose we tell it to resize to 602px. The new transaction will also save the buffer, but it's still the 600px buffer because we haven't received a new one yet. Then suppose the view commits its original 601px buffer. This completes the first transaction, so we apply the 601px width to the container. There's still the second (now only) transaction remaining, so we render the saved buffer from that. But this is still the 600px buffer, and we believe it's 601px. Whoops. The problem here is we can't stack buffers like this. So this commit removes the saved buffer from the instructions, places it in the view instead, and re-saves the latest buffer every time the view completes a transaction and still has further pending transactions. As saved buffers are now specific to views rather than instructions, the functions for saving and removing the saved buffer have been moved to view.c. The calls to save and restore the buffer have been relocated to more appropriate functions too, favouring transaction_commit and transaction_apply rather than transaction_add_container and transaction_destroy.
Diffstat (limited to 'sway/desktop/transaction.c')
-rw-r--r--sway/desktop/transaction.c51
1 files changed, 12 insertions, 39 deletions
diff --git a/sway/desktop/transaction.c b/sway/desktop/transaction.c
index 7975366e..94070363 100644
--- a/sway/desktop/transaction.c
+++ b/sway/desktop/transaction.c
@@ -41,8 +41,6 @@ struct sway_transaction_instruction {
41 struct sway_transaction *transaction; 41 struct sway_transaction *transaction;
42 struct sway_container *container; 42 struct sway_container *container;
43 struct sway_container_state state; 43 struct sway_container_state state;
44 struct wlr_buffer *saved_buffer;
45 int saved_buffer_width, saved_buffer_height;
46 uint32_t serial; 44 uint32_t serial;
47 bool ready; 45 bool ready;
48}; 46};
@@ -57,27 +55,6 @@ static struct sway_transaction *transaction_create() {
57 return transaction; 55 return transaction;
58} 56}
59 57
60static void remove_saved_view_buffer(
61 struct sway_transaction_instruction *instruction) {
62 if (instruction->saved_buffer) {
63 wlr_buffer_unref(instruction->saved_buffer);
64 instruction->saved_buffer = NULL;
65 }
66}
67
68static void save_view_buffer(struct sway_view *view,
69 struct sway_transaction_instruction *instruction) {
70 if (!sway_assert(instruction->saved_buffer == NULL,
71 "Didn't expect instruction to have a saved buffer already")) {
72 remove_saved_view_buffer(instruction);
73 }
74 if (view->surface && wlr_surface_has_buffer(view->surface)) {
75 instruction->saved_buffer = wlr_buffer_ref(view->surface->buffer);
76 instruction->saved_buffer_width = view->surface->current.width;
77 instruction->saved_buffer_height = view->surface->current.height;
78 }
79}
80
81static void transaction_destroy(struct sway_transaction *transaction) { 58static void transaction_destroy(struct sway_transaction *transaction) {
82 // Free instructions 59 // Free instructions
83 for (int i = 0; i < transaction->instructions->length; ++i) { 60 for (int i = 0; i < transaction->instructions->length; ++i) {
@@ -93,7 +70,6 @@ static void transaction_destroy(struct sway_transaction *transaction) {
93 if (con->destroying && !con->instructions->length) { 70 if (con->destroying && !con->instructions->length) {
94 container_free(con); 71 container_free(con);
95 } 72 }
96 remove_saved_view_buffer(instruction);
97 free(instruction); 73 free(instruction);
98 } 74 }
99 list_free(transaction->instructions); 75 list_free(transaction->instructions);
@@ -158,9 +134,6 @@ static void transaction_add_container(struct sway_transaction *transaction,
158 134
159 copy_pending_state(container, &instruction->state); 135 copy_pending_state(container, &instruction->state);
160 136
161 if (container->type == C_VIEW) {
162 save_view_buffer(container->sway_view, instruction);
163 }
164 list_add(transaction->instructions, instruction); 137 list_add(transaction->instructions, instruction);
165} 138}
166 139
@@ -220,6 +193,15 @@ static void transaction_apply(struct sway_transaction *transaction) {
220 193
221 memcpy(&container->current, &instruction->state, 194 memcpy(&container->current, &instruction->state,
222 sizeof(struct sway_container_state)); 195 sizeof(struct sway_container_state));
196
197 if (container->type == C_VIEW) {
198 if (container->sway_view->saved_buffer) {
199 view_remove_saved_buffer(container->sway_view);
200 }
201 if (container->instructions->length > 1) {
202 view_save_buffer(container->sway_view);
203 }
204 }
223 } 205 }
224} 206}
225 207
@@ -294,6 +276,9 @@ static void transaction_commit(struct sway_transaction *transaction) {
294 // mapping and its default geometry doesn't intersect an output. 276 // mapping and its default geometry doesn't intersect an output.
295 struct timespec when; 277 struct timespec when;
296 wlr_surface_send_frame_done(con->sway_view->surface, &when); 278 wlr_surface_send_frame_done(con->sway_view->surface, &when);
279 if (!con->sway_view->saved_buffer) {
280 view_save_buffer(con->sway_view);
281 }
297 } 282 }
298 list_add(con->instructions, instruction); 283 list_add(con->instructions, instruction);
299 } 284 }
@@ -400,18 +385,6 @@ void transaction_notify_view_ready_by_size(struct sway_view *view,
400 } 385 }
401} 386}
402 387
403struct wlr_texture *transaction_get_saved_texture(struct sway_view *view,
404 int *width, int *height) {
405 struct sway_transaction_instruction *instruction =
406 view->swayc->instructions->items[0];
407 if (!instruction->saved_buffer) {
408 return NULL;
409 }
410 *width = instruction->saved_buffer_width;
411 *height = instruction->saved_buffer_height;
412 return instruction->saved_buffer->texture;
413}
414
415void transaction_commit_dirty(void) { 388void transaction_commit_dirty(void) {
416 if (!server.dirty_containers->length) { 389 if (!server.dirty_containers->length) {
417 return; 390 return;