+void EffectChain::find_output_size(EffectChain::Phase *phase)
+{
+ Effect *output_effect = phase->effects.back();
+
+ // If the last effect explicitly sets an output size,
+ // use that.
+ if (output_effect->changes_output_size()) {
+ output_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) {
+ Effect *input = phase->inputs[i];
+ assert(output_effects_to_phase.count(input) != 0);
+ const Phase *input_phase = output_effects_to_phase[input];
+ 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;
+}
+