diff options
author | Brian Ashworth <bosrsf04@gmail.com> | 2018-05-20 09:33:48 -0400 |
---|---|---|
committer | Brian Ashworth <bosrsf04@gmail.com> | 2018-05-20 09:33:47 -0400 |
commit | 750a497a8b5cf7c1ec8c46db7d7a531fcfb1a86f (patch) | |
tree | 929a42028fd7290c80a271bff35bfa306ac8b306 /sway/desktop | |
parent | Merge pull request #2006 from kupospelov/fix-title-pixel-bar (diff) | |
download | sway-750a497a8b5cf7c1ec8c46db7d7a531fcfb1a86f.tar.gz sway-750a497a8b5cf7c1ec8c46db7d7a531fcfb1a86f.tar.zst sway-750a497a8b5cf7c1ec8c46db7d7a531fcfb1a86f.zip |
Pre-multiply alpha for non-textures
Diffstat (limited to 'sway/desktop')
-rw-r--r-- | sway/desktop/output.c | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/sway/desktop/output.c b/sway/desktop/output.c index ebb3ddaa..51c1ffbe 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c | |||
@@ -310,6 +310,13 @@ damage_finish: | |||
310 | pixman_region32_fini(&damage); | 310 | pixman_region32_fini(&damage); |
311 | } | 311 | } |
312 | 312 | ||
313 | static void premultiply_alpha(float color[4], float opacity) { | ||
314 | color[3] *= opacity; | ||
315 | color[0] *= color[3]; | ||
316 | color[1] *= color[3]; | ||
317 | color[2] *= color[3]; | ||
318 | } | ||
319 | |||
313 | /** | 320 | /** |
314 | * Render decorations for a view with "border normal". | 321 | * Render decorations for a view with "border normal". |
315 | * | 322 | * |
@@ -328,7 +335,7 @@ static void render_container_simple_border_normal(struct sway_output *output, | |||
328 | if (view->border_left) { | 335 | if (view->border_left) { |
329 | // Child border - left edge | 336 | // Child border - left edge |
330 | memcpy(&color, colors->child_border, sizeof(float) * 4); | 337 | memcpy(&color, colors->child_border, sizeof(float) * 4); |
331 | color[3] *= con->alpha; | 338 | premultiply_alpha(color, con->alpha); |
332 | box.x = con->x; | 339 | box.x = con->x; |
333 | box.y = con->y + 1; | 340 | box.y = con->y + 1; |
334 | box.width = view->border_thickness; | 341 | box.width = view->border_thickness; |
@@ -346,7 +353,7 @@ static void render_container_simple_border_normal(struct sway_output *output, | |||
346 | } else { | 353 | } else { |
347 | memcpy(&color, colors->child_border, sizeof(float) * 4); | 354 | memcpy(&color, colors->child_border, sizeof(float) * 4); |
348 | } | 355 | } |
349 | color[3] *= con->alpha; | 356 | premultiply_alpha(color, con->alpha); |
350 | box.x = con->x + con->width - view->border_thickness; | 357 | box.x = con->x + con->width - view->border_thickness; |
351 | box.y = con->y + 1; | 358 | box.y = con->y + 1; |
352 | box.width = view->border_thickness; | 359 | box.width = view->border_thickness; |
@@ -364,7 +371,7 @@ static void render_container_simple_border_normal(struct sway_output *output, | |||
364 | } else { | 371 | } else { |
365 | memcpy(&color, colors->child_border, sizeof(float) * 4); | 372 | memcpy(&color, colors->child_border, sizeof(float) * 4); |
366 | } | 373 | } |
367 | color[3] *= con->alpha; | 374 | premultiply_alpha(color, con->alpha); |
368 | box.x = con->x; | 375 | box.x = con->x; |
369 | box.y = con->y + con->height - view->border_thickness; | 376 | box.y = con->y + con->height - view->border_thickness; |
370 | box.width = con->width; | 377 | box.width = con->width; |
@@ -375,7 +382,7 @@ static void render_container_simple_border_normal(struct sway_output *output, | |||
375 | 382 | ||
376 | // Single pixel bar above title | 383 | // Single pixel bar above title |
377 | memcpy(&color, colors->border, sizeof(float) * 4); | 384 | memcpy(&color, colors->border, sizeof(float) * 4); |
378 | color[3] *= con->alpha; | 385 | premultiply_alpha(color, con->alpha); |
379 | box.x = con->x; | 386 | box.x = con->x; |
380 | box.y = con->y; | 387 | box.y = con->y; |
381 | box.width = con->width; | 388 | box.width = con->width; |
@@ -390,7 +397,7 @@ static void render_container_simple_border_normal(struct sway_output *output, | |||
390 | 397 | ||
391 | // Single pixel bar below title | 398 | // Single pixel bar below title |
392 | memcpy(&color, colors->border, sizeof(float) * 4); | 399 | memcpy(&color, colors->border, sizeof(float) * 4); |
393 | color[3] *= con->alpha; | 400 | premultiply_alpha(color, con->alpha); |
394 | box.x = inner_x; | 401 | box.x = inner_x; |
395 | box.y = view->y - 1; | 402 | box.y = view->y - 1; |
396 | box.width = inner_width; | 403 | box.width = inner_width; |
@@ -441,7 +448,7 @@ static void render_container_simple_border_normal(struct sway_output *output, | |||
441 | 448 | ||
442 | // Title background - above the text | 449 | // Title background - above the text |
443 | memcpy(&color, colors->background, sizeof(float) * 4); | 450 | memcpy(&color, colors->background, sizeof(float) * 4); |
444 | color[3] *= con->alpha; | 451 | premultiply_alpha(color, con->alpha); |
445 | box.x = inner_x; | 452 | box.x = inner_x; |
446 | box.y = con->y + 1; | 453 | box.y = con->y + 1; |
447 | box.width = inner_width; | 454 | box.width = inner_width; |
@@ -481,7 +488,7 @@ static void render_container_simple_border_pixel(struct sway_output *output, | |||
481 | if (view->border_left) { | 488 | if (view->border_left) { |
482 | // Child border - left edge | 489 | // Child border - left edge |
483 | memcpy(&color, colors->child_border, sizeof(float) * 4); | 490 | memcpy(&color, colors->child_border, sizeof(float) * 4); |
484 | color[3] *= con->alpha; | 491 | premultiply_alpha(color, con->alpha); |
485 | box.x = con->x; | 492 | box.x = con->x; |
486 | box.y = con->y + view->border_thickness * view->border_top; | 493 | box.y = con->y + view->border_thickness * view->border_top; |
487 | box.width = view->border_thickness; | 494 | box.width = view->border_thickness; |
@@ -499,7 +506,7 @@ static void render_container_simple_border_pixel(struct sway_output *output, | |||
499 | } else { | 506 | } else { |
500 | memcpy(&color, colors->child_border, sizeof(float) * 4); | 507 | memcpy(&color, colors->child_border, sizeof(float) * 4); |
501 | } | 508 | } |
502 | color[3] *= con->alpha; | 509 | premultiply_alpha(color, con->alpha); |
503 | box.x = con->x + con->width - view->border_thickness; | 510 | box.x = con->x + con->width - view->border_thickness; |
504 | box.y = con->y + view->border_thickness * view->border_top; | 511 | box.y = con->y + view->border_thickness * view->border_top; |
505 | box.width = view->border_thickness; | 512 | box.width = view->border_thickness; |
@@ -512,7 +519,7 @@ static void render_container_simple_border_pixel(struct sway_output *output, | |||
512 | if (view->border_top) { | 519 | if (view->border_top) { |
513 | // Child border - top edge | 520 | // Child border - top edge |
514 | memcpy(&color, colors->child_border, sizeof(float) * 4); | 521 | memcpy(&color, colors->child_border, sizeof(float) * 4); |
515 | color[3] *= con->alpha; | 522 | premultiply_alpha(color, con->alpha); |
516 | box.x = con->x; | 523 | box.x = con->x; |
517 | box.y = con->y; | 524 | box.y = con->y; |
518 | box.width = con->width; | 525 | box.width = con->width; |
@@ -529,7 +536,7 @@ static void render_container_simple_border_pixel(struct sway_output *output, | |||
529 | } else { | 536 | } else { |
530 | memcpy(&color, colors->child_border, sizeof(float) * 4); | 537 | memcpy(&color, colors->child_border, sizeof(float) * 4); |
531 | } | 538 | } |
532 | color[3] *= con->alpha; | 539 | premultiply_alpha(color, con->alpha); |
533 | box.x = con->x; | 540 | box.x = con->x; |
534 | box.y = con->y + con->height - view->border_thickness; | 541 | box.y = con->y + con->height - view->border_thickness; |
535 | box.width = con->width; | 542 | box.width = con->width; |