Port to OffscreenEffect

FIXME: Now it makes window title bar key animations lag. Port to paintScreen().
icc-effect-5.27.2
Vitaliy Filippov 2023-01-27 19:10:02 +03:00
parent 59caab3df6
commit cbde35147c
7 changed files with 82 additions and 47 deletions

View File

@ -5,7 +5,14 @@ pkg_check_modules(LCMS2 REQUIRED lcms2)
set_package_properties(LCMS2 PROPERTIES TYPE REQUIRED PURPOSE "Required for ICC color correction.")
set(icc_SOURCES icc.cpp icc.qrc main.cpp)
kconfig_add_kcfg_files(icc_SOURCES iccconfig.kcfgc)
kwin4_add_effect_module(kwin4_effect_icc ${icc_SOURCES})
target_link_libraries(kwin4_effect_icc PRIVATE
kwineffects
kwinglutils
KF5::ConfigGui
KF5::I18n
)
target_link_libraries(kwin4_effect_icc PUBLIC ${LCMS2_LIBRARIES})
target_include_directories(kwin4_effect_icc PUBLIC ${LCMS2_INCLUDE_DIRS})
target_compile_options(kwin4_effect_icc PUBLIC ${LCMS2_CFLAGS_OTHER})
@ -15,16 +22,15 @@ target_compile_options(kwin4_effect_icc PUBLIC ${LCMS2_CFLAGS_OTHER})
if (KWIN_BUILD_KCMS)
set(kwin_icc_config_SRCS icc_config.cpp)
kwin_add_effect_config(kwin_icc_config ${kwin_icc_config_SRCS})
ki18n_wrap_ui(kwin_icc_config_SRCS icc_config.ui)
qt5_add_dbus_interface(kwin_icc_config_SRCS ${kwin_effects_dbus_xml} kwineffects_interface)
# qt5_add_dbus_interface(kwin_icc_config_SRCS ${kwin_effects_dbus_xml} kwineffects_interface)
kconfig_add_kcfg_files(kwin_icc_config_SRCS iccconfig.kcfgc)
kwin_add_effect_config(kwin_icc_config ${kwin_icc_config_SRCS})
target_link_libraries(kwin_icc_config
KF5::ConfigWidgets
KF5::CoreAddons
KF5::I18n
KF5::Service
KF5::XmlGui
KWinEffectsInterface
)
kcoreaddons_desktop_to_json(kwin_icc_config icc_config.desktop SERVICE_TYPES kcmodule.desktop)
install(

View File

@ -20,35 +20,42 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "icc.h"
#include "iccconfig.h"
#include "kwinglplatform.h"
#include <kwinglplatform.h>
#include <kwinglutils.h>
#include "lcms2.h"
#include <lcms2.h>
#include <QAction>
#include <QFile>
#include <KGlobalAccel>
#include <KLocalizedString>
#include <QStandardPaths>
Q_LOGGING_CATEGORY(KWIN_ICC, "kwin_effect_icc", QtWarningMsg)
static const int LUT_POINTS = 64;
static void ensureResources()
{
// Must initialize resources manually because the effect is a static lib.
Q_INIT_RESOURCE(icc);
}
namespace KWin
{
ICCEffect::ICCEffect()
: m_valid(false),
m_shader(NULL),
m_texture(0),
m_clut(NULL)
: m_valid(false)
, m_texture(0)
, m_clut(NULL)
{
initConfig<ICCConfig>();
reconfigure(ReconfigureAll);
connect(effects, &EffectsHandler::windowAdded, this, &ICCEffect::slotWindowAdded);
}
ICCEffect::~ICCEffect()
{
if (m_shader)
delete m_shader;
if (m_clut)
delete[] m_clut;
if (m_texture != 0)
@ -57,7 +64,7 @@ ICCEffect::~ICCEffect()
bool ICCEffect::supported()
{
return effects->compositingType() == OpenGL2Compositing;
return effects->isOpenGLCompositing();
}
void ICCEffect::reconfigure(ReconfigureFlags flags)
@ -71,27 +78,38 @@ void ICCEffect::reconfigure(ReconfigureFlags flags)
loadData();
for (KWin::EffectWindow *window : effects->stackingOrder())
slotWindowAdded(window);
effects->addRepaintFull();
}
void ICCEffect::slotWindowAdded(KWin::EffectWindow *w)
{
if (m_valid) {
redirect(w);
setShader(w, m_shader.get());
}
}
bool ICCEffect::loadData()
{
m_valid = false;
if (m_shader)
delete m_shader;
if (m_clut)
delete[] m_clut;
if (m_texture != 0)
glDeleteTextures(1, &m_texture);
ensureResources();
m_shader = ShaderManager::instance()->generateShaderFromFile(ShaderTrait::MapTexture, QString(), QStringLiteral(":/effects/icc/shaders/icc.frag"));
if (!m_shader->isValid())
{
qCCritical(KWINEFFECTS) << "The shader failed to load!";
qCCritical(KWIN_ICC) << "The shader failed to load!";
return false;
}
ShaderManager::instance()->pushShader(m_shader);
ShaderManager::instance()->pushShader(m_shader.get());
m_shader->setUniform("clut", 3); // GL_TEXTURE3
ShaderManager::instance()->popShader();
@ -194,10 +212,14 @@ GLuint ICCEffect::setupCCTexture(uint8_t *clut)
return 0;
}
glActiveTexture(GL_TEXTURE3);
glBindTexture(GL_TEXTURE_3D, texture);
glActiveTexture(GL_TEXTURE0);
return texture;
}
void ICCEffect::drawWindow(EffectWindow* w, int mask, const QRegion &region, WindowPaintData& data)
/*void ICCEffect::drawWindow(EffectWindow* w, int mask, const QRegion &region, WindowPaintData& data)
{
if (m_valid)
{
@ -205,8 +227,7 @@ void ICCEffect::drawWindow(EffectWindow* w, int mask, const QRegion &region, Win
glBindTexture(GL_TEXTURE_3D, m_texture);
glActiveTexture(GL_TEXTURE0);
ShaderManager *shaderManager = ShaderManager::instance();
shaderManager->pushShader(m_shader);
data.shader = m_shader;
shaderManager->pushShader(m_shader.get());
}
effects->drawWindow(w, mask, region, data);
@ -217,7 +238,7 @@ void ICCEffect::drawWindow(EffectWindow* w, int mask, const QRegion &region, Win
}
}
void ICCEffect::paintEffectFrame(KWin::EffectFrame* frame, const QRegion &region, double opacity, double frameOpacity)
/*void ICCEffect::paintEffectFrame(KWin::EffectFrame* frame, const QRegion &region, double opacity, double frameOpacity)
{
if (m_valid)
{
@ -232,11 +253,16 @@ void ICCEffect::paintEffectFrame(KWin::EffectFrame* frame, const QRegion &region
{
effects->paintEffectFrame(frame, region, opacity, frameOpacity);
}
}
}*/
bool ICCEffect::isActive() const
{
return m_valid;
}
bool ICCEffect::provides(Feature f)
{
return false;
}
} // namespace

View File

@ -21,8 +21,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef KWIN_ICC_H
#define KWIN_ICC_H
#include <kwineffects.h>
#include "kwinglutils.h"
#include <kwinoffscreeneffect.h>
namespace KWin
{
@ -33,24 +33,25 @@ class GLShader;
* Applies cLUT (32x32x32 RGB LUT)-based color correction to the whole desktop
* cLUT is generated from a pair of ICC profiles using LCMS2
*/
class ICCEffect
: public Effect
class ICCEffect : public OffscreenEffect
{
Q_OBJECT
public:
ICCEffect();
~ICCEffect();
~ICCEffect() override;
void reconfigure(ReconfigureFlags flags) override;
void drawWindow(EffectWindow* w, int mask, const QRegion &region, WindowPaintData& data) override;
void paintEffectFrame(KWin::EffectFrame* frame, const QRegion &region, double opacity, double frameOpacity) override;
// void drawWindow(EffectWindow *w, int mask, const QRegion &region, WindowPaintData &data) override;
// void paintEffectFrame(KWin::EffectFrame* frame, const QRegion &region, double opacity, double frameOpacity) override;
bool isActive() const override;
bool provides(Feature) override;
int requestedEffectChainPosition() const override;
static bool supported();
public Q_SLOTS:
void slotWindowAdded(KWin::EffectWindow *w);
protected:
bool loadData();
@ -60,7 +61,7 @@ private:
bool m_valid;
QString m_sourceICC;
QString m_targetICC;
GLShader* m_shader;
std::unique_ptr<GLShader> m_shader;
GLuint m_texture;
uint8_t *m_clut;

View File

@ -20,27 +20,27 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "icc_config.h"
#include <kwineffects_interface.h>
#include "iccconfig.h"
#include <config-kwin.h>
#include "iccconfig.h"
#include <QAction>
#include <KLocalizedString>
#include <KActionCollection>
#include <KAboutData>
#include <KPluginFactory>
#include <QVBoxLayout>
K_PLUGIN_FACTORY_WITH_JSON(ICCEffectConfigFactory,
K_PLUGIN_CLASS(KWin::ICCEffectConfig)
/*K_PLUGIN_FACTORY_WITH_JSON(ICCEffectConfigFactory,
"icc_config.json",
registerPlugin<KWin::ICCEffectConfig>();)
registerPlugin<KWin::ICCEffectConfig>();)*/
namespace KWin
{
ICCEffectConfig::ICCEffectConfig(QWidget* parent, const QVariantList& args) :
KCModule(KAboutData::pluginData(QStringLiteral("icc")), parent, args)
ICCEffectConfig::ICCEffectConfig(QWidget *parent, const QVariantList &args)
: KCModule(parent, args)
{
ui.setupUi(this);
ICCConfig::instance(KWIN_CONFIG);
@ -57,14 +57,14 @@ void ICCEffectConfig::load()
{
KCModule::load();
emit changed(false);
Q_EMIT changed(false);
}
void ICCEffectConfig::save()
{
KCModule::save();
emit changed(false);
Q_EMIT changed(false);
OrgKdeKwinEffectsInterface interface(QStringLiteral("org.kde.KWin"),
QStringLiteral("/Effects"),
QDBusConnection::sessionBus());
@ -73,7 +73,7 @@ void ICCEffectConfig::save()
void ICCEffectConfig::defaults()
{
emit changed(true);
Q_EMIT changed(true);
}

View File

@ -21,8 +21,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef KWIN_ICC_CONFIG_H
#define KWIN_ICC_CONFIG_H
#include <kcmodule.h>
#include "ui_icc_config.h"
#include <KCModule>
namespace KWin
{
@ -35,9 +35,9 @@ public:
~ICCEffectConfig();
public Q_SLOTS:
virtual void save();
virtual void load();
virtual void defaults();
virtual void save() override;
virtual void load() override;
virtual void defaults() override;
private:
::Ui::ICCEffectConfig ui;

View File

@ -3,8 +3,9 @@
namespace KWin
{
KWIN_EFFECT_FACTORY(ICCEffect,
"metadata.json.stripped")
KWIN_EFFECT_FACTORY_SUPPORTED(ICCEffect,
"metadata.json.stripped",
return ICCEffect::supported();)
} // namespace KWin

View File

@ -2,6 +2,7 @@
"KPlugin": {
"Category": "Accessibility",
"Description": "ICC Color Conversion",
"Description[ru]": "ICC цветокоррекция",
"EnabledByDefault": false,
"Id": "icc",
"License": "GPL",