Interface ILspGLResourceCache

All Superinterfaces:
ILcdMultiKeyMap<Object,ALspGLResource>, Map<Object,ALspGLResource>

public interface ILspGLResourceCache extends ILcdMultiKeyMap<Object,ALspGLResource>
Cache that stores OpenGL resource objects. When storing a resource object, the cache becomes its owner and can freely destroy and remove the resource when needed.

Storing a new entry in the cache can result in the removal and destruction of one or more existing entries due to size limitations (getMaxBytes()). Bound ALspGLResource are never removed. Since using the cache can result in a call to destroy, this cache can only be accessed from the painting thread.

This cache uses the tree-like multi-key mechanism from ILcdMultiKeyMap that allows storage and retrieval of OpenGL resource objects by a sequence of keys. This facilitates removal of multiple resources at once by removing an entire branch of the cache tree for example. See ILcdMultiKeyMap for a detailed description of the workings of a multi-key map. The resource cache is not thread-safe and should only be accessed from the painting thread.

Since:
2012.0
See Also:
  • Method Details

    • destroy

      void destroy(ILcdGLDrawable aGLDrawable)
      Frees all resources stored in the cache.
      Parameters:
      aGLDrawable - drawable
    • getResourceCount

      int getResourceCount()
      Gets the number of resources stored in the cache.
      Returns:
      the number of resources stored in the cache
    • getBytes

      long getBytes()
      Gets the sum of the total number of bytes allocated by the resources stored in the cache.
      Returns:
      the total number of bytes held by resources stored in the cache.
    • getBytes

      long getBytes(String aSourceString)
      Gets the sum of the total number of bytes allocated by the resources stored in the cache for the given identifier.
      Parameters:
      aSourceString - the identifier for which the memory usage is queried
      Returns:
      the total number of bytes held by resources stored in the cache for the given identifier
    • getMaxBytes

      long getMaxBytes()
      Gets the maximal number of bytes that can be stored in this cache.
      Returns:
      the maximal number of bytes that can be stored in this cache
    • getSourceStringsInDecreasingOrder

      Collection<String> getSourceStringsInDecreasingOrder()
      Gets the resources' source strings sorted in decreasing bytes usage orders. The source with the most bytes occupied in the cache is the first in the returned collection, the one with the least bytes occupied the last. This list can be useful for debugging purposes.
      Returns:
      the source string identifiers of resources stored in the cache in decreasing bytes usage order.
    • addCacheListener

      void addCacheListener(ILspGLResourceCacheListener aListener)
      Adds the given listener so that it gets notified of key resource events (addition, usage, removal).

      It is highly discouraged to add listeners to the GL resource cache for production purposes since this may result in the generation of a large amount of TLspGLResourceCacheEvent objects. However, it can be useful during monitoring or debugging.

      Parameters:
      aListener - the listener
    • removeCacheListener

      void removeCacheListener(ILspGLResourceCacheListener aListener)
      Removes the given listener so that it stops being notified of resource events.
      Parameters:
      aListener - the listener to remove.
    • getBranch

      ILspGLResourceCache getBranch(Object[] aKeys)
      Description copied from interface: ILcdMultiKeyMap
      Returns the branch that is associated with the given key, or null if the branch does not exist.
      Specified by:
      getBranch in interface ILcdMultiKeyMap<Object,ALspGLResource>
      Parameters:
      aKeys - the key
      Returns:
      the branch associated with the given key, can be null if a branch does not exist.
      See Also:
    • getOrCreateBranch

      ILspGLResourceCache getOrCreateBranch(Object[] aKeys)
      Description copied from interface: ILcdMultiKeyMap
      Creates and returns a new branch for the given key. A new branch (or sub-branch) is only created when necessary.
      Specified by:
      getOrCreateBranch in interface ILcdMultiKeyMap<Object,ALspGLResource>
      Parameters:
      aKeys - the key
      Returns:
      the branch associated with the given key. This method never returns null.
    • branchEntrySet

      Set<? extends Map.Entry<Object,? extends ILspGLResourceCache>> branchEntrySet()
      Description copied from interface: ILcdMultiKeyMap
      Gets the entries of this branch's branch map.
      Specified by:
      branchEntrySet in interface ILcdMultiKeyMap<Object,ALspGLResource>
      Returns:
      the branch entry set
    • branchValues

      Collection<? extends ILspGLResourceCache> branchValues()
      Description copied from interface: ILcdMultiKeyMap
      Gets the values of this branch's leaf map.
      Specified by:
      branchValues in interface ILcdMultiKeyMap<Object,ALspGLResource>
      Returns:
      the branch value set