Repository: microsoft/terminal
File: src/renderer/atlas/common.h (C/C++)

Code before:
        // The background part is in premultiplied alpha, whereas the foreground part is in straight
        // alpha. This is mostly because of Direct2D being annoying, as the former is the only thing
        // it supports for bitmaps, whereas the latter is the only thing it supports for text.
        // Since we implement Direct2D's text blending algorithm, we're equally dependent on
        // straight alpha for BackendD3D, as straight alpha is used in the pixel shader there.
        Buffer<u32, 32> colorBitmap;
        // This exists as a convenience access to colorBitmap and
        // contains a view into the background color bitmap.
        std::span<u32> backgroundBitmap;
        // This exists as a convenience access to colorBitmap and
        // contains a view into the foreground color bitmap.
        std::span<u32> foregroundBitmap;
        // This stride of the colorBitmap is a "count" of u32 and not in bytes.
        size_t colorBitmapRowStride = 0;
        // FYI depth refers to the `colorBitmapRowStride * height` size of each bitmap contained
        // in colorBitmap. colorBitmap contains 2 bitmaps (background and foreground colors).
        size_t colorBitmapDepthStride = 0;
        // A generation of 1 ensures that the backends redraw the background on the first Present().
        // The 1st entry in this array corresponds to the background and the 2nd to the foreground bitmap.
        std::array<til::generation_t, 2> colorBitmapGenerations{ 1, 1 };
        // In columns/rows.
        til::rect cursorRect;
        // The viewport/SwapChain area to be presented. In pixel.
        // NOTE:
        //   This can not use til::rect, because til::rect is constrained to
        //   positive coordinates only, but this one can go out of bounds.
        i32r dirtyRectInPx{};
        // In rows.
        range<u16> invalidatedRows{};
        // In pixel.
        i16 scrollOffset = 0;

        void MarkAllAsDirty() noexcept
        {
            dirtyRectInPx = { 0, 0, s->targetSize.x, s->targetSize.y };
            invalidatedRows = { 0, s->cellCount.y };
            scrollOffset = 0;
        }
    };

    struct IBackend
    {
        virtual ~IBackend() = default;
        virtual void ReleaseResources() noexcept = 0;
        virtual void Render(RenderingPayload& payload) = 0;
        virtual bool RequiresContinuousRedraw() noexcept = 0;
    };
}


Review comment (suggestion):
> because `til::rect` is constrained to positive coordinates only

wait, that's not true though, right? I thought it was 4 `int32_t`'s

Code after:
        // The background part is in premultiplied alpha, whereas the foreground part is in straight
        // alpha. This is mostly because of Direct2D being annoying, as the former is the only thing
        // it supports for bitmaps, whereas the latter is the only thing it supports for text.
        // Since we implement Direct2D's text blending algorithm, we're equally dependent on
        // straight alpha for BackendD3D, as straight alpha is used in the pixel shader there.
        Buffer<u32, 32> colorBitmap;
        // This exists as a convenience access to colorBitmap and
        // contains a view into the background color bitmap.
        std::span<u32> backgroundBitmap;
        // This exists as a convenience access to colorBitmap and
        // contains a view into the foreground color bitmap.
        std::span<u32> foregroundBitmap;
        // This stride of the colorBitmap is a "count" of u32 and not in bytes.
        size_t colorBitmapRowStride = 0;
        // FYI depth refers to the `colorBitmapRowStride * height` size of each bitmap contained
        // in colorBitmap. colorBitmap contains 2 bitmaps (background and foreground colors).
        size_t colorBitmapDepthStride = 0;
        // A generation of 1 ensures that the backends redraw the background on the first Present().
        // The 1st entry in this array corresponds to the background and the 2nd to the foreground bitmap.
        std::array<til::generation_t, 2> colorBitmapGenerations{ 1, 1 };
        // In columns/rows.
        til::rect cursorRect;
        // The viewport/SwapChain area to be presented. In pixel.
        // NOTE:
        //   This cannot use til::rect, because til::rect generally expects positive coordinates only
        //   (`operator!()` checks for negative values), whereas this one can go out of bounds,
        //   whenever glyphs go out of bounds. `AtlasEngine::_present()` will clamp it.
        i32r dirtyRectInPx{};
        // In rows.
        range<u16> invalidatedRows{};
        // In pixel.
        i16 scrollOffset = 0;

        void MarkAllAsDirty() noexcept
        {
            dirtyRectInPx = { 0, 0, s->targetSize.x, s->targetSize.y };
            invalidatedRows = { 0, s->cellCount.y };
            scrollOffset = 0;
        }
    };

    struct IBackend
    {
        virtual ~IBackend() = default;
        virtual void ReleaseResources() noexcept = 0;
        virtual void Render(RenderingPayload& payload) = 0;
        virtual bool RequiresContinuousRedraw() noexcept = 0;
    };
}