diff options
author | Shelley Chen <shchen@google.com> | 2020-07-10 14:52:43 -0700 |
---|---|---|
committer | Julius Werner <jwerner@chromium.org> | 2020-07-15 20:23:07 +0000 |
commit | 31a37887392e81e8a24eca83f4b261019c05ebd5 (patch) | |
tree | b9256963b5c73c8cd0e4719faaba55c7c7c97f83 /payloads/libpayload/drivers/video | |
parent | df5571dc9d94717a3eb32c56c950715b504c1b52 (diff) |
cbgfx: Add blend functions to calculate transparency
Up until now we have no way of adding transparency into our firmware
screens. Add set_blend() and clear_blend() functions to store alpha
value and rgb values to calculate alpha blending in
calculate_colors().
BUG=b:144969091,b:160839199
BRANCH=puff
TEST=dut-control power_state:rec
press ctrl-d
Ensure background is dimmed when dialog pops up
Change-Id: I95468f27836d34ab80392727d726a69c09dc168e
Signed-off-by: Shelley Chen <shchen@google.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/43358
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Yu-Ping Wu <yupingso@google.com>
Reviewed-by: Julius Werner <jwerner@chromium.org>
Diffstat (limited to 'payloads/libpayload/drivers/video')
-rw-r--r-- | payloads/libpayload/drivers/video/graphics.c | 60 |
1 files changed, 54 insertions, 6 deletions
diff --git a/payloads/libpayload/drivers/video/graphics.c b/payloads/libpayload/drivers/video/graphics.c index bb8467bf80..54d3dfa2b2 100644 --- a/payloads/libpayload/drivers/video/graphics.c +++ b/payloads/libpayload/drivers/video/graphics.c @@ -61,6 +61,37 @@ static const struct vector vzero = { .y = 0, }; +struct blend_value { + uint8_t alpha; + struct rgb_color rgb; +}; + +static struct blend_value blend = { + .alpha = 0, + .rgb.red = 0, + .rgb.green = 0, + .rgb.blue = 0, +}; + +int set_blend(const struct rgb_color *rgb, uint8_t alpha) +{ + if (rgb == NULL) + return CBGFX_ERROR_INVALID_PARAMETER; + + blend.alpha = alpha; + blend.rgb = *rgb; + + return CBGFX_SUCCESS; +} + +void clear_blend(void) +{ + blend.alpha = 0; + blend.rgb.red = 0; + blend.rgb.green = 0; + blend.rgb.blue = 0; +} + static void add_vectors(struct vector *out, const struct vector *v1, const struct vector *v2) { @@ -135,16 +166,33 @@ static int within_box(const struct vector *v, const struct rect *bound) return -1; } +/* + * Helper function that applies color and opacity from blend struct + * into the color. + */ +static inline uint8_t apply_blend(uint8_t color, uint8_t blend_color) +{ + if (blend.alpha == 0 || color == blend_color) + return color; + + return (color * (256 - blend.alpha) + + blend_color * blend.alpha) / 256; +} + static inline uint32_t calculate_color(const struct rgb_color *rgb, uint8_t invert) { uint32_t color = 0; - color |= (rgb->red >> (8 - fbinfo->red_mask_size)) - << fbinfo->red_mask_pos; - color |= (rgb->green >> (8 - fbinfo->green_mask_size)) - << fbinfo->green_mask_pos; - color |= (rgb->blue >> (8 - fbinfo->blue_mask_size)) - << fbinfo->blue_mask_pos; + + color |= (apply_blend(rgb->red, blend.rgb.red) + >> (8 - fbinfo->red_mask_size)) + << fbinfo->red_mask_pos; + color |= (apply_blend(rgb->green, blend.rgb.green) + >> (8 - fbinfo->green_mask_size)) + << fbinfo->green_mask_pos; + color |= (apply_blend(rgb->blue, blend.rgb.blue) + >> (8 - fbinfo->blue_mask_size)) + << fbinfo->blue_mask_pos; if (invert) color ^= 0xffffffff; return color; |