renderer: use CRegion foreach over getRects (#10980)

instead of allocating and returning a vector, use forEach to directly
call a function on the rects.
This commit is contained in:
Tom Englund
2025-07-30 11:54:09 +02:00
committed by GitHub
parent 43966cc787
commit 36a8b2226f
4 changed files with 37 additions and 41 deletions

View File

@@ -606,14 +606,14 @@ void CWLSurfaceResource::updateCursorShm(CRegion damage) {
if (const auto RECTS = damage.getRects(); RECTS.size() == 1 && RECTS.at(0).x2 == buf->size.x && RECTS.at(0).y2 == buf->size.y) if (const auto RECTS = damage.getRects(); RECTS.size() == 1 && RECTS.at(0).x2 == buf->size.x && RECTS.at(0).y2 == buf->size.y)
memcpy(shmData.data(), pixelData, bufLen); memcpy(shmData.data(), pixelData, bufLen);
else { else {
for (auto& box : damage.getRects()) { damage.forEachRect([&pixelData, &shmData](const auto& box) {
for (auto y = box.y1; y < box.y2; ++y) { for (auto y = box.y1; y < box.y2; ++y) {
// bpp is 32 INSALLAH // bpp is 32 INSALLAH
auto begin = 4 * box.y1 * (box.x2 - box.x1) + box.x1; auto begin = 4 * box.y1 * (box.x2 - box.x1) + box.x1;
auto len = 4 * (box.x2 - box.x1); auto len = 4 * (box.x2 - box.x1);
memcpy((uint8_t*)shmData.data() + begin, (uint8_t*)pixelData + begin, len); memcpy((uint8_t*)shmData.data() + begin, (uint8_t*)pixelData + begin, len);
} }
} });
} }
} }

View File

@@ -1273,10 +1273,10 @@ void CHyprOpenGLImpl::clear(const CHyprColor& color) {
glClearColor(color.r, color.g, color.b, color.a); glClearColor(color.r, color.g, color.b, color.a);
if (!m_renderData.damage.empty()) { if (!m_renderData.damage.empty()) {
for (auto const& RECT : m_renderData.damage.getRects()) { m_renderData.damage.forEachRect([this](const auto& RECT) {
scissor(&RECT); scissor(&RECT);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
} });
} }
scissor(nullptr); scissor(nullptr);
@@ -1429,16 +1429,16 @@ void CHyprOpenGLImpl::renderRectWithDamage(const CBox& box, const CHyprColor& co
damageClip.intersect(damage); damageClip.intersect(damage);
if (!damageClip.empty()) { if (!damageClip.empty()) {
for (auto const& RECT : damageClip.getRects()) { damageClip.forEachRect([this](const auto& RECT) {
scissor(&RECT); scissor(&RECT);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
} });
} }
} else { } else {
for (auto const& RECT : damage.getRects()) { damage.forEachRect([this](const auto& RECT) {
scissor(&RECT); scissor(&RECT);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
} });
} }
glBindVertexArray(0); glBindVertexArray(0);
@@ -1702,16 +1702,16 @@ void CHyprOpenGLImpl::renderTextureInternalWithDamage(SP<CTexture> tex, const CB
} }
if (!damageClip.empty()) { if (!damageClip.empty()) {
for (auto const& RECT : damageClip.getRects()) { damageClip.forEachRect([this](const auto& RECT) {
scissor(&RECT); scissor(&RECT);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
} });
} }
} else { } else {
for (auto const& RECT : damage.getRects()) { damage.forEachRect([this](const auto& RECT) {
scissor(&RECT); scissor(&RECT);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
} });
} }
glBindVertexArray(0); glBindVertexArray(0);
@@ -1746,10 +1746,10 @@ void CHyprOpenGLImpl::renderTexturePrimitive(SP<CTexture> tex, const CBox& box)
shader->setUniformInt(SHADER_TEX, 0); shader->setUniformInt(SHADER_TEX, 0);
glBindVertexArray(shader->uniformLocations[SHADER_SHADER_VAO]); glBindVertexArray(shader->uniformLocations[SHADER_SHADER_VAO]);
for (auto const& RECT : m_renderData.damage.getRects()) { m_renderData.damage.forEachRect([this](const auto& RECT) {
scissor(&RECT); scissor(&RECT);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
} });
scissor(nullptr); scissor(nullptr);
glBindVertexArray(0); glBindVertexArray(0);
@@ -1789,10 +1789,10 @@ void CHyprOpenGLImpl::renderTextureMatte(SP<CTexture> tex, const CBox& box, CFra
glBindVertexArray(shader->uniformLocations[SHADER_SHADER_VAO]); glBindVertexArray(shader->uniformLocations[SHADER_SHADER_VAO]);
for (auto const& RECT : m_renderData.damage.getRects()) { m_renderData.damage.forEachRect([this](const auto& RECT) {
scissor(&RECT); scissor(&RECT);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
} });
scissor(nullptr); scissor(nullptr);
glBindVertexArray(0); glBindVertexArray(0);
@@ -1885,10 +1885,10 @@ CFramebuffer* CHyprOpenGLImpl::blurFramebufferWithDamage(float a, CRegion* origi
glBindVertexArray(m_shaders->m_shBLURPREPARE.uniformLocations[SHADER_SHADER_VAO]); glBindVertexArray(m_shaders->m_shBLURPREPARE.uniformLocations[SHADER_SHADER_VAO]);
if (!damage.empty()) { if (!damage.empty()) {
for (auto const& RECT : damage.getRects()) { damage.forEachRect([this](const auto& RECT) {
scissor(&RECT, false /* this region is already transformed */); scissor(&RECT, false /* this region is already transformed */);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
} });
} }
glBindVertexArray(0); glBindVertexArray(0);
@@ -1927,10 +1927,10 @@ CFramebuffer* CHyprOpenGLImpl::blurFramebufferWithDamage(float a, CRegion* origi
glBindVertexArray(pShader->uniformLocations[SHADER_SHADER_VAO]); glBindVertexArray(pShader->uniformLocations[SHADER_SHADER_VAO]);
if (!pDamage->empty()) { if (!pDamage->empty()) {
for (auto const& RECT : pDamage->getRects()) { pDamage->forEachRect([this](const auto& RECT) {
scissor(&RECT, false /* this region is already transformed */); scissor(&RECT, false /* this region is already transformed */);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
} });
} }
glBindVertexArray(0); glBindVertexArray(0);
@@ -1988,10 +1988,10 @@ CFramebuffer* CHyprOpenGLImpl::blurFramebufferWithDamage(float a, CRegion* origi
glBindVertexArray(m_shaders->m_shBLURFINISH.uniformLocations[SHADER_SHADER_VAO]); glBindVertexArray(m_shaders->m_shBLURFINISH.uniformLocations[SHADER_SHADER_VAO]);
if (!damage.empty()) { if (!damage.empty()) {
for (auto const& RECT : damage.getRects()) { damage.forEachRect([this](const auto& RECT) {
scissor(&RECT, false /* this region is already transformed */); scissor(&RECT, false /* this region is already transformed */);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
} });
} }
glBindVertexArray(0); glBindVertexArray(0);
@@ -2347,16 +2347,16 @@ void CHyprOpenGLImpl::renderBorder(const CBox& box, const CGradientValueData& gr
damageClip.intersect(m_renderData.damage); damageClip.intersect(m_renderData.damage);
if (!damageClip.empty()) { if (!damageClip.empty()) {
for (auto const& RECT : damageClip.getRects()) { damageClip.forEachRect([this](const auto& RECT) {
scissor(&RECT); scissor(&RECT);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
} });
} }
} else { } else {
for (auto const& RECT : m_renderData.damage.getRects()) { m_renderData.damage.forEachRect([this](const auto& RECT) {
scissor(&RECT); scissor(&RECT);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
} });
} }
glBindVertexArray(0); glBindVertexArray(0);
@@ -2438,16 +2438,16 @@ void CHyprOpenGLImpl::renderBorder(const CBox& box, const CGradientValueData& gr
damageClip.intersect(m_renderData.damage); damageClip.intersect(m_renderData.damage);
if (!damageClip.empty()) { if (!damageClip.empty()) {
for (auto const& RECT : damageClip.getRects()) { damageClip.forEachRect([this](const auto& RECT) {
scissor(&RECT); scissor(&RECT);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
} });
} }
} else { } else {
for (auto const& RECT : m_renderData.damage.getRects()) { m_renderData.damage.forEachRect([this](const auto& RECT) {
scissor(&RECT); scissor(&RECT);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
} });
} }
glBindVertexArray(0); glBindVertexArray(0);
@@ -2508,16 +2508,16 @@ void CHyprOpenGLImpl::renderRoundedShadow(const CBox& box, int round, float roun
damageClip.intersect(m_renderData.damage); damageClip.intersect(m_renderData.damage);
if (!damageClip.empty()) { if (!damageClip.empty()) {
for (auto const& RECT : damageClip.getRects()) { damageClip.forEachRect([this](const auto& RECT) {
scissor(&RECT); scissor(&RECT);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
} });
} }
} else { } else {
for (auto const& RECT : m_renderData.damage.getRects()) { m_renderData.damage.forEachRect([this](const auto& RECT) {
scissor(&RECT); scissor(&RECT);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
} });
} }
glBindVertexArray(0); glBindVertexArray(0);

View File

@@ -1966,9 +1966,7 @@ void CHyprRenderer::damageBox(const int& x, const int& y, const int& w, const in
} }
void CHyprRenderer::damageRegion(const CRegion& rg) { void CHyprRenderer::damageRegion(const CRegion& rg) {
for (auto const& RECT : rg.getRects()) { rg.forEachRect([this](const auto& RECT) { damageBox(RECT.x1, RECT.y1, RECT.x2 - RECT.x1, RECT.y2 - RECT.y1); });
damageBox(RECT.x1, RECT.y1, RECT.x2 - RECT.x1, RECT.y2 - RECT.y1);
}
} }
void CHyprRenderer::damageMirrorsWith(PHLMONITOR pMonitor, const CRegion& pRegion) { void CHyprRenderer::damageMirrorsWith(PHLMONITOR pMonitor, const CRegion& pRegion) {

View File

@@ -118,14 +118,12 @@ void CTexture::update(uint32_t drmFormat, uint8_t* pixels, uint32_t stride, cons
bind(); bind();
auto rects = damage.copy().intersect(CBox{{}, m_size}).getRects();
if (format->flipRB) { if (format->flipRB) {
setTexParameter(GL_TEXTURE_SWIZZLE_R, GL_BLUE); setTexParameter(GL_TEXTURE_SWIZZLE_R, GL_BLUE);
setTexParameter(GL_TEXTURE_SWIZZLE_B, GL_RED); setTexParameter(GL_TEXTURE_SWIZZLE_B, GL_RED);
} }
for (auto const& rect : rects) { damage.copy().intersect(CBox{{}, m_size}).forEachRect([&format, &stride, &pixels](const auto& rect) {
GLCALL(glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, stride / format->bytesPerBlock)); GLCALL(glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, stride / format->bytesPerBlock));
GLCALL(glPixelStorei(GL_UNPACK_SKIP_PIXELS_EXT, rect.x1)); GLCALL(glPixelStorei(GL_UNPACK_SKIP_PIXELS_EXT, rect.x1));
GLCALL(glPixelStorei(GL_UNPACK_SKIP_ROWS_EXT, rect.y1)); GLCALL(glPixelStorei(GL_UNPACK_SKIP_ROWS_EXT, rect.y1));
@@ -133,7 +131,7 @@ void CTexture::update(uint32_t drmFormat, uint8_t* pixels, uint32_t stride, cons
int width = rect.x2 - rect.x1; int width = rect.x2 - rect.x1;
int height = rect.y2 - rect.y1; int height = rect.y2 - rect.y1;
GLCALL(glTexSubImage2D(GL_TEXTURE_2D, 0, rect.x1, rect.y1, width, height, format->glFormat, format->glType, pixels)); GLCALL(glTexSubImage2D(GL_TEXTURE_2D, 0, rect.x1, rect.y1, width, height, format->glFormat, format->glType, pixels));
} });
GLCALL(glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, 0)); GLCALL(glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, 0));
GLCALL(glPixelStorei(GL_UNPACK_SKIP_PIXELS_EXT, 0)); GLCALL(glPixelStorei(GL_UNPACK_SKIP_PIXELS_EXT, 0));