#pragma once

#include <QDialog>
#include <QEvent>
#include <QImage>
#include <QRect>
#include <QWidget>

#include <atomic>
#include <memory>
#include <tuple>
#include <vector>

class QWidget;

class RendererCommon {
public:
    RendererCommon();

    void         onResize(int width, int height);
    virtual void finalize() { }

    virtual std::vector<std::tuple<uint8_t *, std::atomic_flag *>> getBuffers() = 0;

    /* Does renderer implement options dialog */
    virtual bool hasOptions() const { return false; }
    /* Returns options dialog for renderer */
    virtual QDialog *getOptions(QWidget *parent) { return nullptr; }

protected:
    bool eventDelegate(QEvent *event, bool &result);

    QRect    source, destination;
    QWidget *parentWidget { nullptr };

    std::vector<std::atomic_flag> buf_usage;
};
