Skip to content
Snippets Groups Projects

qt: fix CSD window shadow not being rendered within offscreen window

Closed Fatih Uzunoğlu requested to merge fuzun/vlc:qt/fixextentrendering into master
2 unresolved threads

Request review @chub.

This seems a very nasty bug deep down in Qt Scene Graph renderer, not sure what exactly causes this.

Edited by Fatih Uzunoğlu

Merge request reports

Merge request pipeline #472342 passed with warnings

Merge request pipeline passed with warnings for 4c38884a

Test coverage 18.29% from 1 job

Closed by Fatih UzunoğluFatih Uzunoğlu 4 months ago (Oct 10, 2024 2:43pm UTC)

Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • Fatih Uzunoğlu changed the description

    changed the description

    • if you're going to provide a shader, you can directly draw the dropshadow yourself, Rectangular glow is pretty easy to achieve

      https://github.com/qt/qt5compat/blob/dev/src/imports/graphicaleffects5/RectangularGlow.qml https://github.com/qt/qt5compat/blob/dev/src/imports/graphicaleffects5/shaders_ng/rectangularglow.frag

      This would avoid having to require multiple shader pass

      Here is my attempt at it (the spread variable meaning varies from Qt code), this can be drawn on top of the interface without having to hide it

          //draw the window drop shadow ourselve when the windowing system doesn't                                                                                                                       
          //provide them but support extended frame                                                                                                                                                      
          ShaderEffect {
              id: effect
              visible: _extendedFrameVisible
              anchors.fill: parent
      
              opacity:  0.5
      
              property real spread: 1.4
              property color color: "black"
      
              property real relativeSizeX: (MainCtx.windowExtendedMargin / parent.width)
              property real relativeSizeY: (MainCtx.windowExtendedMargin / parent.height)
      
              //states: [                                                                                                                                                                                
              // //FIXME animate                                                                                                                                                                         
              //}                                                                                                                                                                                        
      
              fragmentShader: "qrc:///shaders/RectGlow.frag.qsb"
          }
      #version 440
      
      layout(location = 0) in vec2 qt_TexCoord0;
      layout(location = 0) out vec4 fragColor;
      
      layout(std140, binding = 0) uniform buf {
          // qt_Matrix and qt_Opacity must always be both present                                                                                                                                        
          // if the built-in vertex shader is used.                                                                                                                                                      
          mat4 qt_Matrix;
          float qt_Opacity;
          vec4 color;
          float relativeSizeX;
          float relativeSizeY;
          float spread;
      };
      
      float linearstep(float e0, float e1, float x)
      {
          return clamp((x - e0) / (e1 - e0), 0.0, 1.0);
      }
      
      void main()
      {
          //discard inner rectangle                                                                                                                                                                      
          if (((qt_TexCoord0.x >= relativeSizeX && qt_TexCoord0.x <= (1.0 - relativeSizeX))
              &&
              (qt_TexCoord0.y >= relativeSizeY && qt_TexCoord0.y <= (1.0 - relativeSizeY))))
              discard;
      
          float alpha =
              smoothstep(0.0, relativeSizeX * spread, 0.5 - abs(0.5 - qt_TexCoord0.x)) *
              smoothstep(0.0, relativeSizeY * spread, 0.5 - abs(0.5 - qt_TexCoord0.y));
      
          //float spreadMultiplier = linearstep(spread, 1.0 - spread, alpha);                                                                                                                            
          fragColor = color * qt_Opacity * alpha * alpha;
      }

      it probably deserve some tweaking to get the best result

    • Author Reporter

      While having it done this way would result in better rendering performance, having that if branch in the shader is still bad for the performance.

      Ideally, we should not need to place the effect on top of the interface. This seems to be caused due to offscreen rendering (Qt bug). For example, on Wayland (!5247 (merged)), I don't need to do this.

      So both solutions here (yours and mine) are worse for the performance. Mine is more practical since I don't need extra files and such (easier to revert when it's fixed), and yours would result in better rendering performance.

      My intention here is to have this only as a temporary measure, so that's why I did not come up with a solution as you recommended. I'm not sure how we should proceed with this. Both are fine for me.

    • So both solutions here (yours and mine) are worse for the performance

      that's not the same order of magnitude, you're comparing a branch in a shader to: a first shader pass + an offscreen rendering + the same branch in a shader

      My intention here is to have this only as a temporary measure

      In the long run should remove our dependency on Qt5Compat, so I don't really see the point in trying to keep compatibility with it

    • Author Reporter

      that's not the same order of magnitude, you're comparing a branch in a shader to: a first shader pass + an offscreen rendering + the same branch in a shader

      I agree, my concern was with the practicality.

      In the long run should remove our dependency on Qt5Compat, so I don't really see the point in trying to keep compatibility with it

      I have changed this, can you check again?

    • Please register or sign in to reply
  • Pierre Lamot changed milestone to %4.0

    changed milestone to %4.0

  • Fatih Uzunoğlu mentioned in merge request !5432 (merged)

    mentioned in merge request !5432 (merged)

  • Fatih Uzunoğlu added 94 commits

    added 94 commits

    • 2689c706...d402227b - 92 commits from branch videolan:master
    • c62e34df - qt: introduce HollowRectangularGlow.frag shader
    • b8fb230f - qml: workaround for CSD window shadow is not rendered

    Compare with previous version

  • Fatih Uzunoğlu changed title from qt: fix CSD window shadow not being rendered & fix inverted z/w in fragment shader to qt: fix CSD window shadow not being rendered

    changed title from qt: fix CSD window shadow not being rendered & fix inverted z/w in fragment shader to qt: fix CSD window shadow not being rendered

  • Pierre Lamot
    Pierre Lamot @chub started a thread on an outdated change in commit b8fb230f
337 341 duration: VLCStyle.duration_veryShort
338 342 }
339 343 }
344
345 Component.onCompleted: {
346 console.assert(children[1] instanceof ShaderEffect)
347 children[1].blending = false // we don't need blending
348
349 if (z >= 0)
350 children[1].fragmentShader = "qrc:///shaders/HollowRectangularGlow.frag.qsb"
  • Fatih Uzunoğlu added 2 commits

    added 2 commits

    • e57f57c1 - qt: introduce RectangularGlow.qml that supports hollowing
    • f1eacffb - qml: workaround for CSD window shadow is not rendered

    Compare with previous version

  • Fatih Uzunoğlu added 2 commits

    added 2 commits

    • d598aacc - qt: introduce RectangularGlow.qml that supports hollowing
    • 4c38884a - qml: workaround for CSD window shadow is not rendered

    Compare with previous version

  • Fatih Uzunoğlu changed title from qt: fix CSD window shadow not being rendered to qt: fix CSD window shadow not being rendered within offscreen window

    changed title from qt: fix CSD window shadow not being rendered to qt: fix CSD window shadow not being rendered within offscreen window

  • added MRStatus::NotCompliant label and removed MRStatus::InReview label

  • Fatih Uzunoğlu mentioned in merge request !6267 (merged)

    mentioned in merge request !6267 (merged)

  • Please register or sign in to reply
    Loading