/usr/include/synfig-1.0/synfig/renderer.h is in libsynfig-dev 1.0.2-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 | /* === S Y N F I G ========================================================= */
/*! \file synfig/renderer.h
** \brief Template Header
**
** $Id$
**
** \legal
** ......... ... 2014 Ivan Mahonin
**
** This package is free software; you can redistribute it and/or
** modify it under the terms of the GNU General Public License as
** published by the Free Software Foundation; either version 2 of
** the License, or (at your option) any later version.
**
** This package is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** General Public License for more details.
** \endlegal
*/
/* ========================================================================= */
/* === S T A R T =========================================================== */
#ifndef __SYNFIG_RENDERER_H
#define __SYNFIG_RENDERER_H
/* === H E A D E R S ======================================================= */
#include <ETL/handle>
#include <map>
#include <limits>
/* === M A C R O S ========================================================= */
/* === T Y P E D E F S ===================================================== */
/* === C L A S S E S & S T R U C T S ======================================= */
namespace synfig
{
class Renderer
{
public:
typedef int RendererId;
enum PrimitiveType
{
PrimitiveTypeSurface,
PrimitiveTypePolygon,
PrimitiveTypeColoredPolygon,
PrimitiveTypeMesh
};
enum { PrimitiveTypeCount = 4 };
//! Base class of PrimitiveData (PrimitiveData base), NOT database
class PrimitiveDataBase: public etl::shared_object {
public:
typedef etl::handle<PrimitiveDataBase> Handle;
typedef etl::handle<const PrimitiveDataBase> ConstHandle;
};
template<typename T>
class PrimitiveData: public PrimitiveDataBase {
public:
typedef T Data;
typedef etl::handle<PrimitiveData> Handle;
typedef etl::handle<const PrimitiveData> ConstHandle;
Data data;
};
typedef PrimitiveDataBase::Handle (*FuncCreate)();
typedef PrimitiveDataBase::Handle (*FuncCopy)(PrimitiveDataBase::Handle primitive);
typedef PrimitiveDataBase::Handle (*FuncConvert)(PrimitiveDataBase::Handle primitive);
struct KeyCreate {
PrimitiveType primitive_type;
RendererId renderer_id;
inline KeyCreate():
primitive_type(PrimitiveTypeSurface), renderer_id(0) { }
inline KeyCreate(PrimitiveType primitive_type, RendererId renderer_id):
primitive_type(primitive_type), renderer_id(renderer_id) { }
inline bool operator < (const KeyCreate &other) const
{
return primitive_type < other.primitive_type ? true
: other.primitive_type < primitive_type ? false
: renderer_id < other.renderer_id;
}
};
typedef KeyCreate KeyCopy;
struct KeyConvert {
PrimitiveType primitive_type;
RendererId renderer_id_from;
RendererId renderer_id_to;
inline KeyConvert():
primitive_type(PrimitiveTypeSurface), renderer_id_from(0), renderer_id_to(0) { }
inline KeyConvert(PrimitiveType primitive_type, RendererId renderer_id_from, RendererId renderer_id_to):
primitive_type(primitive_type), renderer_id_from(renderer_id_from), renderer_id_to(renderer_id_to) { }
inline bool operator < (const KeyConvert &other) const
{
return primitive_type < other.primitive_type ? true
: other.primitive_type < primitive_type ? false
: renderer_id_from < other.renderer_id_from ? true
: other.renderer_id_from < renderer_id_from ? false
: renderer_id_to < other.renderer_id_to;
}
};
struct ConvertChainEntry {
public:
int count;
RendererId renderer_id_to;
ConvertChainEntry *next;
FuncConvert func;
inline ConvertChainEntry():
count(0), renderer_id_to(0), next(NULL), func(NULL) { }
};
typedef std::map<KeyCreate, FuncCreate> BookCreate;
typedef std::map<KeyCopy, FuncCopy> BookCopy;
typedef std::map<KeyConvert, FuncConvert> BookConvert;
typedef std::map<KeyConvert, ConvertChainEntry> BookConvertChain;
private:
static RendererId last_registered_id;
static BookCreate book_create;
static BookCopy book_copy;
static BookConvert book_convert;
static BookConvertChain book_convert_chain;
static void build_convert_chain();
protected:
static void register_renderer(int &id);
static void register_func_create(const KeyCreate &key, FuncCreate func);
static void register_func_copy(const KeyCopy &key, FuncCopy func);
static void register_func_convert(const KeyConvert &key, FuncConvert func);
static void unregister_renderer(int &id);
template<typename T>
static PrimitiveDataBase::Handle func_default_create()
{ return new T(); }
static PrimitiveDataBase::Handle func_default_convert(PrimitiveDataBase::Handle primitive)
{ return primitive; }
public:
class PrimitiveBase
{
private:
typedef std::map<RendererId, PrimitiveDataBase::Handle> Map;
typedef Map::value_type Pair;
mutable Map primitives;
bool editing;
public:
const PrimitiveType type;
private:
Map::iterator get_entry(RendererId renderer_id) const;
protected:
inline PrimitiveBase(PrimitiveType type): editing(false), type(type) { }
public:
virtual ~PrimitiveBase();
inline bool is_editing() const { return editing; }
PrimitiveDataBase::ConstHandle get_primitive(RendererId renderer_id) const;
PrimitiveDataBase::Handle begin_edit_primitive(RendererId renderer_id);
void end_edit_primitive();
};
template<typename RendererType, Renderer::PrimitiveType primitive_type>
class TypesTemplate { };
template<PrimitiveType primitive_type>
class Primitive: public PrimitiveBase
{
public:
Primitive(): PrimitiveBase(primitive_type) { }
template<typename RendererType>
const typename TypesTemplate<RendererType, primitive_type>::Data* get()
{
typedef PrimitiveData<typename TypesTemplate<RendererType, primitive_type>::Data> PrimitiveData;
typedef typename PrimitiveData::ConstHandle ConstHandle;
ConstHandle handle =
ConstHandle::cast_dynamic(
PrimitiveBase::get_primitive(
TypesTemplate<RendererType, primitive_type>::get_id()));
return handle ? &handle->data : NULL;
}
template<typename RendererType>
typename TypesTemplate<RendererType, primitive_type>::Data* begin_edit()
{
PrimitiveDataBase::Handle base_handle =
PrimitiveBase::begin_edit_primitive(
TypesTemplate<RendererType, primitive_type>::get_id());
if (base_handle)
{
typedef typename TypesTemplate<RendererType, primitive_type>::Data Data;
typedef PrimitiveData<Data> PrimitiveData;
typedef typename PrimitiveData::Handle Handle;
Handle handle = Handle::cast_dynamic(base_handle);
if (handle) return &handle->data;
Renderer::PrimitiveBase::end_edit_primitive();
}
return NULL;
}
inline void end_edit() { Renderer::PrimitiveBase::end_edit_primitive(); }
};
template<typename T>
class TypesTemplateBase {
typedef T Data;
typedef PrimitiveData<Data> Primitive;
};
template<typename T>
class TypesBase
{
public:
typedef T RendererType;
typedef TypesTemplate<RendererType, PrimitiveTypeSurface> Surface;
typedef TypesTemplate<RendererType, PrimitiveTypePolygon> Polygon;
typedef TypesTemplate<RendererType, PrimitiveTypeColoredPolygon> ColoredPolygon;
typedef TypesTemplate<RendererType, PrimitiveTypeMesh> Mesh;
};
typedef Primitive<PrimitiveTypeSurface> PrimitiveSurface;
typedef Primitive<PrimitiveTypePolygon> PrimitivePolygon;
typedef Primitive<PrimitiveTypeColoredPolygon> PrimitiveColoredPolygon;
typedef Primitive<PrimitiveTypeMesh> PrimitiveMesh;
class Params {
public:
// TODO: blend method, color
PrimitiveBase *out_surface;
const PrimitiveBase *back_surface;
const PrimitiveBase *mesh_texture_surface;
inline Params(): out_surface(NULL), back_surface(NULL), mesh_texture_surface(NULL) { }
};
enum Result {
ResultSuccess,
ResultNotSupported,
ResultFail
};
protected:
bool supported_primitives[PrimitiveTypeCount];
public:
inline bool is_primitive_supported(PrimitiveType primitive_type)
{ return supported_primitives[primitive_type]; }
Renderer();
virtual ~Renderer();
virtual Result render(const Params ¶ms, const PrimitiveBase &primitive);
virtual Result render_surface(const Params ¶ms, const Primitive<PrimitiveTypeSurface> &primitive);
virtual Result render_polygon(const Params ¶ms, const Primitive<PrimitiveTypePolygon> &primitive);
virtual Result render_colored_polygon(const Params ¶ms, const Primitive<PrimitiveTypeColoredPolygon> &primitive);
virtual Result render_mesh(const Params ¶ms, const Primitive<PrimitiveTypeMesh> &primitive);
};
}; /* end namespace synfig */
/* -- E N D ----------------------------------------------------------------- */
#endif
|