Shelley Chen has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/43358 )
Change subject: cbgfx: Add blend functions to calculate transparency ......................................................................
cbgfx: Add blend functions to calculate transparency
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 --- M 3rdparty/blobs M payloads/libpayload/drivers/video/graphics.c M payloads/libpayload/include/cbgfx.h 3 files changed, 84 insertions(+), 4 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/58/43358/1
diff --git a/3rdparty/blobs b/3rdparty/blobs index bbe5d99..7ad2d22 160000 --- a/3rdparty/blobs +++ b/3rdparty/blobs @@ -1 +1 @@ -Subproject commit bbe5d99780d2d085e92d9bae2c0f7b6787419d72 +Subproject commit 7ad2d22452225a14c19b17570cb77920d8fc81a5 diff --git a/payloads/libpayload/drivers/video/graphics.c b/payloads/libpayload/drivers/video/graphics.c index bb8467b..3ed7390 100644 --- a/payloads/libpayload/drivers/video/graphics.c +++ b/payloads/libpayload/drivers/video/graphics.c @@ -61,6 +61,36 @@ .y = 0, };
+static struct blend_value bvalue = { + .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; + + bvalue.rgb.red = rgb->red; + bvalue.rgb.green = rgb->green; + bvalue.rgb.blue = rgb->blue; + bvalue.alpha = alpha; + + return CBGFX_SUCCESS; +} + +int clear_blend(void) +{ + bvalue.rgb.red = 0; + bvalue.rgb.green = 0; + bvalue.rgb.blue = 0; + bvalue.alpha = 0; + + return CBGFX_SUCCESS; +} + static void add_vectors(struct vector *out, const struct vector *v1, const struct vector *v2) { @@ -139,11 +169,29 @@ uint8_t invert) { uint32_t color = 0; - color |= (rgb->red >> (8 - fbinfo->red_mask_size)) + struct rgb_color new_rgb; + + new_rgb.red = rgb->red; + new_rgb.green = rgb->green; + new_rgb.blue = rgb->blue; + if (bvalue.alpha > 0 && + (new_rgb.red != bvalue.rgb.red || + new_rgb.green != bvalue.rgb.green || + new_rgb.blue != bvalue.rgb.blue)) { + + new_rgb.red = (new_rgb.red * (UINT8_MAX - bvalue.alpha) + + bvalue.rgb.red * bvalue.alpha) >> 8; + new_rgb.green = (new_rgb.green * (UINT8_MAX - bvalue.alpha) + + bvalue.rgb.green * bvalue.alpha) >> 8; + new_rgb.blue = (new_rgb.blue * (UINT8_MAX - bvalue.alpha) + + bvalue.rgb.blue * bvalue.alpha) >> 8; + } + + color |= (new_rgb.red >> (8 - fbinfo->red_mask_size)) << fbinfo->red_mask_pos; - color |= (rgb->green >> (8 - fbinfo->green_mask_size)) + color |= (new_rgb.green >> (8 - fbinfo->green_mask_size)) << fbinfo->green_mask_pos; - color |= (rgb->blue >> (8 - fbinfo->blue_mask_size)) + color |= (new_rgb.blue >> (8 - fbinfo->blue_mask_size)) << fbinfo->blue_mask_pos; if (invert) color ^= 0xffffffff; diff --git a/payloads/libpayload/include/cbgfx.h b/payloads/libpayload/include/cbgfx.h index 869f272..313c308 100644 --- a/payloads/libpayload/include/cbgfx.h +++ b/payloads/libpayload/include/cbgfx.h @@ -89,6 +89,11 @@ uint8_t blue; };
+struct blend_value { + uint8_t alpha; + struct rgb_color rgb; +}; + /* * Resolution of scale parameters used to describe height, width, coordinate, * etc. relative to the canvas. For example, if it's 100, scales range from 0 to @@ -210,3 +215,30 @@ * in the original size are returned. */ int get_bitmap_dimension(const void *bitmap, size_t sz, struct scale *dim_rel); + +/** + * Set alpha values to setup transparency calculations + * + * @param[in] rgb Color for transparency + * @param[in] alpha Opacity of color, from 0-255 where + * 0 = completely transparent (no blending) + * 255 = completely opaque + * + * @return CBGFX_* error codes + */ +int set_blend(const struct rgb_color *rgb, uint8_t alpha); + +/** + * Clear alpha and rgb values, thus disabling dimming. + * + * @return CBGFX_* error codes + */ +int clear_blend(void); + +/** + * Constant for 60% opacity + * For reference: + * 255 = 100% opacity + * 0 = 0% opacity + */ +#define OPACITY_60 153