Skip to content

Commit

Permalink
Added abstract memory manager to be able to allocate a framebuffer la…
Browse files Browse the repository at this point in the history
…yer in the RISC OS RMA and still maintain compatibility with Linux for HW acelleration via cluster
  • Loading branch information
pzaino committed Feb 29, 2024
1 parent 9a91aa2 commit c38ff86
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 7 deletions.
8 changes: 7 additions & 1 deletion src/cpp/layer
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,18 @@
* please refer to the official license documentation.
*/

#include <memory> // For std::shared_ptr

#include "mem_manager.hpp"
#include "layer.hpp"

// Constructor implementation
Layer::Layer(pixel_t width, pixel_t height, std::shared_ptr<RenderStrategy> 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<color_t*>(memoryManager->allocate(width * height * sizeof(color_t)));

}

// Destructor implementation
Expand Down
14 changes: 8 additions & 6 deletions src/hpp/layer
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,22 @@
#include <cstdint>
#include <memory> // 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<RenderStrategy> currentRenderStrategy;

public:
std::vector<color_t> 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<RenderStrategy> strategy);
Expand Down
34 changes: 34 additions & 0 deletions src/hpp/mem_manager
Original file line number Diff line number Diff line change
@@ -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 <cstddef>

// 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

0 comments on commit c38ff86

Please sign in to comment.