Changeset View
Changeset View
Standalone View
Standalone View
effects/magnifier/magnifier.cpp
Show All 38 Lines | |||||
39 | { | 39 | { | ||
40 | 40 | | |||
41 | const int FRAME_WIDTH = 5; | 41 | const int FRAME_WIDTH = 5; | ||
42 | 42 | | |||
43 | MagnifierEffect::MagnifierEffect() | 43 | MagnifierEffect::MagnifierEffect() | ||
44 | : zoom(1) | 44 | : zoom(1) | ||
45 | , target_zoom(1) | 45 | , target_zoom(1) | ||
46 | , polling(false) | 46 | , polling(false) | ||
47 | , m_texture(0) | 47 | , m_texture(nullptr) | ||
48 | , m_fbo(0) | 48 | , m_fbo(nullptr) | ||
49 | #ifdef KWIN_HAVE_XRENDER_COMPOSITING | 49 | #ifdef KWIN_HAVE_XRENDER_COMPOSITING | ||
50 | , m_pixmap(XCB_PIXMAP_NONE) | 50 | , m_pixmap(XCB_PIXMAP_NONE) | ||
51 | #endif | 51 | #endif | ||
52 | { | 52 | { | ||
53 | initConfig<MagnifierConfig>(); | 53 | initConfig<MagnifierConfig>(); | ||
54 | QAction* a; | 54 | QAction* a; | ||
55 | a = KStandardAction::zoomIn(this, SLOT(zoomIn()), this); | 55 | a = KStandardAction::zoomIn(this, SLOT(zoomIn()), this); | ||
56 | KGlobalAccel::self()->setDefaultShortcut(a, QList<QKeySequence>() << Qt::META + Qt::Key_Equal); | 56 | KGlobalAccel::self()->setDefaultShortcut(a, QList<QKeySequence>() << Qt::META + Qt::Key_Equal); | ||
▲ Show 20 Lines • Show All 65 Lines • ▼ Show 20 Line(s) | 120 | if (zoom != target_zoom) { | |||
122 | if (target_zoom > zoom) | 122 | if (target_zoom > zoom) | ||
123 | zoom = qMin(zoom * qMax(1 + diff, 1.2), target_zoom); | 123 | zoom = qMin(zoom * qMax(1 + diff, 1.2), target_zoom); | ||
124 | else { | 124 | else { | ||
125 | zoom = qMax(zoom * qMin(1 - diff, 0.8), target_zoom); | 125 | zoom = qMax(zoom * qMin(1 - diff, 0.8), target_zoom); | ||
126 | if (zoom == 1.0) { | 126 | if (zoom == 1.0) { | ||
127 | // zoom ended - delete FBO and texture | 127 | // zoom ended - delete FBO and texture | ||
128 | delete m_fbo; | 128 | delete m_fbo; | ||
129 | delete m_texture; | 129 | delete m_texture; | ||
130 | m_fbo = NULL; | 130 | m_fbo = nullptr; | ||
131 | m_texture = NULL; | 131 | m_texture = nullptr; | ||
132 | destroyPixmap(); | 132 | destroyPixmap(); | ||
133 | } | 133 | } | ||
134 | } | 134 | } | ||
135 | } | 135 | } | ||
136 | effects->prePaintScreen(data, time); | 136 | effects->prePaintScreen(data, time); | ||
137 | if (zoom != 1.0) | 137 | if (zoom != 1.0) | ||
138 | data.paint |= magnifierArea().adjusted(-FRAME_WIDTH, -FRAME_WIDTH, FRAME_WIDTH, FRAME_WIDTH); | 138 | data.paint |= magnifierArea().adjusted(-FRAME_WIDTH, -FRAME_WIDTH, FRAME_WIDTH, FRAME_WIDTH); | ||
139 | } | 139 | } | ||
▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Line(s) | 152 | if (effects->isOpenGLCompositing()) { | |||
190 | verts << areaF.right() + FRAME_WIDTH << areaF.top() - FRAME_WIDTH; | 190 | verts << areaF.right() + FRAME_WIDTH << areaF.top() - FRAME_WIDTH; | ||
191 | // bottom frame | 191 | // bottom frame | ||
192 | verts << areaF.right() + FRAME_WIDTH << areaF.bottom(); | 192 | verts << areaF.right() + FRAME_WIDTH << areaF.bottom(); | ||
193 | verts << areaF.left() - FRAME_WIDTH << areaF.bottom(); | 193 | verts << areaF.left() - FRAME_WIDTH << areaF.bottom(); | ||
194 | verts << areaF.left() - FRAME_WIDTH << areaF.bottom() + FRAME_WIDTH; | 194 | verts << areaF.left() - FRAME_WIDTH << areaF.bottom() + FRAME_WIDTH; | ||
195 | verts << areaF.left() - FRAME_WIDTH << areaF.bottom() + FRAME_WIDTH; | 195 | verts << areaF.left() - FRAME_WIDTH << areaF.bottom() + FRAME_WIDTH; | ||
196 | verts << areaF.right() + FRAME_WIDTH << areaF.bottom() + FRAME_WIDTH; | 196 | verts << areaF.right() + FRAME_WIDTH << areaF.bottom() + FRAME_WIDTH; | ||
197 | verts << areaF.right() + FRAME_WIDTH << areaF.bottom(); | 197 | verts << areaF.right() + FRAME_WIDTH << areaF.bottom(); | ||
198 | vbo->setData(verts.size() / 2, 2, verts.constData(), NULL); | 198 | vbo->setData(verts.size() / 2, 2, verts.constData(), nullptr); | ||
199 | 199 | | |||
200 | ShaderBinder binder(ShaderTrait::UniformColor); | 200 | ShaderBinder binder(ShaderTrait::UniformColor); | ||
201 | binder.shader()->setUniform(GLShader::ModelViewProjectionMatrix, data.projectionMatrix()); | 201 | binder.shader()->setUniform(GLShader::ModelViewProjectionMatrix, data.projectionMatrix()); | ||
202 | vbo->render(GL_TRIANGLES); | 202 | vbo->render(GL_TRIANGLES); | ||
203 | } | 203 | } | ||
204 | if (effects->compositingType() == XRenderCompositing) { | 204 | if (effects->compositingType() == XRenderCompositing) { | ||
205 | #ifdef KWIN_HAVE_XRENDER_COMPOSITING | 205 | #ifdef KWIN_HAVE_XRENDER_COMPOSITING | ||
206 | if (m_pixmap == XCB_PIXMAP_NONE || m_pixmapSize != srcArea.size()) { | 206 | if (m_pixmap == XCB_PIXMAP_NONE || m_pixmapSize != srcArea.size()) { | ||
Show All 16 Lines | 213 | #define DOUBLE_TO_FIXED(d) ((xcb_render_fixed_t) ((d) * 65536)) | |||
223 | }; | 223 | }; | ||
224 | xcb_render_composite(xcbConnection(), XCB_RENDER_PICT_OP_SRC, effects->xrenderBufferPicture(), 0, *m_picture, | 224 | xcb_render_composite(xcbConnection(), XCB_RENDER_PICT_OP_SRC, effects->xrenderBufferPicture(), 0, *m_picture, | ||
225 | srcArea.x(), srcArea.y(), 0, 0, 0, 0, srcArea.width(), srcArea.height()); | 225 | srcArea.x(), srcArea.y(), 0, 0, 0, 0, srcArea.width(), srcArea.height()); | ||
226 | xcb_flush(xcbConnection()); | 226 | xcb_flush(xcbConnection()); | ||
227 | xform.matrix11 = DOUBLE_TO_FIXED(1.0/zoom); | 227 | xform.matrix11 = DOUBLE_TO_FIXED(1.0/zoom); | ||
228 | xform.matrix22 = DOUBLE_TO_FIXED(1.0/zoom); | 228 | xform.matrix22 = DOUBLE_TO_FIXED(1.0/zoom); | ||
229 | #undef DOUBLE_TO_FIXED | 229 | #undef DOUBLE_TO_FIXED | ||
230 | xcb_render_set_picture_transform(xcbConnection(), *m_picture, xform); | 230 | xcb_render_set_picture_transform(xcbConnection(), *m_picture, xform); | ||
231 | xcb_render_set_picture_filter(xcbConnection(), *m_picture, 4, const_cast<char*>("good"), 0, NULL); | 231 | xcb_render_set_picture_filter(xcbConnection(), *m_picture, 4, const_cast<char*>("good"), 0, nullptr); | ||
232 | xcb_render_composite(xcbConnection(), XCB_RENDER_PICT_OP_SRC, *m_picture, 0, effects->xrenderBufferPicture(), | 232 | xcb_render_composite(xcbConnection(), XCB_RENDER_PICT_OP_SRC, *m_picture, 0, effects->xrenderBufferPicture(), | ||
233 | 0, 0, 0, 0, area.x(), area.y(), area.width(), area.height() ); | 233 | 0, 0, 0, 0, area.x(), area.y(), area.width(), area.height() ); | ||
234 | xcb_render_set_picture_filter(xcbConnection(), *m_picture, 4, const_cast<char*>("fast"), 0, NULL); | 234 | xcb_render_set_picture_filter(xcbConnection(), *m_picture, 4, const_cast<char*>("fast"), 0, nullptr); | ||
235 | xcb_render_set_picture_transform(xcbConnection(), *m_picture, identity); | 235 | xcb_render_set_picture_transform(xcbConnection(), *m_picture, identity); | ||
236 | const xcb_rectangle_t rects[4] = { | 236 | const xcb_rectangle_t rects[4] = { | ||
237 | { int16_t(area.x()+FRAME_WIDTH), int16_t(area.y()), uint16_t(area.width()-FRAME_WIDTH), uint16_t(FRAME_WIDTH)}, | 237 | { int16_t(area.x()+FRAME_WIDTH), int16_t(area.y()), uint16_t(area.width()-FRAME_WIDTH), uint16_t(FRAME_WIDTH)}, | ||
238 | { int16_t(area.right()-FRAME_WIDTH), int16_t(area.y()+FRAME_WIDTH), uint16_t(FRAME_WIDTH), uint16_t(area.height()-FRAME_WIDTH)}, | 238 | { int16_t(area.right()-FRAME_WIDTH), int16_t(area.y()+FRAME_WIDTH), uint16_t(FRAME_WIDTH), uint16_t(area.height()-FRAME_WIDTH)}, | ||
239 | { int16_t(area.x()), int16_t(area.bottom()-FRAME_WIDTH), uint16_t(area.width()-FRAME_WIDTH), uint16_t(FRAME_WIDTH)}, | 239 | { int16_t(area.x()), int16_t(area.bottom()-FRAME_WIDTH), uint16_t(area.width()-FRAME_WIDTH), uint16_t(FRAME_WIDTH)}, | ||
240 | { int16_t(area.x()), int16_t(area.y()), uint16_t(FRAME_WIDTH), uint16_t(area.height()-FRAME_WIDTH)} | 240 | { int16_t(area.x()), int16_t(area.y()), uint16_t(FRAME_WIDTH), uint16_t(area.height()-FRAME_WIDTH)} | ||
241 | }; | 241 | }; | ||
242 | xcb_render_fill_rectangles(xcbConnection(), XCB_RENDER_PICT_OP_SRC, effects->xrenderBufferPicture(), | 242 | xcb_render_fill_rectangles(xcbConnection(), XCB_RENDER_PICT_OP_SRC, effects->xrenderBufferPicture(), | ||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Line(s) | 283 | if (target_zoom <= 1) { | |||
285 | if (polling) { | 285 | if (polling) { | ||
286 | polling = false; | 286 | polling = false; | ||
287 | effects->stopMousePolling(); | 287 | effects->stopMousePolling(); | ||
288 | } | 288 | } | ||
289 | if (zoom == target_zoom) { | 289 | if (zoom == target_zoom) { | ||
290 | effects->makeOpenGLContextCurrent(); | 290 | effects->makeOpenGLContextCurrent(); | ||
291 | delete m_fbo; | 291 | delete m_fbo; | ||
292 | delete m_texture; | 292 | delete m_texture; | ||
293 | m_fbo = NULL; | 293 | m_fbo = nullptr; | ||
294 | m_texture = NULL; | 294 | m_texture = nullptr; | ||
295 | destroyPixmap(); | 295 | destroyPixmap(); | ||
296 | } | 296 | } | ||
297 | } | 297 | } | ||
298 | effects->addRepaint(magnifierArea().adjusted(-FRAME_WIDTH, -FRAME_WIDTH, FRAME_WIDTH, FRAME_WIDTH)); | 298 | effects->addRepaint(magnifierArea().adjusted(-FRAME_WIDTH, -FRAME_WIDTH, FRAME_WIDTH, FRAME_WIDTH)); | ||
299 | } | 299 | } | ||
300 | 300 | | |||
301 | void MagnifierEffect::toggle() | 301 | void MagnifierEffect::toggle() | ||
302 | { | 302 | { | ||
Show All 40 Lines |