Changeset View
Changeset View
Standalone View
Standalone View
effects/backgroundcontrast/contrast.cpp
Show First 20 Lines • Show All 187 Lines • ▼ Show 20 Line(s) | 177 | { | |||
---|---|---|---|---|---|
188 | 188 | | |||
189 | if (auto internal = w->internalWindow()) { | 189 | if (auto internal = w->internalWindow()) { | ||
190 | internal->installEventFilter(this); | 190 | internal->installEventFilter(this); | ||
191 | } | 191 | } | ||
192 | 192 | | |||
193 | updateContrastRegion(w); | 193 | updateContrastRegion(w); | ||
194 | } | 194 | } | ||
195 | 195 | | |||
196 | void ContrastEffect::paintScreen(int mask, QRegion region, KWin::ScreenPaintData & data) | ||||
197 | { | ||||
198 | Effect::paintScreen(mask, region, data); | ||||
199 | m_screenRotation = data.screenRotation(); | ||||
200 | } | ||||
201 | | ||||
196 | bool ContrastEffect::eventFilter(QObject *watched, QEvent *event) | 202 | bool ContrastEffect::eventFilter(QObject *watched, QEvent *event) | ||
197 | { | 203 | { | ||
198 | auto internal = qobject_cast<QWindow*>(watched); | 204 | auto internal = qobject_cast<QWindow*>(watched); | ||
199 | if (internal && event->type() == QEvent::DynamicPropertyChange) { | 205 | if (internal && event->type() == QEvent::DynamicPropertyChange) { | ||
200 | QDynamicPropertyChangeEvent *pe = static_cast<QDynamicPropertyChangeEvent*>(event); | 206 | QDynamicPropertyChangeEvent *pe = static_cast<QDynamicPropertyChangeEvent*>(event); | ||
201 | if (pe->propertyName() == "kwin_background_region" || | 207 | if (pe->propertyName() == "kwin_background_region" || | ||
202 | pe->propertyName() == "kwin_background_contrast" || | 208 | pe->propertyName() == "kwin_background_contrast" || | ||
203 | pe->propertyName() == "kwin_background_intensity" || | 209 | pe->propertyName() == "kwin_background_intensity" || | ||
▲ Show 20 Lines • Show All 265 Lines • ▼ Show 20 Line(s) | |||||
469 | } | 475 | } | ||
470 | 476 | | |||
471 | void ContrastEffect::paintEffectFrame(EffectFrame *frame, QRegion region, double opacity, double frameOpacity) | 477 | void ContrastEffect::paintEffectFrame(EffectFrame *frame, QRegion region, double opacity, double frameOpacity) | ||
472 | { | 478 | { | ||
473 | //FIXME: this is a no-op for now, it should figure out the right contrast, intensity, saturation | 479 | //FIXME: this is a no-op for now, it should figure out the right contrast, intensity, saturation | ||
474 | effects->paintEffectFrame(frame, region, opacity, frameOpacity); | 480 | effects->paintEffectFrame(frame, region, opacity, frameOpacity); | ||
475 | } | 481 | } | ||
476 | 482 | | |||
483 | static QMatrix4x4 orientateRect(int rotation, const QRect &screen) | ||||
484 | { | ||||
485 | QMatrix4x4 m; | ||||
486 | if (rotation != 0) { | ||||
487 | m.rotate(-rotation, 0, 0, 1); | ||||
488 | | ||||
489 | //the coordinates origin changes as we rotate | ||||
490 | if (rotation == 90) | ||||
491 | m.translate(-screen.width(), 0); | ||||
492 | else if (rotation == 270) | ||||
493 | m.translate(0, -screen.height()); | ||||
494 | } | ||||
495 | return m; | ||||
496 | } | ||||
497 | | ||||
477 | void ContrastEffect::doContrast(EffectWindow *w, const QRegion& shape, const QRect& screen, const float opacity, const QMatrix4x4 &screenProjection) | 498 | void ContrastEffect::doContrast(EffectWindow *w, const QRegion& shape, const QRect& screen, const float opacity, const QMatrix4x4 &screenProjection) | ||
478 | { | 499 | { | ||
479 | const QRegion actualShape = shape & screen; | 500 | const QRegion actualShape = shape & screen; | ||
480 | const QRect r = actualShape.boundingRect(); | 501 | const QRect r = actualShape.boundingRect(); | ||
481 | 502 | | |||
482 | qreal scale = GLRenderTarget::virtualScreenScale(); | 503 | qreal scale = GLRenderTarget::virtualScreenScale(); | ||
483 | 504 | | |||
484 | // Upload geometry for the horizontal and vertical passes | 505 | // Upload geometry for the horizontal and vertical passes | ||
485 | GLVertexBuffer *vbo = GLVertexBuffer::streamingBuffer(); | 506 | GLVertexBuffer *vbo = GLVertexBuffer::streamingBuffer(); | ||
486 | vbo->reset(); | 507 | vbo->reset(); | ||
487 | uploadGeometry(vbo, actualShape); | 508 | uploadGeometry(vbo, actualShape); | ||
488 | vbo->bindArrays(); | 509 | vbo->bindArrays(); | ||
489 | 510 | | |||
490 | // Create a scratch texture and copy the area in the back buffer that we're | 511 | // Create a scratch texture and copy the area in the back buffer that we're | ||
491 | // going to blur into it | 512 | // going to blur into it | ||
492 | GLTexture scratch(GL_RGBA8, r.width() * scale, r.height() * scale); | 513 | const auto transform = orientateRect(m_screenRotation, screen); | ||
514 | const QRect sg = transform.mapRect(GLRenderTarget::virtualScreenGeometry()); | ||||
515 | const QRect hr = transform.mapRect(r.translated(-sg.topLeft())); | ||||
516 | GLTexture scratch(GL_RGBA8, hr.width() * scale, hr.height() * scale); | ||||
493 | scratch.setFilter(GL_LINEAR); | 517 | scratch.setFilter(GL_LINEAR); | ||
494 | scratch.setWrapMode(GL_CLAMP_TO_EDGE); | 518 | scratch.setWrapMode(GL_CLAMP_TO_EDGE); | ||
495 | scratch.bind(); | 519 | scratch.bind(); | ||
496 | 520 | | |||
497 | const QRect sg = GLRenderTarget::virtualScreenGeometry(); | 521 | glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, hr.x() * scale, (sg.height() - hr.y() - hr.height()) * scale, | ||
498 | glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, (r.x() - sg.x()) * scale, (sg.height() - (r.y() - sg.y() + r.height())) * scale, | | |||
499 | scratch.width(), scratch.height()); | 522 | scratch.width(), scratch.height()); | ||
500 | 523 | | |||
501 | // Draw the texture on the offscreen framebuffer object, while blurring it horizontally | 524 | // Draw the texture on the offscreen framebuffer object, while blurring it horizontally | ||
502 | 525 | | |||
503 | shader->setColorMatrix(m_colorMatrices.value(w)); | 526 | shader->setColorMatrix(m_colorMatrices.value(w)); | ||
504 | shader->bind(); | 527 | shader->bind(); | ||
505 | 528 | | |||
506 | 529 | | |||
507 | shader->setOpacity(opacity); | 530 | shader->setOpacity(opacity); | ||
508 | // Set up the texture matrix to transform from screen coordinates | 531 | // Set up the texture matrix to transform from screen coordinates | ||
509 | // to texture coordinates. | 532 | // to texture coordinates. | ||
510 | QMatrix4x4 textureMatrix; | 533 | QMatrix4x4 textureMatrix; | ||
534 | if (m_screenRotation) { | ||||
535 | textureMatrix.translate(.5, .5); | ||||
536 | textureMatrix.rotate(m_screenRotation, 0, 0, 1); | ||||
537 | textureMatrix.translate(-.5, -.5); | ||||
538 | } | ||||
511 | textureMatrix.scale(1.0 / r.width(), -1.0 / r.height(), 1); | 539 | textureMatrix.scale(1.0 / r.width(), -1.0 / r.height(), 1); | ||
512 | textureMatrix.translate(-r.x(), -r.height() - r.y(), 0); | 540 | textureMatrix.translate(-r.x(), -r.height() - r.y(), 0); | ||
513 | shader->setTextureMatrix(textureMatrix); | 541 | shader->setTextureMatrix(textureMatrix); | ||
514 | shader->setModelViewProjectionMatrix(screenProjection); | 542 | shader->setModelViewProjectionMatrix(screenProjection); | ||
515 | 543 | | |||
516 | vbo->draw(GL_TRIANGLES, 0, actualShape.rectCount() * 6); | 544 | vbo->draw(GL_TRIANGLES, 0, actualShape.rectCount() * 6); | ||
517 | 545 | | |||
518 | scratch.unbind(); | 546 | scratch.unbind(); | ||
Show All 13 Lines |