/*
 *   Copyright © 2015 Robert Metsäranta <therealestrob@gmail.com>
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *   General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; see the file COPYING.  if not, write to
 *   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 *   Boston, MA 02110-1301, USA.
 */

#pragma once

#include "ShapeCornersShader.h"
#include <kwinoffscreeneffect.h>


namespace KWin {

class ShapeCornersEffect final : public OffscreenEffect
{
    Q_OBJECT
public:
    ShapeCornersEffect();
    ~ShapeCornersEffect() override;

    static bool supported();
    static bool enabledByDefault()
    {
        return supported();
    }

    void reconfigure(ReconfigureFlags flags) override;
    void prePaintWindow(EffectWindow *w, WindowPrePaintData &data, std::chrono::milliseconds time) override;

    void drawWindow(EffectWindow *w, int mask, const QRegion &region, WindowPaintData &data) override;

    [[nodiscard]] int requestedEffectChainPosition() const override
    {
        return 99;
    }
    [[nodiscard]] bool blocksDirectScanout() const override
    {
        return false;
    }

private Q_SLOTS:
    void windowAdded(EffectWindow *window);
    void windowRemoved(EffectWindow *window);
    void windowResized(EffectWindow *window, const QRectF &);

private:
    ShapeCornersShader m_shaderManager;
    float m_cornerSize = 12.0f;

    bool hasRoundCorners(EffectWindow *w);
    template<bool vertical>
    bool checkTiled(double window_start, const double &screen_end, double gap = -1);
};

}