lottie/player: take buffer argument by value. 06/186306/1
authorsubhransu mohanty <sub.mohanty@samsung.com>
Thu, 9 Aug 2018 01:10:44 +0000 (10:10 +0900)
committersubhransu mohanty <sub.mohanty@samsung.com>
Thu, 9 Aug 2018 01:10:44 +0000 (10:10 +0900)
As we have async rendering, we can't rely on the caller to keep the buffer alive till render finish.

Change-Id: Ic7f9670a5e5003424c2b695c171a13717e531b21

inc/lottieplayer.h
src/lottie/lottieplayer.cpp

index 795a347..1fcdb77 100644 (file)
@@ -30,11 +30,11 @@ class LOTPlayerPrivate;
 class LOTNode;
 
 struct LOT_EXPORT LOTBuffer {
-    uint32_t *buffer;
-    int       width;
-    int       height;
-    int       bytesPerLine;
-    bool      clear;
+    uint32_t *buffer = nullptr;
+    int       width = 0;
+    int       height = 0;
+    int       bytesPerLine = 0;
+    bool      clear = true;
 };
 
 class LOT_EXPORT LOTPlayer {
@@ -54,8 +54,8 @@ public:
     // TODO: Consider correct position...
     void              setSize(int width, int height);
     void              size(int &width, int &height) const;
-    std::future<bool> render(float pos, LOTBuffer &buffer);
-    bool              renderSync(float pos, LOTBuffer &buffer);
+    std::future<bool> render(float pos, LOTBuffer buffer);
+    bool              renderSync(float pos, LOTBuffer buffer);
 
 public:
     LOTPlayerPrivate *d;
index 8683b8e..382bf2c 100644 (file)
@@ -200,12 +200,12 @@ public:
     }
 
     std::future<bool> render(LOTPlayerPrivate *impl, float pos,
-                             LOTBuffer &buffer)
+                             LOTBuffer &&buffer)
     {
         RenderTask *task = new RenderTask();
         task->playerImpl = impl;
         task->pos = pos;
-        task->buffer = buffer;
+        task->buffer = std::move(buffer);
         return async(task);
     }
 };
@@ -262,12 +262,12 @@ const std::vector<LOTNode *> &LOTPlayer::renderList() const
     return d->renderList();
 }
 
-std::future<bool> LOTPlayer::render(float pos, LOTBuffer &buffer)
+std::future<bool> LOTPlayer::render(float pos, LOTBuffer buffer)
 {
-    return render_scheduler.render(d, pos, buffer);
+    return render_scheduler.render(d, pos, std::move(buffer));
 }
 
-bool LOTPlayer::renderSync(float pos, LOTBuffer &buffer)
+bool LOTPlayer::renderSync(float pos, LOTBuffer buffer)
 {
     return d->render(pos, buffer);
 }