KiCad PCB EDA Suite
KIGFX::NONCACHED_CONTAINER Class Reference

#include <noncached_container.h>

Inheritance diagram for KIGFX::NONCACHED_CONTAINER:
KIGFX::VERTEX_CONTAINER

Public Member Functions

 NONCACHED_CONTAINER (unsigned int aSize=defaultInitSize)
 
virtual ~NONCACHED_CONTAINER ()
 
virtual void SetItem (VERTEX_ITEM *aItem) override
 Function SetItem() sets the item in order to modify or finishes its current modifications. More...
 
virtual VERTEXAllocate (unsigned int aSize) override
 Function Allocate() returns allocated space (possibly resizing the used memory chunk or allocating a new chunk if it was not stored before) for the given number of vertices associated with the current item (set by SetItem()). More...
 
void Delete (VERTEX_ITEM *aItem) override
 Function Delete() erases the selected item. More...
 
virtual void Clear () override
 Function Clear() removes all the data stored in the container and restores its original state. More...
 
virtual unsigned int GetSize () const override
 Function GetSize() returns amount of vertices currently stored in the container. More...
 
virtual void Map ()
 Function Map() prepares the container for vertices updates. More...
 
virtual void Unmap ()
 Function Unmap() finishes the vertices updates stage. More...
 
virtual void FinishItem ()
 Function FinishItem() does the cleaning after adding an item. More...
 
virtual VERTEXGetAllVertices () const
 Function GetAllVertices() returns all the vertices stored in the container. More...
 
virtual VERTEXGetVertices (unsigned int aOffset) const
 Function GetVertices() returns vertices stored at the specific offset. More...
 
bool IsDirty ()
 Function IsDirty() returns information about container cache state. More...
 
void SetDirty ()
 Function SetDirty() sets the dirty flag, so vertices in the container are going to be reuploaded to the GPU on the next frame. More...
 

Static Public Member Functions

static VERTEX_CONTAINERMakeContainer (bool aCached)
 Function MakeContainer() Returns a pointer to a new container of an appropriate type. More...
 

Protected Member Functions

unsigned int usedSpace () const
 Function usedSpace() returns size of the used memory space. More...
 

Protected Attributes

unsigned int m_freePtr
 < Index of the free first space where a vertex can be stored More...
 
unsigned int m_freeSpace
 How big is the current container, expressed in vertices. More...
 
unsigned int m_currentSize
 Store the initial size, so it can be resized to this on Clear() More...
 
unsigned int m_initialSize
 Actual storage memory (should be handled using malloc/realloc/free to speed up resizing) More...
 
VERTEXm_vertices
 State flags. More...
 
bool m_failed
 
bool m_dirty
 

Static Protected Attributes

static const unsigned int defaultInitSize = 1048576
 

Detailed Description

Definition at line 41 of file noncached_container.h.

Constructor & Destructor Documentation

NONCACHED_CONTAINER::NONCACHED_CONTAINER ( unsigned int  aSize = defaultInitSize)

Definition at line 37 of file noncached_container.cpp.

References KIGFX::VERTEX_CONTAINER::m_vertices.

37  :
38  VERTEX_CONTAINER( aSize ), m_freePtr( 0 )
39 {
40  m_vertices = static_cast<VERTEX*>( malloc( aSize * sizeof( VERTEX ) ) );
41  memset( m_vertices, 0x00, aSize * sizeof( VERTEX ) );
42 }
unsigned int m_freePtr
< Index of the free first space where a vertex can be stored
VERTEX * m_vertices
State flags.
VERTEX_CONTAINER(unsigned int aSize=defaultInitSize)
How many vertices we can store in the container.
NONCACHED_CONTAINER::~NONCACHED_CONTAINER ( )
virtual

Definition at line 45 of file noncached_container.cpp.

References KIGFX::VERTEX_CONTAINER::m_vertices.

46 {
47  free( m_vertices );
48 }
VERTEX * m_vertices
State flags.

Member Function Documentation

VERTEX * NONCACHED_CONTAINER::Allocate ( unsigned int  aSize)
overridevirtual

Function Allocate() returns allocated space (possibly resizing the used memory chunk or allocating a new chunk if it was not stored before) for the given number of vertices associated with the current item (set by SetItem()).

The newly allocated space is added at the end of the chunk used by the current item and may serve to store new vertices.

Parameters
aSizeis the number of vertices to be allocated.
Returns
Pointer to the allocated space or NULL in case of failure.

Implements KIGFX::VERTEX_CONTAINER.

Definition at line 58 of file noncached_container.cpp.

References KIGFX::VERTEX_CONTAINER::m_currentSize, m_freePtr, KIGFX::VERTEX_CONTAINER::m_freeSpace, and KIGFX::VERTEX_CONTAINER::m_vertices.

59 {
60  if( m_freeSpace < aSize )
61  {
62  // Double the space
63  VERTEX* newVertices = static_cast<VERTEX*>( realloc( m_vertices,
64  m_currentSize * 2 *
65  sizeof(VERTEX) ) );
66 
67  if( newVertices != NULL )
68  {
69  m_vertices = newVertices;
71  m_currentSize *= 2;
72  }
73  else
74  {
75  return NULL;
76  }
77  }
78 
79  VERTEX* freeVertex = &m_vertices[m_freePtr];
80 
81  // Move to the next free chunk
82  m_freePtr += aSize;
83  m_freeSpace -= aSize;
84 
85  return freeVertex;
86 }
unsigned int m_freePtr
< Index of the free first space where a vertex can be stored
unsigned int m_currentSize
Store the initial size, so it can be resized to this on Clear()
VERTEX * m_vertices
State flags.
unsigned int m_freeSpace
How big is the current container, expressed in vertices.
void NONCACHED_CONTAINER::Clear ( )
overridevirtual

Function Clear() removes all the data stored in the container and restores its original state.

Implements KIGFX::VERTEX_CONTAINER.

Definition at line 89 of file noncached_container.cpp.

References KIGFX::VERTEX_CONTAINER::m_currentSize, m_freePtr, and KIGFX::VERTEX_CONTAINER::m_freeSpace.

90 {
91  m_freePtr = 0;
93 }
unsigned int m_freePtr
< Index of the free first space where a vertex can be stored
unsigned int m_currentSize
Store the initial size, so it can be resized to this on Clear()
unsigned int m_freeSpace
How big is the current container, expressed in vertices.
void KIGFX::NONCACHED_CONTAINER::Delete ( VERTEX_ITEM aItem)
inlineoverridevirtual

Function Delete() erases the selected item.

Parameters
aItemis the item to be erased.

Implements KIGFX::VERTEX_CONTAINER.

Definition at line 54 of file noncached_container.h.

54 {}
virtual void KIGFX::VERTEX_CONTAINER::FinishItem ( )
inlinevirtualinherited

Function FinishItem() does the cleaning after adding an item.

Reimplemented in KIGFX::CACHED_CONTAINER.

Definition at line 75 of file vertex_container.h.

75 {};
virtual VERTEX* KIGFX::VERTEX_CONTAINER::GetAllVertices ( ) const
inlinevirtualinherited

Function GetAllVertices() returns all the vertices stored in the container.

It is especially useful for transferring data to the GPU memory.

Definition at line 107 of file vertex_container.h.

References KIGFX::VERTEX_CONTAINER::m_vertices.

Referenced by KIGFX::GPU_NONCACHED_MANAGER::EndDrawing().

108  {
109  return m_vertices;
110  }
VERTEX * m_vertices
State flags.
virtual unsigned int KIGFX::NONCACHED_CONTAINER::GetSize ( ) const
inlineoverridevirtual

Function GetSize() returns amount of vertices currently stored in the container.

Reimplemented from KIGFX::VERTEX_CONTAINER.

Definition at line 60 of file noncached_container.h.

References m_freePtr.

61  {
62  // As the m_freePtr points to the first free space, we can safely assume
63  // that this is the number of vertices stored inside
64  return m_freePtr;
65  }
unsigned int m_freePtr
< Index of the free first space where a vertex can be stored
virtual VERTEX* KIGFX::VERTEX_CONTAINER::GetVertices ( unsigned int  aOffset) const
inlinevirtualinherited

Function GetVertices() returns vertices stored at the specific offset.

Parameters
aOffsetis the offset.

Definition at line 117 of file vertex_container.h.

References KIGFX::VERTEX_CONTAINER::m_vertices.

118  {
119  return &m_vertices[aOffset];
120  }
VERTEX * m_vertices
State flags.
bool KIGFX::VERTEX_CONTAINER::IsDirty ( )
inlineinherited

Function IsDirty() returns information about container cache state.

Clears the flag after calling the function.

Returns
true in case the vertices have to be reuploaded.

Definition at line 136 of file vertex_container.h.

References KIGFX::VERTEX_CONTAINER::m_dirty.

Referenced by KIGFX::GPU_CACHED_MANAGER::BeginDrawing().

137  {
138  bool state = m_dirty;
139 
140  m_dirty = false;
141 
142  return state;
143  }
VERTEX_CONTAINER * VERTEX_CONTAINER::MakeContainer ( bool  aCached)
staticinherited

Function MakeContainer() Returns a pointer to a new container of an appropriate type.

Definition at line 37 of file vertex_container.cpp.

Referenced by KIGFX::VERTEX_MANAGER::VERTEX_MANAGER().

38 {
39  if( aCached )
40  return new CACHED_CONTAINER;
41  else
42  return new NONCACHED_CONTAINER;
43 }
virtual void KIGFX::VERTEX_CONTAINER::Map ( )
inlinevirtualinherited

Function Map() prepares the container for vertices updates.

Reimplemented in KIGFX::CACHED_CONTAINER.

Definition at line 55 of file vertex_container.h.

55 {}
void KIGFX::VERTEX_CONTAINER::SetDirty ( )
inlineinherited

Function SetDirty() sets the dirty flag, so vertices in the container are going to be reuploaded to the GPU on the next frame.

Definition at line 150 of file vertex_container.h.

References KIGFX::VERTEX_CONTAINER::m_dirty.

151  {
152  m_dirty = true;
153  }
void NONCACHED_CONTAINER::SetItem ( VERTEX_ITEM aItem)
overridevirtual

Function SetItem() sets the item in order to modify or finishes its current modifications.

Parameters
aItemis the item or NULL in case of finishing the item.

Implements KIGFX::VERTEX_CONTAINER.

Definition at line 51 of file noncached_container.cpp.

52 {
53  // Nothing has to be done, as the noncached container
54  // does not care about VERTEX_ITEMs ownership
55 }
virtual void KIGFX::VERTEX_CONTAINER::Unmap ( )
inlinevirtualinherited

Function Unmap() finishes the vertices updates stage.

Reimplemented in KIGFX::CACHED_CONTAINER.

Definition at line 61 of file vertex_container.h.

62  {}
unsigned int KIGFX::VERTEX_CONTAINER::usedSpace ( ) const
inlineprotectedinherited

Function usedSpace() returns size of the used memory space.

Returns
Size of the used memory space (expressed as a number of vertices).Default initial size of a container (expressed in vertices)

Definition at line 179 of file vertex_container.h.

References KIGFX::VERTEX_CONTAINER::m_freeSpace.

Referenced by KIGFX::CACHED_CONTAINER::defragmentResize(), KIGFX::CACHED_CONTAINER::defragmentResizeMemcpy(), and KIGFX::CACHED_CONTAINER::test().

Member Data Documentation

const unsigned int KIGFX::VERTEX_CONTAINER::defaultInitSize = 1048576
staticprotectedinherited

Definition at line 185 of file vertex_container.h.

bool KIGFX::VERTEX_CONTAINER::m_dirty
protectedinherited
bool KIGFX::VERTEX_CONTAINER::m_failed
protectedinherited
unsigned int KIGFX::NONCACHED_CONTAINER::m_freePtr
protected

< Index of the free first space where a vertex can be stored

Definition at line 69 of file noncached_container.h.

Referenced by Allocate(), Clear(), and GetSize().

unsigned int KIGFX::VERTEX_CONTAINER::m_initialSize
protectedinherited

Actual storage memory (should be handled using malloc/realloc/free to speed up resizing)

Definition at line 165 of file vertex_container.h.

Referenced by KIGFX::CACHED_CONTAINER::Delete().


The documentation for this class was generated from the following files: