]> git.sesse.net Git - movit/commitdiff
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 ffc64fb7f76a2828c3d182f7cdd8cf73c11cd186..1f6c47c9d236a56ec688ff52d21452083600fc95 100644 (file)
@@ -300,8 +300,7 @@ double compute_sum_sq_error(const Tap<float>* weights, unsigned num_weights,
 }  // namespace
 
 ResampleEffect::ResampleEffect()
 }  // 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),
          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.
        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));
        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();
        CHECK(vpass->set_int("direction", SingleResamplePassEffect::VERTICAL));
 
        update_size();
@@ -321,21 +322,16 @@ ResampleEffect::ResampleEffect()
 
 ResampleEffect::~ResampleEffect()
 {
 
 ResampleEffect::~ResampleEffect()
 {
-       if (owns_effects) {
-               delete hpass;
-               delete vpass;
-       }
 }
 
 void ResampleEffect::rewrite_graph(EffectChain *graph, Node *self)
 {
 }
 
 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;
        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,
 } 
 
 // We get this information forwarded from the first blur pass,
index 1822a3ea6b261fa833d59c4e4e2e0e276b83ca4b..027a497cc5fb5d6616ad43190117e4f91ed025d9 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.
        
        // 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;
        int input_width, input_height, output_width, output_height;
 
        float offset_x, offset_y;