kwin: deduplicate code for fixed to double and vice-versa conversion

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2022-10-02 00:53:42 +03:00
parent 8d5a89b004
commit 0bb374548b
5 changed files with 42 additions and 47 deletions

View file

@ -32,6 +32,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifdef KWIN_BUILD_COMPOSITE #ifdef KWIN_BUILD_COMPOSITE
#include <kwinxrenderutils.h> #include <kwinxrenderutils.h>
#include <xcbutils.h>
#include <xcb/render.h> #include <xcb/render.h>
#endif #endif
@ -135,23 +136,21 @@ void MagnifierEffect::paintScreen(int mask, QRegion region, ScreenPaintData& dat
xcb_create_pixmap(connection(), 32, m_pixmap, rootWindow(), m_pixmapSize.width(), m_pixmapSize.height()); xcb_create_pixmap(connection(), 32, m_pixmap, rootWindow(), m_pixmapSize.width(), m_pixmapSize.height());
m_picture.reset(new XRenderPicture(m_pixmap, 32)); m_picture.reset(new XRenderPicture(m_pixmap, 32));
} }
#define DOUBLE_TO_FIXED(d) ((xcb_render_fixed_t) ((d) * 65536))
static xcb_render_transform_t identity = { static xcb_render_transform_t identity = {
DOUBLE_TO_FIXED(1), DOUBLE_TO_FIXED(0), DOUBLE_TO_FIXED(0), KWIN_DOUBLE_TO_FIXED(1), KWIN_DOUBLE_TO_FIXED(0), KWIN_DOUBLE_TO_FIXED(0),
DOUBLE_TO_FIXED(0), DOUBLE_TO_FIXED(1), DOUBLE_TO_FIXED(0), KWIN_DOUBLE_TO_FIXED(0), KWIN_DOUBLE_TO_FIXED(1), KWIN_DOUBLE_TO_FIXED(0),
DOUBLE_TO_FIXED(0), DOUBLE_TO_FIXED(0), DOUBLE_TO_FIXED(1) KWIN_DOUBLE_TO_FIXED(0), KWIN_DOUBLE_TO_FIXED(0), KWIN_DOUBLE_TO_FIXED(1)
}; };
static xcb_render_transform_t xform = { static xcb_render_transform_t xform = {
DOUBLE_TO_FIXED(1), DOUBLE_TO_FIXED(0), DOUBLE_TO_FIXED(0), KWIN_DOUBLE_TO_FIXED(1), KWIN_DOUBLE_TO_FIXED(0), KWIN_DOUBLE_TO_FIXED(0),
DOUBLE_TO_FIXED(0), DOUBLE_TO_FIXED(1), DOUBLE_TO_FIXED(0), KWIN_DOUBLE_TO_FIXED(0), KWIN_DOUBLE_TO_FIXED(1), KWIN_DOUBLE_TO_FIXED(0),
DOUBLE_TO_FIXED(0), DOUBLE_TO_FIXED(0), DOUBLE_TO_FIXED(1) KWIN_DOUBLE_TO_FIXED(0), KWIN_DOUBLE_TO_FIXED(0), KWIN_DOUBLE_TO_FIXED(1)
}; };
xcb_render_composite(connection(), XCB_RENDER_PICT_OP_SRC, effects->xrenderBufferPicture(), 0, *m_picture, xcb_render_composite(connection(), XCB_RENDER_PICT_OP_SRC, effects->xrenderBufferPicture(), 0, *m_picture,
srcArea.x(), srcArea.y(), 0, 0, 0, 0, srcArea.width(), srcArea.height()); srcArea.x(), srcArea.y(), 0, 0, 0, 0, srcArea.width(), srcArea.height());
xcb_flush(connection()); xcb_flush(connection());
xform.matrix11 = DOUBLE_TO_FIXED(1.0/zoom); xform.matrix11 = KWIN_DOUBLE_TO_FIXED(1.0/zoom);
xform.matrix22 = DOUBLE_TO_FIXED(1.0/zoom); xform.matrix22 = KWIN_DOUBLE_TO_FIXED(1.0/zoom);
#undef DOUBLE_TO_FIXED
xcb_render_set_picture_transform(connection(), *m_picture, xform); xcb_render_set_picture_transform(connection(), *m_picture, xform);
xcb_render_set_picture_filter(connection(), *m_picture, 4, const_cast<char*>("good"), 0, NULL); xcb_render_set_picture_filter(connection(), *m_picture, 4, const_cast<char*>("good"), 0, NULL);
xcb_render_composite(connection(), XCB_RENDER_PICT_OP_SRC, *m_picture, 0, effects->xrenderBufferPicture(), xcb_render_composite(connection(), XCB_RENDER_PICT_OP_SRC, *m_picture, 0, effects->xrenderBufferPicture(),

View file

@ -34,6 +34,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <KLocalizedString> #include <KLocalizedString>
#include <kdebug.h> #include <kdebug.h>
#ifdef KWIN_BUILD_COMPOSITE
#include <xcbutils.h>
#endif
#include <math.h> #include <math.h>
namespace KWin namespace KWin
@ -121,13 +125,11 @@ void TrackMouseEffect::paintScreen(int mask, QRegion region, ScreenPaintData& da
const float dx = m_size[i].width()/2.0; const float dx = m_size[i].width()/2.0;
const float dy = m_size[i].height()/2.0; const float dy = m_size[i].height()/2.0;
const xcb_render_picture_t picture = *m_picture[i]; const xcb_render_picture_t picture = *m_picture[i];
#define DOUBLE_TO_FIXED(d) ((xcb_render_fixed_t) ((d) * 65536))
xcb_render_transform_t xform = { xcb_render_transform_t xform = {
DOUBLE_TO_FIXED( cosine ), DOUBLE_TO_FIXED( -sine ), DOUBLE_TO_FIXED( dx - cosine*dx + sine*dy ), KWIN_DOUBLE_TO_FIXED( cosine ), KWIN_DOUBLE_TO_FIXED( -sine ), KWIN_DOUBLE_TO_FIXED( dx - cosine*dx + sine*dy ),
DOUBLE_TO_FIXED( sine ), DOUBLE_TO_FIXED( cosine ), DOUBLE_TO_FIXED( dy - sine*dx - cosine*dy ), KWIN_DOUBLE_TO_FIXED( sine ), KWIN_DOUBLE_TO_FIXED( cosine ), KWIN_DOUBLE_TO_FIXED( dy - sine*dx - cosine*dy ),
DOUBLE_TO_FIXED( 0.0 ), DOUBLE_TO_FIXED( 0.0 ), DOUBLE_TO_FIXED( 1.0 ) KWIN_DOUBLE_TO_FIXED( 0.0 ), KWIN_DOUBLE_TO_FIXED( 0.0 ), KWIN_DOUBLE_TO_FIXED( 1.0 )
}; };
#undef DOUBLE_TO_FIXED
xcb_render_set_picture_transform(connection(), picture, xform); xcb_render_set_picture_transform(connection(), picture, xform);
xcb_render_set_picture_filter(connection(), picture, 8, "bilinear", 0, NULL); xcb_render_set_picture_filter(connection(), picture, 8, "bilinear", 0, NULL);
const QRect &rect = m_lastRect[i]; const QRect &rect = m_lastRect[i];

View file

@ -27,8 +27,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <QApplication> #include <QApplication>
#include <QStyle> #include <QStyle>
#include <QtGui/QVector2D> #include <QVector2D>
#include <QtDBus/QDBusConnection>
#include <kaction.h> #include <kaction.h>
#include <kactioncollection.h> #include <kactioncollection.h>
#include <kstandardaction.h> #include <kstandardaction.h>
@ -38,6 +37,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifdef KWIN_BUILD_COMPOSITE #ifdef KWIN_BUILD_COMPOSITE
#include <kwinxrenderutils.h> #include <kwinxrenderutils.h>
#include <xcbutils.h>
#include <xcb/render.h> #include <xcb/render.h>
#endif #endif
#include <xcb/xfixes.h> #include <xcb/xfixes.h>
@ -286,18 +286,17 @@ void ZoomEffect::paintScreen(int mask, QRegion region, ScreenPaintData& data)
#ifdef KWIN_BUILD_COMPOSITE #ifdef KWIN_BUILD_COMPOSITE
if (xrenderPicture) { if (xrenderPicture) {
#define DOUBLE_TO_FIXED(d) ((xcb_render_fixed_t) ((d) * 65536))
static xcb_render_transform_t xrenderIdentity = { static xcb_render_transform_t xrenderIdentity = {
DOUBLE_TO_FIXED(1), DOUBLE_TO_FIXED(0), DOUBLE_TO_FIXED(0), KWIN_DOUBLE_TO_FIXED(1), KWIN_DOUBLE_TO_FIXED(0), KWIN_DOUBLE_TO_FIXED(0),
DOUBLE_TO_FIXED(0), DOUBLE_TO_FIXED(1), DOUBLE_TO_FIXED(0), KWIN_DOUBLE_TO_FIXED(0), KWIN_DOUBLE_TO_FIXED(1), KWIN_DOUBLE_TO_FIXED(0),
DOUBLE_TO_FIXED(0), DOUBLE_TO_FIXED(0), DOUBLE_TO_FIXED(1) KWIN_DOUBLE_TO_FIXED(0), KWIN_DOUBLE_TO_FIXED(0), KWIN_DOUBLE_TO_FIXED(1)
}; };
if (mousePointer == MousePointerScale) { if (mousePointer == MousePointerScale) {
xcb_render_set_picture_filter(connection(), *xrenderPicture, 4, const_cast<char*>("good"), 0, NULL); xcb_render_set_picture_filter(connection(), *xrenderPicture, 4, const_cast<char*>("good"), 0, NULL);
const xcb_render_transform_t xform = { const xcb_render_transform_t xform = {
DOUBLE_TO_FIXED(1.0 / zoom), DOUBLE_TO_FIXED(0), DOUBLE_TO_FIXED(0), KWIN_DOUBLE_TO_FIXED(1.0 / zoom), KWIN_DOUBLE_TO_FIXED(0), KWIN_DOUBLE_TO_FIXED(0),
DOUBLE_TO_FIXED(0), DOUBLE_TO_FIXED(1.0 / zoom), DOUBLE_TO_FIXED(0), KWIN_DOUBLE_TO_FIXED(0), KWIN_DOUBLE_TO_FIXED(1.0 / zoom), KWIN_DOUBLE_TO_FIXED(0),
DOUBLE_TO_FIXED(0), DOUBLE_TO_FIXED(0), DOUBLE_TO_FIXED(1) KWIN_DOUBLE_TO_FIXED(0), KWIN_DOUBLE_TO_FIXED(0), KWIN_DOUBLE_TO_FIXED(1)
}; };
xcb_render_set_picture_transform(connection(), *xrenderPicture, xform); xcb_render_set_picture_transform(connection(), *xrenderPicture, xform);
} }
@ -305,7 +304,6 @@ void ZoomEffect::paintScreen(int mask, QRegion region, ScreenPaintData& data)
effects->xrenderBufferPicture(), 0, 0, 0, 0, rect.x(), rect.y(), rect.width(), rect.height()); effects->xrenderBufferPicture(), 0, 0, 0, 0, rect.x(), rect.y(), rect.width(), rect.height());
if (mousePointer == MousePointerScale) if (mousePointer == MousePointerScale)
xcb_render_set_picture_transform(connection(), *xrenderPicture, xrenderIdentity); xcb_render_set_picture_transform(connection(), *xrenderPicture, xrenderIdentity);
#undef DOUBLE_TO_FIXED
} }
#endif #endif
} }

View file

@ -51,10 +51,6 @@ namespace KWin
xcb_render_picture_t SceneXrender::buffer = XCB_RENDER_PICTURE_NONE; xcb_render_picture_t SceneXrender::buffer = XCB_RENDER_PICTURE_NONE;
ScreenPaintData SceneXrender::screen_paint; ScreenPaintData SceneXrender::screen_paint;
#define DOUBLE_TO_FIXED(d) ((xcb_render_fixed_t) ((d) * 65536))
#define FIXED_TO_DOUBLE(f) ((double) ((f) / 65536.0))
static xcb_render_pictformat_t findFormatForVisual(xcb_visualid_t visual) static xcb_render_pictformat_t findFormatForVisual(xcb_visualid_t visual)
{ {
static QHash<xcb_visualid_t, xcb_render_pictformat_t> s_cache; static QHash<xcb_visualid_t, xcb_render_pictformat_t> s_cache;
@ -453,14 +449,14 @@ void SceneXrender::Window::performPaint(int mask, QRegion region, WindowPaintDat
transformed_shape |= toplevel->shadow()->shadowRegion(); transformed_shape |= toplevel->shadow()->shadowRegion();
xcb_render_transform_t xform = { xcb_render_transform_t xform = {
DOUBLE_TO_FIXED(1), DOUBLE_TO_FIXED(0), DOUBLE_TO_FIXED(0), KWIN_DOUBLE_TO_FIXED(1), KWIN_DOUBLE_TO_FIXED(0), KWIN_DOUBLE_TO_FIXED(0),
DOUBLE_TO_FIXED(0), DOUBLE_TO_FIXED(1), DOUBLE_TO_FIXED(0), KWIN_DOUBLE_TO_FIXED(0), KWIN_DOUBLE_TO_FIXED(1), KWIN_DOUBLE_TO_FIXED(0),
DOUBLE_TO_FIXED(0), DOUBLE_TO_FIXED(0), DOUBLE_TO_FIXED(1) KWIN_DOUBLE_TO_FIXED(0), KWIN_DOUBLE_TO_FIXED(0), KWIN_DOUBLE_TO_FIXED(1)
}; };
static xcb_render_transform_t identity = { static xcb_render_transform_t identity = {
DOUBLE_TO_FIXED(1), DOUBLE_TO_FIXED(0), DOUBLE_TO_FIXED(0), KWIN_DOUBLE_TO_FIXED(1), KWIN_DOUBLE_TO_FIXED(0), KWIN_DOUBLE_TO_FIXED(0),
DOUBLE_TO_FIXED(0), DOUBLE_TO_FIXED(1), DOUBLE_TO_FIXED(0), KWIN_DOUBLE_TO_FIXED(0), KWIN_DOUBLE_TO_FIXED(1), KWIN_DOUBLE_TO_FIXED(0),
DOUBLE_TO_FIXED(0), DOUBLE_TO_FIXED(0), DOUBLE_TO_FIXED(1) KWIN_DOUBLE_TO_FIXED(0), KWIN_DOUBLE_TO_FIXED(0), KWIN_DOUBLE_TO_FIXED(1)
}; };
if (mask & PAINT_WINDOW_TRANSFORMED) { if (mask & PAINT_WINDOW_TRANSFORMED) {
@ -473,8 +469,8 @@ void SceneXrender::Window::performPaint(int mask, QRegion region, WindowPaintDat
} }
if (!qFuzzyCompare(xscale, 1.0) || !qFuzzyCompare(yscale, 1.0)) { if (!qFuzzyCompare(xscale, 1.0) || !qFuzzyCompare(yscale, 1.0)) {
scaled = true; scaled = true;
xform.matrix11 = DOUBLE_TO_FIXED(1.0 / xscale); xform.matrix11 = KWIN_DOUBLE_TO_FIXED(1.0 / xscale);
xform.matrix22 = DOUBLE_TO_FIXED(1.0 / yscale); xform.matrix22 = KWIN_DOUBLE_TO_FIXED(1.0 / yscale);
// transform the shape for clipping in paintTransformedScreen() // transform the shape for clipping in paintTransformedScreen()
QVector<QRect> rects = transformed_shape.rects(); QVector<QRect> rects = transformed_shape.rects();
@ -652,9 +648,9 @@ xcb_render_composite(connection(), XCB_RENDER_PICT_OP_OVER, m_xrenderShadow->pic
} }
if (previous->size() != pixmap->size()) { if (previous->size() != pixmap->size()) {
xcb_render_transform_t xform2 = { xcb_render_transform_t xform2 = {
DOUBLE_TO_FIXED(FIXED_TO_DOUBLE(xform.matrix11) * previous->size().width() / pixmap->size().width()), DOUBLE_TO_FIXED(0), DOUBLE_TO_FIXED(0), KWIN_DOUBLE_TO_FIXED(KWIN_FIXED_TO_DOUBLE(xform.matrix11) * previous->size().width() / pixmap->size().width()), KWIN_DOUBLE_TO_FIXED(0), KWIN_DOUBLE_TO_FIXED(0),
DOUBLE_TO_FIXED(0), DOUBLE_TO_FIXED(FIXED_TO_DOUBLE(xform.matrix22) * previous->size().height() / pixmap->size().height()), DOUBLE_TO_FIXED(0), KWIN_DOUBLE_TO_FIXED(0), KWIN_DOUBLE_TO_FIXED(KWIN_FIXED_TO_DOUBLE(xform.matrix22) * previous->size().height() / pixmap->size().height()), KWIN_DOUBLE_TO_FIXED(0),
DOUBLE_TO_FIXED(0), DOUBLE_TO_FIXED(0), DOUBLE_TO_FIXED(1) KWIN_DOUBLE_TO_FIXED(0), KWIN_DOUBLE_TO_FIXED(0), KWIN_DOUBLE_TO_FIXED(1)
}; };
xcb_render_set_picture_transform(connection(), previous->picture(), xform2); xcb_render_set_picture_transform(connection(), previous->picture(), xform2);
} }
@ -929,12 +925,12 @@ void SceneXrender::EffectFrame::renderUnstyled(xcb_render_picture_t pict, const
QVector<xcb_render_pointfix_t> points; QVector<xcb_render_pointfix_t> points;
xcb_render_pointfix_t point; xcb_render_pointfix_t point;
point.x = DOUBLE_TO_FIXED(roundness); point.x = KWIN_DOUBLE_TO_FIXED(roundness);
point.y = DOUBLE_TO_FIXED(roundness); point.y = KWIN_DOUBLE_TO_FIXED(roundness);
points << point; points << point;
for (int ii = 0; ii <= num_segments; ++ii) { for (int ii = 0; ii <= num_segments; ++ii) {
point.x = DOUBLE_TO_FIXED(x + roundness); point.x = KWIN_DOUBLE_TO_FIXED(x + roundness);
point.y = DOUBLE_TO_FIXED(y + roundness); point.y = KWIN_DOUBLE_TO_FIXED(y + roundness);
points << point; points << point;
//apply the rotation matrix //apply the rotation matrix
t = x; t = x;
@ -1085,8 +1081,5 @@ xcb_render_picture_t SceneXRenderShadow::picture(Shadow::ShadowElements element)
return *m_pictures[element]; return *m_pictures[element];
} }
#undef DOUBLE_TO_FIXED
#undef FIXED_TO_DOUBLE
} // namespace } // namespace
#endif #endif

View file

@ -30,6 +30,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <xcb/xcb.h> #include <xcb/xcb.h>
#include <xcb/composite.h> #include <xcb/composite.h>
#define KWIN_DOUBLE_TO_FIXED(d) ((xcb_render_fixed_t) ((d) * 65536))
#define KWIN_FIXED_TO_DOUBLE(f) ((double) ((f) / 65536.0))
namespace KWin { namespace KWin {
namespace Xcb { namespace Xcb {