/* * Copyright (c) 2022, Liav A. * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include namespace Kernel::Memory { class SharedFramebufferVMObject final : public VMObject { public: class FakeWritesFramebufferVMObject final : public VMObject { public: static ErrorOr> try_create(Badge, SharedFramebufferVMObject const& parent_object); private: FakeWritesFramebufferVMObject(SharedFramebufferVMObject const& parent_object, FixedArray>&& new_physical_pages) : VMObject(move(new_physical_pages)) , m_parent_object(parent_object) { } virtual StringView class_name() const override { return "FakeWritesFramebufferVMObject"sv; } virtual ErrorOr> try_clone() override { return Error::from_errno(ENOTIMPL); } virtual Span const> physical_pages() const override { return m_parent_object->fake_sink_framebuffer_physical_pages(); } virtual Span> physical_pages() override { return m_parent_object->fake_sink_framebuffer_physical_pages(); } NonnullLockRefPtr m_parent_object; }; class RealWritesFramebufferVMObject final : public VMObject { public: static ErrorOr> try_create(Badge, SharedFramebufferVMObject const& parent_object); private: RealWritesFramebufferVMObject(SharedFramebufferVMObject const& parent_object, FixedArray>&& new_physical_pages) : VMObject(move(new_physical_pages)) , m_parent_object(parent_object) { } virtual StringView class_name() const override { return "RealWritesFramebufferVMObject"sv; } virtual ErrorOr> try_clone() override { return Error::from_errno(ENOTIMPL); } virtual Span const> physical_pages() const override { return m_parent_object->real_framebuffer_physical_pages(); } virtual Span> physical_pages() override { return m_parent_object->real_framebuffer_physical_pages(); } NonnullLockRefPtr m_parent_object; }; virtual ~SharedFramebufferVMObject() override = default; static ErrorOr> try_create_for_physical_range(PhysicalAddress paddr, size_t size); static ErrorOr> try_create_at_arbitrary_physical_range(size_t size); virtual ErrorOr> try_clone() override { return Error::from_errno(ENOTIMPL); } void switch_to_fake_sink_framebuffer_writes(Badge); void switch_to_real_framebuffer_writes(Badge); virtual Span const> physical_pages() const override; virtual Span> physical_pages() override; Span> fake_sink_framebuffer_physical_pages(); Span const> fake_sink_framebuffer_physical_pages() const; Span> real_framebuffer_physical_pages(); Span const> real_framebuffer_physical_pages() const; FakeWritesFramebufferVMObject const& fake_writes_framebuffer_vmobject() const { return *m_fake_writes_framebuffer_vmobject; } FakeWritesFramebufferVMObject& fake_writes_framebuffer_vmobject() { return *m_fake_writes_framebuffer_vmobject; } RealWritesFramebufferVMObject const& real_writes_framebuffer_vmobject() const { return *m_real_writes_framebuffer_vmobject; } RealWritesFramebufferVMObject& real_writes_framebuffer_vmobject() { return *m_real_writes_framebuffer_vmobject; } private: SharedFramebufferVMObject(FixedArray>&& new_physical_pages, CommittedPhysicalPageSet, AnonymousVMObject& real_framebuffer_vmobject); virtual StringView class_name() const override { return "SharedFramebufferVMObject"sv; } ErrorOr create_fake_writes_framebuffer_vm_object(); ErrorOr create_real_writes_framebuffer_vm_object(); NonnullLockRefPtr m_real_framebuffer_vmobject; LockRefPtr m_fake_writes_framebuffer_vmobject; LockRefPtr m_real_writes_framebuffer_vmobject; bool m_writes_are_faked { false }; mutable RecursiveSpinlock m_writes_state_lock { LockRank::None }; CommittedPhysicalPageSet m_committed_pages; }; }