/*---------------------------------------------------------------------------* Project: Horizon File: MemoryManager.h Copyright (C)2009-2012 Nintendo Co., Ltd. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. $Rev: 46365 $ *---------------------------------------------------------------------------*/ #ifndef DEMO_MEMORY_MANAGER_H_ #define DEMO_MEMORY_MANAGER_H_ #include namespace demo { namespace detail { /*! @brief Class that manages memory regions allocated for graphics. Allocates or releases regions in main memory or VRAM as needed. */ class MemoryManager : private nn::util::NonCopyable { public: /*! @brief Constructor. */ MemoryManager(void); /*! @brief Destructor. */ virtual ~MemoryManager(); /*! @brief Initializes the memory manager class. Using the memory region specified by the parameters, allocates the buffers needed for DMPGL initialization and rendering. This function must be called once before use. Starting from the second call, all further calls are ignored if the class was not destroyed by Finalize function. @param[in] fcramAddress Start address of the memory region in FCRAM used for graphics @param[in] memorySize Size of the memory region used for graphics */ void Initialize(const uptr fcramAddress, const size_t memorySize); /*! @brief Finalizes the memory manager class. */ void Finalize(void); /*! @brief This allocates a memory region managed by this class. @param[in] area Memory region to allocate @param[in] aim Purpose of the allocated buffer @param[in] id ID of the buffer to allocate @param[in] size Size of the buffer to allocate @return Returns the address of the allocated buffer. */ void* Allocate(GLenum area, GLenum aim, GLuint id, GLsizei size); /*! @brief Frees the memory region allocated by this class. Note that the region is not freed if the area parameter specifies VRAM. @param[in] area Memory region that contains the buffer to free @param[in] aim Purpose of the buffer to free @param[in] id ID of the buffer to free @param[in] addr Address of the buffer to free */ void Deallocate(GLenum area, GLenum aim, GLuint id, void* addr); /*! @brief The current free capacity and maximum capacity of main memory and VRAM are sent to debug output. */ void PrintFreeMemorySize(void); private: bool m_Initialized; u8 m_Pad[3]; uptr m_pStartAddrFcram; uptr m_CurrentAddrVramA; uptr m_CurrentAddrVramB; nn::fnd::ExpHeap m_HeapOnFcram; size_t m_AllocatedBlockSize; public: bool m_DebugPrint; NN_PADDING3; }; } // namespace detail /*! @brief Initializes the memory manager class. @param[in] fcramAddress Start address of the memory region in FCRAM used for graphics @param[in] memorySize Size of the memory region used for graphics */ void InitializeMemoryManager(const uptr fcramAddress, const size_t memorySize); /*! @brief Terminate the memory manager. */ void FinalizeMemoryManager(void); /*! @brief The current free capacity and maximum capacity of main memory and VRAM are sent to debug output. */ void PrintMemoryManagerInfo(void); /*! @brief Memory allocator specified in the parameter to the nngxInitialize function @param[in] area Memory region to allocate @param[in] aim Purpose of the allocated buffer @param[in] id ID of the buffer to allocate @param[in] size Size of the buffer to allocate @return Returns the address of the allocated buffer. */ void* GetAllocator(GLenum area, GLenum aim, GLuint id, GLsizei size); /*! @brief Memory deallocator specified as an argument to the nngxInitialize function @param[in] area Memory region that contains the buffer to free @param[in] aim Purpose of the buffer to free @param[in] id ID of the buffer to free @param[in] addr Address of the buffer to free */ void GetDeallocator(GLenum area, GLenum aim, GLuint id, void* addr); /*! @brief Function that allocates the buffer from the heap in main memory managed by the memory manager :private For internal processing by the demo library. Call the allocator as a system application. @param[in] size Size of the buffer to allocate @return Returns the address of the allocated buffer. */ void* Alloc(size_t size); void* Alloc(GLenum aim, const size_t size); void* Alloc(GLenum area, GLenum aim, const size_t size); /*! @brief Free the buffer allocated from the heap in main memory. :private For internal processing by the demo library. @param[in] Address of the buffer to free */ void Free(void* ptr); } #endif