+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();
+
+ // If the last effect explicitly sets an output size,
+ // use that.
+ if (output_node->effect->changes_output_size()) {
+ output_node->effect->get_output_size(&phase->output_width, &phase->output_height);
+ return;
+ }
+
+ // If not, look at the input phases, if any. We select the largest one
+ // (really assuming they all have the same aspect currently), by pixel count.
+ if (!phase->inputs.empty()) {
+ unsigned best_width = 0, best_height = 0;
+ for (unsigned i = 0; i < phase->inputs.size(); ++i) {
+ Node *input = phase->inputs[i];
+ assert(input->phase->output_width != 0);
+ assert(input->phase->output_height != 0);
+ if (input->phase->output_width * input->phase->output_height > best_width * best_height) {
+ best_width = input->phase->output_width;
+ best_height = input->phase->output_height;
+ }
+ }
+ assert(best_width != 0);
+ assert(best_height != 0);
+ phase->output_width = best_width;
+ phase->output_height = best_height;
+ return;
+ }
+
+ // OK, no inputs. Just use the global width/height.
+ // TODO: We probably want to use the texture's size eventually.
+ phase->output_width = width;
+ phase->output_height = height;
+}
+