LibCore+LibGfx+LibWeb: Move MetalContext into LibGfx

Since the Metal context is currently only used by LibGfx, it could be
moved there to avoid having Metal as a dependency for everything that
uses LibCore.
This commit is contained in:
Aliaksandr Kalenik 2024-09-26 17:01:07 +02:00 committed by Alexander Kalenik
commit c4bc4fc5f6
Notes: github-actions[bot] 2024-11-07 12:49:24 +00:00
10 changed files with 22 additions and 16 deletions

View file

@ -91,7 +91,6 @@ endif()
if (APPLE)
list(APPEND SOURCES IOSurface.cpp)
list(APPEND SOURCES MetalContext.mm)
endif()
serenity_lib(LibCore core)
@ -103,7 +102,6 @@ if (APPLE)
target_link_libraries(LibCore PUBLIC "-framework CoreServices")
target_link_libraries(LibCore PUBLIC "-framework Foundation")
target_link_libraries(LibCore PUBLIC "-framework IOSurface")
target_link_libraries(LibCore PUBLIC "-framework Metal")
endif()
if (ANDROID)

View file

@ -70,6 +70,10 @@ set(SOURCES
SkiaBackendContext.cpp
)
if (APPLE)
list(APPEND SOURCES MetalContext.mm)
endif()
serenity_lib(LibGfx gfx)
target_link_libraries(LibGfx PRIVATE LibCompress LibCore LibCrypto LibFileSystem LibRIFF LibTextCodec LibIPC LibUnicode LibURL)
@ -129,3 +133,7 @@ if (ENABLE_SWIFT)
target_link_libraries(LibGfx PRIVATE AK)
add_swift_target_properties(LibGfx LAGOM_LIBRARIES AK)
endif()
if (APPLE)
target_link_libraries(LibCore PUBLIC "-framework Metal")
endif()

View file

@ -13,7 +13,7 @@ static_assert(false, "This file must only be used for macOS");
#include <AK/Forward.h>
#include <LibCore/IOSurface.h>
namespace Core {
namespace Gfx {
class MetalTexture {
public:
@ -29,7 +29,7 @@ public:
virtual void const* device() const = 0;
virtual void const* queue() const = 0;
virtual OwnPtr<MetalTexture> create_texture_from_iosurface(IOSurfaceHandle const&) = 0;
virtual OwnPtr<MetalTexture> create_texture_from_iosurface(Core::IOSurfaceHandle const&) = 0;
virtual ~MetalContext() {};
};

View file

@ -5,11 +5,11 @@
*/
#include <AK/OwnPtr.h>
#include <LibCore/MetalContext.h>
#include <LibGfx/MetalContext.h>
#import <Metal/Metal.h>
namespace Core {
namespace Gfx {
class MetalTextureImpl final : public MetalTexture {
public:
@ -42,7 +42,7 @@ public:
void const* device() const override { return m_device; }
void const* queue() const override { return m_queue; }
OwnPtr<MetalTexture> create_texture_from_iosurface(IOSurfaceHandle const& iosurface) override
OwnPtr<MetalTexture> create_texture_from_iosurface(Core::IOSurfaceHandle const& iosurface) override
{
auto* const descriptor = [[MTLTextureDescriptor alloc] init];
descriptor.pixelFormat = MTLPixelFormatBGRA8Unorm;

View file

@ -72,7 +72,7 @@ NonnullRefPtr<PaintingSurface> PaintingSurface::wrap_bitmap(Bitmap& bitmap)
}
#ifdef AK_OS_MACOS
NonnullRefPtr<PaintingSurface> PaintingSurface::wrap_metal_surface(Core::MetalTexture& metal_texture, RefPtr<SkiaBackendContext> context)
NonnullRefPtr<PaintingSurface> PaintingSurface::wrap_metal_surface(Gfx::MetalTexture& metal_texture, RefPtr<SkiaBackendContext> context)
{
IntSize const size { metal_texture.width(), metal_texture.height() };
auto image_info = SkImageInfo::Make(size.width(), size.height(), kBGRA_8888_SkColorType, kPremul_SkAlphaType);

View file

@ -14,7 +14,7 @@
#include <LibGfx/SkiaBackendContext.h>
#ifdef AK_OS_MACOS
# include <LibCore/MetalContext.h>
# include <LibGfx/MetalContext.h>
#endif
class SkCanvas;
@ -28,7 +28,7 @@ public:
static NonnullRefPtr<PaintingSurface> wrap_bitmap(Bitmap&);
#ifdef AK_OS_MACOS
static NonnullRefPtr<PaintingSurface> wrap_metal_surface(Core::MetalTexture&, RefPtr<SkiaBackendContext>);
static NonnullRefPtr<PaintingSurface> wrap_metal_surface(Gfx::MetalTexture&, RefPtr<SkiaBackendContext>);
#endif
RefPtr<Bitmap> create_snapshot() const;

View file

@ -109,7 +109,7 @@ private:
sk_sp<GrDirectContext> m_context;
};
RefPtr<SkiaBackendContext> SkiaBackendContext::create_metal_context(Core::MetalContext const& metal_context)
RefPtr<SkiaBackendContext> SkiaBackendContext::create_metal_context(Gfx::MetalContext const& metal_context)
{
GrMtlBackendContext backend_context;
backend_context.fDevice.retain((GrMTLHandle)metal_context.device());

View file

@ -10,7 +10,7 @@
#include <AK/RefCounted.h>
#ifdef AK_OS_MACOS
# include <LibCore/MetalContext.h>
# include <LibGfx/MetalContext.h>
#endif
#ifdef USE_VULKAN
@ -32,7 +32,7 @@ public:
#endif
#ifdef AK_OS_MACOS
static RefPtr<Gfx::SkiaBackendContext> create_metal_context(Core::MetalContext const&);
static RefPtr<Gfx::SkiaBackendContext> create_metal_context(Gfx::MetalContext const&);
#endif
SkiaBackendContext() {};

View file

@ -31,7 +31,7 @@ TraversableNavigable::TraversableNavigable(JS::NonnullGCPtr<Page> page)
#ifdef AK_OS_MACOS
auto display_list_player_type = page->client().display_list_player_type();
if (display_list_player_type == DisplayListPlayerType::SkiaGPUIfAvailable) {
m_metal_context = Core::get_metal_context();
m_metal_context = Gfx::get_metal_context();
m_skia_backend_context = Gfx::SkiaBackendContext::create_metal_context(*m_metal_context);
}
#endif

View file

@ -16,7 +16,7 @@
#include <WebContent/BackingStoreManager.h>
#ifdef AK_OS_MACOS
# include <LibCore/MetalContext.h>
# include <LibGfx/MetalContext.h>
#endif
#ifdef USE_VULKAN
@ -147,7 +147,7 @@ private:
RefPtr<Gfx::SkiaBackendContext> m_skia_backend_context;
#ifdef AK_OS_MACOS
OwnPtr<Core::MetalContext> m_metal_context;
OwnPtr<Gfx::MetalContext> m_metal_context;
#endif
};