Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c1c461af authored by Alex Sakhartchouk's avatar Alex Sakhartchouk
Browse files

Add LambdaMessage to SurfaceFlinger

LambdaMessage allows for a cleaner, more compact way to create and
dispatch messages inside SurfaceFlinger. A follow up CL uses this
method, but it was isolated here to keep added functionality and
helper facilities separate.

Bug: 62215749
Test: Compile
Change-Id: I9e13e04f1b67fd60f01bcab02fe4f19c91c10bd4
(cherry picked from commit 117698b8)
parent 5a556bc7
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -30,6 +30,8 @@

#include "Barrier.h"

#include <functional>

namespace android {

class IDisplayEventConnection;
@@ -58,6 +60,21 @@ private:
    mutable Barrier barrier;
};

class LambdaMessage : public MessageBase {
public:
    explicit LambdaMessage(std::function<void()> handler)
          : MessageBase(), mHandler(std::move(handler)) {}

    bool handler() override {
        mHandler();
        // This return value is no longer checked, so it's always safe to return true
        return true;
    }

private:
    const std::function<void()> mHandler;
};

// ---------------------------------------------------------------------------

class MessageQueue {