Skip to content

Commit

Permalink
Output the graph in dot form at finalize time.
Browse files Browse the repository at this point in the history
  • Loading branch information
sesse committed Oct 8, 2012
1 parent 4ccde68 commit f99ad33
Show file tree
Hide file tree
Showing 18 changed files with 53 additions and 1 deletion.
4 changes: 4 additions & 0 deletions blur_effect.h
Expand Up @@ -17,6 +17,8 @@ class BlurEffect : public Effect {
public:
BlurEffect();

virtual std::string effect_type_id() const { return "BlurEffect"; }

// We want this for the same reason as ResizeEffect; we could end up scaling
// down quite a lot.
virtual bool needs_texture_bounce() const { return true; }
Expand All @@ -43,6 +45,8 @@ class BlurEffect : public Effect {
class SingleBlurPassEffect : public Effect {
public:
SingleBlurPassEffect();
virtual std::string effect_type_id() const { return "SingleBlurPassEffect"; }

std::string output_fragment_shader();

virtual bool needs_texture_bounce() const { return true; }
Expand Down
1 change: 1 addition & 0 deletions colorspace_conversion_effect.h
Expand Up @@ -14,6 +14,7 @@
class ColorSpaceConversionEffect : public Effect {
public:
ColorSpaceConversionEffect();
virtual std::string effect_type_id() const { return "ColorSpaceConversionEffect"; }
std::string output_fragment_shader();

virtual bool needs_srgb_primaries() const { return false; }
Expand Down
2 changes: 2 additions & 0 deletions diffusion_effect.h
Expand Up @@ -20,6 +20,7 @@ class OverlayMatteEffect;
class DiffusionEffect : public Effect {
public:
DiffusionEffect();
virtual std::string effect_type_id() const { return "DiffusionEffect"; }

virtual void add_self_to_effect_chain(EffectChain *chain, const std::vector<Effect *> &input);
virtual bool set_float(const std::string &key, float value);
Expand All @@ -41,6 +42,7 @@ class DiffusionEffect : public Effect {
class OverlayMatteEffect : public Effect {
public:
OverlayMatteEffect();
virtual std::string effect_type_id() const { return "OverlayMatteEffect"; }
std::string output_fragment_shader();

unsigned num_inputs() const { return 2; }
Expand Down
7 changes: 6 additions & 1 deletion effect.h
Expand Up @@ -46,7 +46,12 @@ void set_uniform_vec3(GLuint glsl_program_num, const std::string &prefix, const
void set_uniform_vec4_array(GLuint glsl_program_num, const std::string &prefix, const std::string &key, const float *values, size_t num_values);

class Effect {
public:
public:
// An identifier for this type of effect, mostly used for debug output
// (but some special names, like "ColorSpaceConversionEffect", holds special
// meaning). Same as the class name is fine.
virtual std::string effect_type_id() const = 0;

// Whether this effects expects its input (and output) to be in
// linear gamma, ie. without an applied gamma curve. Most effects
// will want this, although the ones that never actually look at
Expand Down
22 changes: 22 additions & 0 deletions effect_chain.cpp
Expand Up @@ -414,6 +414,26 @@ void EffectChain::construct_glsl_programs(Node *output)
std::reverse(phases.begin(), phases.end());
}

void EffectChain::output_dot(const char *filename)
{
FILE *fp = fopen(filename, "w");
if (fp == NULL) {
perror(filename);
exit(1);
}

fprintf(fp, "digraph G {\n");
for (unsigned i = 0; i < nodes.size(); ++i) {
fprintf(fp, " n%ld [label=\"%s\"];\n", (long)nodes[i], nodes[i]->effect->effect_type_id().c_str());
for (unsigned j = 0; j < nodes[i]->outgoing_links.size(); ++j) {
fprintf(fp, " n%ld -> n%ld;\n", (long)nodes[i], (long)nodes[i]->outgoing_links[j]);
}
}
fprintf(fp, "}\n");

fclose(fp);
}

void EffectChain::find_output_size(Phase *phase)
{
Node *output_node = phase->effects.back();
Expand Down Expand Up @@ -453,6 +473,8 @@ void EffectChain::find_output_size(Phase *phase)

void EffectChain::finalize()
{
output_dot("final.dot");

// Find the output effect. This is, simply, one that has no outgoing links.
// If there are multiple ones, the graph is malformed (we do not support
// multiple outputs right now).
Expand Down
4 changes: 4 additions & 0 deletions effect_chain.h
Expand Up @@ -123,6 +123,10 @@ class EffectChain {
// that depends on it (whenever possible).
void construct_glsl_programs(Node *output);

// Output the current graph to the given file in a Graphviz-compatible format;
// only useful for debugging.
void output_dot(const char *filename);

unsigned width, height;
ImageFormat output_format;

Expand Down
2 changes: 2 additions & 0 deletions flat_input.h
Expand Up @@ -9,6 +9,8 @@ class FlatInput : public Input {
public:
FlatInput(ImageFormat format, MovitPixelFormat pixel_format, unsigned width, unsigned height);

virtual std::string effect_type_id() const { return "FlatInput"; }

// Create the texture itself. We cannot do this in the constructor,
// because we don't necessarily know all the settings (sRGB texture,
// mipmap generation) at that point.
Expand Down
1 change: 1 addition & 0 deletions gamma_compression_effect.h
Expand Up @@ -15,6 +15,7 @@
class GammaCompressionEffect : public Effect {
public:
GammaCompressionEffect();
virtual std::string effect_type_id() const { return "GammaCompressionEffect"; }
std::string output_fragment_shader();

virtual bool needs_srgb_primaries() const { return false; }
Expand Down
1 change: 1 addition & 0 deletions gamma_expansion_effect.h
Expand Up @@ -15,6 +15,7 @@
class GammaExpansionEffect : public Effect {
public:
GammaExpansionEffect();
virtual std::string effect_type_id() const { return "GammaExpansionEffect"; }
std::string output_fragment_shader();

virtual bool needs_linear_light() const { return false; }
Expand Down
1 change: 1 addition & 0 deletions glow_effect.h
Expand Up @@ -11,6 +11,7 @@ class MixEffect;
class GlowEffect : public Effect {
public:
GlowEffect();
virtual std::string effect_type_id() const { return "GlowEffect"; }

virtual bool needs_srgb_primaries() const { return false; }

Expand Down
1 change: 1 addition & 0 deletions lift_gamma_gain_effect.h
Expand Up @@ -22,6 +22,7 @@
class LiftGammaGainEffect : public Effect {
public:
LiftGammaGainEffect();
virtual std::string effect_type_id() const { return "LiftGammaGainEffect"; }
std::string output_fragment_shader();

void set_gl_state(GLuint glsl_program_num, const std::string &prefix, unsigned *sampler_num);
Expand Down
1 change: 1 addition & 0 deletions mirror_effect.h
Expand Up @@ -8,6 +8,7 @@
class MirrorEffect : public Effect {
public:
MirrorEffect();
virtual std::string effect_type_id() const { return "MirrorEffect"; }
std::string output_fragment_shader();

virtual bool needs_linear_light() const { return false; }
Expand Down
1 change: 1 addition & 0 deletions mix_effect.h
Expand Up @@ -8,6 +8,7 @@
class MixEffect : public Effect {
public:
MixEffect();
virtual std::string effect_type_id() const { return "MixEffect"; }
std::string output_fragment_shader();

virtual bool needs_srgb_primaries() const { return false; }
Expand Down
1 change: 1 addition & 0 deletions resize_effect.h
Expand Up @@ -10,6 +10,7 @@
class ResizeEffect : public Effect {
public:
ResizeEffect();
virtual std::string effect_type_id() const { return "ResizeEffect"; }
std::string output_fragment_shader();

// We want processing done pre-filtering and mipmapped,
Expand Down
1 change: 1 addition & 0 deletions sandbox_effect.h
Expand Up @@ -13,6 +13,7 @@
class SandboxEffect : public Effect {
public:
SandboxEffect();
virtual std::string effect_type_id() const { return "SandboxEffect"; }
std::string output_fragment_shader();

void set_gl_state(GLuint glsl_program_num, const std::string &prefix, unsigned *sampler_num);
Expand Down
1 change: 1 addition & 0 deletions saturation_effect.h
Expand Up @@ -12,6 +12,7 @@
class SaturationEffect : public Effect {
public:
SaturationEffect();
virtual std::string effect_type_id() const { return "SaturationEffect"; }
std::string output_fragment_shader();

private:
Expand Down
1 change: 1 addition & 0 deletions vignette_effect.h
Expand Up @@ -9,6 +9,7 @@
class VignetteEffect : public Effect {
public:
VignetteEffect();
virtual std::string effect_type_id() const { return "VignetteEffect"; }
std::string output_fragment_shader();

virtual bool needs_srgb_primaries() const { return false; }
Expand Down
2 changes: 2 additions & 0 deletions ycbcr_input.h
Expand Up @@ -31,6 +31,8 @@ class YCbCrInput : public Input {
const YCbCrFormat &ycbcr_format,
unsigned width, unsigned height);

virtual std::string effect_type_id() const { return "YCbCrInput"; }

// Create the texture itself. We cannot do this in the constructor,
// because we don't necessarily know all the settings (sRGB texture,
// mipmap generation) at that point.
Expand Down

0 comments on commit f99ad33

Please sign in to comment.