Skip to content

Commit 2000098

Browse files
Copilotdy-tea
andauthored
Fix blur capture robustness and null derefs
Co-authored-by: dy-tea <165158232+dy-tea@users.noreply.github.com>
1 parent b06e645 commit 2000098

3 files changed

Lines changed: 30 additions & 15 deletions

File tree

src/effects.c

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,8 @@ static bool rebuild_live_blur(output_t *output, uint64_t shared_blurred, pixman_
751751
effects_output_t *ctx = output->effects;
752752
int w = output->width, h = output->height;
753753
bool any = false;
754+
bool blur_buf_reusable = ctx->blur_buf && ctx->blur_native[0] && ctx->blur_buf_w == ctx->blur_w &&
755+
ctx->blur_buf_h == ctx->blur_h;
754756

755757
struct be_blur_params bp = {
756758
.algorithm = blur_algorithm,
@@ -814,9 +816,12 @@ static bool rebuild_live_blur(output_t *output, uint64_t shared_blurred, pixman_
814816
}
815817

816818
int n_scissor = 0;
817-
const pixman_box32_t *scissor = blur_damage_boxes(ctx, damage, w, h, &n_scissor);
818-
effects_backend->blur(&ctx->be_state, shared_blurred, ctx->blur_w, ctx->blur_h, &bp,
819-
ctx->blur_native[0], scissor, n_scissor, NULL);
819+
const pixman_box32_t *scissor = NULL;
820+
if (blur_buf_reusable)
821+
scissor = blur_damage_boxes(ctx, damage, w, h, &n_scissor);
822+
if (!effects_backend->blur(&ctx->be_state, shared_blurred, ctx->blur_w, ctx->blur_h, &bp,
823+
ctx->blur_native[0], scissor, n_scissor, NULL))
824+
return false;
820825
ctx->blur_gen = ctx->backdrop_gen;
821826
}
822827
any = true;
@@ -1061,6 +1066,8 @@ static void push_blur_to_toplevels(output_t *output) {
10611066
static bool rebuild_live_blur_layers(output_t *output, uint64_t bg_tex, pixman_region32_t *damage) {
10621067
effects_output_t *ctx = output->effects;
10631068
int w = output->width, h = output->height;
1069+
bool layer_blur_buf_reusable = ctx->layer_blur_buf && ctx->layer_blur_native[0] &&
1070+
ctx->layer_blur_buf_w == ctx->blur_w && ctx->layer_blur_buf_h == ctx->blur_h;
10641071

10651072
struct be_blur_params bp = {
10661073
.algorithm = blur_algorithm,
@@ -1090,9 +1097,12 @@ static bool rebuild_live_blur_layers(output_t *output, uint64_t bg_tex, pixman_r
10901097
return false;
10911098

10921099
int n_scissor = 0;
1093-
const pixman_box32_t *scissor = blur_damage_boxes(ctx, damage, w, h, &n_scissor);
1094-
effects_backend->blur(&ctx->be_state, bg_tex, ctx->blur_w, ctx->blur_h, &bp,
1095-
ctx->layer_blur_native[0], scissor, n_scissor, NULL);
1100+
const pixman_box32_t *scissor = NULL;
1101+
if (layer_blur_buf_reusable)
1102+
scissor = blur_damage_boxes(ctx, damage, w, h, &n_scissor);
1103+
if (!effects_backend->blur(&ctx->be_state, bg_tex, ctx->blur_w, ctx->blur_h, &bp,
1104+
ctx->layer_blur_native[0], scissor, n_scissor, NULL))
1105+
return false;
10961106
ctx->layer_blur_gen = ctx->backdrop_gen;
10971107
return true;
10981108
}
@@ -1735,7 +1745,7 @@ static bool rebuild_corner_masks(output_t *output, uint64_t bg_tex) {
17351745
if (content_r.width <= 0 || content_r.height <= 0)
17361746
continue;
17371747

1738-
uint64_t src;
1748+
uint64_t src = 0;
17391749
if (bg_tex) {
17401750
src = bg_tex;
17411751
} else {
@@ -1775,10 +1785,12 @@ static bool rebuild_corner_masks(output_t *output, uint64_t bg_tex) {
17751785
if (bnode)
17761786
HIDE_IF(&bnode->node);
17771787
}
1778-
HIDE_IF(&tl->blur->mica_node->node);
1779-
HIDE_IF(&tl->blur->acrylic_node->node);
1788+
if (tl->blur->mica_node)
1789+
HIDE_IF(&tl->blur->mica_node->node);
1790+
if (tl->blur->acrylic_node)
1791+
HIDE_IF(&tl->blur->acrylic_node->node);
17801792
}
1781-
if (tl->rounded)
1793+
if (tl->rounded && tl->rounded->corner_mask_node)
17821794
HIDE_IF(&tl->rounded->corner_mask_node->node);
17831795

17841796
wlr_damage_ring_add_whole(&ctx->capture_scene_output->damage_ring);
@@ -1937,12 +1949,13 @@ static uint64_t capture_full_scene_to_tex(output_t *output, effects_output_t *ct
19371949
wlr_scene_output_set_position(ctx->capture_scene_output, -0x7fff, -0x7fff);
19381950

19391951
if (!ok || !ctx->capture_state.buffer) {
1940-
wlr_buffer_unlock(ctx->capture_state.buffer);
1952+
if (ctx->capture_state.buffer)
1953+
wlr_buffer_unlock(ctx->capture_state.buffer);
19411954
ctx->capture_state.buffer = NULL;
19421955
return 0;
19431956
}
19441957

1945-
uint64_t result;
1958+
uint64_t result = 0;
19461959
effects_backend->capture_readback(ctx->capture_state.buffer, &ctx->be_state, screen_fbo, 0, 0, w, h,
19471960
0, 0, w, h, &result);
19481961

src/effects_gles2.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,8 @@ static bool gles2_blur(be_output_state_t *state, uint64_t src_handle, int src_w,
791791
if (out_handle)
792792
*out_handle = 0;
793793
} else {
794-
*out_handle = src_handle;
794+
if (out_handle)
795+
*out_handle = src_handle;
795796
}
796797
return true;
797798
}

src/effects_vk.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,7 @@ static bool vk_init(struct wlr_renderer *r, struct wlr_allocator *a) {
840840
for (int i = 0; i < 4; i++) {
841841
VkAttachmentLoadOp loadOp = (VkAttachmentLoadOp[]){
842842
VK_ATTACHMENT_LOAD_OP_CLEAR,
843-
VK_ATTACHMENT_LOAD_OP_DONT_CARE,
843+
VK_ATTACHMENT_LOAD_OP_LOAD,
844844
VK_ATTACHMENT_LOAD_OP_CLEAR,
845845
VK_ATTACHMENT_LOAD_OP_LOAD,
846846
} [i];
@@ -1756,7 +1756,8 @@ static bool vk_blur(be_output_state_t *state, uint64_t src_handle, int src_w, in
17561756
if (out_handle)
17571757
*out_handle = 0;
17581758
} else {
1759-
*out_handle = src_handle;
1759+
if (out_handle)
1760+
*out_handle = src_handle;
17601761
}
17611762
return true;
17621763
}

0 commit comments

Comments
 (0)