drm_hwcomposer: Add hwc3 frontend stub

Adds a stub implementation of the HWC3 interface and service.
This is a barebones implementation of HWC3 interface that should contain
all the necessary code to build a HWC3 module but provides no
functionality.

The project [1] was used as a reference.
[1]: https://android.googlesource.com/platform/hardware/google/graphics/common/+/refs/tags/android-13.0.0_r18/hwc3/

Change-Id: I99754bb72f12183a94b24b7182cb7857173b31d2
Co-authored-by: Roman Stratiienko <r.stratiienko@gmail.com>
Signed-off-by: Dennis Tsiang <dennis.tsiang@arm.com>
Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
Signed-off-by: Normunds Rieksts <normunds.rieksts@arm.com>
Signed-off-by: Drew Davenport <ddavenport@google.com>
diff --git a/hwc3/service.cpp b/hwc3/service.cpp
new file mode 100644
index 0000000..f7527b7
--- /dev/null
+++ b/hwc3/service.cpp
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2021-2022, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <android/binder_manager.h>
+#include <android/binder_process.h>
+#include <binder/ProcessState.h>
+#include <sched.h>
+
+#include "Composer.h"
+#include "utils/log.h"
+
+using aidl::android::hardware::graphics::composer3::impl::Composer;
+
+int main(int /*argc*/, char* argv[]) {
+  (void)argv;
+  ALOGI("hwc3-drm starting up");
+
+  // same as SF main thread
+  struct sched_param param = {0};
+  param.sched_priority = 2;
+  if (sched_setscheduler(0, SCHED_FIFO | SCHED_RESET_ON_FORK, &param) != 0) {
+    ALOGE("Couldn't set SCHED_FIFO: %d", errno);
+  }
+
+  auto composer = ndk::SharedRefBase::make<Composer>();
+  if (!composer) {
+    ALOGE("Failed to create composer");
+    return -ENOMEM;
+  }
+
+  const std::string instance = std::string() + Composer::descriptor +
+                               "/default";
+  ALOGI("HWC3 service name %s", instance.c_str());
+  auto status = AServiceManager_addServiceWithFlags(
+      composer->asBinder().get(), instance.c_str(),
+      AServiceManager_AddServiceFlag::ADD_SERVICE_ALLOW_ISOLATED);
+  if (status != STATUS_OK) {
+    ALOGE("Failed to register service. Error %d", (int)status);
+    return -EINVAL;
+  }
+
+  ABinderProcess_joinThreadPool();
+  return EXIT_FAILURE;  // should not reach
+}