mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-01 13:49:16 +00:00
LibWeb+LibGfx: Support alpha
in CanvasRenderingContext2D
This is implemented by these related changes: * The Skia alpha type 'Opaque' is selected for surfaces that were created with the intention of not having an alpha channel. Previously we were simply creating one with alpha. * Clearing now happens through Skia's `clear()` which always uses the source color's value for the result, instead of setting all values to 0. * CanvasRenderingContext2D selects a different clearing color based on the `alpha` context attribute's value.
This commit is contained in:
parent
fac0f82031
commit
35efd4d14b
Notes:
github-actions[bot]
2025-04-29 11:52:28 +00:00
Author: https://github.com/gmta
Commit: 35efd4d14b
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4506
Reviewed-by: https://github.com/shannonbooth
7 changed files with 68 additions and 12 deletions
|
@ -30,7 +30,7 @@ struct PaintingSurface::Impl {
|
|||
NonnullRefPtr<PaintingSurface> PaintingSurface::create_with_size(RefPtr<SkiaBackendContext> context, IntSize size, BitmapFormat color_type, AlphaType alpha_type)
|
||||
{
|
||||
auto sk_color_type = to_skia_color_type(color_type);
|
||||
auto sk_alpha_type = alpha_type == AlphaType::Premultiplied ? kPremul_SkAlphaType : kUnpremul_SkAlphaType;
|
||||
auto sk_alpha_type = to_skia_alpha_type(color_type, alpha_type);
|
||||
auto image_info = SkImageInfo::Make(size.width(), size.height(), sk_color_type, sk_alpha_type, SkColorSpace::MakeSRGB());
|
||||
|
||||
if (!context) {
|
||||
|
@ -50,7 +50,7 @@ NonnullRefPtr<PaintingSurface> PaintingSurface::create_with_size(RefPtr<SkiaBack
|
|||
NonnullRefPtr<PaintingSurface> PaintingSurface::wrap_bitmap(Bitmap& bitmap)
|
||||
{
|
||||
auto color_type = to_skia_color_type(bitmap.format());
|
||||
auto alpha_type = bitmap.alpha_type() == AlphaType::Premultiplied ? kPremul_SkAlphaType : kUnpremul_SkAlphaType;
|
||||
auto alpha_type = to_skia_alpha_type(bitmap.format(), bitmap.alpha_type());
|
||||
auto size = bitmap.size();
|
||||
auto image_info = SkImageInfo::Make(bitmap.width(), bitmap.height(), color_type, alpha_type, SkColorSpace::MakeSRGB());
|
||||
auto surface = SkSurfaces::WrapPixels(image_info, bitmap.begin(), bitmap.pitch());
|
||||
|
@ -102,7 +102,7 @@ PaintingSurface::~PaintingSurface()
|
|||
void PaintingSurface::read_into_bitmap(Bitmap& bitmap)
|
||||
{
|
||||
auto color_type = to_skia_color_type(bitmap.format());
|
||||
auto alpha_type = bitmap.alpha_type() == AlphaType::Premultiplied ? kPremul_SkAlphaType : kUnpremul_SkAlphaType;
|
||||
auto alpha_type = to_skia_alpha_type(bitmap.format(), bitmap.alpha_type());
|
||||
auto image_info = SkImageInfo::Make(bitmap.width(), bitmap.height(), color_type, alpha_type, SkColorSpace::MakeSRGB());
|
||||
SkPixmap const pixmap(image_info, bitmap.begin(), bitmap.pitch());
|
||||
m_impl->surface->readPixels(pixmap, 0, 0);
|
||||
|
@ -111,7 +111,7 @@ void PaintingSurface::read_into_bitmap(Bitmap& bitmap)
|
|||
void PaintingSurface::write_from_bitmap(Bitmap const& bitmap)
|
||||
{
|
||||
auto color_type = to_skia_color_type(bitmap.format());
|
||||
auto alpha_type = bitmap.alpha_type() == AlphaType::Premultiplied ? kPremul_SkAlphaType : kUnpremul_SkAlphaType;
|
||||
auto alpha_type = to_skia_alpha_type(bitmap.format(), bitmap.alpha_type());
|
||||
auto image_info = SkImageInfo::Make(bitmap.width(), bitmap.height(), color_type, alpha_type, SkColorSpace::MakeSRGB());
|
||||
SkPixmap const pixmap(image_info, bitmap.begin(), bitmap.pitch());
|
||||
m_impl->surface->writePixels(pixmap, 0, 0);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue