1/*
2 * Copyright 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#include <binder/ProcessState.h>
17#include <binder/IServiceManager.h>
18#include <hwbinder/IPCThreadState.h>
19#include <impl/vr_hwc.h>
20#include <inttypes.h>
21
22#include "vr_composer.h"
23
24int main() {
25  android::ProcessState::self()->startThreadPool();
26
27  // Register the hwbinder HWC HAL service used by SurfaceFlinger while in VR
28  // mode.
29  const char instance[] = "vr";
30  android::sp<IComposer> service =
31      android::dvr::HIDL_FETCH_IComposer(instance);
32
33  LOG_ALWAYS_FATAL_IF(!service.get(), "Failed to get service");
34  LOG_ALWAYS_FATAL_IF(service->isRemote(), "Service is remote");
35
36  LOG_ALWAYS_FATAL_IF(service->registerAsService(instance) != android::OK,
37                      "Failed to register service");
38
39  android::sp<android::dvr::VrComposer> composer =
40      new android::dvr::VrComposer();
41
42  android::dvr::ComposerView* composer_view =
43      android::dvr::GetComposerViewFromIComposer(service.get());
44  composer_view->RegisterObserver(composer.get());
45
46  android::sp<android::IServiceManager> sm(android::defaultServiceManager());
47
48  // Register the binder service used by VR Window Manager service to receive
49  // frame information from VR HWC HAL.
50  android::status_t status = sm->addService(
51      android::dvr::VrComposer::SERVICE_NAME(), composer.get(),
52      false /* allowIsolated */);
53  LOG_ALWAYS_FATAL_IF(status != android::OK,
54                      "VrDisplay service failed to start: %" PRId32, status);
55
56  android::hardware::ProcessState::self()->startThreadPool();
57  android::hardware::IPCThreadState::self()->joinThreadPool();
58
59  composer_view->UnregisterObserver(composer.get());
60
61  return 0;
62}
63