Truly independent web browser
/*
* Copyright (c) 2024, Aliaksandr Kalenik <[email protected]>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#if !defined(AK_OS_MACOS)
static_assert(false, "This file must only be used for macOS");
#endif
#include <AK/Forward.h>
#include <AK/RefCounted.h>
#include <AK/RefPtr.h>
#include <LibCore/IOSurface.h>
namespace Gfx {
class MetalTexture {
public:
virtual void const* texture() const = 0;
virtual size_t width() const = 0;
virtual size_t height() const = 0;
virtual ~MetalTexture() { }
};
// The component layout a texture reads a surface's plane through, which for a planar surface differs per plane.
enum class MetalTextureFormat : u8 {
BGRA8,
RGBA8,
R8,
RG8,
R16,
RG16,
};
class MetalContext : public RefCounted<MetalContext> {
public:
virtual void const* device() const = 0;
virtual void const* queue() const = 0;
virtual OwnPtr<MetalTexture> create_texture_from_iosurface(Core::IOSurfaceHandle const&, MetalTextureFormat, size_t plane) = 0;
// Whether the rows of the surface's plane are aligned as the GPU needs the rows of a linear texture in that format.
virtual bool rows_have_linear_texture_alignment(Core::IOSurfaceHandle const&, MetalTextureFormat, size_t plane) const = 0;
// Calls back on a Metal thread.
virtual void when_committed_work_is_scheduled(Function<void()>&&) = 0;
virtual ~MetalContext() { }
};
RefPtr<MetalContext> get_metal_context();
}