#pragma once #if !defined(BAD_APPLE_OS_DRAW_HPP_INCLUDED) #define BAD_APPLE_OS_DRAW_HPP_INCLUDED #include #include namespace draw { const unsigned SIZE_FULL = static_cast(-1); struct Pixel { uint8_t blue = 0; uint8_t green = 0; uint8_t red = 0; uint8_t reserved_ = 0; }; class Framebuffer { protected: Pixel* mBase = nullptr; unsigned mWidth = 0; unsigned mHeight = 0; unsigned mPitch = 0; public: Framebuffer() = default; Framebuffer(const Framebuffer&) = default; Framebuffer(Pixel* base, unsigned width, unsigned height, unsigned pitch) noexcept : mBase(base), mWidth(width), mHeight(height), mPitch(pitch) {} [[nodiscard]] Pixel* getBase() const noexcept { return mBase; } [[nodiscard]] unsigned getWidth() const noexcept { return mWidth; } [[nodiscard]] unsigned getHeight() const noexcept { return mHeight; } [[nodiscard]] unsigned getPitch() const noexcept { return mPitch; } [[nodiscard]] unsigned getBufferSize() const noexcept { return mPitch * mHeight * sizeof(Pixel); } void setPixel(unsigned posX, unsigned posY, Pixel pixel) noexcept; }; class OwningFramebuffer : public Framebuffer { private: std::vector mPixels; public: OwningFramebuffer() = default; OwningFramebuffer(const OwningFramebuffer&) noexcept = default; OwningFramebuffer(OwningFramebuffer&&) noexcept = default; OwningFramebuffer(unsigned width, unsigned height, unsigned pitch) noexcept; OwningFramebuffer& operator=(const OwningFramebuffer&) noexcept = default; OwningFramebuffer& operator=(OwningFramebuffer&&) noexcept = default; static OwningFramebuffer makeFrom(const Framebuffer& other) noexcept { return OwningFramebuffer(other.getWidth(), other.getHeight(), other.getPitch()); } }; void initializeDefaultFramebuffer(const Framebuffer& framebuffer) noexcept; void setPixelDirect(unsigned posX, unsigned posY, Pixel pixel) noexcept; void setPixel(unsigned posX, unsigned posY, Pixel pixel) noexcept; void flushPixels() noexcept; } #endif // !defined(BAD_APPLE_OS_FRAMEBUFFER_HPP_INCLUDED)