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
diff --git a/services/surfaceflinger/MessageQueue.h b/services/surfaceflinger/MessageQueue.h
index 85a33c8..14f50bb 100644
--- a/services/surfaceflinger/MessageQueue.h
+++ b/services/surfaceflinger/MessageQueue.h
@@ -30,6 +30,8 @@
 
 #include "Barrier.h"
 
+#include <functional>
+
 namespace android {
 
 class IDisplayEventConnection;
@@ -58,6 +60,21 @@
     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 {