/* * Copyright (c) 2022, kleines Filmröllchen . * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include "Filters/Filter.h" #include #include #include #include #include #include #include namespace PixelPaint { class ImageProcessingCommand : public RefCounted { public: virtual void execute() = 0; virtual ~ImageProcessingCommand() = default; }; // A command applying a filter from a source to a target bitmap. class FilterApplicationCommand : public ImageProcessingCommand { public: FilterApplicationCommand(NonnullRefPtr, NonnullRefPtr); virtual void execute() override; virtual ~FilterApplicationCommand() = default; private: NonnullRefPtr m_filter; NonnullRefPtr m_target_layer; }; // A command based on a custom user function. class FunctionCommand : public ImageProcessingCommand { public: FunctionCommand(Function function) : m_function(move(function)) { } virtual void execute() override { m_function(); } private: Function m_function; }; // A utility class that allows various PixelPaint systems to execute image processing commands asynchronously on another thread. class ImageProcessor final { friend struct AK::SingletonInstanceCreator; public: static ImageProcessor* the(); ErrorOr enqueue_command(NonnullRefPtr command); private: ImageProcessor(); void processor_main(); // Only the memory in the queue is in shared memory, i.e. the smart pointers themselves. // The actual data will remain in normal memory, but for this application we're not using multiple processes so it's fine. using Queue = Core::SharedSingleProducerCircularQueue>; Queue m_command_queue; NonnullRefPtr m_processor_thread; Threading::Mutex m_wakeup_mutex {}; Threading::ConditionVariable m_wakeup_variable; }; }