Changeset View
Changeset View
Standalone View
Standalone View
plugins/scenes/opengl/scene_opengl.cpp
Show First 20 Lines • Show All 561 Lines • ▼ Show 20 Line(s) | |||||
562 | } | 562 | } | ||
563 | 563 | | |||
564 | /** | 564 | /** | ||
565 | * Render cursor texture in case hardware cursor is disabled. | 565 | * Render cursor texture in case hardware cursor is disabled. | ||
566 | * Useful for screen recording apps or backends that can't do planes. | 566 | * Useful for screen recording apps or backends that can't do planes. | ||
567 | */ | 567 | */ | ||
568 | void SceneOpenGL2::paintCursor() | 568 | void SceneOpenGL2::paintCursor() | ||
569 | { | 569 | { | ||
570 | Cursor* cursor = Cursors::self()->currentCursor(); | ||||
571 | | ||||
570 | // don't paint if we use hardware cursor or the cursor is hidden | 572 | // don't paint if we use hardware cursor or the cursor is hidden | ||
571 | if (!kwinApp()->platform()->usesSoftwareCursor() || | 573 | if (!kwinApp()->platform()->usesSoftwareCursor() || | ||
572 | kwinApp()->platform()->isCursorHidden() || | 574 | kwinApp()->platform()->isCursorHidden() || | ||
573 | kwinApp()->platform()->softwareCursor().isNull()) { | 575 | cursor->image().isNull()) { | ||
574 | return; | 576 | return; | ||
575 | } | 577 | } | ||
576 | 578 | | |||
577 | // lazy init texture cursor only in case we need software rendering | 579 | // lazy init texture cursor only in case we need software rendering | ||
578 | if (!m_cursorTexture) { | 580 | if (!m_cursorTexture) { | ||
579 | auto updateCursorTexture = [this] { | 581 | auto updateCursorTexture = [this] { | ||
580 | // don't paint if no image for cursor is set | 582 | // don't paint if no image for cursor is set | ||
581 | const QImage img = kwinApp()->platform()->softwareCursor(); | 583 | const QImage img = Cursors::self()->currentCursor()->image(); | ||
582 | if (img.isNull()) { | 584 | if (img.isNull()) { | ||
583 | return; | 585 | return; | ||
584 | } | 586 | } | ||
585 | m_cursorTexture.reset(new GLTexture(img)); | 587 | m_cursorTexture.reset(new GLTexture(img)); | ||
586 | }; | 588 | }; | ||
587 | 589 | | |||
588 | // init now | 590 | // init now | ||
589 | updateCursorTexture(); | 591 | updateCursorTexture(); | ||
590 | 592 | | |||
591 | // handle shape update on case cursor image changed | 593 | // handle shape update on case cursor image changed | ||
592 | connect(kwinApp()->platform(), &Platform::cursorChanged, this, updateCursorTexture); | 594 | connect(Cursors::self(), &Cursors::currentCursorChanged, this, updateCursorTexture); | ||
593 | } | 595 | } | ||
594 | 596 | | |||
595 | // get cursor position in projection coordinates | 597 | // get cursor position in projection coordinates | ||
596 | const QPoint cursorPos = Cursor::pos() - kwinApp()->platform()->softwareCursorHotspot(); | 598 | const QPoint cursorPos = cursor->pos() - cursor->hotspot(); | ||
597 | const QRect cursorRect(0, 0, m_cursorTexture->width(), m_cursorTexture->height()); | 599 | const QRect cursorRect(0, 0, m_cursorTexture->width(), m_cursorTexture->height()); | ||
598 | QMatrix4x4 mvp = m_projectionMatrix; | 600 | QMatrix4x4 mvp = m_projectionMatrix; | ||
599 | mvp.translate(cursorPos.x(), cursorPos.y()); | 601 | mvp.translate(cursorPos.x(), cursorPos.y()); | ||
600 | 602 | | |||
601 | // handle transparence | 603 | // handle transparence | ||
602 | glEnable(GL_BLEND); | 604 | glEnable(GL_BLEND); | ||
603 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | 605 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | ||
604 | 606 | | |||
605 | // paint texture in cursor offset | 607 | // paint texture in cursor offset | ||
606 | m_cursorTexture->bind(); | 608 | m_cursorTexture->bind(); | ||
607 | ShaderBinder binder(ShaderTrait::MapTexture); | 609 | ShaderBinder binder(ShaderTrait::MapTexture); | ||
608 | binder.shader()->setUniform(GLShader::ModelViewProjectionMatrix, mvp); | 610 | binder.shader()->setUniform(GLShader::ModelViewProjectionMatrix, mvp); | ||
609 | m_cursorTexture->render(QRegion(cursorRect), cursorRect); | 611 | m_cursorTexture->render(QRegion(cursorRect), cursorRect); | ||
610 | m_cursorTexture->unbind(); | 612 | m_cursorTexture->unbind(); | ||
611 | 613 | | |||
612 | kwinApp()->platform()->markCursorAsRendered(); | 614 | cursor->markAsRendered(); | ||
613 | 615 | | |||
614 | glDisable(GL_BLEND); | 616 | glDisable(GL_BLEND); | ||
615 | } | 617 | } | ||
616 | 618 | | |||
617 | qint64 SceneOpenGL::paint(const QRegion &damage, const QList<Toplevel *> &toplevels) | 619 | qint64 SceneOpenGL::paint(const QRegion &damage, const QList<Toplevel *> &toplevels) | ||
618 | { | 620 | { | ||
619 | // actually paint the frame, flushed with the NEXT frame | 621 | // actually paint the frame, flushed with the NEXT frame | ||
620 | createStackingOrder(toplevels); | 622 | createStackingOrder(toplevels); | ||
▲ Show 20 Lines • Show All 2100 Lines • Show Last 20 Lines |