mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-20 16:28:54 +00:00
LibWeb: Use Accelerate framework on macOS to premultiply bitmap data
This leverages hardware acceleration to speed things up considerably, shaving ~500ms of load time off of https://cloudflare.com/
This commit is contained in:
parent
67432e35f1
commit
4350bccf8e
Notes:
github-actions[bot]
2025-08-23 12:10:18 +00:00
Author: https://github.com/awesomekling
Commit: 4350bccf8e
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5964
Reviewed-by: https://github.com/gmta ✅
2 changed files with 40 additions and 2 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2018-2024, Andreas Kling <andreas@ladybird.org>
|
* Copyright (c) 2018-2025, Andreas Kling <andreas@ladybird.org>
|
||||||
* Copyright (c) 2022, Timothy Slater <tslater2006@gmail.com>
|
* Copyright (c) 2022, Timothy Slater <tslater2006@gmail.com>
|
||||||
* Copyright (c) 2024, Jelle Raaijmakers <jelle@ladybird.org>
|
* Copyright (c) 2024, Jelle Raaijmakers <jelle@ladybird.org>
|
||||||
*
|
*
|
||||||
|
@ -12,6 +12,10 @@
|
||||||
#include <LibGfx/ShareableBitmap.h>
|
#include <LibGfx/ShareableBitmap.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
|
#ifdef AK_OS_MACOS
|
||||||
|
# include <Accelerate/Accelerate.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace Gfx {
|
namespace Gfx {
|
||||||
|
|
||||||
struct BackingStore {
|
struct BackingStore {
|
||||||
|
@ -280,6 +284,39 @@ void Bitmap::set_alpha_type_destructive(AlphaType alpha_type)
|
||||||
if (alpha_type == m_alpha_type)
|
if (alpha_type == m_alpha_type)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
#ifdef AK_OS_MACOS
|
||||||
|
vImage_Buffer buf { .data = m_data, .height = vImagePixelCount(height()), .width = vImagePixelCount(width()), .rowBytes = pitch() };
|
||||||
|
vImage_Error err;
|
||||||
|
if (m_alpha_type == AlphaType::Unpremultiplied) {
|
||||||
|
switch (m_format) {
|
||||||
|
case BitmapFormat::BGRA8888:
|
||||||
|
case BitmapFormat::BGRx8888:
|
||||||
|
err = vImagePremultiplyData_BGRA8888(&buf, &buf, kvImageNoFlags);
|
||||||
|
break;
|
||||||
|
case BitmapFormat::RGBA8888:
|
||||||
|
case BitmapFormat::RGBx8888:
|
||||||
|
err = vImagePremultiplyData_RGBA8888(&buf, &buf, kvImageNoFlags);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
VERIFY_NOT_REACHED();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
switch (m_format) {
|
||||||
|
case BitmapFormat::BGRA8888:
|
||||||
|
case BitmapFormat::BGRx8888:
|
||||||
|
err = vImageUnpremultiplyData_BGRA8888(&buf, &buf, kvImageNoFlags);
|
||||||
|
break;
|
||||||
|
case BitmapFormat::RGBA8888:
|
||||||
|
case BitmapFormat::RGBx8888:
|
||||||
|
err = vImageUnpremultiplyData_RGBA8888(&buf, &buf, kvImageNoFlags);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
VERIFY_NOT_REACHED();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
VERIFY(err == kvImageNoError);
|
||||||
|
#else
|
||||||
|
// FIXME: Make this fast on other platforms too.
|
||||||
if (m_alpha_type == AlphaType::Unpremultiplied) {
|
if (m_alpha_type == AlphaType::Unpremultiplied) {
|
||||||
for (auto y = 0; y < height(); ++y) {
|
for (auto y = 0; y < height(); ++y) {
|
||||||
for (auto x = 0; x < width(); ++x)
|
for (auto x = 0; x < width(); ++x)
|
||||||
|
@ -293,7 +330,7 @@ void Bitmap::set_alpha_type_destructive(AlphaType alpha_type)
|
||||||
} else {
|
} else {
|
||||||
VERIFY_NOT_REACHED();
|
VERIFY_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
m_alpha_type = alpha_type;
|
m_alpha_type = alpha_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -168,6 +168,7 @@ endif()
|
||||||
|
|
||||||
if (APPLE)
|
if (APPLE)
|
||||||
target_link_libraries(LibCore PUBLIC "-framework Metal")
|
target_link_libraries(LibCore PUBLIC "-framework Metal")
|
||||||
|
target_link_libraries(LibCore PUBLIC "-framework Accelerate")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (HAS_VULKAN)
|
if (HAS_VULKAN)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue