diff --git a/src/cpp/layer b/src/cpp/layer index fbd11ba..01f3c03 100644 --- a/src/cpp/layer +++ b/src/cpp/layer @@ -18,12 +18,18 @@ * please refer to the official license documentation. */ +#include // For std::shared_ptr + +#include "mem_manager.hpp" #include "layer.hpp" // Constructor implementation Layer::Layer(pixel_t width, pixel_t height, std::shared_ptr strategy) : width(width), height(height), opacity(1.0f), visible(true), currentRenderStrategy(strategy) { - pixels.resize(width * height, 0); // Initialize pixel buffer with default color (0) + + // Initialize pixel buffer with default color (0) + pixels = static_cast(memoryManager->allocate(width * height * sizeof(color_t))); + } // Destructor implementation diff --git a/src/hpp/layer b/src/hpp/layer index 0e1fafc..f5c3e43 100644 --- a/src/hpp/layer +++ b/src/hpp/layer @@ -25,20 +25,22 @@ #include #include // For std::shared_ptr +#include "mem_manager.hpp" #include "render_strategy.hpp" typedef uint32_t color_t; // 32-bit color typedef uint32_t pixel_t; // 32-bit pixel, assuming it represents dimensions class Layer { -private: + private: std::shared_ptr currentRenderStrategy; -public: - std::vector pixels; // Pixel data for this layer - float opacity; // Layer opacity - bool visible; // Layer visibility - pixel_t width, height; // Dimensions of the layer + public: + color_t* pixels; // The actual layer is defined by MemoryManager interface + float opacity; // Layer opacity + bool visible; // Layer visibility + pixel_t width; // horizontal dimension of the layer + pixel_t height; // vertical dimension of the layer // Constructor and destructor Layer(pixel_t width, pixel_t height, std::shared_ptr strategy); diff --git a/src/hpp/mem_manager b/src/hpp/mem_manager new file mode 100644 index 0000000..7751b81 --- /dev/null +++ b/src/hpp/mem_manager @@ -0,0 +1,34 @@ +/* + * This file is part of: + * MicroFB, a minimal framebuffer library for RISC OS + * + * Description: + * This project aims to provide a simple and efficient way to manage + * the framebuffer on RISC OS using C++11. It abstracts the direct + * interaction with the GraphicsV API, offering a higher-level + * interface for drawing operations and framebuffer manipulation. + * + * Author: + * Paolo Fabio Zaino, all rights reserved. + * Distributed under License: + * CDDL v1.1 (Common Development and Distribution License Version + * 1.1) The use of this project is subject to the terms of the + * CDDL v1.1. This project can be used and distributed according + * to the terms of this license. For details on the CDDL v1.1, + * please refer to the official license documentation. + */ + +#ifndef MEMMANAGER_HPP +#define MEMMANAGER_HPP + +#include + +// Abstracted memory manager interface +class MemoryManager { + public: + virtual ~MemoryManager() {} + virtual void* allocate(size_t size) = 0; + virtual void deallocate(void* memory) = 0; +}; + +#endif // MEMMANAGER_HPP