Lumiera  0.pre.03
»edityourfreedom«
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 PROC_ENGINE_BUFFR_PROVIDER_H
42 #define PROC_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 proc {
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 
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 proc::engine
171 #endif
A marker data type used in metadata / buffer management of the render engine.
bool was_created_by_this_provider(BufferDescriptor const &) const
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...
BufferDescriptor getDescriptor()
define a "buffer type" for automatically creating an instance of the template type embedded into the ...
BuffHandle lockBufferFor()
convenience shortcut: prepare and claim ("lock") a buffer suitable to hold an object of the given typ...
Any copy and copy construction prohibited.
Definition: nocopy.hpp:46
An opaque descriptor to identify the type and further properties of a data buffer.
Definition: buffhandle.hpp:81
inline string literal This is a marker type to indicate that
Definition: symbol.hpp:75
Interface: a facility providing and managing working buffers for media calculations.
A pair of functors to maintain a datastructure within a buffer.
LUMIERA_ERROR_DECLARE(BUFFER_MANAGEMENT)
Problem providing working buffers.
void emergencyCleanup(BuffHandle const &target, bool invokeDtor=false)
BufferDescriptor getDescriptorFor(size_t storageSize=0)
describe the kind of buffer managed by this provider
Handle for a buffer for processing data, abstracting away the actual implementation.
Definition: buffhandle.hpp:111
virtual void detachBuffer(HashVal typeID, LocalKey const &)=0
void releaseBuffer(BuffHandle const &)
BufferProvider API: declare done and detach.
Mix-Ins to allow or prohibit various degrees of copying and cloning.
Marker types to indicate a literal string and a Symbol.
virtual void mark_emitted(HashVal typeID, LocalKey const &)=0
bool verifyValidity(BufferDescriptor const &) const
BufferProvider(Literal implementationID)
build a new provider instance, managing a family of buffers.
an opaque ID to be used by the BufferProvider implementation.
A front-end to support the buffer management within the render nodes.
void attachTypeHandler(BuffHandle const &target, BufferDescriptor const &reference)
allow for attaching and owing an object within an already created buffer
size_t getBufferSize(HashVal typeID) const
Helper holding a pair of type-build-up and destruction functors.
virtual BuffHandle provideLockedBuffer(HashVal typeID)=0
Lumiera error handling (C++ interface).
uint announce(uint count, BufferDescriptor const &)
BufferProvider API: declare in advance the need for working buffers.
BuffHandle lockBuffer(BufferDescriptor const &)
BufferProvider API: retrieve a single buffer for exclusive use.
Hash value types and utilities.
size_t HashVal
a STL compatible hash value
Definition: hash-value.h:56
virtual ~BufferProvider()
this is an ABC
virtual uint prepareBuffers(uint count, HashVal typeID)=0
unique_ptr< BufferMetadata > meta_
void emitBuffer(BuffHandle const &)
BufferProvider API: state transition to emitted state.
Proc-Layer implementation namespace root.
Definition: id-scheme.hpp:63