Lumiera  0.pre.03
»edit your freedom«
buffer-provider.hpp
Go to the documentation of this file.
1 /*
2  BUFFER-PROVIDER.hpp - Abstraction for Buffer management during playback/render
3 
4  Copyright (C) Lumiera.org
5  2011, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 */
22 
41 #ifndef STEAM_ENGINE_BUFFR_PROVIDER_H
42 #define STEAM_ENGINE_BUFFR_PROVIDER_H
43 
44 
45 #include "lib/error.hpp"
46 #include "lib/symbol.hpp"
47 #include "lib/hash-value.h"
51 #include "lib/nocopy.hpp"
52 
53 #include <memory>
54 
55 
56 namespace steam {
57 namespace engine {
58 
59  using lib::Literal;
60  using std::unique_ptr;
61 
62 
63  class BufferMetadata;
64 
65 
66  LUMIERA_ERROR_DECLARE (BUFFER_MANAGEMENT);
67 
68 
83  {
84  unique_ptr<BufferMetadata> meta_;
85 
86 
87  protected: /* === for Implementation by concrete providers === */
88 
89  BufferProvider (Literal implementationID);
90 
91  virtual uint prepareBuffers (uint count, HashVal typeID) =0;
92 
93  virtual BuffHandle provideLockedBuffer (HashVal typeID) =0;
94  virtual void mark_emitted (HashVal typeID, LocalKey const&) =0;
95  virtual void detachBuffer (HashVal typeID, LocalKey const&) =0;
96 
97 
98  public:
99  virtual ~BufferProvider();
100 
101 
102  uint announce (uint count, BufferDescriptor const&);
103 
105  void emitBuffer (BuffHandle const&);
106  void releaseBuffer (BuffHandle const&);
107 
108  template<typename BU>
110 
112  void attachTypeHandler (BuffHandle const& target, BufferDescriptor const& reference);
113 
114  void emergencyCleanup (BuffHandle const& target, bool invokeDtor =false);
115 
116 
118  BufferDescriptor getDescriptorFor(size_t storageSize=0);
119  BufferDescriptor getDescriptorFor(size_t storageSize, TypeHandler specialTreatment);
120 
121  template<typename BU>
123 
124 
125 
126  /* === API for BuffHandle internal access === */
127 
128  bool verifyValidity (BufferDescriptor const&) const;
129  size_t getBufferSize (HashVal typeID) const;
130 
131  protected:
132  BuffHandle buildHandle (HashVal typeID, void* storage, LocalKey const&);
133 
134  bool was_created_by_this_provider (BufferDescriptor const&) const;
135  };
136 
137 
138 
139 
140  /* === Implementation === */
141 
149  template<typename BU>
150  BuffHandle
152  {
153  BufferDescriptor attach_object_automatically = getDescriptor<BU>();
154  return lockBuffer (attach_object_automatically);
155  }
156 
157 
162  template<typename BU>
165  {
166  return getDescriptorFor (sizeof(BU), TypeHandler::create<BU>());
167  }
168 
169 
170 }} // namespace steam::engine
171 #endif
A marker data type used in metadata / buffer management of the render engine.
void attachTypeHandler(BuffHandle const &target, BufferDescriptor const &reference)
allow for attaching and owing an object within an already created buffer
void releaseBuffer(BuffHandle const &)
BufferProvider API: declare done and detach.
Any copy and copy construction prohibited.
Definition: nocopy.hpp:46
BuffHandle lockBufferFor()
convenience shortcut: prepare and claim ("lock") a buffer suitable to hold an object of the given typ...
inline string literal This is a marker type to indicate that
Definition: symbol.hpp:85
BuffHandle buildHandle(HashVal typeID, void *storage, LocalKey const &)
callback from implementation to build and enrol a BufferHandle, to be returned to the client as resul...
void emergencyCleanup(BuffHandle const &target, bool invokeDtor=false)
Steam-Layer implementation namespace root.
Mix-Ins to allow or prohibit various degrees of copying and cloning.
an opaque ID to be used by the BufferProvider implementation.
uint announce(uint count, BufferDescriptor const &)
BufferProvider API: declare in advance the need for working buffers.
Marker types to indicate a literal string and a Symbol.
LUMIERA_ERROR_DECLARE(BUFFER_MANAGEMENT)
Problem providing working buffers.
BufferDescriptor getDescriptorFor(size_t storageSize=0)
describe the kind of buffer managed by this provider
An opaque descriptor to identify the type and further properties of a data buffer.
Definition: buffhandle.hpp:85
A front-end to support the buffer management within the render nodes.
BuffHandle lockBuffer(BufferDescriptor const &)
BufferProvider API: retrieve a single buffer for exclusive use.
Helper holding a pair of type-build-up and destruction functors.
BufferProvider(Literal implementationID)
build a new provider instance, managing a family of buffers.
Lumiera error handling (C++ interface).
Hash value types and utilities.
Handle for a buffer for processing data, abstracting away the actual implementation.
Definition: buffhandle.hpp:115
size_t HashVal
a STL compatible hash value
Definition: hash-value.h:56
virtual ~BufferProvider()
this is an ABC
A pair of functors to maintain a datastructure within a buffer.
bool verifyValidity(BufferDescriptor const &) const
Interface: a facility providing and managing working buffers for media calculations.
void emitBuffer(BuffHandle const &)
BufferProvider API: state transition to emitted state.
BufferDescriptor getDescriptor()
define a "buffer type" for automatically creating an instance of the template type embedded into the ...