VR: Update VR Window Manager to use the VR Hardware Composer service
Decouples VR HWC from VR Window Manager.
Bug: 36051907
Test: Compiled and ran on device in VR mode.
Change-Id: Ifd76e742148765b3cf3e71b0cf538b920814eb7b
diff --git a/services/vr/hardware_composer/vr_hwc.rc b/services/vr/hardware_composer/vr_hwc.rc
index 5d3c4f7..52d4da8 100644
--- a/services/vr/hardware_composer/vr_hwc.rc
+++ b/services/vr/hardware_composer/vr_hwc.rc
@@ -3,4 +3,3 @@
user system
group system graphics
onrestart restart surfaceflinger
- disabled
diff --git a/services/vr/vr_window_manager/Android.bp b/services/vr/vr_window_manager/Android.bp
index a7a341c..0406331 100644
--- a/services/vr/vr_window_manager/Android.bp
+++ b/services/vr/vr_window_manager/Android.bp
@@ -41,6 +41,7 @@
"libperformance",
"libpdx_default_transport",
"libcutils",
+ "libvr_hwc-binder",
"libvr_manager",
"libvirtualtouchpadclient",
]
diff --git a/services/vr/vr_window_manager/hwc_callback.cpp b/services/vr/vr_window_manager/hwc_callback.cpp
index 19b220b..43f5042 100644
--- a/services/vr/vr_window_manager/hwc_callback.cpp
+++ b/services/vr/vr_window_manager/hwc_callback.cpp
@@ -38,26 +38,29 @@
HwcCallback::~HwcCallback() {
}
-base::unique_fd HwcCallback::OnNewFrame(const ComposerView::Frame& display_frame) {
- auto& frame = display_frame.layers;
- std::vector<HwcLayer> hwc_frame(frame.size());
-
- for (size_t i = 0; i < frame.size(); ++i) {
+binder::Status HwcCallback::onNewFrame(
+ const ParcelableComposerFrame& parcelable_frame,
+ ParcelableUniqueFd* fence) {
+ ComposerView::Frame frame = parcelable_frame.frame();
+ std::vector<HwcLayer> hwc_frame(frame.layers.size());
+ for (size_t i = 0; i < frame.layers.size(); ++i) {
+ const ComposerView::ComposerLayer& layer = frame.layers[i];
hwc_frame[i] = HwcLayer{
- .fence = frame[i].fence,
- .buffer = frame[i].buffer,
- .crop = frame[i].crop,
- .display_frame = frame[i].display_frame,
- .blending = static_cast<int32_t>(frame[i].blend_mode),
- .appid = frame[i].app_id,
- .type = static_cast<HwcLayer::LayerType>(frame[i].type),
- .alpha = frame[i].alpha,
+ .fence = layer.fence,
+ .buffer = layer.buffer,
+ .crop = layer.crop,
+ .display_frame = layer.display_frame,
+ .blending = static_cast<int32_t>(layer.blend_mode),
+ .appid = layer.app_id,
+ .type = static_cast<HwcLayer::LayerType>(layer.type),
+ .alpha = layer.alpha,
};
}
- return client_->OnFrame(std::make_unique<Frame>(
- std::move(hwc_frame), display_frame.display_id, display_frame.removed,
- display_frame.display_width, display_frame.display_height));
+ fence->set_fence(client_->OnFrame(std::make_unique<Frame>(
+ std::move(hwc_frame), frame.display_id, frame.removed,
+ frame.display_width, frame.display_height)));
+ return binder::Status::ok();
}
HwcCallback::Frame::Frame(std::vector<HwcLayer>&& layers, uint32_t display_id,
diff --git a/services/vr/vr_window_manager/hwc_callback.h b/services/vr/vr_window_manager/hwc_callback.h
index c0d965a..f1f91a1 100644
--- a/services/vr/vr_window_manager/hwc_callback.h
+++ b/services/vr/vr_window_manager/hwc_callback.h
@@ -1,14 +1,16 @@
#ifndef VR_WINDOW_MANAGER_HWC_CALLBACK_H_
#define VR_WINDOW_MANAGER_HWC_CALLBACK_H_
+#include <android/dvr/BnVrComposerCallback.h>
+#include <android-base/unique_fd.h>
+
#include <deque>
#include <functional>
#include <mutex>
#include <vector>
-#include <android-base/unique_fd.h>
-#include <impl/vr_composer_view.h>
-#include <impl/vr_hwc.h>
+#include "impl/vr_composer_view.h"
+#include "impl/vr_hwc.h"
namespace android {
@@ -20,7 +22,7 @@
using Recti = ComposerView::ComposerLayer::Recti;
using Rectf = ComposerView::ComposerLayer::Rectf;
-class HwcCallback : public VrComposerView::Callback {
+class HwcCallback : public BnVrComposerCallback {
public:
struct HwcLayer {
enum LayerType : uint32_t {
@@ -110,7 +112,8 @@
~HwcCallback() override;
private:
- base::unique_fd OnNewFrame(const ComposerView::Frame& frame) override;
+ binder::Status onNewFrame(const ParcelableComposerFrame& frame,
+ ParcelableUniqueFd* fence) override;
Client *client_;
diff --git a/services/vr/vr_window_manager/surface_flinger_view.cpp b/services/vr/vr_window_manager/surface_flinger_view.cpp
index c0ee1fc..aef23a1 100644
--- a/services/vr/vr_window_manager/surface_flinger_view.cpp
+++ b/services/vr/vr_window_manager/surface_flinger_view.cpp
@@ -1,5 +1,7 @@
#include "surface_flinger_view.h"
+#include <android/dvr/IVrComposer.h>
+#include <binder/IServiceManager.h>
#include <impl/vr_composer_view.h>
#include <private/dvr/native_buffer.h>
@@ -14,22 +16,20 @@
SurfaceFlingerView::~SurfaceFlingerView() {}
bool SurfaceFlingerView::Initialize(HwcCallback::Client *client) {
- const char vr_hwcomposer_name[] = "vr";
- vr_hwcomposer_ = HIDL_FETCH_IComposer(vr_hwcomposer_name);
- if (!vr_hwcomposer_.get()) {
- ALOGE("Failed to get vr_hwcomposer");
+ sp<IServiceManager> sm(defaultServiceManager());
+ vr_composer_ = interface_cast<IVrComposer>(
+ sm->getService(IVrComposer::SERVICE_NAME()));
+
+ String8 service_name(IVrComposer::SERVICE_NAME().string());
+ if (!vr_composer_.get()) {
+ ALOGE("Faild to connect to %s", service_name.c_str());
return false;
}
- if (vr_hwcomposer_->isRemote()) {
- ALOGE("vr_hwcomposer service is remote");
- return false;
- }
-
- const android::status_t vr_hwcomposer_status =
- vr_hwcomposer_->registerAsService(vr_hwcomposer_name);
- if (vr_hwcomposer_status != OK) {
- ALOGE("Failed to register vr_hwcomposer service");
+ composer_callback_ = new HwcCallback(client);
+ binder::Status status = vr_composer_->registerObserver(composer_callback_);
+ if (!status.isOk()) {
+ ALOGE("Failed to register observer with %s", service_name.c_str());
return false;
}
diff --git a/services/vr/vr_window_manager/surface_flinger_view.h b/services/vr/vr_window_manager/surface_flinger_view.h
index 3ea2b21..1bea38d 100644
--- a/services/vr/vr_window_manager/surface_flinger_view.h
+++ b/services/vr/vr_window_manager/surface_flinger_view.h
@@ -3,14 +3,13 @@
#include <memory>
-#include <impl/vr_composer_view.h>
-
#include "hwc_callback.h"
namespace android {
namespace dvr {
class IDisplay;
+class IVrComposer;
class Texture;
struct TextureLayer {
@@ -34,8 +33,8 @@
bool skip_first_layer) const;
private:
- sp<IComposer> vr_hwcomposer_;
- std::unique_ptr<VrComposerView> vr_composer_view_;
+ sp<IVrComposer> vr_composer_;
+ sp<HwcCallback> composer_callback_;
SurfaceFlingerView(const SurfaceFlingerView&) = delete;
void operator=(const SurfaceFlingerView&) = delete;