Repository: hyprwm/Hyprland
File: src/protocols/types/SurfaceState.cpp (C++)

Code before:
    Vector2D trc = transform % 2 == 1 ? Vector2D{bufferSize.y, bufferSize.x} : bufferSize;

    bufferDamage = surfaceDamage.scale(scale).transform(wlTransformToHyprutils(invertTransform(transform)), trc.x, trc.y).add(bufferDamage);
    damage.clear();
    return bufferDamage;
}

void SSurfaceState::updateSynchronousTexture(SP<CTexture> lastTexture) {
    auto [dataPtr, fmt, size] = buffer->buffer->beginDataPtr(0);
    if (dataPtr) {
        auto drmFmt = NFormatUtils::shmToDRM(fmt);
        auto stride = bufferSize.y ? size / bufferSize.y : 0;
        if (lastTexture && lastTexture->m_isSynchronous && lastTexture->m_vSize == bufferSize) {
            texture = lastTexture;
            texture->update(drmFmt, dataPtr, stride, accumulateBufferDamage());
        } else
            texture = makeShared<CTexture>(drmFmt, dataPtr, stride, bufferSize);
    }
    buffer->buffer->endDataPtr();
}

void SSurfaceState::reset() {
    damage.clear();
    bufferDamage.clear();
    transform = WL_OUTPUT_TRANSFORM_NORMAL;
    scale     = 1;
    offset    = {};
    size      = {};
}

void SSurfaceState::updateFrom(SSurfaceState& ref) {
    updated = ref.updated;

    if (ref.updated & SURFACE_UPDATED_BUFFER) {
        ref.updated &= ~SURFACE_UPDATED_BUFFER;
        *this = ref;
        ref.damage.clear();
        ref.bufferDamage.clear();
        ref.buffer.reset();
    } else {
        if (ref.updated & SURFACE_UPDATED_DAMAGE) {
            damage       = ref.damage;
            bufferDamage = ref.bufferDamage;
        }

        if (ref.updated & SURFACE_UPDATED_INPUT)
            input = ref.input;

        if (ref.updated & SURFACE_UPDATED_OPAQUE)
            opaque = ref.opaque;


Review comment (suggestion):
who said so? I've seen apps that do:
```
attach buffer
commit
set scale 
set something
commit
attach buffer 2 
commit
...
```

Code after:
    Vector2D trc = transform % 2 == 1 ? Vector2D{bufferSize.y, bufferSize.x} : bufferSize;

    bufferDamage = surfaceDamage.scale(scale).transform(wlTransformToHyprutils(invertTransform(transform)), trc.x, trc.y).add(bufferDamage);
    damage.clear();
    return bufferDamage;
}

void SSurfaceState::updateSynchronousTexture(SP<CTexture> lastTexture) {
    auto [dataPtr, fmt, size] = buffer->beginDataPtr(0);
    if (dataPtr) {
        auto drmFmt = NFormatUtils::shmToDRM(fmt);
        auto stride = bufferSize.y ? size / bufferSize.y : 0;
        if (lastTexture && lastTexture->m_isSynchronous && lastTexture->m_vSize == bufferSize) {
            texture = lastTexture;
            texture->update(drmFmt, dataPtr, stride, accumulateBufferDamage());
        } else
            texture = makeShared<CTexture>(drmFmt, dataPtr, stride, bufferSize);
    }
    buffer->endDataPtr();
}

void SSurfaceState::reset() {
    updated.all = false;

    // After commit, there is no pending buffer until the next attach.
    buffer = {};

    // applies only to the buffer that is attached to the surface
    acquire = {};

    // wl_surface.commit assings pending ... and clears pending damage.
    damage.clear();
    bufferDamage.clear();
}

void SSurfaceState::updateFrom(SSurfaceState& ref) {
    updated = ref.updated;

    if (ref.updated.buffer) {
        buffer     = ref.buffer;
        texture    = ref.texture;
        size       = ref.size;
        bufferSize = ref.bufferSize;
    }

    if (ref.updated.damage) {
        damage       = ref.damage;
        bufferDamage = ref.bufferDamage;
    }

    if (ref.updated.input)