Skip to content

core: Accumulate render damage #9808

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from

Conversation

PlasmaPower
Copy link
Contributor

Describe your PR, what does it fix/add?

If a client commits multiple times before we next render, we should accumulate damage instead of replacing it.

Is there anything you want to mention? (unchecked code, possible bugs, found problems, breaking compatibility, etc.)

Nope

Is it ready for merging, or does it need work?

Ready for merging

@ikalco
Copy link
Contributor

ikalco commented Mar 31, 2025

I think you can just keep track of damage in surface.current, something like this

diff --git a/src/desktop/WLSurface.cpp b/src/desktop/WLSurface.cpp
index 11da7b68..4f8e7429 100644
--- a/src/desktop/WLSurface.cpp
+++ b/src/desktop/WLSurface.cpp
@@ -99,6 +99,7 @@ CRegion CWLSurface::computeDamage() const {
         return {};
 
     CRegion damage = m_pResource->current.accumulateBufferDamage();
+    m_pResource->current.bufferDamage.clear();
     damage.transform(wlTransformToHyprutils(m_pResource->current.transform), m_pResource->current.bufferSize.x, m_pResource->current.bufferSize.y);
 
     const auto BUFSIZE    = m_pResource->current.bufferSize;
diff --git a/src/protocols/types/SurfaceState.cpp b/src/protocols/types/SurfaceState.cpp
old mode 100644
new mode 100755
index a97f69b4..f81c6bb0
--- a/src/protocols/types/SurfaceState.cpp
+++ b/src/protocols/types/SurfaceState.cpp
@@ -74,8 +74,8 @@ void SSurfaceState::updateFrom(SSurfaceState& ref) {
     }
 
     if (ref.updated.damage) {
-        damage       = ref.damage;
-        bufferDamage = ref.bufferDamage;
+        damage.add(ref.damage);
+        bufferDamage.add(ref.bufferDamage);
     }
 
     if (ref.updated.input)
diff --git a/src/protocols/types/SurfaceState.hpp b/src/protocols/types/SurfaceState.hpp
index 07ade832..b58aa9a8 100644
--- a/src/protocols/types/SurfaceState.hpp
+++ b/src/protocols/types/SurfaceState.hpp
@@ -55,7 +55,7 @@ struct SSurfaceState {
     void         updateSynchronousTexture(SP<CTexture> lastTexture);
 
     // helpers
-    CRegion accumulateBufferDamage();       // transforms state.damage and merges it into state.bufferDamage
+    CRegion accumulateBufferDamage();       // returns total damage in buffer coords
     void    updateFrom(SSurfaceState& ref); // updates this state based on a reference state.
     void    reset();                        // resets pending state after commit
 };

@PlasmaPower
Copy link
Contributor Author

That breaks the damage passed to updating the shm texture and cursor.

@gulafaran
Copy link
Contributor

no regressions here, lgtm.

if (!m_pResource->current.texture)
return {};

CRegion damage = m_pResource->current.accumulateBufferDamage();
CRegion damage = m_pResource->damageSinceLastRender;
m_pResource->damageSinceLastRender.clear();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is incredibly unintuitive and not documented

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's already documented in the comment I added to computeRenderDamage in the .hpp. Should I rename the method or add additional documentation?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just not do this. Why? Maybe add another method to explicitly clear render damage

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I forgot about this. I added the separate method.

@PlasmaPower
Copy link
Contributor Author

Actually I don't think this is necessary, because it looks like the surface should be damaged per commit not per render

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants