libbinder \
libinput \
libhardware \
+ libhwbinder \
libsync \
libutils \
libgui \
break;
case MainThreadTask::EnteringVrMode:
if (!initialized_) {
- if (AllocateResources())
- ALOGE("Failed to allocate resources");
+ LOG_ALWAYS_FATAL_IF(AllocateResources(),
+ "Failed to allocate resources");
}
break;
case MainThreadTask::ExitingVrMode:
namespace android {
namespace dvr {
-VrComposerView::VrComposerView() : composer_view_(nullptr) {}
+VrComposerView::VrComposerView(
+ std::unique_ptr<VrComposerView::Callback> callback)
+ : composer_view_(nullptr), callback_(std::move(callback)) {}
VrComposerView::~VrComposerView() {
composer_view_->UnregisterObserver(this);
composer_view_->RegisterObserver(this);
}
-Return<void> VrComposerView::registerCallback(
- const sp<IVrComposerCallback>& callback) {
- callback_ = callback;
- return Void();
-}
-
-Return<void> VrComposerView::releaseFrame() {
+void VrComposerView::ReleaseFrame() {
+ LOG_ALWAYS_FATAL_IF(!composer_view_, "VrComposerView not initialized");
composer_view_->ReleaseFrame();
- return Void();
}
void VrComposerView::OnNewFrame(const ComposerView::Frame& frame) {
+ std::lock_guard<std::mutex> guard(mutex_);
if (!callback_.get()) {
- releaseFrame();
+ ReleaseFrame();
return;
}
- std::vector<IVrComposerCallback::Layer> layers;
- std::vector<native_handle_t*> fences;
- for (size_t i = 0; i < frame.size(); ++i) {
- native_handle_t* fence;
- if (frame[i].fence->isValid()) {
- fence = native_handle_create(1, 0);
- fence->data[0] = frame[i].fence->dup();
- } else {
- fence = native_handle_create(0, 0);
- }
- fences.push_back(fence);
-
- layers.push_back(IVrComposerCallback::Layer{
- .buffer = hidl_handle(frame[i].buffer->getNativeBuffer()->handle),
- .fence = hidl_handle(fence),
- .display_frame = frame[i].display_frame,
- .crop = frame[i].crop,
- .blend_mode= frame[i].blend_mode,
- .alpha = frame[i].alpha,
- .type = frame[i].type,
- .app_id = frame[i].app_id,
- });
- }
-
- auto status =
- callback_->onNewFrame(hidl_vec<IVrComposerCallback::Layer>(layers));
- if (!status.isOk()) {
- ALOGE("Failed to send onNewFrame: %s", status.description().c_str());
- releaseFrame();
- }
-
- for (size_t i = 0; i < fences.size(); ++i) {
- native_handle_close(fences[i]);
- native_handle_delete(fences[i]);
- }
-}
-
-VrComposerView* GetVrComposerViewFromIVrComposerView(IVrComposerView* view) {
- return static_cast<VrComposerView*>(view);
-}
-
-IVrComposerView* HIDL_FETCH_IVrComposerView(const char* name) {
- return new VrComposerView();
+ callback_->OnNewFrame(frame);
}
} // namespace dvr
#ifndef VR_WINDOW_MANAGER_COMPOSER_IMPL_VR_COMPOSER_VIEW_H_
#define VR_WINDOW_MANAGER_COMPOSER_IMPL_VR_COMPOSER_VIEW_H_
-#include <android/dvr/composer/1.0/IVrComposerCallback.h>
-#include <android/dvr/composer/1.0/IVrComposerView.h>
+#include <memory>
#include "vr_hwc.h"
namespace android {
namespace dvr {
-using composer::V1_0::IVrComposerView;
-using composer::V1_0::IVrComposerCallback;
-
-class VrComposerView : public IVrComposerView, public ComposerView::Observer {
+class VrComposerView : public ComposerView::Observer {
public:
- VrComposerView();
+ class Callback {
+ public:
+ virtual ~Callback() = default;
+ virtual void OnNewFrame(const ComposerView::Frame& frame) = 0;
+ };
+
+ VrComposerView(std::unique_ptr<Callback> callback);
~VrComposerView() override;
void Initialize(ComposerView* composer_view);
- // IVrComposerView
- Return<void> registerCallback(const sp<IVrComposerCallback>& callback)
- override;
- Return<void> releaseFrame() override;
+ void ReleaseFrame();
// ComposerView::Observer
void OnNewFrame(const ComposerView::Frame& frame) override;
private:
ComposerView* composer_view_;
- sp<IVrComposerCallback> callback_;
+ std::unique_ptr<Callback> callback_;
+ std::mutex mutex_;
};
-VrComposerView* GetVrComposerViewFromIVrComposerView(IVrComposerView* view);
-
-IVrComposerView* HIDL_FETCH_IVrComposerView(const char* name);
-
} // namespace dvr
} // namespace android
} // namespace
-HwcCallback::HwcCallback(IVrComposerView* composer_view, Client* client)
- : composer_view_(composer_view),
- client_(client) {
- composer_view_->registerCallback(this);
+HwcCallback::HwcCallback(Client* client) : client_(client) {
}
HwcCallback::~HwcCallback() {
- composer_view_->registerCallback(nullptr);
}
-Return<void> HwcCallback::onNewFrame(
- const hidl_vec<IVrComposerCallback::Layer>& frame) {
-
+void HwcCallback::OnNewFrame(const ComposerView::Frame& frame) {
std::vector<HwcLayer> hwc_frame(frame.size());
for (size_t i = 0; i < frame.size(); ++i) {
- int fence = frame[i].fence.getNativeHandle()->numFds ?
- dup(frame[i].fence.getNativeHandle()->data[0]) : -1;
-
hwc_frame[i] = HwcLayer{
- .fence = new Fence(fence),
- .buffer = GetBufferFromHandle(frame[i].buffer.getNativeHandle()),
+ .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),
};
}
- std::lock_guard<std::mutex> guard(mutex_);
client_->OnFrame(std::make_unique<Frame>(std::move(hwc_frame)));
-
- return Void();
}
HwcCallback::Frame::Frame(std::vector<HwcLayer>&& layers)
#include <mutex>
#include <vector>
-#include <android/dvr/composer/1.0/IVrComposerCallback.h>
-#include <android/dvr/composer/1.0/IVrComposerView.h>
+#include <impl/vr_composer_view.h>
#include <impl/vr_hwc.h>
namespace android {
using Recti = ComposerView::ComposerLayer::Recti;
using Rectf = ComposerView::ComposerLayer::Rectf;
-using composer::V1_0::IVrComposerCallback;
-using composer::V1_0::IVrComposerView;
-
-class HwcCallback : public IVrComposerCallback {
+class HwcCallback : public VrComposerView::Callback {
public:
struct HwcLayer {
enum LayerType : uint32_t {
virtual void OnFrame(std::unique_ptr<Frame>) = 0;
};
- explicit HwcCallback(IVrComposerView* composer_view, Client* client);
+ explicit HwcCallback(Client* client);
~HwcCallback() override;
private:
- // This is the only method called on the binder thread. Everything else is
- // called on the render thread.
- Return<void> onNewFrame(const hidl_vec<IVrComposerCallback::Layer>& frame)
- override;
-
- IVrComposerView* composer_view_;
+ void OnNewFrame(const ComposerView::Frame& frame) override;
Client *client_;
- std::mutex mutex_;
-
HwcCallback(const HwcCallback&) = delete;
void operator=(const HwcCallback&) = delete;
#include "surface_flinger_view.h"
-#include <binder/IServiceManager.h>
#include <impl/vr_composer_view.h>
#include <private/dvr/native_buffer.h>
SurfaceFlingerView::~SurfaceFlingerView() {}
bool SurfaceFlingerView::Initialize(HwcCallback::Client *client) {
- const char instance[] = "DaydreamDisplay";
- composer_service_ = IVrComposerView::getService(instance);
- if (composer_service_ == nullptr) {
- ALOGE("Failed to initialize composer service");
+ sp<IComposer> vr_hwcomposer = IComposer::getService("vr_hwcomposer");
+ if (!vr_hwcomposer.get()) {
+ ALOGE("vr_hwcomposer not registered as service");
return false;
}
- if (!composer_service_->isRemote()) {
- ALOGE("Composer service is not remote");
- return false;
- }
+ vr_composer_view_ =
+ std::make_unique<VrComposerView>(std::make_unique<HwcCallback>(client));
+ vr_composer_view_->Initialize(GetComposerViewFromIComposer(
+ vr_hwcomposer.get()));
// TODO(dnicoara): Query this from the composer service.
width_ = 1920;
height_ = 1080;
-
- composer_observer_.reset(new HwcCallback(composer_service_.get(), client));
return true;
}
}
void SurfaceFlingerView::ReleaseFrame() {
- composer_service_->releaseFrame();
+ vr_composer_view_->ReleaseFrame();
}
} // namespace dvr
#ifndef APPLICATIONS_EXPERIMENTS_SURFACE_FLINGER_DEMO_SURFACE_FLINGER_VIEW_H_
#define APPLICATIONS_EXPERIMENTS_SURFACE_FLINGER_DEMO_SURFACE_FLINGER_VIEW_H_
-#include <utils/StrongPointer.h>
-
#include <memory>
+#include <impl/vr_composer_view.h>
+
#include "hwc_callback.h"
namespace android {
void ReleaseFrame();
private:
- sp<IVrComposerView> composer_service_;
- std::unique_ptr<HwcCallback> composer_observer_;
-
+ std::unique_ptr<VrComposerView> vr_composer_view_;
int width_ = 0;
int height_ = 0;
#include <binder/IPCThreadState.h>
#include <binder/IServiceManager.h>
#include <binder/ProcessState.h>
+#include <hwbinder/IPCThreadState.h>
+#include <impl/vr_composer_view.h>
+#include <impl/vr_hwc.h>
#include "shell_view.h"
#include "vr_window_manager_binder.h"
+using namespace android;
+using namespace android::dvr;
+
int main(int /* argc */, char** /* argv */) {
+ android::ProcessState::self()->startThreadPool();
+
+ // Create vr_hwcomposer.
+ const char vr_hwcomposer_name[] = "vr_hwcomposer";
+ sp<IComposer> vr_hwcomposer = HIDL_FETCH_IComposer(vr_hwcomposer_name);
+ LOG_ALWAYS_FATAL_IF(!vr_hwcomposer.get(), "Failed to get vr_hwcomposer");
+ LOG_ALWAYS_FATAL_IF(vr_hwcomposer->isRemote(),
+ "vr_hwcomposer service is remote");
+
+ const android::status_t vr_hwcomposer_status =
+ vr_hwcomposer->registerAsService(vr_hwcomposer_name);
+ LOG_ALWAYS_FATAL_IF(vr_hwcomposer_status != ::android::OK,
+ "Failed to register vr_hwcomposer service");
+
+ // ShellView needs to be created after vr_hwcomposer.
android::dvr::ShellView app;
const int app_status = app.Initialize(nullptr, nullptr, nullptr);
LOG_ALWAYS_FATAL_IF(app_status != 0, "failed to initialize: %d", app_status);
- android::service::vr::VrWindowManagerBinder service(app);
- const int status = service.Initialize();
+ // Create vr_wm_binder.
+ android::service::vr::VrWindowManagerBinder vr_wm_binder(app);
+ const int status = vr_wm_binder.Initialize();
LOG_ALWAYS_FATAL_IF(status != 0, "initialization failed: %d", status);
- android::ProcessState::self()->startThreadPool();
-
android::sp<android::IServiceManager> sm(android::defaultServiceManager());
- const android::status_t service_status = sm->addService(
- android::service::vr::VrWindowManagerBinder::SERVICE_NAME(), &service,
- false /*allowIsolated*/);
- LOG_ALWAYS_FATAL_IF(service_status != android::OK, "service not added: %d",
- static_cast<int>(service_status));
+ const android::status_t vr_wm_binder_status =
+ sm->addService(
+ android::service::vr::VrWindowManagerBinder::SERVICE_NAME(),
+ &vr_wm_binder, false /*allowIsolated*/);
+ LOG_ALWAYS_FATAL_IF(vr_wm_binder_status != android::OK,
+ "vr_wm_binder service not added: %d",
+ static_cast<int>(vr_wm_binder_status));
- app.SetControllerDataProvider(&service);
+ app.SetControllerDataProvider(&vr_wm_binder);
- while (true)
+ android::hardware::ProcessState::self()->startThreadPool();
+
+ while (true) {
app.DrawFrame();
+ }
+ android::hardware::IPCThreadState::self()->joinThreadPool();
android::IPCThreadState::self()->joinThreadPool();
+
return 0;
}
user system
group system graphics input
cpuset /system
- disabled
-
-on property:persist.daydream.vr_wm=1
- enable vr_wm