In ResampleEffect, use std::unique_ptr instead of managing ownership ourselves.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 14 Jan 2018 23:48:29 +0000 (00:48 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 14 Jan 2018 23:48:29 +0000 (00:48 +0100)
resample_effect.cpp
resample_effect.h

index ffc64fb..1f6c47c 100644 (file)
@@ -300,8 +300,7 @@ double compute_sum_sq_error(const Tap<float>* weights, unsigned num_weights,
 }  // namespace
 
 ResampleEffect::ResampleEffect()
-       : owns_effects(true),
-         input_width(1280),
+       : input_width(1280),
          input_height(720),
          offset_x(0.0f), offset_y(0.0f),
          zoom_x(1.0f), zoom_y(1.0f),
@@ -311,9 +310,11 @@ ResampleEffect::ResampleEffect()
        register_int("height", &output_height);
 
        // The first blur pass will forward resolution information to us.
-       hpass = new SingleResamplePassEffect(this);
+       hpass_owner.reset(new SingleResamplePassEffect(this));
+       hpass = hpass_owner.get();
        CHECK(hpass->set_int("direction", SingleResamplePassEffect::HORIZONTAL));
-       vpass = new SingleResamplePassEffect(nullptr);
+       vpass_owner.reset(new SingleResamplePassEffect(this));
+       vpass = vpass_owner.get();
        CHECK(vpass->set_int("direction", SingleResamplePassEffect::VERTICAL));
 
        update_size();
@@ -321,21 +322,16 @@ ResampleEffect::ResampleEffect()
 
 ResampleEffect::~ResampleEffect()
 {
-       if (owns_effects) {
-               delete hpass;
-               delete vpass;
-       }
 }
 
 void ResampleEffect::rewrite_graph(EffectChain *graph, Node *self)
 {
-       Node *hpass_node = graph->add_node(hpass);
-       Node *vpass_node = graph->add_node(vpass);
+       Node *hpass_node = graph->add_node(hpass_owner.release());
+       Node *vpass_node = graph->add_node(vpass_owner.release());
        graph->connect_nodes(hpass_node, vpass_node);
        graph->replace_receiver(self, hpass_node);
        graph->replace_sender(self, vpass_node);
        self->disabled = true;
-       owns_effects = false;
 } 
 
 // We get this information forwarded from the first blur pass,
index 1822a3e..027a497 100644 (file)
@@ -93,8 +93,8 @@ private:
        
        // Both of these are owned by us if owns_effects is true (before finalize()),
        // and otherwise owned by the EffectChain.
-       bool owns_effects;
-       SingleResamplePassEffect *hpass, *vpass;
+       std::unique_ptr<SingleResamplePassEffect> hpass_owner, vpass_owner;
+       SingleResamplePassEffect *hpass = nullptr, *vpass = nullptr;
        int input_width, input_height, output_width, output_height;
 
        float offset_x, offset_y;